Payment System

SG Payment system incorporates third-party vendors billing system to help you implement in-app purchasing (IAP) function easier.

Development Setting

Please follow settings bellow before using Apple In-App Purchase service.


1.XCode settings


  1. In navigator area, select your project.
  2. From editor area, click Capabilities.
  3. Turn on In-App Purchase.
  4. Import StoreKit.

IAP Initialization

Functions

IAPInit(productIDs: [String]) -> Void

Description
  • Initialize In-App Purchase service.
Example

1
2
3
4
5
productIDs.append("ConsumbleItem")
productIDs.append("NonConsumable")
productIDs.append("AutoSubscription")
productIDs.append("NonAutoSbuscriptions")
SGSDK.Instance.IAPInit(productIDs: productIDs)

Parameters
  • productIDs is the ID you set in iTunes Connect account.
Response

Pay

Functions

Pay(payRequest: SGPayRequest) -> Void

Description
  • Launches third-party vendor IAP flow, and uploads order information to SG server.
  • SGPayRequest.PaymentChannel needs to set as "AppStore"。
Example

SGSDK.Instance.Pay(payRequest: initPayReq(productId: productIDs[0], payMethod: "managed"))
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
private func initPayReq(productId: String, payMethod: String) -> SGPayRequest {
    let req = SGPayRequest()
    req.ProductId = productId
    req.PaymentMethod = payMethod
    req.PaymentChannel = "AppStore"
    req.ServerId = "Server ID"
    req.ServerName = "Server Name"
    req.RoleId = "9487"
    req.RoleName = "Roger"
    req.RoleLevel = 99
    req.PayNotifyUrl = "PAY_NOTIFY_URL"
    return req
}

Parameters Response

Get Order

Functions

GetOrder(orderId: String, gameKey: String, openId: String, sign: String) -> Void

Description
  • Obtain detailed order and receipt information of previous successful orders.
Parameters
gameKey Your developer identification.
openId SG member ID. You can obtain it through GetOpenID() after user login.
orderId Order ID you passed in when making the purchase.
sign Signature generated from above three parameters.
Please refer to signature algorithm.
Response

Restore Purchase

Functions

RestorePurchase() -> Void

Description
  • When users switch to a new phone, you need to call this function to restore purchased for Non-Consumable and Auto-renewing subscription products.
Response