Using the Google Play In-app Billing Service

From Appmethod Topics
Jump to: navigation, search

Go Up to Adding In-App Payments to Your Mobile Apps


Google Play In-app Billing is the Google in-app payment service for Android. This topic describes how to give your applications access to Google Play In-app Billing using FireMonkey. See Adding In-App Payments to Your Mobile Apps for more information.

Note: The following information complements the main documentation topic about Android development. Read Android Mobile Application Development before you continue.

Supported Devices

FireMonkey supports Google Play In-app Billing on devices running Android 2.2 or later and the latest version of the Google Play store. See also FireMonkey Platform Prerequisites, Android Requirements.

Note: Android emulators are not supported.

Prerequisites

Before you can use the Google Play In-app Billing service, you must:

Configuring Your Application for In-app Billing in Google Play

Google requires you to have a draft application uploaded before you can add in-app products.

Before you start adding Google Play In-app Billing support to your application, upload your application in its current state to Google Play:

  1. Prepare your application for deployment.
  2. Create a signed .apk package for your application.
  3. Upload your new application to Google Play.

On the page of your application, on the Google Play Developer Console, click Services and APIs. The Services and APIs page shows the license key of your application. When you configure your instance of TInAppPurchase to connect to Google Play, you must copy this license key into the ApplicationLicenseKey property.

TInAppPurchase supports Managed In-app Products. See In-app Billing Version 3, Product Types for more information about Managed products.

Note: Subscriptions are not currently supported.

Adding Google Play In-app Billing Support to Your Mobile Apps

Note: To learn how to add in-app payments to your mobile applications, read Adding In-App Payments to Your Mobile Apps. This section only provides documentation for some additional features that are exclusive to the Google Play In-app Billing service.

Using a Developer Payload String to Verify Purchases

When you use the Google Play In-app Billing service, you may give the TInAppPurchase.TransactionPayload property a value, a code of some kind, that is unique to the user of your application. This value is sent to the Google Play In-app Billing service when your user purchases a product from your application.

During the purchase, the Google Play In-app Billing service sends you back a developer payload string that should match the string that you previously defined in the TransactionPayload property. To check that both strings match and thus verify that the purchase was indeed ordered by your user, handle the OnVerifyPayload event:

procedure TForm1.InAppPurchase1VerifyPayload(Sender: TObject; const Payload: string; var PayloadOk: Boolean);
begin
  if Payload.Compare(FPayload) <> 0 then
    PayloadOk := False;
end;

If the handler of this event sets <PayloadOk> to False, the purchase is invalidated.

Warning: The same user may use your application on different devices. The developer payload string must be the same across different devices for the same user. For example, it cannot be a random string generated by your application, as this string would not be the same on all devices.

Testing Your In-App Purchase Products

You can test your in-app purchase products without incurring charges using test users. See Testing In-app Billing.

See Also