-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from primer-io/vm/drop-in-example_v2
Drop In Checkout example app
- Loading branch information
Showing
52 changed files
with
1,524 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/build | ||
|
||
# security | ||
*.pem | ||
*.crt | ||
.env/ | ||
.env.example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# 💳 DropIn Checkout Example | ||
|
||
This example demonstrates how to integrate support for DropIn Checkout in your Android app. | ||
|
||
## Getting Started | ||
|
||
To run the example app: | ||
|
||
1. Clone the repo: | ||
```sh | ||
git clone https://github.com/primer-io/checkout-examples-android.git | ||
``` | ||
2. Open the project in Android Studio 🚀 | ||
|
||
Select `drop-in-checkout` configuration and run the project. | ||
|
||
3. Setup the client token server | ||
|
||
Refer to the instructions provided in the [example-backend Readme](https://github.com/primer-io/checkout-example-backend/blob/main/README.md) | ||
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](https://github.com/primer-io/checkout-example-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](src/main/java/io/primer/checkout/cobadged/configuration/data/api/ClientSessionService.kt#L26). | ||
- 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](https://developer.android.com/topic/architecture). | ||
|
||
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 DropIn Initialization and Events | ||
|
||
- [PrimerDropInRepository](src/main/java/io/primer/checkout/dropin/checkout/data/repository/PrimerDropInRepository.kt) | ||
contains the necessary code for initializing the Primer Universal Checkout SDK and managing checkout lifecycle events. | ||
- Use this repository to set up the base structure and manage Primer Universal Checkout events within your application. | ||
|
||
|
||
### UI/Presentation | ||
|
||
We have organized our code into two ViewModels to streamline the integration process: | ||
|
||
#### 1. Primer DropIn Initialization and Events | ||
|
||
- [CheckoutDropInViewModel](src/main/java/io/primer/checkout/cobadged/configuration/viewmodel/CheckoutConfigurationViewModel.kt) | ||
focuses on retrieving and validating client token needed for SDK initialization. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import com.android.build.api.dsl.Packaging | ||
|
||
plugins { | ||
alias(libs.plugins.android.application) | ||
alias(libs.plugins.kotlin.android) | ||
alias(libs.plugins.kotlin.parcelize) | ||
alias(libs.plugins.kotlin.serialization) | ||
alias(libs.plugins.ksp) | ||
alias(libs.plugins.hilt) | ||
} | ||
|
||
android { | ||
namespace = "io.primer.checkout.dropin" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
applicationId = "io.primer.checkout.dropin" | ||
minSdk = 21 | ||
targetSdk = 34 | ||
versionCode = 1 | ||
versionName = "1.0" | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
vectorDrawables { | ||
useSupportLibrary = true | ||
} | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = JavaVersion.VERSION_17.toString() | ||
|
||
// Enable Coroutines and Flow APIs | ||
freeCompilerArgs = | ||
freeCompilerArgs + "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi" | ||
freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlinx.coroutines.FlowPreview" | ||
} | ||
buildFeatures { | ||
compose = true | ||
buildConfig = true | ||
} | ||
composeOptions { | ||
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get() | ||
} | ||
// Multiple dependency bring these files in. Exclude them to enable | ||
// our test APK to build (has no effect on our AARs) | ||
fun Packaging.() { | ||
resources.excludes += "/META-INF/AL2.0" | ||
resources.excludes += "/META-INF/LGPL2.1" | ||
} | ||
} | ||
|
||
dependencies { | ||
ksp(libs.hilt.android.compiler) | ||
|
||
implementation(libs.androidx.core.ktx) | ||
implementation(libs.androidx.lifecycle.viewmodel.ktx) | ||
implementation(libs.androidx.lifecycle.viewmodel.compose) | ||
implementation(libs.androidx.navigation.compose) | ||
implementation(libs.material) | ||
implementation(libs.okhttp3.logging.interceptor) | ||
implementation(libs.retrofit2.converter.kotlinx.serialization) | ||
implementation(libs.retrofit2) | ||
implementation(libs.kotlinx.serialization.json) | ||
implementation(libs.kotlinx.coroutines.android) | ||
implementation(libs.kotlinx.coroutines.core) | ||
implementation(libs.hilt.android) | ||
implementation(libs.hilt.navigation.compose) | ||
|
||
implementation(libs.primer.sdk) | ||
implementation(libs.primer.threeds.sdk) | ||
|
||
testImplementation(libs.junit) | ||
} | ||
|
||
apply { | ||
from("$rootDir/config/lint.gradle") | ||
} |
Oops, something went wrong.