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.
If there is an error, TCGBError will be returned.

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.
If there is an error, TCGBError will be returned.

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.
If there is an error, TCGBError will be returned.

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(), ^{
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Item Purchase"
                                                                    message:[NSString stringWithFormat:@"You Canceled."]
                                                                   delegate:nil
                                                          cancelButtonTitle:@"OK"
                                                          otherButtonTitles:nil, nil];

                [alertView show];
            });
        } else if (error) {
            dispatch_async(dispatch_get_main_queue(), ^{
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Item Purchase"
                                         message:[NSString stringWithFormat:@"There was an Error : %ld", (long)error.code]
                                                                   delegate:nil
                                                          cancelButtonTitle:@"OK"
                                                          otherButtonTitles:nil, nil];

                [alertView show];
            });
        }
    }];
}

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.
This instance has the paymentSequence, itemSequence, PurchaseToken information.
If there is an error, TCGBError will be returned.

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.

+ (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’.
These two variables are array of TCGBPurchasableReceipt.
Each key has a list of TCGBPurchasableReceipt that has uncompleted purchase information.
If there is an error, TCGBError will be returned.

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.
    }];
}

Discussion

Request a retrying transaction which is not completed to IAP Server

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