This repository contains a reusable AltaPay Merchant Android SDK along with a demo android application that demonstrates how to integrate and execute AltaPay payment flows using WebView.
This project is structured as a multi-module Android project:
-
AltaPay Merchant SDK (Library Module)
- Clean, reusable SDK for creating AltaPay payment requests
- Retrofit + Kotlin + Coroutines based
- No Android
Contextdependency
-
Demo Android Application
- Shows real-world SDK usage
- WebView-based payment flow
- Progress dialog handling
android-payment-app/
│
├── altapayMerchant/ # Android library module (SDK)
│ ├── src/main/java/
│ │ └── com.altapay.merchant
│ ├── build.gradle
│ └── consumer-rules.pro
│
├── app/ # Demo Android application
│ ├── src/main/java/
│ │ └── com.syeda.paymentdemo
│ ├── src/main/res/layout/
│ └── build.gradle
│
├── gradle/
├── build.gradle
├── settings.gradle
└── README.md
- Android Studio Hedgehog or newer
- JDK 17
- Android SDK 21+
- Active Internet connection
-
Clone the repository
git clone https://github.com/AltaPay/android-payment-app.git cd android-payment-app -
Open the project in Android Studio:
File > Open > select android-payment-appWait for Gradle sync to complete.
- Select the app run configuration
- Connect an Android device or start an emulator
- Click Run
Update AltaPay credentials in
MainActivity.kt:val paymentClient = PaymentClient( PaymentConfig( username = "YOUR_API_USERNAME", password = "YOUR_API_PASSWORD" ) )
Do not hardcode credentials in production apps.
-
Copy
altapayMerchantinto your project root. -
Update
settings.gradle:include(":altapayMerchant") -
Add dependency in
app/build.gradle: and Sync Gradle.dependencies { implementation project(":altapayMerchant") }
Add to AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />val paymentClient = PaymentClient(
PaymentConfig(
username = "YOUR_API_USERNAME",
password = "YOUR_API_PASSWORD"
)
)fun getPaymentParams(): Map<String, String> = mapOf(
"terminal" to "YourTerminal",
"shop_orderid" to "ORDER_12345",
"amount" to "100.00",
"currency" to "EUR",
"config[callback_form]" to "https://yourdomain.com/callback"
)paymentClient.createPaymentAsync(
paymentUrl = "https://gateway.altapay.com/payment",
params = getPaymentParams(),
callback = object : PaymentCallback {
override fun onSuccess(result: PaymentResult) {
webView.loadUrl(result.redirectUrl)
}
override fun onError(error: PaymentError) {
Toast.makeText(this@MainActivity, error.message, Toast.LENGTH_LONG).show()
}
}
)lifecycleScope.launch {
try {
val result = paymentClient.createPayment(
paymentUrl = "https://gateway.altapay.com/payment",
params = getPaymentParams()
)
webView.loadUrl(result.redirectUrl)
} catch (e: PaymentException) {
Toast.makeText(this@MainActivity, e.message, Toast.LENGTH_LONG).show()
}
}webView.settings.javaScriptEnabled = true
webView.settings.domStorageEnabled = true
webView.webViewClient = WebViewClient()| Parameter | Description |
|---|---|
| terminal | Merchant terminal identifier |
| shop_orderid | Unique order ID |
| amount | Payment amount |
| currency | Currency code |
| Other parameters | Parameters value |
- Network errors
- Authentication failures
- Invalid XML responses
- Parsing exceptions
Errors are returned via PaymentError or thrown as PaymentException.
Distributed under the MIT License. See LICENSE for more information.
