Initiate Payment

Once user selects one of the instrument and click on pay, hit the Create Order API from your backend and get the Order 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)
Parameter NameTypeDescription
requestB2BPGTransactionRequestThe object to which you should pass merchantId, orderId, token, appSchema, paymentMode.
viewControllerUIViewControllerThe UIView controller instance that you want to present the checkout page.

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) }
Parameter NameTypeDescription
merchantIdStringThe merchant Id provided by PhonePe
orderIdStringThe unique Merchant Order ID
tokenStringThe order token received in the backend from Create Order API call.
appSchemaStringYour App schema created under the URL Schema of info.plist file.
This helps to redirect back to the merchant app after the user has completed the payment.
paymentModeEnumPass the details of the Payment mode selected by the user.

The Payment mode should be of ppeIntent type.

public init(type withConstraint: String?, id: String? = nil)

The detail Payment mode code syntax looks like below

PaymentMode.ppeIntent(request: PPEIntentPaymentMode(type: selectedInstrument.type, id: selectedInstrument.id))
Parameter NameTypeDescription
idStringThe respective Id of the instrument selected by the user on the checkout page.
typeStringThe respective type of the instrument selected by the user on the checkout page

Example

let paymentMode = PaymentMode.ppeIntent(request: PPEIntentPaymentMode(type: selectedInstrument.type, id: selectedInstrument.id)) let request = B2BPGTransactionRequest(merchantId: "MERCHANT-ID", orderId: "ORDER-ID", token: "ORDER_TOKEN", appSchema: "YOUR-APP-SCHEMA", paymentMode: paymentMode) ppPayment.startTransaction(request: request, on: vc) { _, state in print(state) }

After you hit the startTransaction Method, SDK will handle all the cases and get the callback to you after the completion. Then, you need to call the Order Status API, to get the final status of the payment.