# Android SDK integration

A guide to integrating the Peach Orchestration mobile SDK into a native Android app using Kotlin and the `io.hyperswitch` SDK. Minimum: Android 7.0 (API 24)+.

## What this page covers
- Ten sections: Prerequisites, Installation, Configuration, Basic integration, Payment methods, Saved cards, Error handling, Customisation, Testing, Troubleshooting
- Android Studio/Kotlin prerequisites and getting Dashboard credentials (publishable key `pk_snd_xxx`/`pk_prd_xxx`)
- Gradle setup, the Juspay Maven repository, and ProGuard/R8 rules
- Creating and presenting the `PaymentSheet` with a `client_secret` from your backend
- Payment methods: cards, Google Pay, bank redirects (deep links), PayJustNow (BNPL)
- Saved cards via customer configuration + ephemeral keys, and Setup Intents (`presentWithSetupIntent`)
- Theming with `PaymentSheet.Appearance`, dark mode, error handling, testing and troubleshooting

## Key steps / API

Dependency: `implementation("io.hyperswitch:hyperswitch-sdk-android:+")` with the Maven repo `https://maven.juspay.in/hyper-sdk/`. ProGuard: `-keep class io.hyperswitch.** { *; }`.

```kotlin
import io.hyperswitch.PaymentSession
import io.hyperswitch.paymentsheet.PaymentSheet
import io.hyperswitch.paymentsheet.PaymentSheetResult

// 1. Build the session with your publishable key
paymentSession = PaymentSession.Builder(this, "pk_test_your_publishable_key")
    .customBackendUrl("https://app.sandbox-next.peachpayments.com/api")
    .build()

// 2. Initialise with a client secret fetched from your server
paymentSession.initPaymentSession(clientSecret)

// 3. Present the payment sheet
paymentSession.presentPaymentSheet { result ->
    when (result) {
        is PaymentSheetResult.Completed -> { /* success */ }
        is PaymentSheetResult.Canceled  -> { /* user dismissed */ }
        is PaymentSheetResult.Failed    -> { /* result.error */ }
    }
}
```

Other real API surface referenced in the source:
- `PaymentSheet.Configuration(merchantDisplayName, googlePay, paymentMethodOrder, customer, allowsDelayedPaymentMethods)`
- `PaymentSheet.GooglePayConfiguration(environment, countryCode, currencyCode, merchantName)`
- `PaymentSheet.CustomerConfiguration(id, ephemeralKeySecret)` for saved cards
- `paymentSheet.presentWithPaymentIntent(...)` / `paymentSheet.presentWithSetupIntent(...)`
- Theming: `PaymentSheet.Appearance` with `PaymentSheet.Colors`, `PaymentSheet.Shapes(cornerRadiusDp)`, `PaymentSheet.Typography`, `PaymentSheet.PrimaryButton`
- Deep-link handling in `onNewIntent(...)` for redirect-based payments

Sandbox API base is `https://app.sandbox-next.peachpayments.com/api`; production is `https://app.next.peachpayments.com/api`. Google Pay requires the merchant ID to be configured on your Peach Payments account. Create the `PaymentSession` in the Activity's `onCreate()`.

## Related
- [Android SDK customisation](/sdk-customization-android.md): live simulator that restyles the Android payment sheet
- [iOS SDK](/sdk-mobile-ios.md): native iOS equivalent
- [Web SDK](/sdk-web.md): browser integration
- [API Playground](/playground.md): create a payment intent and get a `client_secret`
- [Testing](/docs/testing.md): test cards and sandbox guidance

---

Interactive version: https://playground.peachpayments.com/sdk-mobile/android
