Add a script to receive a payment token

Due to the integration peculiarities, you must use the CreatePaystationToken script instead of the standard PlayFab REST API GetPaymentToken method to create a payment token.

To add CreatePaystationToken script:

  1. Create a file with the JavaScript code containing the following parameters:
    • <title_ID>Title ID of your PlayFab project. You can find it in the project settings in Title Settings > API Features section or in the address bar of the browser when navigating to the project settings.
    • <project_ID>Project ID from your Publisher Account. You can find it in Project settings > Project ID.
    • <your_authorization_basic_key> — the Merchant ID:API key pair encoded according to the Base64 standard. You can find Merchant ID in your Publisher Account > Project settings > Webhooks. You can find API key in your Publisher Account > Company settings > API key.
    • <merchant_ID>Merchant ID from your Publisher Account.

Copy
Full screen
Small screen
handlers.CreatePaystationToken = function (args) {

  let playFabProjectId = "<title_ID>"; // replace with your PlayFab Project ID
  let merchantId = "<merchant_ID>"; // replace with your Xsolla Merchant ID
  let authToken = "<your_authorization_basic_key>"; // base64(merchantId:merchantApiKey)
  let projectId = <project_ID>; // replace with your Xsolla Project ID

  let headers = {
    "Authorization": "Basic " + authToken
  };

  let body = {
    user: {
      id: {
        hidden: true,
        value: currentPlayerId
      },
      name: {
        value: server.GetUserAccountInfo({"PlayFabId": currentPlayerId}).UserInfo.Username
      }
    },
    settings: {
      project_id: projectId,
      xsolla_product_tag: (args.sdkTag === null || args.sdkTag === "") ? "SDK-payments_ver-0_integr-playfab_engine-0_enginever-0" : args.sdkTag,
      ui: {
        theme: (args.theme === null || args.theme === "") ? "default_dark" : args.theme,
      }
    },
    purchase: {
      virtual_items: {
        items: [
          {
            sku: args.sku,
            amount: args.amount
          }
        ]
      }
    },
    custom_parameters: {
      TitleId: playFabProjectId,
      PfId: currentPlayerId,
      PfOrderId: args.orderId
    }
  };

  if (args.sandbox) body.settings.mode = "sandbox"

  let url = "https://api.xsolla.com/merchant/v2/merchants/" + merchantId + "/token";
  let content = JSON.stringify(body);
  let httpMethod = "post";
  let contentType = "application/json";

  let response = http.request(url, httpMethod, content, contentType, headers);
  return JSON.parse(response);
}

  1. Go to PlayFab project settings.
  2. Click Automation in the side menu.
  3. Go to the Revisions tab.
  4. Click Upload new revision.
  5. Select the created file and save the script revision.

Continue reading