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 Name | Type | Description |
---|---|---|
request | B2BPGTransactionRequest | The object to which you should pass merchantId, orderId, token, appSchema, paymentMode. |
viewController | UIViewController | The 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 Name | Type | Description |
---|---|---|
merchantId | String | The merchant Id provided by PhonePe |
orderId | String | The unique Merchant Order ID |
token | String | The order token received in the backend from Create Order API call. |
appSchema | String | Your 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. |
paymentMode | Enum | Pass 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 Name | Type | Description |
---|---|---|
id | String | The respective Id of the instrument selected by the user on the checkout page. |
type | String | The 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.