requestPayment
Overview
requestPayment:options: initiates a payment request.
The caller needs to pass the stateHandle corresponding to the current game or business state, along with the payment request parameters SUDOPRequestPaymentOptions. Based on the passed trade number, sign data, and signature, the SDK continues to process the payment flow.
Type Declaration
objectivec
@interface SUDOPRequestPaymentOptions : NSObject
@property(nonatomic, copy) NSString *sudTradeNo;
@property(nonatomic, copy) NSString *signData;
@property(nonatomic, copy) NSString *signature;
@endMethod Declaration
objectivec
/**
Requests a payment with the specified state handle and options.
@param stateHandle The state handle object that manages the payment state.
@param options The options configuration for the payment request.
*/
- (void)requestPayment:(id<SUDOPStateHandle>)stateHandle
options:(SUDOPRequestPaymentOptions *)options;Parameters
SUDOPRequestPaymentOptions
| Parameter | Type | Required | Description |
|---|---|---|---|
sudTradeNo | NSString * | Yes | The payment transaction order number, typically generated by the business server, used to uniquely identify a payment transaction. |
signData | NSString * | Yes | The sign data, typically generated by the business server based on the payment parameters. signData is a JSON-formatted string. See the field descriptions below. |
signature | NSString * | Yes | The signature, used to verify the validity and integrity of the payment request. |
signData Field Descriptions
signData is a JSON-formatted string that contains the following fields:
| Field | Required | Type | Description |
|---|---|---|---|
mode | Yes | String | Payment scenario. Currently supported types: goods - direct item purchase; coin - game coins |
env | Yes | number | Environment configuration: 0 - production environment; 1 - test environment |
productId | Conditional | String | Product ID (required for direct item purchase scenarios) |
unitPrice | Conditional | number | Unit price of the product, in cents (required for direct item purchase scenarios) |
quantity | Yes | number | Purchase quantity |
currency | Yes | String | Currency: CNY |
outTradeNo | Yes | String | Business order number |
attach | No | String | Pass-through data |
Method Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
stateHandle | id<SUDOPStateHandle> | Yes | The state handle object, used to identify or manage the current payment-related state context. |
options | SUDOPRequestPaymentOptions * | Yes | The payment request parameter object, containing the trade number, sign data, and signature. |
Example
objectivec
id<SUDOPStateHandle> stateHandle = self.stateHandle;
SUDOPRequestPaymentOptions *options = [[SUDOPRequestPaymentOptions alloc] init];
options.sudTradeNo = @"trade_202405310001";
options.signData = @"your_sign_data";
options.signature = @"your_signature";
[self requestPayment:stateHandle options:options];Process Flow
- The business side creates a payment order.
- The business server generates
sudTradeNo,signData, andsignature. - The client creates a
SUDOPRequestPaymentOptionsobject and fills in the parameters. - The client calls
requestPayment:options:to initiate the payment request. - The SDK continues to process the payment flow based on the passed parameters.
- The payment result is typically notified via the SDK callback, the game state callback, or the business server callback.
Notes
stateHandleshould not be empty; otherwise the SDK may fail to identify the current payment state context.optionsshould not be empty and should contain the complete payment request parameters.sudTradeNoshould be unique, to avoid duplicate payments or order state confusion.signDataandsignatureshould be generated by the business server, to avoid exposing the signing key on the client.- If the signature has a validity period, ensure the interface is called within that period.
- This method has no synchronous return value; the final payment result should be based on the callback or the server-side order state.
- If this interface triggers a payment UI, it is recommended to call it on the main thread.
