Step 1. Install

Add the following to your build.gradle file:

repositories {
  mavenCentral()
}

dependencies {
  implementation 'io.primer:android:1.5.1'
}

Step 2. Prepare Universal Checkout event listeners

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) {
        }
    }
};

Step 3. Prepare the Client Token

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) 

Step 4. Initialise and show the Universal Checkout


// 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);

Step 5. Handle callbacks for creating and resuming payments

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.

Handling CheckoutEvent.TokenizationSuccess: