TCGBPurchase Class Reference
Inherits from | NSObject |
---|---|
Declared in | TCGBPurchase.h |
Overview
The TCGBPurchase class provides several APIs related to purchasing processes.
Before using these APIs, You should be logged in. Because every TCGBPurchase API need informations that are obtained from TCGBServer.
If you do not have been authenticated, you will get TCGB_ERROR_NOT_LOGGED_IN error.
Request Item List
+ requestItemListPurchasableWithCompletion:
This is the primary method for obtaining ItemList which is registered at ToastCloud IAP Console and Apple Itunes Connect.
+ (void)requestItemListPurchasableWithCompletion:(void ( ^ ) ( NSArray<TCGBPurchasableItem*> *purchasableItemArray , TCGBError *error ))completion
Parameters
completion |
completion may return the NSArray of TCGBPurchasableItem. |
---|
Discussion
Request a item list which is purchasable. This list has items which are registered in both Market(AppStore) and ToastCloud IAP Console.
Warning: You should call this method after logged in
, otherwise you will get TCGB_ERROR_NOT_LOGGED_IN error in the completion.
Usage Example
- (void)viewDidLoad {
[TCGBPurchase requestItemListPurchasableWithCompletion:^(NSArray *purchasableItemArray, TCGBError *error) {
NSMutableArray *itemArrayMutable = [[NSMutableArray alloc] init];
[purchasableItemArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
TCGBPurchasableItem *item = (TCGBPurchasableItem *)obj;
[itemArrayMutable addObject:item];
}];
}];
}
Declared In
TCGBPurchase.h
+ requestItemListAtIAPConsoleWithCompletion:
This is the method for obtaining ItemList which is registered at ToastCloud IAP Console.
+ (void)requestItemListAtIAPConsoleWithCompletion:(void ( ^ ) ( NSArray<TCGBPurchasableItem*> *purchasableItemArray , TCGBError *error ))completion
Parameters
completion |
completion may return the NSArray of TCGBPurchasableItem. |
---|
Discussion
Request a item list which is purchasable. This list has items which are only registered in ToastCloud IAP Console, not Market(AppStore)
Warning: You should call this method after logged in
, otherwise you will get TCGB_ERROR_NOT_LOGGED_IN error in the completion.
Usage Example
- (void)viewDidLoad {
[TCGBPurchase requestItemListAtIAPConsoleWithCompletion:^(NSArray *purchasableItemArray, TCGBError *error) {
NSMutableArray *itemArrayMutable = [[NSMutableArray alloc] init];
[purchasableItemArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
TCGBPurchasableItem *item = (TCGBPurchasableItem *)obj;
[itemArrayMutable addObject:item];
}];
}];
}
Declared In
TCGBPurchase.h
Request Purchasing Item
+ requestPurchaseWithItemSeq:viewController:completion:
This is the method to request purchasing item which identifier is itemSeq. There is a viewController parameter and you may put your top most viewController. If you don’t, this method will find out top most view controller and put it in the parameter.
+ (void)requestPurchaseWithItemSeq:(long)itemSeq viewController:(UIViewController *)viewController completion:(void ( ^ ) ( TCGBPurchasableReceipt *purchasableReceipt , TCGBError *error ))completion
Parameters
itemSeq |
itemID which you want to purchase. |
---|---|
viewController |
represent to current viewcontroller. |
completion |
completion may return the TCGBPurchasableReceipt instance. |
Discussion
Request Purchasing Item that has itemId.
Warning: You should call this method after logged in
, otherwise you will get TCGB_ERROR_NOT_LOGGED_IN error in the completion.
Usage Example
- (void)purchasingItem:(long)itemSeq {
[TCGBPurchase requestPurchaseWithItemSeq:itemSeq viewController:self completion:^(TCGBPurchasableReceipt *purchasableReceipt, TCGBError *error) {
if (error.code == TCGB_ERROR_PURCHASE_USER_CANCELED) {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Item Purchase"
message:[NSString stringWithFormat:@"You Canceled."]
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:defaultAction];
[parentViewController presentViewController:alertController animated:NO completion:nil];
});
} else if (error) {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Item Purchase"
message:[NSString stringWithFormat:@"There was an Error : %ld", (long)error.code]
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:defaultAction];
[parentViewController presentViewController:alertController animated:NO completion:nil];
});
}
}];
}
Declared In
TCGBPurchase.h
+ requestPurchaseWithGamebaseProductId:viewController:completion:
This is the method to request purchasing item which identifier is gamebaseProductID. There is a viewController parameter and you may put your top most viewController. If you don’t, this method will find out top most view controller and put it in the parameter.
+ (void)requestPurchaseWithGamebaseProductId:(NSString *)gamebaseProductId viewController:(UIViewController *)viewController completion:(void ( ^ ) ( TCGBPurchasableReceipt *purchasableReceipt , TCGBError *error ))completion
Parameters
gamebaseProductId |
gamebaseProductID which you want to purchase. |
---|---|
viewController |
represent to current viewcontroller. |
completion |
completion may return the TCGBPurchasableReceipt instance. |
Discussion
Request Purchasing Item that has gamebaseProductID.
Warning: You should call this method after logged in
, otherwise you will get TCGB_ERROR_NOT_LOGGED_IN error in the completion.
Usage Example
(void)purchasingItem:(NSString )gamebaseProductId { [TCGBPurchase requestPurchaseWithGamebaseProductId:gamebaseProductId viewController:self completion:^(TCGBPurchasableReceipt purchasableReceipt, TCGBError error) { if (error.code == TCGB_ERROR_PURCHASE_USER_CANCELED) { dispatch_async(dispatch_get_main_queue(), ^{ UIAlertController alertController = [UIAlertController alertControllerWithTitle:@“Item Purchase” message:[NSString stringWithFormat:@“You Canceled.”] preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@“OK” style:UIAlertActionStyleDefault handler:nil]; [alertController addAction:defaultAction];
[parentViewController presentViewController:alertController animated:NO completion:nil]; }); } else if (error) { dispatch_async(dispatch_get_main_queue(), ^{ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Item Purchase" message:[NSString stringWithFormat:@"There was an Error : %ld", (long)error.code] preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; [alertController addAction:defaultAction]; [parentViewController presentViewController:alertController animated:NO completion:nil]; }); }
}]; }
Declared In
TCGBPurchase.h
+ requestPurchaseWithGamebaseProductId:payload:viewController:completion:
This is the method to request purchasing item which identifier is gamebaseProductID. There is a viewController parameter and you may put your top most viewController. If you don’t, this method will find out top most view controller and put it in the parameter. You can set a custom payment. After payment is completed, you will receive it throgh purchasableReceipt.
+ (void)requestPurchaseWithGamebaseProductId:(NSString *)gamebaseProductId payload:(NSString *)payload viewController:(UIViewController *)viewController completion:(void ( ^ ) ( TCGBPurchasableReceipt *purchasableReceipt , TCGBError *error ))completion
Parameters
gamebaseProductId |
gamebaseProductID which you want to purchase. |
---|---|
payload |
user define payload |
viewController |
represent to current viewcontroller. |
completion |
completion may return the TCGBPurchasableReceipt instance. |
Discussion
Request Purchasing Item that has gamebaseProductID.
Warning: You should call this method after logged in
, otherwise you will get TCGB_ERROR_NOT_LOGGED_IN error in the completion.
Usage Example
(void)purchasingItem:(NSString )gamebaseProductId payload:(NSString )payload { [TCGBPurchase requestPurchaseWithGamebaseProductId:gamebaseProductId payload:payload viewController:self completion:^(TCGBPurchasableReceipt purchasableReceipt, TCGBError error) { if (error.code == TCGB_ERROR_PURCHASE_USER_CANCELED) { dispatch_async(dispatch_get_main_queue(), ^{ UIAlertController alertController = [UIAlertController alertControllerWithTitle:@“Item Purchase” message:[NSString stringWithFormat:@“You Canceled.”] preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction defaultAction = [UIAlertAction actionWithTitle:@“OK” style:UIAlertActionStyleDefault handler:nil]; [alertController addAction:defaultAction];
[parentViewController presentViewController:alertController animated:NO completion:nil]; }); } else if (error) { dispatch_async(dispatch_get_main_queue(), ^{ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Item Purchase" message:[NSString stringWithFormat:@"There was an Error : %ld", (long)error.code] preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; [alertController addAction:defaultAction]; [parentViewController presentViewController:alertController animated:NO completion:nil]; }); }
}]; }
Declared In
TCGBPurchase.h
Request non-consumed Item List
+ requestItemListOfNotConsumedWithCompletion:
This method provides an item list that have non-consumed.
+ (void)requestItemListOfNotConsumedWithCompletion:(void ( ^ ) ( NSArray<TCGBPurchasableReceipt*> *purchasableReceiptArray , TCGBError *error ))completion
Parameters
completion |
completion may return the NSArray of TCGBPurchasableReceipt instances. |
---|
Discussion
Request a Item List which is not consumed. You should deliver this itemReceipt to your game server to consume it or request consuming API to ToastCloud IAP Server. You may call this method after logged in and deal with these non-consumed items.
Warning: You should call this method after logged in
, otherwise you will get TCGB_ERROR_NOT_LOGGED_IN error in the completion.
Usage Example
- (void)viewDidLoad {
[TCGBPurchase requestItemListOfNotConsumedWithCompletion:^(NSArrayTCGBPurchasableReceipt *> *purchasableReceiptArray, TCGBError *error) {
// should deal with this not-consumed items.
}];
}
Declared In
TCGBPurchase.h
Request retry purchasing processes
+ requestRetryTransactionWithCompletion:
This method is for retrying failed purchasing proccesses. (Deprecated: As of release 2.6.0, SDK retries transaction automatically in internal process. You don’t need to call explicitly. Result is always success.
Usage Example
- (void)viewDidLoad {
[TCGBPurchase requestRetryTransactionWithCompletion:^(TCGBPurchasableRetryTransactionResult *transactionResult, TCGBError *error) {
// should deal with this retry transaction result.
// if succeeded, you may send result to your gameserver and add item to user.
}];
}</span>)
+ (void)requestRetryTransactionWithCompletion:(void ( ^ ) ( TCGBPurchasableRetryTransactionResult *transactionResult , TCGBError *error ))completion
Parameters
completion |
completion may return the TCGBPurchasableRetryTransactionResult which has two member variables which are named ‘successList’ and ‘failList’. |
---|
Discussion
Request a retrying transaction which is not completed to IAP Server
Declared In
TCGBPurchase.h
+ requestActivatedPurchasesWithCompletion:
This method provides item list that are currently subscribed.
+ (void)requestActivatedPurchasesWithCompletion:(void ( ^ ) ( NSArray<TCGBPurchasableReceipt*> *purchasableReceiptArray , TCGBError *error ))completion
Parameters
completion |
completion pass to API result. |
---|
Availability
Added 2.6.0.
Discussion
Request a list of payment products that are currently subscribed. If there is a subscription purchased from another platform (such as Android), the itemSeq value is returned as -1.
Declared In
TCGBPurchase.h
+ requestRestoreWithCompletion:
This method restore auto-renewable subscription products.
+ (void)requestRestoreWithCompletion:(void ( ^ ) ( NSArray<TCGBPurchasableReceipt*> *purchasableReceiptArray , TCGBError *error ))completion
Parameters
completion |
The handler to execute after the restore is complete. |
---|
Availability
Added 2.6.0.
Discussion
Restores the transaction of the AppStore’s auto-renewable subscription product and returns a list of active subscription products.
Declared In
TCGBPurchase.h
Settter and Getter Store
+ setStoreCode:
This is a method for set up the store. It should be available StoreCode such as “AS”. In normal cases, This method is not needed. Most of application uses “AS”(Apple AppStore) as a store. If not, you should set this value for using a specific store.
+ (void)setStoreCode:(NSString *)storeCode
Parameters
storeCode |
storeCode represents store that item is registered and where you can buy item. |
---|
Discussion
Set a specific store for access this store.
Declared In
TCGBPurchase.h
+ storeCode
This method returns a store code that is set up.
+ (NSString *)storeCode
Return Value
storecode that is already set up.
Declared In
TCGBPurchase.h
Add SKPaymentTransactionObserver to support 'App Store Promotion'
+ setPromotionIAPHandler:
This is a method for add observer to App Store Connect for receiving a notification - paymentQueue:shouldAddStorePayment:forProduct: -.
If you want to deliver some items that have been purchased to user, you should implement this handler.
You can receive a TCGBPurchasableReceipt object and receive whether error or success by callback.
This handler return same information with ‘requestPurchaseWithItemSeq:viewController:completion:’
+ (void)setPromotionIAPHandler:(void ( ^ ) ( TCGBPurchasableReceipt *purchasableReceipt , TCGBError *error ))handler
Parameters
handler |
handler may return the result of purchase by App Store Promotion. |
---|
Discussion
Warning: You should call this method after logged in
, and you sould call this before an other APIs in TCGBPurchase.
This method can work on iOS11 or later.
Usage Example
- (void)wantToAddTransactionObserver {
[TCGBPurchase setPromotionIAPHandler:^(TCGBPurchasableReceipt *purchasableReceipt, TCGBError *error) {
// should deal with this not-consumed items.
}];
}
Declared In
TCGBPurchase.h