Finishing a payment

The Intent result contains a PaymentResult object. Access it using the key PaymentResultInfo.ResultKeys.Transaction.

1import com.yoco.payments.sdk.data.result.PaymentResult
2
3val transactionResult: PaymentResult? = data?.getSerializableExtra(PaymentResultInfo.ResultKeys.Transaction) as PaymentResult?

Response Result Codes

Every returning intent will pass back a result code which will provide specific info on the result of the transaction.

Result CodeValue
PaymentResultInfo.ResultCode.SUCCESSFUL1
PaymentResultInfo.ResultCode.IN_PROGRESS2
PaymentResultInfo.ResultCode.ERROR_TRANSACTION_FAILED3
PaymentResultInfo.ResultCode.ERROR_CANCELLED4
PaymentResultInfo.ResultCode.ERROR_PERMISSION_DENIED5
PaymentResultInfo.ResultCode.ERROR_NO_CONNECTIVITY6
PaymentResultInfo.ResultCode.ERROR_INVALID_TOKEN7
PaymentResultInfo.ResultCode.ERROR_BLUETOOTH_DISABLED8
PaymentResultInfo.ResultCode.ERROR_REFUND_FAILED9
PaymentResultInfo.ResultCode.ERROR_TRANSACTION_LOOKUP_FAILED10
PaymentResultInfo.ResultCode.ERROR_TRANSACTION_NOT_FOUND11
PaymentResultInfo.ResultCode.ERROR_PRINT_FAILED12
PaymentResultInfo.ResultCode.ERROR_TIMED_OUT13
PaymentResultInfo.ResultCode.ERROR_PAIRING_FAILED14
PaymentResultInfo.ResultCode.ERROR_TRANSACTION_UNKNOWN15

Usage

After a successful or failed payment from YocoSDK.charge() flow an Intent result will be returned, containing info related to the transaction.

The standard way of handling an intent result:

1import com.yoco.payments.sdk.YocoSDK
2
3override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
4 super.onActivityResult(requestCode, resultCode, data)
5 // Check for the result of the charge request
6 if (requestCode == PaymentResultInfo.RequestCode.CHARGE_REQUEST) {
7 // Handle charge result here
8 }
9}

Activity Results API

You can handle the result of a payment by using the Activity Results API with androidx.

Required Dependencies:

1implementation 'androidx.activity:activity-ktx:1.5.0' //Activity
2implementation 'androidx.fragment:fragment-ktx:1.5.0' //Fragment

Instantiate the result contract, which may be passed to the YocoSDK as the result. There is no need to use the request code, as we tie the contract to the charge() implementation.

1import androidx.activity.result.ActivityResultLauncher
2import androidx.activity.result.contract.ActivityResultContracts
3
4private val chargeResult: ActivityResultLauncher<Intent> =
5 registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
6 if (result.resultCode == Activity.RESULT_OK) {
7 // Handle charge result here
8 }
9 }
10
11// Access SDK
12YocoSDK.charge(
13 ...
14 result = chargeResult
15)
16
17// or
18
19private val refundResult: ActivityResultLauncher<Intent> =
20 registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
21 System.err.println("Result Code: ${result.resultCode}") // PaymentSDK.Response.ResultCode
22 if (result.resultCode == Activity.RESULT_OK) {
23 // Handle refund result here
24 }
25 }
26
27YocoSDK.refund(
28 ...
29 result = refundResult
30)