payments by Trigger.io

You are currently viewing a version of this module which is not the current active version.
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 add 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