Making a payment

Basic usage

To initiate a payment, you will need to call the YocoSDK.charge() method. This can only be done once the SDK has been initialised and authorised.

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

The following example demonstrates the basic usage of the YocoSDK.charge() method:

Basic usage
1import com.yoco.payments.sdk.YocoSDK
2import com.yoco.payments.sdk.data.enums.PaymentType
3import com.yoco.payments.sdk.data.enums.SupportedCurrency
4
5val amount = amountStr.toLong() * 100
6
7// Initiating the payment
8YocoSDK.charge(
9 context = context,
10 amountInCents = amount,
11 paymentType = PaymentType.CARD,
12 currency = SupportedCurrency.ZAR,
13)

The context that is passed as a parameter MUST be calling Activity/Fragment’s context and NOT the application context.

Advanced usage

To pass additional information, use the paymentParameters argument in the YocoSDK.charge() call.

Here is a more advanced example of the YocoSDK.charge() method with optional parameters:

Advanced usage
1import com.yoco.payments.sdk.YocoSDK
2
3val amount = amountStr.toLong() * 100
4
5val userInfo = hashMapOf<String, Any>(
6 "UserId" to "test01",
7 "Title" to "Manager"
8)
9
10val metaData = hashMapOf(
11 "meta" to "data"
12)
13
14val paymentParams = PaymentParameters(
15 receiptDelegate = null,
16 userInfo = userInfo,
17 metaData = metaData,
18 staffMember = YocoStaff(name = "John", staffNumber = "007"),
19 note = "test note",
20 billId = "test-bill-id",
21 transactionCompleteNotifier = { _: Int, _: PaymentResult ->
22 // Do something once the payment is complete
23 },
24 receiptNumber = UUID.randomUUID().toString()
25)
26
27// Initiating the payment
28YocoSDK.charge(
29 context = context,
30 amountInCents = amount,
31 paymentType = PaymentType.CARD,
32 currency = SupportedCurrency.ZAR,
33 tippingConfig = this.tippingConfig, // Defaults to TippingConfig.DO_NOT_ASK_FOR_TIP
34 printerConfig = this.printerConfig,
35 paymentParameters = paymentParams
36)

If no users are authenticated, the login flow will start. Once completed, the payment flow will continue.

Supported PaymentType values

Here is a list of the currently supported payment methods:

MethodValue
Card (default)PaymentType.CARD
CashPaymentType.CASH

PaymentType.CASH will show the receipt screen and will not go through any payment process.

Supported TippingConfig values

ConfigurationValue
Do not ask for tipTippingConfig.DO_NOT_ASK_FOR_TIP
Ask for tip on readerTippingConfig.ASK_FOR_TIP_ON_CARD_MACHINE
Include amount as tip (programmatically)TippingConfig.INCLUDE_TIP_IN_AMOUNT(tipInCents:)

Supported Currencies

Here is a list of the currently supported currencies:

CurrencyValue
South African Rand (default)SupportedCurrency.ZAR