Refunding a payment

Basic usage

To refund a payment, invoke the refund function, providing the transactionId that was returned to you when you processed the payment. This requires an authenticated user with the correct refund permissions to be able to perform a refund.

If no user has logged in, you will be prompted to login using your Yoco account details. If successful, it will continue to the refund flow.

Basic example
1import com.yoco.payments.sdk.YocoSDK
2
3// Initiating the refund
4YocoSDK.refund(
5 context = requireContext(),
6 transactionId = 'exampleTransactionId',
7 result = refundResult
8)

Advanced usage

This example shows you some of the extra functionality you can add to your use of the SDK by adding a RefundParameters object to the refund function call.

Advanced usage
1import com.yoco.payments.sdk.YocoSDK
2import com.yoco.payments.sdk.data.YocoStaff
3import com.yoco.payments.sdk.data.params.RefundParameters
4
5val userInfo = HashMap<String, Any>().apply {
6 this["UserId"] = "test01"
7 this["Title"] = "manager"
8}
9val refundParams = RefundParameters(
10 staffMember = YocoStaff(name = "John", staffNumber = "007"),
11 receiptDelegate = null,
12 userInfo = userInfo,
13 refundCompleteNotifier = { _: Int, result: PaymentResult ->
14 // Do something once the refund is complete
15 }
16)
17
18// Initiating the refund
19YocoSDK.refund(
20 context = requireContext(),
21 transactionId = 'exampleTransactionId',
22 refundParameters = refundParams,
23 result = refundResult
24)

The context that is passed as a parameter must be calling activity/fragment’s context and not the application context.

Finalise the payment

When calling the YocoSDK.refund() method without a ActivityResultLauncher, and instead handling the PaymentResult in onActivityResult, the RequestCode will be assigned the PaymentResultInfo.RequestCode.REFUND_REQUEST value.

To finalise the payment using the ActivityResultLauncher contract, see how to finalise the payment.