Payment Flow

Here is the process flow of a payment, from SDK to Server and back to SDK.

  1. Invoke SDK pay(SGPayRequest req) function in you App.
  2. Based on setting of SGPayRequest.PaymentChannel, SDK launches third party vendor (google, apple or wechat) IAP flow.
  3. After successfully purchasing the item, SDK upload order and receipt information to SG server for validation. If valid, it returns Code = 1101 to SDK. Otherwise, refer to 【Response Code Definition】for more detail.
  4. If you need to validate orders through your own backend server before SG server returns a valid message to SDK, you can setup Paid Notify URL in developer console. SG server will invoke the URL and wait for ok status before return to SDK.
  5. After your own validation, you need to send "ok" to SG server, in order for it to return Code:1101 to the SDK.

Paid Notify URL

  • If you need to validate orders through your own backend server before SG server returns a valid message to SDK, you have to setup Paid Notify URL value.
  • In SG Developer console, click on the game you want to validate payment.
  • Enter your Paid Notify URL.

Developer Backend Server Example

  • For security reason, we strongly recommend you set up Paid Notify URL, and process SG server payment response through your backend server before issuing game items.
  • node.js backend server sample code :
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    exports.SGPay = function(req, res) {
        var receivedData ='';
        req.addListener('data', function(chunk){
            receivedData += chunk;
        });
    
        req.addListener('end', function() {
            try {
                console.log('SG paid received.\n');
                console.log(info);
    
                if (receivedData == 'ok') {
                    //check if order illegal in game server
                    res.json('ok.');
                    //send game item
                } else {
                    res.json('Order status error.');
                }
            } catch (e) {
                res.json('Try error ' + e);
            }
        });
    }