1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- //
- // IAPUtils.cpp
- // cocos2d_libs
- //
- // Created by ZhengSong on 2021/5/6.
- //
- #include "IAPUtils.h"
- #include "IAPPlatform.h"
- #include "IAPDelegate.h"
- #include "cocos2d.h"
- static iap::IAPUtils* mIAPUtils = nullptr;
- iap::IAPUtils* iap::IAPUtils::getInstance() {
- if (!mIAPUtils) {
- mIAPUtils = new(std::nothrow) iap::IAPUtils();
- }
- return mIAPUtils;
- }
- iap::IAPUtils::IAPUtils()
- : _delegate(nullptr)
- {
-
- }
- iap::IAPUtils::~IAPUtils() {
-
- }
- iap::IAPProductInfo iap::IAPUtils::getProductInfo(const std::string &productId) {
- return iap::IAPPlatform::getProductInfo(productId);
- }
- void iap::IAPUtils::purchase(const std::string &productId) {
- auto scene = Director::getInstance()->getRunningScene();
- scene->scheduleOnce([=](float) {
- if (_delegate != nullptr) {
- _delegate->onProductPurchaseSuccess(productId);
- }
- }, 0.1, "SCH_SimPurchaseSuccess");
- }
- void iap::IAPUtils::setLogMode(bool isLog) {
- iap::IAPPlatform::setLogMode(isLog);
- }
- void iap::IAPUtils::loadIAPConfig() {
- }
- void iap::IAPUtils::initWithProductIds(const std::map<std::string, IAPProductType> &productIds) {
- if (_isInited) {
- return;
- }
- _isInited = true;
- }
- #pragma mark - 平台回调
- void iap::IAPUtils::nativeCallback_onProductInfoSyncFinished() {
- if (_delegate != nullptr) {
- _delegate->onProductInfoSyncFinished();
- }
- }
- void iap::IAPUtils::nativeCallback_onPurchaseSuccess(const std::string& productId) {
- if (_delegate != nullptr) {
- _delegate->onProductPurchaseSuccess(productId);
- }
- }
- void iap::IAPUtils::nativeCallback_onPurchaseFail(const std::string& productId, int errorCode, const std::string& errorMsg) {
- if (_delegate != nullptr) {
- _delegate->onProductPurchaseFail(productId, errorCode, errorMsg);
- }
- }
- void iap::IAPUtils::nativeCallback_onSyncPurchasedProducts(const std::string& productIdListJson) {
- }
|