Samsung Pay Integration Guide (Android)
This guide walks you through integrating Samsung Pay payments into your Android application using the Moyasar Android SDK. Samsung Pay support is provided by the Android SDK package and depends on Samsung's native Pay SDK.
Prerequisites
Before you begin, ensure you have:
- Moyasar account — Sign up if you haven't already
- Publishable API key — Get your API keys
- Samsung Developer Account — Create and configure your Samsung Pay service
- Moyasar Android SDK — the SDK publishes artifact coordinates; see Installation below
- Samsung Android device — Samsung Pay works only on Samsung devices (emulators and non-Samsung devices are not supported)
Samsung Pay Setup
Before integrating in your app, complete the Samsung Pay setup:
- Create a Samsung Developer Account and apply for Samsung Pay service
- Generate and download the CSR from Moyasar Dashboard → Settings → Samsung Certificate → Request CSR
- Create an InApp Online Payment service in Samsung Pay Service Management
- Register your Android app with the exact package name you will publish under
- Note your Service ID — you will need it in the SDK configuration
Once you complete integration and perform test payments, your Service ID needs to be approved by Samsung Pay. Contact Moyasar to assist with activation.
Installation
The SDK is published with groupId com.moyasar and artifactId android-sdk (the repository's library module includes Samsung Pay integration). As of this writing the SDK version in the repository is 1.0.12 — confirm the latest version in the Android SDK repository/releases before publishing.
Add the dependency to your app module build.gradle (Kotlin DSL shown):
dependencies {
implementation("com.moyasar:android-sdk:1.0.12")
}
Note: The Moyasar Android SDK bundles the Samsung Pay SDK JAR inside the library (libs/samsungpay_2.22.00.jar in the SDK project). You usually do not need to add the Samsung JAR separately.
Android Configuration
Both steps below are required for Samsung Pay to work on Android. Without them, the Samsung Pay button will not appear or the payment flow will fail.
1. Set Minimum SDK Version
Samsung Pay and the Moyasar SDK require a minimum SDK level. Ensure your app's minSdkVersion is at least 21. In app/build.gradle:
android {
defaultConfig {
minSdkVersion 21
}
}
Implementation
The Moyasar Android SDK exposes helper classes for Samsung Pay under the package com.moyasar.android.sdk.samsungpay (the SDK repository includes data.SamsungPayConfig, and presentation helpers such as SamsungPayFragment and SamsungPayManager). Construct a SamsungPayConfig with your Service ID and merchant details and use the SDK's presentation components to start the payment flow.
1. Configure SamsungPayConfig
Create the configuration object required by the SDK:
import com.moyasar.android.sdk.samsungpay.data.SamsungPayConfig
val samsungConfig = SamsungPayConfig(
serviceId = "YOUR_SAMSUNG_SERVICE_ID",
merchantName = "YOUR_STORE_NAME",
orderNumber = "ORDER-1234", // optional: max 36 chars, alphanumeric and hyphen
manual = false // true if you want manual capture (authorize-only)
)
Parameter notes:
serviceId: Your Samsung Pay Service ID from the Samsung Developer PortalmerchantName: Display name shown to the user during paymentorderNumber: Optional. Unique alphanumeric transaction ID (max 36 chars). If omitted the SDK generates one.manual: Set totruefor manual capture (authorize without charging)
2. Start the Samsung Pay Flow
The SDK provides presentation helpers in com.moyasar.android.sdk.samsungpay.presentation such as SamsungPayFragment and SamsungPayManager to start the payment UI and handle callbacks. Usage depends on your app architecture (Activity / Fragment). Example (high-level):
// The Android SDK provides Payment with Samsung-Pay:
Using the ready-made Fragment (SamsungPayFragment)
import com.moyasar.android.sdk.samsungpay.presentation.SamsungPayFragment
import com.moyasar.android.sdk.core.domain.entities.PaymentResult
val fragment = SamsungPayFragment.newInstance(application, paymentRequest) { paymentResult: PaymentResult ->
when (paymentResult) {
is PaymentResult.Success -> {
// Payment succeeded
}
is PaymentResult.Failed -> {
// Handle failure/cancellation
}
}
}
supportFragmentManager.beginTransaction()
.replace(R.id.your_container_id, fragment)
.commit()
Important: refer to the Android SDK source in sdk/src/main/java/com/moyasar/android/sdk/samsungpay/presentation for the precise API and callback types (the project provides SamsungPayFragment.kt and SamsungPayManager.kt).
Testing
Test Environment
- Use sandbox API keys (
pk_test_...) for testing - Test on a real Samsung Android device — emulators and simulators do not support Samsung Pay
- Add a real card to Samsung Wallet on your test device
Test Amounts
Samsung Pay testing uses amount-based simulation. Different amounts return different results (amounts shown in minor units — halalas for SAR):
| Amount (Minor Unit) | Amount (SAR) | Status | Response |
|---|---|---|---|
| 20000 to 30000 | 200.00 to 300.00 | paid | APPROVED |
| 100000 to 110000 | 1000.00 to 1100.00 | failed | UNSPECIFIED FAILURE |
| 110100 to 120000 | 1101.00 to 1200.00 | failed | INSUFFICIENT FUNDS |
| 120100 to 130000 | 1201.00 to 1300.00 | failed | DECLINED: LOST CARD |
| 130100 to 140000 | 1301.00 to 1400.00 | failed | DECLINED |
| 140100 to 150000 | 1401.00 to 1500.00 | failed | DECLINED: EXPIRED CARD |
See the full Samsung Pay Testing guide for all test amounts.
Use amounts between 20000–30000 (SAR 200–300) to simulate successful payments in the sandbox.
Running Example
See the Moyasar Android SDK repository for example apps.
Production Deployment
Before going live:
- Replace test API keys with live keys (
pk_live_...) - Ensure your package name matches the one registered in Samsung Pay
- Complete Samsung Pay service approval with Samsung
- Verify payment status on your backend for every transaction
- Test the full flow on a production Samsung device
Troubleshooting
| Issue | Solution |
|---|---|
| Samsung Pay UI not appearing | Ensure you're running on a Samsung device with Samsung Wallet installed and configured |
| "Service ID invalid" | Verify your Service ID in the Samsung Developer Portal and that your app's package name is registered |
| Payment fails immediately | Check that you're using the correct API key (test vs live) and that the amount is in the minor unit (halalas for SAR) |
| Build fails on Android | Ensure minSdkVersion is at least 21 and spay_sdk_api_level meta-data is present in AndroidManifest |
| Samsung Pay not available | Ensure you are using a recent version of the Moyasar Android SDK that includes Samsung Pay integration. |
Support
For integration help or Samsung Pay activation: