Android SDK
The SDK handles the payment interface and payment interactions. Your server creates payments, confirms final results, and fulfills orders.
Prerequisites and environment
Android 8.0 (API 26) or later is required. The examples use Kotlin.
Prepare a merchant account and server-side API Key for the same environment, server endpoints for creating payments and receiving notifications, and the SDK package. Keep credentials on your server. For payment methods that require authentication or an external redirect, configure returnUrl when creating the payment. Complete the relevant wallet configuration before enabling a native wallet.
Install the SDK
Download and extract
Obtain the onerway-android-<SDK_VERSION>.zip offline Maven distribution from Onerway. Replace <SDK_VERSION> with the actual version, using the same version for the package and the Maven dependency.
The recommended location after extraction is your project root:
YourAndroidProject/
├── app/
├── local-maven/
│ └── onerway-android-<SDK_VERSION>/
│ └── com/onerway/sdk/...
├── settings.gradle.kts
└── build.gradle.kts
The ZIP contains local Maven repositories for the SDK modules. Do not copy only an individual AAR. Gradle still resolves third-party dependencies from google() and mavenCentral().
Configure the Maven repository
In settings.gradle.kts:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven {
url = uri(rootDir.resolve("local-maven/onerway-android-<SDK_VERSION>"))
}
}
}
For the Groovy DSL, configure settings.gradle:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven {
url = uri("${rootDir}/local-maven/onerway-android-<SDK_VERSION>")
}
}
}
The Maven URL must point to the repository root containing the com/ directory.
Add the dependency
In app/build.gradle.kts:
android {
defaultConfig {
minSdk = 26
}
}
dependencies {
implementation("com.onerway.sdk:onerway-android:<SDK_VERSION>")
}
For the Groovy DSL:
dependencies {
implementation "com.onerway.sdk:onerway-android:<SDK_VERSION>"
}
You only need to add the onerway-android dependency.
Verify the dependency
Run Gradle Sync, then run:
./gradlew :app:dependencies --configuration debugRuntimeClasspath
The dependency tree should include:
com.onerway.sdk:onerway-android:<SDK_VERSION>
Initialize and configure
Runtime environment
The SDK environment must match the environment in which your server created the payment. Always setting environment explicitly is recommended; avoid relying on its default value.
environment selects the SDK runtime environment and has type OnerwayEnvironment.
| Value | Environment | Description |
|---|---|---|
PRODUCTION | Production | Uses production merchant configuration |
SANDBOX | Sandbox | Uses sandbox accounts and payment sessions |
The default is SANDBOX. For production, pass OnerwayEnvironment.PRODUCTION.
Initialize the SDK
Call configure in the Application.onCreate method used by your app. The class name below is an example. If you already have a custom Application class, add the initialization code to that class.
OnerwaySDK.configure(context, config)
package com.example.app
import android.app.Application
import com.onerway.sdk.core.OnerwayConfig
import com.onerway.sdk.core.OnerwayEnvironment
import com.onerway.sdk.core.OnerwaySDK
import com.onerway.sdk.core.OnerwayThemeMode
class MerchantApplication : Application() {
override fun onCreate() {
super.onCreate()
OnerwaySDK.configure(
context = applicationContext,
config = OnerwayConfig(
environment = OnerwayEnvironment.PRODUCTION,
locale = null,
themeMode = OnerwayThemeMode.FOLLOW_HOST,
),
)
}
}
Register the Application class your app uses in app/src/main/AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:name=".MerchantApplication">
<!-- Keep your app's existing components. -->
</application>
</manifest>
The SDK already provides the network permission, checkout Activity, and Google Pay configuration. You do not need to declare them again in your app's AndroidManifest.xml. For return configuration, see “Handle authentication, external redirects, and returns to your app”.
Configuration options
Set the following fields in OnerwayConfig:
| Field | Type | Default | Description |
|---|---|---|---|
environment | OnerwayEnvironment | SANDBOX | Runtime environment: PRODUCTION or SANDBOX |
locale | String? | Omitted | Language tag; see Languages for supported values |
paymentMethods | Set<String>? | Omitted | Payment method display allowlist, using the payment method identifiers returned by the server |
brandColor | Int? | Omitted | ARGB brand color; when omitted, uses the color returned by the server, or the SDK default if the server does not provide a valid color |
themeMode | OnerwayThemeMode | FOLLOW_HOST | Appearance mode; see the table below |
themeMode | Description |
|---|---|
FOLLOW_HOST | Uses the host Activity's light or dark appearance when checkout opens and keeps it unchanged throughout this payment |
LIGHT | Always light |
DARK | Always dark |
paymentMethods uses dynamic payment method identifiers returned by the API, with no fixed enum. When omitted, checkout displays the methods available for the order. An empty set leaves no available methods: the SDK returns sdk_error / no_available_payment_methods and closes checkout. This option only filters the display; it does not enable methods absent from the server configuration or change their order.
Languages
locale supports these language tags:
ar, de, en, es, fi, fr, it, ja, ko, nl, no, pl, pt, ru, sv, th, vi, zh-cn, zh-tw.
When omitted, the SDK reads the app or system language. Unsupported languages fall back to en.
Obtain a payment session from your server and present checkout
Obtain a payment session from your server
- Your app calls your own server endpoint for creating a payment.
- Your server sends
merchantNoand authenticates with theApiKeyheader to create an SDK transaction, following Request authentication. SetpaymentMode=APPandosType=ANDROID. Follow that endpoint's requirements for other parameters and conditionally required fields. - Your server saves the mapping between your order,
paymentId, and the returned transaction identifier, then returnspaymentIdto your app. - Your app calls the native SDK with a non-empty
paymentId.
Keep the API Key, webhook signing keys, request authentication, and Webhook signature verification on your server.
Your own session endpoint can return an object such as the following. You define the endpoint name and object format:
{
"merchantTxnId": "YOUR_ORDER_ID",
"paymentId": "PAYMENT_ID_FROM_ONERWAY"
}
If the payment requires authentication or an external redirect, configure your HTTPS returnUrl when your server creates the payment. The notifyUrl notification endpoint receives payment notifications on your server. The return restores the interaction; the notification confirms the order. Neither replaces the other.
Call the SDK
Call the SDK from your existing payment entry point. The wrapper class below is an example; you can also call OnerwayCheckout.present directly.
OnerwayCheckout.present(activity, params, callback)
| Parameter | Type | Required | Description |
|---|---|---|---|
activity | Activity | Yes | The currently visible host Activity |
params | CheckoutParams | Yes | Contains a non-empty paymentId: String |
callback | (PaymentResult) -> Unit | Yes | Runs on the main thread, at most once per presentation |
import android.app.Activity
import com.onerway.sdk.core.CheckoutParams
import com.onerway.sdk.core.PaymentReasonType
import com.onerway.sdk.core.PaymentResult
import com.onerway.sdk.ui.OnerwayCheckout
class OnerwayCheckoutLauncher {
private var isPresenting = false
fun present(
activity: Activity,
paymentId: String,
onResult: (PaymentResult) -> Unit,
) {
if (isPresenting) return
isPresenting = true
try {
OnerwayCheckout.present(
activity = activity,
params = CheckoutParams(paymentId = paymentId),
) { result ->
isPresenting = false
onResult(result)
}
} catch (error: RuntimeException) {
isPresenting = false
throw error
}
}
}
fun handlePaymentResult(result: PaymentResult) {
val reason = result.reason
when {
reason?.type == PaymentReasonType.CANCELED -> {
showOrderPage()
}
result.paymentStatus == "S" -> {
verifyOnMerchantServer(result.paymentId)
}
result.paymentStatus == "P" || result.paymentStatus == "A" -> {
showPending(result.paymentId)
}
result.paymentStatus == "N" -> {
showNotCompleted(result.paymentId)
}
reason != null -> {
showCheckoutError(reason.code)
}
else -> {
verifyOnMerchantServer(result.paymentId)
}
}
}
Implement showOrderPage, verifyOnMerchantServer, showPending, showNotCompleted, and showCheckoutError in your app. These methods should retain the current order and confirm its status with your server. In particular, do not create a new order solely because the result is N or the user cancels.
Call requirements:
- Call
OnerwaySDK.configurefirst. - Call on the main thread and pass the currently visible Activity. From a Fragment, use
requireActivity(). - Present only one checkout at a time within the same process.
- An empty
paymentIdreturnssdk_error / invalid_payment_idthrough the callback. - Calling before initialization or opening a second checkout concurrently throws an exception.
- The callback runs on the main thread, at most once per presentation.
Handle client payment results
PaymentResult
| Field | Type | Description |
|---|---|---|
paymentId | String | Payment session identifier |
transactionId | String? | Server transaction identifier; null until available |
paymentMethod | String? | Payment method obtained by the SDK; null until available |
paymentStatus | String? | Non-empty values are S, P, A, or N; null on cancellation or error, in which case read reason |
reason | PaymentReason? | Cancellation or error reason |
Payment statuses and merchant handling
When checkout ends, handle paymentStatus as follows:
paymentStatus | Meaning | Merchant handling |
|---|---|---|
S | The SDK has received a successful payment result | Show success; fulfill the order after your server confirms the result |
P | The payment is processing or the result still needs confirmation | Show a confirmation-in-progress message and continue querying from your server |
A | The SDK has received an authorized result | Follow your server's pre-authorization and capture results; do not treat this as funds having been collected |
N | The SDK has received a payment-not-completed result | Confirm the order status with your server; do not automatically create a new order based only on this value |
When the user cancels or the SDK exits with an error result, paymentStatus is null. Read reason.type and reason.code for the reason. After cancellation, an error, or a network timeout, query the order status from your server to confirm it.
Handle results using reason.type and reason.code. Do not determine order status from an error message.
The SDK handles payment retries, authentication, and external redirects. If the user only cancels wallet authorization or dismisses a recoverable error message, checkout remains open and the completion callback does not run.
PaymentResult, the return URL, and SDK pages are for client interactions only. Base fulfillment, shipping, account top-ups, and accounting on results confirmed by a signature-verified Webhook or a server-side query, and process them idempotently by merchant order. The end of the client flow does not mean the server-side order has reached a final state.
Reason types
reason.type.rawValue | Description |
|---|---|
canceled | The customer closed the entire checkout |
validation_error | Local parameter or form validation error; reserved, not returned in the current version |
api_error | Payment API or backend business error |
sdk_error | SDK configuration, invocation, network, or internal error |
PaymentReason
| Field | Type | Description |
|---|---|---|
type | PaymentReasonType | Reason category; see Reason types |
code | String | Reason code for application logic and troubleshooting |
message | String? | Display or diagnostic information; do not use it to determine payment status |
param | String? | Related parameter |
declineCode | String? | Reserved; always null in the current version |
errors | List<PaymentFieldError>? | Reserved; always null in the current version |
Optional fields are null when no corresponding information is available.
Payment identifiers
| Identifier | Source | Purpose |
|---|---|---|
merchantTxnId | Generated by your server | Associates the payment with your order |
paymentId | Create SDK transaction response | Opens checkout and identifies the payment session |
transactionId | SDK result callback | Identifies the server transaction |
transactionId is the server transaction identifier obtained by the SDK and is null until available. The same paymentId may have different transaction identifiers after payment attempts or retries. Associate the transaction using the value in the current callback, and confirm its final status on your server.
Handle authentication, external redirects, and returns to your app
The SDK automatically opens authentication or external payment pages in the system browser. Some payment methods redirect to a third-party app instead.
After payment, the platform redirects the user to the returnUrl configured when you created the payment, and the system opens your app directly. The platform handles the return. The SDK does not need to participate, and you do not need to pass the return URL to the SDK. Handling after return depends on whether the original SDK session is still active; see After returning to your app.
Configure the return URL
- When your server creates the payment, set
returnUrlto a URL that opens your app. A domain-verified HTTPS App Link is recommended:https://pay.example.com/payment/return - Your app must be able to receive this URL through its routing. For an HTTPS App Link, associate the domain with your app using
assetlinks.json. You do not need to add a dedicated Activity for this purpose. - If you need a custom scheme, such as
myapp://payment/return, first confirm with Onerway whether the current order type supports it.
After returning to your app
- If the original checkout is still alive, the SDK automatically queries the payment status when it returns to the foreground and invokes the callback once. You do not need to listen for the browser closing, confirm the payment again, or implement polling.
- If the app has restarted, the original checkout has closed, or the query fails, query your server from your order page to confirm the result.
- Do not use
status, amounts, or other parameters in the return URL to determine the payment result. Use a server-side query or Webhook for the final status.
Optional: handle return links explicitly
OnerwayCheckout.resumeFromReturn is an optional recovery method that brings a still-active checkout to the foreground or restores a session when needed. It is not part of the standard integration steps. Omitting it does not affect the return or server-side order queries.
OnerwayCheckout.resumeFromReturn(activity, uri, callback): Boolean
| Parameter | Type | Description |
|---|---|---|
activity | Activity | The current return-link entry Activity |
uri | Uri? | Return URL whose HTTPS scheme, domain, and path your app has validated |
callback | (PaymentResult) -> Unit | Result callback for a rebuilt session; an active session keeps the original present callback |
Call configure first, using configuration consistent with the original payment. true means the SDK handled the link; it does not mean payment succeeded. false means the SDK did not handle it, and your order page must confirm the result with your server. Do not use status parameters in the URL to determine payment success.
Platform wallets
Google Pay app integration and production approval
Before enabling Google Pay, complete the Android app integration configuration and production approval.
- Manage your integration details in your Google Pay & Wallet Console, and confirm the business details and app ownership.
- Follow the Google Pay Android production guide to add your Android app, submit integration screenshots, and request production access.
- Confirm with Onerway that your Google Pay merchant and gateway configuration is active. The SDK uses the configuration returned by the server for the current order; the server supplies the gateway parameters.
- Verify on a physical device using a release-signed build, and complete Google's review and publishing requirements.
The current SDK uses the Google Pay production environment in PRODUCTION and the Google Pay test environment in SANDBOX. The Onerway SDK environment, merchant configuration, and Google app production access must all meet the requirements.
When the server includes Google Pay and the device passes the availability check, the SDK displays the official button. You do not need to implement wallet button submission or handle wallet tokens yourself.
Closing the Google Pay authorization page cancels only that wallet operation. Checkout remains open, and the SDK does not immediately invoke your callback. For testing and display requirements, see the Google Pay Android integration checklist.
Debugging, integration verification, and further references
Troubleshooting
| Symptom | What to check |
|---|---|
| Gradle cannot find the SDK | Whether the ZIP was fully extracted, the Maven URL points to the root containing com/, and the versions match |
| Duplicate classes or dependency conflicts | Run :app:dependencies and check for manually added duplicate dependencies |
| SDK is not initialized | Whether the Application class actually used by the app is registered in the Manifest and configure runs |
invalid_payment_id | Whether your server returns a valid paymentId, without extra spaces or truncation |
| Order fails to load | Whether paymentId was created in the environment selected by the SDK |
| Checkout opens more than once | Repeated taps on the payment button or repeated calls to present in onResume |
| No callback received | Whether the SDK result page is still open, the user returned to the original checkout, or the app restarted or the original session ended |
paymentStatus is null | Read reason.type and reason.code; the status is null for cancellations and errors |
| App Link does not open the app | Manifest, assetlinks.json, package name, signing certificate fingerprint, domain, and path |
| The app opens after a return but the order is not updated | Query the order from your server on your order page; do not rely on return URL parameters |
The optional recovery method returns false | Whether paymentId matches and the session has expired |
| Google Pay is not displayed | Backend configuration, physical device, wallet account, and merchant and gateway configuration |
When reporting an issue, provide the SDK version, app version, build type, masked paymentId, time of occurrence, Android version, reproduction steps, and reason.code. Do not send card numbers, CVV, full payment tokens, merchant keys, or unmasked user information.
Integration verification
Test at least: a normal payment; authentication success and cancellation; wallet cancellation; repeated taps; network interruptions; P/A/N results; unknown or null results; returning from an external redirect to the original session; confirming results from your order page after an app restart; repeated return handling; and Webhooks arriving more than once or before the client result.
For every scenario, check that the app and server order mappings agree, processing is deduplicated by merchant order, fulfillment for S waits for server confirmation, A is not treated as successful collection, and closing the page or a timeout is not incorrectly recorded as failure. Any transactionId returned to your app's business module must be the transaction identifier confirmed by your server. After testing, recheck App Links and native wallets using a release-signed build.
After an app interruption, restore the order and query the existing payment from your server before deciding whether to continue. Do not automatically resubmit while processing or when the result is unknown, and do not create a new order just because a page disappears.
Further scenarios and references
- Create an SDK transaction: Server-side fields and payment intent status definitions.
- Webhook notifications: Notification signature verification, acknowledgement, retries, and idempotency rules.
- Payment result notification: Standard payment results.
- Subscriptions: Server-side subscription flows. Do not trigger recurring charges from client success events.