Example usage
The following example highlights how a developer might use the VIVEPORT In-App Purchase API in their title.
Before you begin:
- Make sure you have a VIVEPORT ID and key for your title before trying to implement any of the API functions.
- Make sure you have an API key before implementing any of the IAP API functions.
- Keep in mind that prices must be set in each billable currency. Developers are responsible for managing their own exchange rates.
-
Call the Top Level API using
Viveport.Api.Init
to initialize the VIVEPORT SDK. For Unity developers, this is typically called as MonobehaviorStart()
. -
Call
IAPurchase.IsReady()
to initialize the Session Token API. -
Do any of the following:
-
Call
Request()[NEW]
to request the price of an IAP item by item namepchItemName
. -
Call
Purchase()
to purchase item specified bypchPurchaseId
. -
Call
Query()
if the end user has already purchased the item specified bypchPurchaseId
. Call without apchPurchaseID
to get an entire list of purchases. -
Call
GetBalance()
to get the balance of the end user’s wallet. -
Call
RequestSubscription()
to generate a subscription ID to subscribe to a plan that has not been specified in the VIVEPORT Developer Console. -
Call
RequestSubscriptionWithPlanID()
to subscribe to a plan in the VIVEPORT Developer Console that has a Plan ID. -
Call
Subscribe()
to subscribe to a plan with aSubscriptionID
fromRequestSubscription()
orRequestSubscriptionWithPlanID()
. -
Call
QuerySubscription()
to check subscription status using the subscription ID received from the callback ofSubscribe()
. IfpchSubscriptionId
is null, the callback will retrieve all subscriptions as an array. -
Call
QuerySubscriptionList()
to check all subscriptions as an array. -
Call
CancelSubscription()
to cancel the subscription specified bypchSubscriptionId
.
-
Call
-
Call
Viveport.Api.Shutdown
to release VIVEPORT SDK resources when no longer needed. In Unity, this is typically either in MonoBehaviorOnDestroy()
or beforeApplication.Quit()
.