Gamebase SDK for Unity 2.76.0 Toast Gamebase Platform

Loading...
Searching...
No Matches

## ◆ RequestPurchase() [3/3]

static void RequestPurchase | ( | string | gamebaseProductId,
|  | string | payload,
|  | GamebaseCallback.GamebaseDelegate< GamebaseResponse.Purchase.PurchasableReceipt > | callback )
| static

Call following API of an item to purchase by using gamebaseProductId to send a purchase request.

When a game user cancels purchasing, the PURCHASE_USER_CANCELED error will be returned.

Since
  Added 2.11.0.

Parameters

  gamebaseProductId | Represent to gamebase product ID.
  payload | The input payload is delivered when the purchase is completed.
  callback | Callback pass to API result.

Example Usage :

public void RequestPurchaseSample(string gamebaseProductId)
{
string userPayload = "{\"description\":\"This is example\",\"channelId\":\"delta\",\"characterId\":\"abc\"}";
Gamebase.Purchase.RequestPurchase(gamebaseProductId, userPayload, (purchasableReceipt, error) =>
{
if (Gamebase.IsSuccess(error) == true)
{
var message = new StringBuilder();
message.AppendLine("RequestPurchase succeeded.");
message.AppendLine(string.Format("itemSeq:{0}", purchasableReceipt.itemSeq));
message.AppendLine(string.Format("price:{0}", purchasableReceipt.price));
message.AppendLine(string.Format("currency:{0}", purchasableReceipt.currency));
// You will need paymentSeq and purchaseToken when calling the Consume API.
// Refer to the following document for the Consume API.
// http://docs.toast.com/en/Game/Gamebase/en/api-guide/#purchaseiap
message.AppendLine(string.Format("paymentSeq:{0}", purchasableReceipt.paymentSeq));
message.AppendLine(string.Format("purchaseToken:{0}", purchasableReceipt.purchaseToken));
// userPayload value entered when calling API
message.AppendLine(string.Format("userPayload:{0}", purchasableReceipt.payload));
Debug.Log(message);
}
else
{
if (error.code == GamebaseErrorCode.PURCHASE_USER_CANCELED)
{
Debug.Log("User canceled purchase.");
}
else
{
// Check the error code and handle the error appropriately.
Debug.Log(string.Format("RequestPurchase failed. error is {0}", error));
}
}
});
}
Toast.Gamebase.Gamebase.Purchase.RequestPurchase
static void RequestPurchase(long itemSeq, GamebaseCallback.GamebaseDelegate< GamebaseResponse.Purchase.PurchasableReceipt > callback)
Call following API of an item to purchase by using itemSeq to send a purchase request.
Definition Gamebase.cs:2115
Toast.Gamebase.Gamebase.Purchase
The Purchase class provides several APIs related to purchasing processes.
Definition Gamebase.cs:2069
Toast.Gamebase.Gamebase.IsSuccess
static bool IsSuccess(GamebaseError error)
Return true if the GamebaseException object is null or the error code is zero.
Definition Gamebase.cs:57
Toast.Gamebase.Gamebase
The Gamebase class is core of Gamebase service.
Definition Gamebase.cs:11