Skip to content

Latest commit

 

History

History

co-badged-cards

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

💳 Co-Badged Cards Example

This example demonstrates how to integrate support for co-badged cards in your Android app.

Getting Started

To run the example app:

  1. Clone the repo:
git clone https://github.com/primer-io/checkout-examples-android.git
  1. Open the project in Android Studio 🚀

Select co-badged-cards configuration and run the project.

  1. 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.

Setting Checkout Backend URL

  • 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.

Manually Created Client Token

  • 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.

Understanding the integration

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:

Repositories

We have organized our code into two repositories to streamline the integration process:

1. Primer Headless Initialization and Events

  • 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.

2. Card Input Functions using PrimerHeadlessUniversalCheckoutRawDataManager

  • CardInputRepository focuses specifically on card input functions leveraging the PrimerHeadlessUniversalCheckoutRawDataManager.
  • It provides functions and utilities for handling card inputs during the checkout process.

UI/Presentation

We have organized our code into two ViewModels to streamline the integration process:

1. Primer Headless Initialization and Events

2. Card Input Functions using CardInputViewModel

  • CardInputViewModel focuses specifically on card input functions leveraging the CardInputRepository.
  • It provides functions and utilities for handling card inputs during the checkout process.

3. Card Screen presentation using CardScreen

  • CardScreen is a Composable that presents the card screen.