Skip to content

Samsung Pay

Gautam Chibde edited this page Sep 8, 2023 · 3 revisions

Prerequisite

Inside you AndroidManifest.xml file add the

<application
......
  <meta-data
    android:name="spay_sdk_api_level"
    android:value="2.18" /> // most recent SDK version is recommended to leverage the latest APIs
  ......
</application>

Android R OS(targetSdkVersion 30)

From Android R OS (if the target SDK version is 30), you must include the following element in the Android manifest.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" package="xxx.xxx.xxx.xxx">
  <queries>
    <package android:name="com.samsung.android.spay" />
    <package android:name="com.samsung.android.samsungpay.gear" /> 
  </queries>

Debug and Release mode

Apps configured for one of two modes can be registered in the Samsung Pay Developers site for the purpose of integrating Samsung Pay functionalities.

  • Debug mode – for testing and QA; requires debug key and allowed Samsung account(s) in build in order to test.
  • Release mode – for market release to end users; does not need a debug key or an allowed list of Samsung accounts in a Samsung-approved build to run.
Debug mode

To enable debug mode, you must add debug_mode and spay_debug_api_key to your AndroidManifest.xml file. The spay_debug_api_key is generated by the Samsung Pay Developers portal when you create a new In-App payments service. The spay_debug_api_key is valid for 90 days and can be updated on the Samsung Pay Developers portal.

<application
  ......
  <meta-data
    android:name="debug_mode"
    android:value="Y" />
  <meta-data
    android:name="spay_debug_api_key"
    android:value="debug api key from your samsung account" /> 
  ......
</application>
Release mode

To enable release mode, set debug_mode = N in your AndroidManifest.xml file.

With release mode enabled, your partner app is verified by its signature instead of a spay_debug_api_key, and there is no time limit.

<application
  ......
  <meta-data 
    android:name="debug_mode" 
    android:value="N" />
  ......
</application>

ProGuard rules

If your app(s) have any issue with ProGuard, the following rules are recommended:

dontwarn com.samsung.android.sdk.samsungpay.** 
-keep class com.samsung.android.sdk.** { *; } 
-keep interface com.samsung.android.sdk.** { *; }

When DexGuard is employed, the following additional rules apply:

-keepresourcexmlelements manifest/application/meta-data@name=debug_mode 
-keepresourcexmlelements manifest/application/meta-data@name=spay_debug_api_key 
-keepresourcexmlelements manifest/application/meta-data@name=spay_sdk_api_level

Samsung Pay example

To seamlessly integrate Samsung Pay into your Android app, you can utilize the Payment SDK for Android. This guide will walk you through the necessary steps to enable Samsung Pay as a payment option within your application.

Add the SDK Dependency

Begin by adding the payment SDK dependency to your project's build.gradle file.

implementation 'com.github.network-international.payment-sdk-android:payment-sdk-samsungpay:1.0.0'

Import the SDK and Implement the SamsungPayResponse Interface

Next, you'll need to import the payment SDK and implement the SamsungPayResponse interface in the class where you plan to initiate Samsung Pay payments. This interface will allow you to handle the payment responses effectively. By implementing this interface, your class will be able to respond to successful or failed Samsung Pay transactions.

Initiating the Samsung Pay Payment

To initiate a Samsung Pay payment, call the launchSamsungPay method with the necessary parameters, including the Order received from N-Genius and your merchant identifier.

import payment.sdk.android.PaymentClient

@WorkerThread
fun initiateSamsungPay(order: Order) {
    val paymentClient = PaymentClient(context = activity, serviceId = "your service id")
    val merchantName = "Your Merchant Name"
    paymentClient.launchSamsungPay(order = order, merchantName = merchantName, samsungPayResponse = this)
}

Ensure that you replace "Your Merchant Name" with your actual merchant name.

Handling Payment Responses

Once the Samsung Pay transaction is completed, you will receive the response in the callback methods: onSuccess() and onFailure(). These methods must be implemented in the same class where you implemented the SamsungPayResponse interface.

override fun onSuccess() {
    // Handle a successful Samsung Pay transaction here
    // You can update your UI or perform any necessary post-payment actions
}

override fun onFailure() {
    // Handle a failed Samsung Pay transaction here
    // You can display an error message to the user or take appropriate action
}

FAQ & Troubleshooting

Q: If the Samsung Pay app throws ERROR_NOT_ALLOWED (-6) / ERROR_UNABLE_TO_VERIFY_CALLER (-359), what needs to be checked on the partner app side?

In test mode:

  1. Verify that "debug_mode" is set as "Y" in your Android Manifest.
  2. Verify that your "spay_debug_api_key" is valid in Android Manifest. Go to the Samsung Pay Developers portal, sign in, and open your service details to check/retrieve the correct debug API key.
  3. Verify that your "spay_debug_api_key" has not expired.
  4. Verify that the "serviceId" is correct; make sure it was generated for the test mode and not for release.
  5. Verify that the “serviceType” is correct; make sure it is same as the value assigned by the Samsung Pay Developers portal when you create the service.
  6. Verify that the device’s Samsung Account is registered (allowed) under TEST ACCOUNTS in the service details.

For release:

  1. Verify that "debug_mode" is set as "N" in your Android Manifest.
  2. Verify that "spay_debug_api_key" is not defined in your Android Manifest (it must be an empty string or "").
  3. Verify that the "serviceId" is correct; make sure it was generated for release and not for the test mode.
  4. Verify that the “serviceType” is correct; make sure it is same as the value assigned by the Samsung Pay Developers portal when you create the service.
  5. Ask your Samsung Pay relationship manager (RM) to confirm that the status of your service is "Approved".

Q: I received an onSuccess() callback for a getAllCards() response but the card list is empty even though there already one or more installed cards in SamsungPay.

The most common reason for returning an empty card list is a mismatch between the issuer name registered on the Samsung Pay Developers portal and the actual issuer name for the card. If you cannot confirm the actual issuer name of the card, just enroll the card with SamsungPay and see its detail information. Below is a sample screen shot of the test card, with the issuer name highlighted in yellow.

Q: Why does the app display the message "The current version of this app isn't supported"?

To address this issue, it is necessary to upload the APK file of your app to the Samsung developer console by creating a new release version. Then, set one of the approved versions as the minimal version, which will establish the minimum required version for the app to function correctly.

Additionally, ensure that the app uploaded to the Samsung console has the same signature as the version uploaded to the Play Store. Samsung Wallet app utilizes the app's signature to verify its authenticity in release mode.

Q: Which Devices support Samsung Pay

The initial devices launched with Samsung Pay are listed on the supported devices page.