Skip to content

sud.requestVirtualPayment ​

Starts a virtual payment request. All three artifacts — signData, paySig, and signature — must be produced by Game SVR. The client only relays them unchanged.

Parameters ​

Object object ​

PropertyTypeDefaultRequiredDescription
signDatastringYesSignature data constructed by Game SVR as a JSON string; see the signData table below
paySigstringYesPayment-state signature: lowercase hexadecimal hmac_sha256(pay_sign_key, signData)
signaturestringYesUser-state signature: lowercase hexadecimal hmac_sha256(session_key, signData), using the session_key Base64 string itself as the HMAC key without decoding it
successfunctionNoCallback for a successful payment
failfunctionNoCallback for a failed payment
completefunctionNoCallback invoked when the call ends, after success, cancellation, or failure

Fields of signData ​

FieldTypeDefaultRequiredDescription
modestringYesgoods for direct item purchase, coin for game currency purchase
envnumberYes0 for production, 1 for testing
productIdstringConditionalRequired for direct item purchase
unitPricenumberYesItem unit price in cents (required for direct item purchase)
quantitynumberYesAmount of game currency to purchase; must be one of the fixed tiers configured for the product
currencystringYesCurrency; only CNY is currently supported
outTradeNostringYesBusiness order number, generated by Game SVR and globally unique
attachstringNoBusiness passthrough data, returned unchanged in the delivery webhook

Callback Parameters ​

success ​

PropertyTypeDescription
sudTradeNostringSUD business order number

fail ​

PropertyTypeDescription
errCodenumberError code
errMsgstringError message

complete carries no arguments. It is invoked after success or fail, and runs only once per request.

Notes ​

  • The client must not take part in assembling signData or computing signatures, and must never touch pay_sign_key or session_key. Game SVR issues the three artifacts and the client passes them to this API unchanged.
  • signData must be passed in its original form, including its spaces and line breaks. Never sign first and then deserialize and re-serialize the JSON: any re-serialization can change spaces, key order, or escaping and cause signature verification to fail.
  • The success callback only means the client-side payment flow ended; it does not mean the goods were delivered. Never grant assets based on success. Delivery must be driven by the webhook Game SVR receives. See section 5 of Virtual Payment Configuration - Direct IAP.
  • Do not start the same order more than once concurrently. Block new order requests while a previous one is still awaiting confirmation.
  • complete runs on success, user cancellation, and failure alike. Never treat complete as a success signal.

Example Code ​

javascript
// signData / paySig / signature all come from the Game SVR order endpoint; do not build them on the client
sud.requestVirtualPayment({
    signData: orderFromGameServer.signData,
    paySig: orderFromGameServer.paySig,
    signature: orderFromGameServer.signature,
    success: (res) => {
        // Only means the client-side payment flow ended; delivery is driven by the server webhook
        console.log('Client payment flow finished', res.sudTradeNo);
    },
    fail: (err) => {
        console.error('Payment failed or was cancelled', err.errCode, err.errMsg);
    },
    complete: () => {
        console.log('Payment call finished');
    },
});