UMIVERSE SDK
  • UMIVERSE SDK Doc
    • Overview
    • Configure Secret Key and API Domain
    • Sync Account
      • OAuth login
        • Preparations for OAuth
        • Use Authorization_Code to get UMI_UID
        • Decrypt Authorization Code
          • AES Decrypt
    • Dive Points
      • Increase DivePoint
        • API
      • Mission System
        • Request task panel view in H5 game
    • Game Recharge
      • Initiate Recharge Request
      • Handle Recharge Completion
  • Signature
    • Typescript
    • PHP
    • Java
    • C++
  • SDK DEMO
  • Legacy
    • API Key/Secret
    • SignUp & SignIn
    • Get UMI UID
    • Authentication
    • Umiverse Features
      • Mint
      • Send a server-generated item to Umi account
      • Get all items that the player can put up for sale
      • Send an item to a player
      • Deduct an item from a player
    • Redirect
  • Developer Console
    • Add Game Information
Powered by GitBook
On this page
  1. UMIVERSE SDK Doc
  2. Game Recharge

Initiate Recharge Request

The recharge process involves communication between a child iframe (game page) and the parent page. This ensures a seamless and secure user experience for initiating and completing recharge transactions.

Step 1: Send Recharge Information

Overview:

• The game (child iframe) sends a recharge request to the UMIVERSE platform (parent page) using the postMessage API.

• This request contains critical information such as the order ID, recharge amount, merchant ID, timestamp, and a secure signature for verification.

Recharge Request Format

The following is the format of the recharge request sent from the child iframe to the parent page:

const jsonData = {
    orderId: "ORDER12345",  // Unique order ID
    amount: "50",          // Amount in USD
    merchantId: "MERCHANT01", // UMI-MERCHANTID
    ts: Math.floor(Date.now() / 1000), // Current timestamp in seconds
    sign: "generated_signature", // Signature for request verification
    extraParams: "game-specific-data", // Additional data (optional)
};

window.parent.postMessage(jsonData, "*");

How to Send the Request:

Use the postMessage method in JavaScript to send the recharge information from the iframe to the parent page.

window.parent.postMessage(jsonData, "*");

Signature Generation

The sign field is crucial for ensuring the integrity and authenticity of the request. The signature is generated as follows:

1. Algorithm:

• Concatenate the values of the parameters in the jsonData object (in the order they appear) into a single string.

• Append the current timestamp (ts) and the secret key (UMI-API-KEY) to the string.

• Use the MD5 hashing algorithm to generate the signature.

2. Code Implementation:

function createSign(ts, param = null, key = "UMI-API-KEY") {
    let str = `${param['merchantId']}${param['orderId']${param['amount']${param['description']}}}`
    str += `${ts}${key}`;
    const sign = MD5(str).toString();
    return sign;
}

3. Example Usage:

const jsonData = {
    orderId: "ORDER12345",
    amount: "50",
    merchantId: "MERCHANT01",
    ts: Math.floor(Date.now() / 1000),
    extraParams: "optional-data",
};

// Generate the signature
jsonData.sign = createSign(jsonData.ts, jsonData, "UMI-API-SECRET");

// Send the recharge request
window.parent.postMessage(jsonData, "*");

PreviousGame RechargeNextHandle Recharge Completion

Last updated 3 months ago