IAPUtils.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // IAPUtils.cpp
  3. // cocos2d_libs
  4. //
  5. // Created by ZhengSong on 2021/5/6.
  6. //
  7. #include "IAPUtils.h"
  8. #include "IAPPlatform.h"
  9. #include "IAPDelegate.h"
  10. static iap::IAPUtils* mIAPUtils = nullptr;
  11. iap::IAPUtils* iap::IAPUtils::getInstance() {
  12. if (!mIAPUtils) {
  13. mIAPUtils = new(std::nothrow) iap::IAPUtils();
  14. }
  15. return mIAPUtils;
  16. }
  17. iap::IAPUtils::IAPUtils()
  18. : _delegate(nullptr)
  19. {
  20. }
  21. iap::IAPUtils::~IAPUtils() {
  22. }
  23. iap::IAPProductInfo iap::IAPUtils::getProductInfo(const std::string &productId) {
  24. return iap::IAPPlatform::getProductInfo(productId);
  25. }
  26. void iap::IAPUtils::purchase(const std::string &productId) {
  27. }
  28. void iap::IAPUtils::setLogMode(bool isLog) {
  29. iap::IAPPlatform::setLogMode(isLog);
  30. }
  31. void iap::IAPUtils::loadIAPConfig() {
  32. }
  33. void iap::IAPUtils::initWithProductIds(const std::map<std::string, IAPProductType> &productIds) {
  34. if (_isInited) {
  35. return;
  36. }
  37. _isInited = true;
  38. }
  39. #pragma mark - 平台回调
  40. void iap::IAPUtils::nativeCallback_onProductInfoSyncFinished() {
  41. if (_delegate != nullptr) {
  42. _delegate->onProductInfoSyncFinished();
  43. }
  44. }
  45. void iap::IAPUtils::nativeCallback_onPurchaseSuccess(const std::string& productId) {
  46. if (_delegate != nullptr) {
  47. _delegate->onProductPurchaseSuccess(productId);
  48. }
  49. }
  50. void iap::IAPUtils::nativeCallback_onPurchaseFail(const std::string& productId, int errorCode, const std::string& errorMsg) {
  51. if (_delegate != nullptr) {
  52. _delegate->onProductPurchaseFail(productId, errorCode, errorMsg);
  53. }
  54. }
  55. void iap::IAPUtils::nativeCallback_onSyncPurchasedProducts(const std::string& productIdListJson) {
  56. }