iap_ios.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef BB_IAP_IOS_H
  2. #define BB_IAP_IOS_H
  3. #import <bbmonkey.h>
  4. #ifdef __OBJC__
  5. #import <StoreKit/StoreKit.h>
  6. class BBIAPStore;
  7. @interface BBIAPStoreDelegate : NSObject<SKProductsRequestDelegate,SKPaymentTransactionObserver>{
  8. @private
  9. BBIAPStore *_peer;
  10. }
  11. -(id)initWithPeer:(BBIAPStore*)peer;
  12. -(void)productsRequest:(SKProductsRequest*)request didReceiveResponse:(SKProductsResponse*)response;
  13. -(void)paymentQueue:(SKPaymentQueue*)queue updatedTransactions:(NSArray*)transactions;
  14. -(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue*)queue;
  15. -(void)paymentQueue:(SKPaymentQueue*)queue restoreCompletedTransactionsFailedWithError:(NSError*)error;
  16. -(void)request:(SKRequest*)request didFailWithError:(NSError*)error;
  17. @end
  18. #else
  19. #include <objc/objc.h>
  20. typedef struct objc_object SKProduct;
  21. typedef struct objc_object SKProductsRequest;
  22. typedef struct objc_object SKProductsResponse;
  23. typedef struct objc_object SKPaymentQueue;
  24. typedef struct objc_object NSArray;
  25. typedef struct objc_object NSError;
  26. typedef struct objc_object SKRequest;
  27. typedef struct objc_object BBIAPStoreDelegate;
  28. typedef struct objc_object NSNumberFormatter;
  29. #endif
  30. struct BBProduct : public bbObject{
  31. BBProduct();
  32. ~BBProduct();
  33. SKProduct *product;
  34. bool valid;
  35. bbString title;
  36. bbString identifier;
  37. bbString description;
  38. bbString price;
  39. int type;
  40. bool owned;
  41. bool interrupted;
  42. };
  43. struct BBIAPStore : public bbObject{
  44. BBIAPStore();
  45. bool OpenStoreAsync( bbArray<bbGCVar<BBProduct>> products );
  46. bool BuyProductAsync( BBProduct* product );
  47. bool GetOwnedProductsAsync();
  48. void CloseStore();
  49. bool IsRunning();
  50. int GetResult();
  51. static bool CanMakePayments();
  52. BBProduct *FindProduct( bbString id );
  53. void OnRequestProductDataResponse( SKProductsRequest *request,SKProductsResponse *response );
  54. void OnUpdatedTransactions( SKPaymentQueue *queue,NSArray *transactions );
  55. void OnRestoreTransactionsFinished( SKPaymentQueue *queue,NSError *error );
  56. void OnRequestFailed( SKRequest *request,NSError *error );
  57. virtual void gcMark();
  58. BBIAPStoreDelegate *_delegate;
  59. NSNumberFormatter *_priceFormatter;
  60. bbArray<bbGCVar<BBProduct>> _products;
  61. bool _running;
  62. int _result;
  63. };
  64. #endif