Skip to content

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;

@end

Method 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 ​

ParameterTypeRequiredDescription
sudTradeNoNSString *YesThe payment transaction order number, typically generated by the business server, used to uniquely identify a payment transaction.
signDataNSString *YesThe sign data, typically generated by the business server based on the payment parameters. signData is a JSON-formatted string. See the field descriptions below.
signatureNSString *YesThe 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:

FieldRequiredTypeDescription
modeYesStringPayment scenario. Currently supported types: goods - direct item purchase; coin - game coins
envYesnumberEnvironment configuration: 0 - production environment; 1 - test environment
productIdConditionalStringProduct ID (required for direct item purchase scenarios)
unitPriceConditionalnumberUnit price of the product, in cents (required for direct item purchase scenarios)
quantityYesnumberPurchase quantity
currencyYesStringCurrency: CNY
outTradeNoYesStringBusiness order number
attachNoStringPass-through data

Method Parameters ​

ParameterTypeRequiredDescription
stateHandleid<SUDOPStateHandle>YesThe state handle object, used to identify or manage the current payment-related state context.
optionsSUDOPRequestPaymentOptions *YesThe 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 ​

  1. The business side creates a payment order.
  2. The business server generates sudTradeNo, signData, and signature.
  3. The client creates a SUDOPRequestPaymentOptions object and fills in the parameters.
  4. The client calls requestPayment:options: to initiate the payment request.
  5. The SDK continues to process the payment flow based on the passed parameters.
  6. The payment result is typically notified via the SDK callback, the game state callback, or the business server callback.

Notes ​

  • stateHandle should not be empty; otherwise the SDK may fail to identify the current payment state context.
  • options should not be empty and should contain the complete payment request parameters.
  • sudTradeNo should be unique, to avoid duplicate payments or order state confusion.
  • signData and signature should 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.