Skip to content

primer-io/sdk-android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Primer Android SDK

Primer's Official Universal Checkout Android SDK



Maven Central CircleCI


💪 Features of the Android SDK

💳   Create great payment experiences with our highly customizable Universal Checkout

🧩   Connect and configure any new payment method without a single line of code

✅   Dynamically handle 3DS 2.0 across processors and be SCA ready

♻️   Store payment methods for recurring and repeat payments

🔒   Always PCI compliant without redirecting customers

📚 Documentation

Consider looking at the following resources:

💡 Support

For any support or integration related queries, feel free to Contact Us.

🚀 Quick start

Take a look at our Quick Start Guide for accepting your first payment with Universal Checkout.


🧱 Installation

Prerequisites

  • android-studio

Add the following to your app/build.gradle file:

repositories {
  mavenCentral()
}

dependencies {
  implementation 'io.primer:android:latest.version'
}

For more details about SDK versions, please see our changelog.

It is highly recommended adding following settings to your app/build.gradle file:

android {
    kotlinOptions {
        freeCompilerArgs += '-Xjvm-default=all'
    }
}

👩‍💻 Usage

📋 Prerequisites

🔍  Initializing the SDK

Prepare the PrimerCheckoutListener that will handle the callbacks that happen during the lifecycle. Import the Primer SDK and set its listener as shown in the following example:

class CheckoutActivity : AppCompatActivity() {

    private val listener = object : PrimerCheckoutListener {

        override fun onCheckoutCompleted(checkoutData: PrimerCheckoutData) {
            // Primer checkout completed with checkoutData
            // show an order confirmation screen, fulfil the order...
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        configureCheckout()
    }

    private fun configureCheckout() {
        // Initialize the SDK with the default settings.
        Primer.instance.configure(listener = listener)
    }
}

Note: Check the SDK API Reference for more options to customize your SDK.

🔍  Rendering the checkout

Now you can use the client token that you generated on your backend. Call the showUniversalCheckout function (as shown below) to present Universal Checkout.

class CheckoutActivity : AppCompatActivity() {
 
    // other code goes here
 
    private fun setupObservers() {
        viewModel.clientToken.observe(this) { clientToken ->
            showUniversalCheckout(clientToken)
        }
    }
 
    private fun showUniversalCheckout(clientToken: String) {
        Primer.instance.showUniversalCheckout(this, clientToken)
    }
}

You should now be able to see Universal Checkout! The user can now interact with Universal Checkout, and the SDK will create the payment. The payment’s data will be returned on onCheckoutCompleted(checkoutData).

Note: There are more options which can be passed to Universal Checkout. Please refer to the section below for more information.

Running

To run the example, simply press the play button from Android Studio to launch on a virtual device.

Debugging

Logcat has a habit of misbehaving, so you might need to attach the debugger and set breakpoints to find out what's really going on.

Contributing guidelines:

Contributing doc