IAPProcess.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // IAPProcess.hpp
  3. // TileManor
  4. //
  5. // Created by 徐炼新 on 2024/1/18.
  6. //
  7. #ifndef IAPProcess_hpp
  8. #define IAPProcess_hpp
  9. #include "cocos2d.h"
  10. #include "IAPConf.hpp"
  11. #include "IAP/IAPDelegate.h"
  12. #include "RUQCoreLayer.h"
  13. class IAPProcess : cocos2d::Ref, public iap::IAPDelegate {//}, public MapUIModule {
  14. public:
  15. static IAPProcess* getInstance();
  16. void doWhileLaunched();
  17. // 用户购买了某个商品
  18. void buy(const GoodsInfo& gi, int placementId, std::function<void()> cbIfSuccess, std::function<void()> cbIfFail);
  19. // 注册一个商品
  20. void registerAProduct(const std::string& id);
  21. // IAP
  22. virtual void onProductInfoSyncFinished() override;
  23. virtual void onProductPurchaseSuccess(const std::string &productId) override;
  24. virtual void onProductPurchaseFail(const std::string &productId, int errorCode, const std::string &errorMsg) override;
  25. virtual void syncPurchasedProducts(const std::vector<std::string>& productIds) override;
  26. // UIModule
  27. virtual bool needDoWhileMapIsReady(bool& bSkippable) const;
  28. virtual void doWhileMapIsReady(std::function<void()> cb);
  29. private:
  30. IAPProcess();
  31. virtual ~IAPProcess();
  32. /// 显示购买成功界面
  33. void showIAPSuccess(const GoodsInfo& gi);
  34. void init();
  35. private:
  36. static IAPProcess* _instance;
  37. std::function<void()> _cbIfSuccess = nullptr;
  38. std::function<void()> _cbIfFail = nullptr;
  39. redutils::QCoreLayer* _efxLoading = nullptr;
  40. int _placementId = 0;
  41. bool _bLaunching = false;
  42. std::list<std::string> _productsIDs;
  43. };
  44. #endif /* IAPProcess_hpp */