开发者控制台
感谢您的访问。此页面目前仅提供英语版本。我们正在开发中文版本。谢谢您的理解。

DRM Methods, Events, and Integration

This document gives an overview of the available DRM methods and events for the Unity plugin. It also provides you with some examples to help get started.

Unity plugin DRM methods

Use method calls to initiate requests. The supporting data objects table below describes the events.

Return Type Method Method Summary Event
void VerifyLicense() Initiates the request to get the license/entitlement. None
RequestOutput VerifyLicense() Initiates the request to get the license/entitlement. LicenseResponse

DRM supporting data objects

The following table describes event objects.

Object Members Description
LicenseReponse string requestId The request ID originally returned by VerifyLicense.
string status License status of the app. One of LICENSED, NOT_LICENSED, EXPIRED, ERROR_VERIFICATION, ERROR_INVALID_LICENSING_KEYS, UNKNOWN_ERROR. For details, see License Statuses.

License statuses

This feature is only available in the Unity plugin. When you call VerifyLicense(), the licensing service sends back one of the license statuses defined in the following table.

License Status Description
LICENSED The user has a valid license.
NOT_LICENSED The user does not have a valid license. He or she is not entitled to use the application.
ERROR_VERIFICATION There was an error in trying to verify the license. Reasons for the verification error might be due to the following:
  • Amazon was not able to validate the metadata of the app (such as the checksum, signature, package name, etc).
  • The license received has been tampered with during transit.
ERROR_INVALID_LICENSING_KEYS The user has license keys but they are not valid. Reasons for the invalid licensing keys might be due to the following:
  • You did not add the public key to your app, or you added it to the incorrect folder.
  • The public key you added does not match the corresponding private key that is with Amazon.
EXPIRED

The user's license has expired and the user's current license is now not valid. A license is valid for 60 days. After 30 days, the Appstore tries to renew the license every 24 hours.

If the user if offline for more than 60 days, the Appstore will be unable to renew the license before it expires. If the license expires, the app will no longer launch for the customer.

Other reasons for expired licenses might be due to the following:

  • The customer might have requested cancellation of his or her order.
  • The Appstore fulfilled the customer's order optimistically (before the payment transaction was finalized), but later the charge failed so the license was revoked.

UNKNOWN_ERROR This status indicates an internal error at Amazon's end.

DRM API sample code

If you aren't familiar with calling methods and handling events in Unity, see Initiate method calls and Handle events in Unity.

VerifyLicense

VerifyLicense initiates the request to verify the license. It is an asynchronous function.

using com.amazon.device.iap.cpt;

// Obtain object used to interact with plugin
IAmazonIapV2 iapService = AmazonIapV2Impl.Instance;

// Call synchronous operation with no input
RequestOutput requestOutput = iapService.VerifyLicense();

LicenseReponse

Add a new eventHandler and register to LicenseResponseListener.

using com.amazon.device.iap.cpt;

// Obtain object used to interact with plugin
IAmazonIapV2 iapService = AmazonIapV2Impl.Instance;


// Define event handler
void EventHandler(LicenseResponse response)
{
        string staus = response.getStatus();
        switch (status) {
        case LICENSED:
            Log.d(TAG, "LicenseResponse status: " + status);
            break;
        case NOT_LICENSED:
            Log.d(TAG, "LicenseResponse status: " + status);
        case EXPIRED:
            Log.d(TAG, "LicenseResponse status: " + status);
            break;
        case ERROR_VERIFICATION:
            Log.d(TAG, "LicenseResponse status: " + status);
        case ERROR_INVALID_LICENSING_KEYS:
            Log.d(TAG, "LicenseResponse status: " + status);
        case UNKNOWN_ERROR:
            Log.d(TAG, "LicenseResponse status: " + status);
 }

 // Register for an event
 iapService.AddLicenseResponseListener(EventHandler);

LicenseResponse returns the response from the VerifyLicense call.


Last updated: Jan 19, 2022