Payment Gateway SDK — Android
Integrate DigetPay payments into your native Android application using the official DigetPay Android SDK.
The SDK provides a single entry point through DigetPay for hosted checkout, card payments, recurring payments, transaction operations, and payment result handling.
Requirements
| Requirement | Supported Version |
|---|---|
| SDK Version | 1.0 |
| Minimum Android | Android 7.0+ |
| Minimum API Level | 24+ |
| Recommended Compile SDK | 36 |
| Kotlin | 2.0+ |
| Java Target | 11 |
| Languages | Kotlin / Java |
| 3-D Secure | Supported |
| Hosted Checkout | Supported |
Installation
The DigetPay Android SDK is distributed as an AAR.
Add the SDK to your application and include its required runtime dependencies in your app module.
The AAR does not embed its transitive runtime dependencies, including Retrofit, OkHttp, Coroutines, and AndroidX. Make sure these dependencies are available in your application before using the SDK.
Quick Start
1. Initialize the SDK
Initialize DigetPay once before starting a payment:
DigetPay.initialize(
context = this,
config = DigetPayConfig(
apiKey = "YOUR_API_KEY",
environment = Environment.SANDBOX,
enableLogging = BuildConfig.DEBUG
)
)Use Environment.SANDBOX while testing and Environment.PRODUCTION for live payments.
Use a mobile-restricted or publishable API key in the application. Never embed a server secret or privileged credential in the Android application.
2. Start Hosted Checkout
Hosted Checkout is the recommended payment flow.
DigetPay.checkout(
activity = this,
request = CheckoutRequest(
merchantOrderId = "ORDER-123",
amount = 125.0,
currency = "SAR",
customerName = "Ahmed Ali",
customerEmail = "[[email protected]](mailto:[email protected])",
customerPhone = "+966501234567"
),
callback = object : PaymentCallback \{
override fun onSuccess(result: PaymentResult) {
actionId.
override fun onFailure(error: PaymentError) {
override fun onCancelled() {
checkout screen.
}
)The SDK opens the DigetPay-hosted checkout screen, handles the payment flow and 3-D Secure challenge, and returns the final result through PaymentCallback.
Recommended Payment Flow
The standard hosted checkout flow is:
- Initialize the SDK using
DigetPay.initialize(). - Create a checkout using
DigetPay.checkout(). - Customer completes payment on the DigetPay-hosted checkout screen.
- SDK verifies the final result and returns it through
PaymentCallback. - Verify the transaction on your backend before fulfilling the order.
For a successful payment, store the relevant identifiers such as:
sessionIdtransactionIdmerchantOrderId
Do not rely only on the visual success page. Your backend should verify the final transaction status before marking an order as paid.
Payment Flows
Hosted Checkout
Hosted Checkout keeps the payment experience on DigetPay's hosted payment page.
The SDK handles:
- Checkout initialization
- Hosted payment screen
- Customer payment
- 3-D Secure
- Redirect handling
- Final payment result
- Success, failure, and cancellation callbacks
This is the recommended flow for most Android integrations.
Card Payment
The SDK also supports direct card payments.
This flow collects card information inside the application and submits the payment through the SDK.
Because raw card data is handled by the application, this integration increases your PCI-DSS responsibilities.
Prefer Hosted Checkout unless your integration has been assessed for the required PCI-DSS scope.
Recurring Payments
The SDK supports recurring payment flows and payment tokenization for subsequent charges.
Use recurring functionality only when the required customer consent, token handling, and backend controls are implemented correctly.
Callbacks & Results
Payment results are delivered through PaymentCallback.
| Callback | Description |
|---|---|
onSuccess() | Payment completed successfully |
onFailure() | Payment failed or was declined |
onCancelled() | Customer cancelled or closed the payment flow |
Operation requests such as capture, void, and refund use OperationCallback.
Always handle all callback outcomes and avoid treating a missing callback as a successful payment.
Payment Operations
The SDK supports common transaction operations, including:
| Operation | Supported |
|---|---|
| Payment Status | ✓ |
| Capture | ✓ |
| Void | ✓ |
| Refund | ✓ |
| Recurring Charges | ✓ |
For payment lifecycle operations, keep the transaction identifiers on your backend and use your server-side integration for business-critical order state management.
SDK Components
The main SDK components include:
| Component | Purpose |
|---|---|
DigetPay | Main SDK entry point |
DigetPayConfig | SDK configuration |
Environment | Sandbox or Production environment |
CheckoutRequest | Hosted checkout request |
CardPaymentRequest | Direct card payment request |
RecurringRequest | Recurring payment request |
PaymentResult | Successful payment result |
PaymentCallback | Payment result callbacks |
OperationCallback | Transaction operation callbacks |
ErrorCode | Structured error information |
Environment Configuration
Use the appropriate environment when initializing the SDK:
Environment.SANDBOX
for testing, and:
Environment.PRODUCTION
for live transactions.
Keep environment selection configurable so that test builds do not accidentally use production credentials.
Security
API Keys
The Android application contains credentials that can potentially be extracted from the APK.
For this reason:
- Use a mobile-restricted or publishable API key.
- Never embed a server secret in the application.
- Do not hard-code privileged backend credentials.
- Rotate a key if it is exposed.
- Keep sensitive and privileged operations behind your backend.
Card Data
Hosted Checkout is preferred because card details are entered on the DigetPay-hosted payment page.
If you use direct card payment, your application handles raw card information and your PCI-DSS scope is increased.
Transaction Verification
Do not fulfill an order based only on the client-side callback.
Your backend should verify the transaction and maintain the authoritative order state.
Versioning & Compatibility
Current SDK Version
| SDK | Current Version |
|---|---|
| DigetPay Android SDK | 1.0 |
Platform Support
| Platform Requirement | Version |
|---|---|
| Minimum Android | 7.0 |
| Minimum API | 24 |
| Recommended Compile SDK | 36 |
| Kotlin | 2.0+ |
| Java Target | 11 |
Future SDK releases may increase the minimum supported Android or build-tool versions. Check the release notes before upgrading.
Logging
Logging can be enabled during development:
enableLogging = BuildConfig.DEBUG
Keep SDK logging disabled in production unless it is specifically required for troubleshooting.
Never log sensitive payment credentials or raw card information in your own application logs.
Error Handling
DigetPay provides structured payment and operation errors.
Handle errors based on their returned error information rather than assuming every failure is a network failure.
Recommended handling:
- Display a user-friendly message.
- Record the technical error on your backend where appropriate.
- Allow the customer to retry when the error is recoverable.
- Verify the transaction status before retrying an uncertain payment.
Android Permissions
The SDK requires network access to communicate with DigetPay services.
Make sure your application has the required Internet permission in its Android configuration:
<uses-permission android:name="android.permission.INTERNET" />Best Practices
- Initialize the SDK once during application startup.
- Use Sandbox for development and testing.
- Use Hosted Checkout as the default payment flow.
- Never expose server secrets in the mobile application.
- Store
sessionId,transactionId, and order identifiers on your backend. - Verify successful payments server-side.
- Do not log raw card data or sensitive credentials.
- Keep the SDK updated to supported releases.
- Test success, failure, cancellation, and 3-D Secure scenarios before production.
Full Android DocumentationFor the complete installation guide, configuration details, payment flows, examples, error handling, and generated API reference, see the full DigetPay Android SDK documentation:
Related
Updated 28 days ago

