Initiate Payment

Once user selects one of the payment instrument and clicks on pay, call the Create Order API from your backend and get the Order Token and merchant order id.

Call PhonePeKt.startTransaction to start the transaction flow.

import com.phonepe.intent.sdk.api.PhonePeInitException import com.phonepe.intent.sdk.api.PhonePeKt import com.phonepe.intent.sdk.api.models.transaction.TransactionRequest try{ PhonePeKt.startTransaction( context = this, request = TransactionRequest( orderId = "Order_123", token = "OrderTokenValue", paymentMode = paymentMode ), activityResultLauncher = activityResultLauncher ) } catch(ex: PhonePeInitException){ // Transaction could not be started. // Either re-init the SDK and call startTransaction again or use other instruments to complete your transaction. }
Parameter NameTypeDescription
orderIdStringThe unique Merchant Order ID
tokenStringThe order token received in the backend from Create Order API call.
paymentModePpeIntentPaymentModePass the details of the payment mode selected by the user.
activityResultLauncherActivityResultLauncher<Intent>Pass your activityResultLauncher where you would like to handle the activityResult

When user selects an instrument, pass the type and iD of the selected instrument to getPaymentMode method to get the paymentMode.

PpeIntentPaymentMode( instrumentType: String, instrumentId: String?)
import com.phonepe.intent.sdk.api.models.transaction.paymentMode.PpeIntentPaymentMode val paymentMode = PpeIntentPaymentMode(instrument.type, instrument.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

Get Payment completion result in your activityResultLauncher in your activity or fragment.

private val activityResultLauncher: ActivityResultLauncher<Intent> = registerForActivityResult( StartActivityForResult() ) { // Todo: call Order Status API }

Once you get callback from SDK, you need to call the Order Status API, to get the final status of the payment.