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 Name | Type | Description |
---|---|---|
orderId | String | The unique Merchant Order ID |
token | String | The order token received in the backend from Create Order API call. |
paymentMode | PpeIntentPaymentMode | Pass the details of the payment mode selected by the user. |
activityResultLauncher | ActivityResultLauncher<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 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 |
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.