payments by Trigger.io

Currently displaying version

payments: In-app payments

The forge.payments namespace allows access to native in-app payment processing.

For detailed guidance on usage read the Using in-app payments guide.

Config options

Android Public Key
Google Play license key for your app. You can get this from the Google Play Developer Console.

API

forge.payments.transactionReceived.addListener(callback)

iOS, Android

Triggered for all payment transaction events, if the payments module is used this listener must be added on all pages to handle transaction events.

Parameters:
callback
function(data, confirm) called when transaction is received with two arguments described below

The callback for this event will be invoked with two arguments, the first is an object containing the following keys:

  • orderId: A unique order ID returned from iTunes or Google Play, use this to match refunds or cancellations to purchases.
  • productId: The product involved in this transaction
  • purchaseTime: The date and time of purchase
  • purchaseState: One of PURCHASED, REFUNDED, CANCELED or EXPIRED. Gives the state of the transaction, only PURCHASED exists on iOS.
  • notificationId: An internal identifier used by Forge when confirming transactions.
  • receipt: Receipt information which can be sent to a server and verified with iTunes or Google Play. See the guide for more details.

The 2nd argument is a function used to confirm the transaction has been processed, this is required by both iOS and Android to confirm the transaction has been both received and correctly processed.

Example:

forge.payments.transactionReceived.addListener(function (data, confirm) {
  if (data.purchaseState == "PURCHASED") {
      alert("Thanks for buying: "+data.productId);
      confirm();
  } else {
      alert("Your product '"+productId+"' has been removed");
      confirm();
  }
});

forge.payments.purchaseProduct(productId, success, error)

iOS, Android

Purchase an in-app product identified by productId. The success callback will be called when the purchase has been approved by the user; after this the transaction information will be returned via the transactionReceived listener.

Parameters:
productId
string product id registered with iTunes or Google Play
success
function() purchase approved
error
function(content) called with details of any error which may occur

forge.payments.startSubscription(productId, success, error)

iOS, Android

The same as purchaseProduct but starts a subscription rather than a one-off purchase.

Parameters:
productId
string product id registered with iTunes or Google Play
success
function() purchase approved
error
function(content) called with details of any error which may occur

forge.payments.restoreTransactions(success, error)

iOS, Android

If in-app products are managed by iTunes or Google Play, previous transactions may be requested at any time. This allows transactions to be restored on a new device or if the app has been reinstalled. The success callback will be called once the request is made; after this the transaction information will be returned via the transactionReceived listener.

Parameters:
success
function() purchase approved
error
function(content) called with details of any error which may occur

forge.payments.consumePurchase(productId, success, error)

Android

Consumes an in-app product identified by productId. The success callback will be called when the purchase has been successfully consumed.

Parameters:
productId
string product id registered with iTunes or Google Play
success
function() purchase consumed
error
function(content) called with details of any error which may occur

Note: As of Version 3 of the Google In-app Billing API, all in-app products are managed. This means that the user's ownership of all in-app item purchases is maintained by Google Play, and your application can query the user's purchase information when needed. When the user successfully purchases an in-app product, that purchase is recorded in Google Play. Once an in-app product is purchased, it is considered to be "owned". In-app products in the "owned" state cannot be purchased from Google Play. You must send a consumption request for the "owned" in-app product before Google Play makes it available for purchase again. Consuming the in-app product reverts it to the "unowned" state, and discards the previous purchase data.

forge.payments.manageSubscriptions(success, error)

iOS

Opens the iTunes Subscription management screen to allow your user to manage their subscription.

Parameters:
success
function()
error
function(content) called with details of any error which may occur