JS SDK

To seamlessly integrate Appcharge’s Checkout JS SDK into your application, follow these steps:

  1. Install the SDK:
    In your app, execute npm i appcharge-checkout-js-sdk to install the Appcharge Checkout JS SDK.
npm i appcharge-checkout-js-sdk
  1. Integrate the Library:
    Note that the Appcharge's JS SDK is comprised of two components, AppchargeCheckout and AppchargeCheckoutInit.
    AppchargeCheckoutInit should be called once at the top level of the web app - this will create a handshake with Appcharge's Checkout solution, resulting in faster loading times for the checkout itself.
AppchargeCheckoutInit({
  checkoutToken: 'yourCheckoutToken',
  environment: 'sandbox',
});

checkoutToken (string): The checkout Public Key for your store as written in the Appcharge dashboard.

environment (string): The environment for Appcharge Checkout. Use 'sandbox' for testing and 'prod' for the production environment.

AppchargeCheckout should be called each time a user selects an offer in your application and makes an action that requires payment (clicking on a bundle, for example). It performs a server-to-server request to create a checkout session, more data can be found here.

AppchargeCheckout({
  checkoutUrl,
  sessionToken,
  checkoutToken,
  locale,,
  onClose: onCloseCallback,
  onInitialLoad: onInitialLoadCallback,
  onOrderCreated: onOrderCreatedCallback,
  onOrderCompletedFailed: onOrderCompletedFailedCallback,
  onOrderCompletedSuccessfully: onOrderCompletedSuccessfullyCallback,
  onPaymentIntentFailed: onPaymentIntentFailedCallback,
  onPaymentIntentSuccess: onPaymentIntentSuccessCallback,
});

Note: If you want to localize your checkout, please refer to the Checkout Language Localization documentation.

  1. Working with the Library:
    Once you have your checkoutUrl and your sessionToken, you can start working with Appcharge's Checkout, here's a quick sample of how to do so:
const bundle = document.querySelector(".bundle");
bundle.addEventListener("click", () => {
    AppchargeCheckout({
      checkoutUrl: RECEIVED_CHECKOUT_URL,
      sessionToken: RECEIVED_SESSION_TOKEN,
      checkoutToken: CHECKOUT_TOKEN
      onClose: () => {
        console.log("Checkout Closed"); // Hook to the close event of Appcharge's Checkout
      },
  });
});
  1. Appcharge's checkout component allowed properties:
PropTypeMandatoryParams availableDescription
checkoutUrlstringYesNoThe checkoutUrl as provided by the "backend-to-backend" request
sessionTokenstringYesNoThe session token as provided by the "backend-to-backend" request
checkoutTokenstringYesNoUnique public token for each game. Used to distinguish multiple game stores under the same domain
localestringNoNoDefines the checkout language. Use displayName;ISOcode if the display name differs from the ISO 639-1 code (e.g., spanish;es), or just the ISO code if they match (e.g., es)
onCloseFunctionNoYesThe checkout popup has closed
onOrderCreatedFunctionNoYesOrder has been created
onOrderCompletedFailedFunctionNoYesThe order has failed due to an internal error/publisher reward error
onOrderCompletedSuccessfullyFunctionNoYesAn order has updated with the publisher and confirmation was received
onPaymentIntentFailedFunctionNoYesThe player has clicked on ‘Pay’ and the payment failed
onPaymentIntentSuccessFunctionNoYesThe player has clicked on ‘Pay’ and the payment has been charged successfully

All frontend events are received with a set of parameters, please notice that not all parameters are available for every event, parameters that are not available will be undefined.

NameTypeDescription
orderIdstringUnique identifier for the order.
orderExternalIdstringExternal identifier for the order.
datestringDate of the order.
sessionIdstringIdentifier for the session associated with the order.
purchaseInvoiceIdstringIdentifier for the associated purchase invoice.
appChargePaymentIdstringIdentifier for the payment associated with the order.
bundleNamestringName of the bundle associated with the order.
bundleIdstringIdentifier for the bundle.
bundleSKUstringStock Keeping Unit (SKU) for the bundle.
productsProduct[]Array of products included in the order.
totalSumnumberTotal sum of the order.
totalSumCurrencystringCurrency of the total sum.
paymentMethodNamestringName of the payment method used for the order.
userIdstring(Optional) Identifier for the user placing the order.
userCountrystring(Optional) Country associated with the user.
reasonstring(Optional) Reason for the order or additional notes.
  1. Price points:

The getPricePoints function allows you to retrieve price points for your store. It takes two parameters:

  1. environment (string, mandatory): This parameter specifies the environment and can be either sandbox or prod.
  2. domain (string, optional): This parameter is the domain of your store. If not provided, the function will use the current domain as the default.
async function fetchPricePoints() {
  const pricePoints = await getPricePoints('sandbox');
}