Initiate Payment

Once user selects one of the payment option and click on pay, Hit the Create Order API from your backend and get the token and merchant order id.

Call the startTransaction method of the PPPayment class.

public func startTransaction(request: PhonePePayment.B2BPGTransactionRequest, on viewController: UIViewController, completion: @escaping PhonePePayment.PPTransactionCompletion) viewController - The UIView controller instance that you want to present the checkout page request - B2B Transation Request, details are below.

Example

ppPayment.startTransaction(request: request, on: vc) { _, state in print(state) }

Basically, The B2BPGTransactionRequest is a object that you need to pass the SDK and SDK will handle the request and get back the response after the payment completion. In the completion handle you get the state of the payment. After that, You need to call the status API from backend to get the status of the transaction.

In B2BPGTransactionRequest, We need 5 parameters to init the object.

public struct B2BPGTransactionRequest { public init(merchantId: String, orderId: String, token: String, appSchema: String, paymentMode: PhonePePayment.PaymentMode) }

Merchant ID – Provided by the integration Team
Order ID – Unique Order ID that you creates
token: When you call the order API, you get the token
appSchema: The app schema that you need to pass for redirect to the merchant app after the payment succedded.
paymentMode: The Payment mode that you need to pass as per your use case.

The Payment mode should be of ppeIntent type.

public enum PaymentMode { case ppeIntent(request: PPEIntentPaymentMode) }

The detail Payment mode code syntax looks like below

// PPE Intent Payments public struct PPEIntentPaymentMode { // Pass the account id that the user select public init(accountId: String) }

Example

let mode = PaymentMode.ppeIntent(request: PPEIntentPaymentMode.init(accountId: accountId))

After you hit the startTransaction Method, SDK will handle all the cases and get the callback to you after the completion