Amazon Developer

as

Settings
Sign out
Notifications
Alexa
Amazon Appstore
Ring
AWS
Documentation
Support
Contact Us
My Cases
Develop
Test
Publish
Monetize
Engage users
Device specifications
Resources
Skip to main content
This document provides sample code showing how to use the Unity Plugin for the In-App Purchasing (IAP) v2.0 SDK. You can download the Unity plugin here: Licensed under the Apache License, Version 2.0 (the “License”). You may not use this file except in compliance with the License. A copy of the License is located at https://aws.amazon.com/apache-2-0/ or in the “license” file accompanying this file. This file is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Methods and events

You can initiate method calls and listen for events. Method calls initiate requests, some of which return a response. Events are asynchronous system-generated messages that are sent in response to method calls to return the requested data to you. All of the method calls, except for NotifyFulfillment, request data from the system. When you initiate a request for data, the system immediately returns an object containing a requestId string, which is a unique request identification string. The requested data is returned asynchronously via an event. The NotifyFulfillment method call does not return a response because its purpose is to notify Amazon that your app has delivered the purchased item to the user. To get the data contained in an event, you must define a handler function and bind it to an event listener for the specific type of event. The returned data, accessible from within your event handler, includes a unique requestId that matches the requestId that was returned in the request method call. You can use the requestIds to match a specific request to a specific response, if necessary.

Initiate method calls in Unity

To initiate a method call, you must perform the following general steps:
  1. Construct the object used to interact with the plugin.
  2. If needed, construct the object used to pass input to the operation.
  3. For asynchronous operations, define a callback function that is invoked when a response is ready.
  4. Call the operation, passing in any required input and/or callback function as arguments.

GetUserData

GetUserData initiates a request to retrieve the user ID and marketplace of the currently logged-in user.

Purchase

Purchase initiates a purchase flow for a product.

GetProductData

GetProductData initiates a request to retrieve item data for up to 100 SKUs.

GetPurchaseUpdates

GetPurchaseUpdates initiates a request to retrieve updates about items the customer has purchased and/or cancelled.

NotifyFulfillment

NotifyFulfillment notifies Amazon about the purchase fulfillment.

Handle events in Unity

To handle an event, you must perform the following general steps:
  1. Construct the object used to interact with the plugin.
  2. Define an event handler.
  3. Register your event handler with an event listener.

GetUserDataResponse

GetUserDataResponse returns the response from the GetUserData call.

PurchaseResponse

PurchaseResponse returns the response from the Purchase call.

GetProductDataResponse

GetProductDataResponse returns the response from the GetProductData call.

GetPurchaseUpdatesResponse

GetPurchaseUpdatesResponse returns the response from the GetProductData call.

Example

Create a file for Puchaser class. Add the following code:
Add a method that will handle the response from the purchase function first:
Now we are ready to make some purchases. Paste the below code in any function that is going to actually do the purchasing of a previously-defined SKU “100_gold_stars”.
The method EventHandler() will run when the response from the purchase function is received by the game.
Last modified on January 15, 2022