Add the following to your build.gradle
file:
repositories {
mavenCentral()
}
dependencies {
implementation 'io.primer:android:1.5.1'
}
Implement the CheckoutEventListener
to handle different events that happen during the checkout lifecycle:
private val listener = object : CheckoutEventListener {
override fun onCheckoutEvent(event: CheckoutEvent) {
when (event) {
is CheckoutEvent.TokenizationSuccess -> {}
is CheckoutEvent.TokenizationError -> {}
is CheckoutEvent.ResumeSuccess -> {}
is CheckoutEvent.ResumeError -> {}
is CheckoutEvent.ApiError -> {}
}
}
}
Or if you are using Java:
private CheckoutEventListener listener = new CheckoutEventListener() {
@Override
public void onCheckoutEvent(@NonNull CheckoutEvent checkoutEvent) {
if (checkoutEvent instanceof CheckoutEvent.TokenizationSuccess) {
} else if (checkoutEvent instanceof CheckoutEvent.TokenizationError) {
} else if (checkoutEvent instanceof CheckoutEvent.ResumeSuccess) {
} else if (checkoutEvent instanceof CheckoutEvent.ResumeError) {
} else if (checkoutEvent instanceof CheckoutEvent.ApiError) {
}
}
};
Make an API call to your backend to fetch a Client Token for the checkout session.
fun fetchClientToken { result -> this.clientToken = result.clientToken }
Or if you are using Java:
void fetchClientToken(result -> this.clientToken = result.clientToken)
// Some payment methods require additional configuration to be passed in PrimerConfig()
Primer.instance.configure(listener)
// Show the Universal Checkout
Primer.instance.showUniversalCheckout(context, this.clientToken)
Or if you are using Java:
// Some payment methods require additional configuration to be passed in PrimerConfig()
// For Primer SDK 1.5.1+
Primer.getInstance().configure(new PrimerConfig(), listener);
// For previous versions
Primer.Companion.getInstance().configure(new PrimerConfig(), listener);
// Show the Universal Checkout
// For Primer SDK 1.5.1+
Primer.getInstance().showUniversalCheckout(context, this.clientToken);
// For previous versions
Primer.Companion.getInstance().showUniversalCheckout(context, this.clientToken);
Once the payment method data has been securely captured, Primer will return a uniform paymentMethodToken
via CheckoutEvent.TokenizationSuccess
. This can be safely passed to your server to create a payment with the Payments API.
CheckoutEvent.TokenizationSuccess
: