This example demonstrates how to integrate support for co-badged cards in your Android app.
To run the example app:
- Clone the repo:
git clone https://github.com/primer-io/checkout-examples-android.git
- Open the project in Android Studio 🚀
Select co-badged-cards
configuration and run the project.
- Setup the client token server
Refer to the instructions provided in the example-backend Readme to set up the server for generating the client token needed to initialize the SDK.
This project requires a server to communicate with Primer's API. To get started quickly, we encourage you to use the companion backend.
- You can set the URL of the checkout backend to initiate the checkout generated in step 3.
- The application provides an input field where you can input this URL or you can set the
BASE_URL
field defined in the ClientSessionService. - When the URL is set, you can request new client token in the example app.
- On the initial screen of your application, there's an option to manually input a client token.
- Paste the client token generated specifically for your integration to start the checkout process.
We have followed a very simple Android architectural principles as describe in Android documentation.
We have used following stack:
- Hilt for DI
- Retrofit for API calls
- Jetpack Compose + ViewModels on the UI/presentation layer
For easier separation of concerns, application was split into:
We have organized our code into two repositories to streamline the integration process:
- PrimerHeadlessRepository contains the necessary code for initializing the Primer Headless SDK and managing checkout lifecycle events.
- Use this repository to set up the base structure and manage Primer Headless events within your application.
- CardInputRepository
focuses specifically on card input functions leveraging the
PrimerHeadlessUniversalCheckoutRawDataManager
. - It provides functions and utilities for handling card inputs during the checkout process.
We have organized our code into two ViewModels to streamline the integration process:
- CheckoutConfigurationViewModel focuses on retrieving and validating client token needed for SDK initialization.
- CardInputViewModel
focuses specifically on card input functions leveraging the
CardInputRepository
. - It provides functions and utilities for handling card inputs during the checkout process.
- CardScreen is a Composable that presents the card screen.