Check the Samsung Pay status

To check the Samsung Pay status:

  1. Create a PartnerInfo or SamsungPaySdkFlutter object.
  2. Call the getSamsungPayStatus() method.

The status check includes various actions on the Samsung Wallet app and the Samsung Pay server:

  • With the Samsung Wallet app:
    • The SDK checks whether the Samsung Wallet app is installed on the device and Samsung Pay is supported.
    • The SDK checks whether the Samsung Wallet app setup is complete, whether the app needs an update, and whether the Samsung Pay-related SDK API level used in your app is compatible with the Samsung Wallet app version.
  • With the Samsung Pay server:
    • The SDK checks whether your app details - app name, service ID, and certificate signing request (CSR) - match their registration on the Samsung Pay Portal.

Step 1: Create a PartnerInfo or SamsungPaySdkFlutter object

Configure a valid PartnerInfo (for the Samsung Pay SDK for Android) or SamsungPaySdkFlutter (for the Samsung Pay SDK for Flutter) object. Samsung Pay uses this object for:

  • Validating the app’s identity and registration
  • Performing SDK version and API compatibility checks
  • Verifying the allowlist/blocklist status

To create the PartnerInfo or SamsungPaySdkFlutter object:

  1. Include the following in the PartnerInfo or SamsungPaySdkFlutter object:

    • serviceId (SID): Unique ID for the service created during partner onboarding.

    • ServiceType: Type of service created during partner onboarding.

    Samsung Pay SDK for Android:

    val serviceId = "partner_app_service_id"
    val bundle = Bundle()
    bundle.putString(SamsungPay.PARTNER_SERVICE_TYPE, SamsungPay.ServiceType.INAPP_PAYMENT.toString())
    val partnerInfo = PartnerInfo(serviceId, bundle)
    

    Samsung Pay SDK for Flutter:

    String serviceId;
    Map<String,dynamic> data;
    static final samsungPaySdkFlutterPlugin = SamsungPaySdkFlutter(PartnerInfo(serviceId: 'partner_app_service_id', data: {SpaySdk.PARTNER_SERVICE_TYPE:ServiceType.APP2APP.name.toString()}));
    
  2. For the Samsung Pay SDK for Android only, you also need to create a SamsungPay instance with the PartnerInfo object:

    Samsung Pay SDK for Android:

    val samsungPay = SamsungPay(context, partnerInfo)
    

Step 2: Call the getSamsungPayStatus() method

Call the getSamsungPayStatus() method, provided by the SamsungPay (for the Samsung Pay SDK for Android) or SamsungPaySdkFlutter (for the Samsung Pay SDK for Flutter) class, to check whether Samsung Pay is available and ready for use on the device.

The getSamsungPayStatus() operation result is delivered to the StatusListener interface, which provides the following events:

  • onSuccess(): Called when the operation is successful. The listener returns the Samsung Pay status, as well as extra bundle data related to the request. The possible statuses are:

    • SPAY_READY: Samsung Pay is activated and ready to use. You can display the Samsung Pay button.

    • SPAY_NOT_SUPPORTED: Samsung Pay is not supported on this device; either the device is incompatible or the Samsung Wallet app is not installed.

    • SPAY_NOT_READY: Samsung Pay is not completely activated. Check the returned bundle date for the EXTRA_ERROR_REASON key and take appropriate action:

      • ERROR_SPAY_SETUP_NOT_COMPLETE: Samsung Pay setup is not complete. Display a pop-up message and ask the customer whether they want to activate Samsung Pay. If yes, call the activateSamsungPay() method to activate Samsung Pay.
      • ERROR_SPAY_APP_NEED_TO_UPDATE: Samsung Wallet app requires an update. Display a pop-up message and ask the customer whether they want to update the Samsung Wallet app. If yes, call the goToUpdatePage() method to update the Samsung Wallet app.
      • ERROR_PARTNER_INFO_INVALID: Partner app information is invalid, using an invalid SDK version, service type, or API level:
        • ERROR_PARTNER_SDK_API_LEVEL: Your app is using the wrong API level. To resolve the error, set a valid API level in your app.
        • ERROR_PARTNER_SERVICE_TYPE: Your app has either not set a ServiceType value in the PartnerInfo or SamsungPaySdkFlutter object, or the ServiceType value is invalid. To resolve the error, set a valid service type in the object.
  • onFail(): Called when the operation fails. The listener returns the error code, as well as extra bundle data with the EXTRA_ERROR_REASON key, defining the reason for the failure.

The following code snippet is an example of using the getSamsungPayStatus() method:

Samsung Pay SDK for Android:

val serviceId = "partner_app_service_id"
val bundle = Bundle()
bundle.putString(SamsungPay.PARTNER_SERVICE_TYPE, SamsungPay.ServiceType.INAPP_PAYMENT.toString())
val partnerInfo = PartnerInfo(serviceId, bundle)
val samsungPay = SamsungPay(context, partnerInfo)
/*
 * Method to get the Samsung Pay status on the device.
 * Partner apps must call this method to
 * check the current status of Samsung Pay before any other operations.
 */
samsungPay.getSamsungPayStatus(object : StatusListener {
    override fun onSuccess(status: Int, bundle: Bundle) {
        when (status) {
            SamsungPay.SPAY_NOT_SUPPORTED ->
                // Samsung Pay is not supported
                samsungPayButton.setVisibility(View.INVISIBLE)

            SamsungPay.SPAY_NOT_READY -> {
                // Activate or update Samsung Pay, as needed
                samsungPayButton.setVisibility(View.INVISIBLE)
                val errorReason = bundle.getInt(SamsungPay.EXTRA_ERROR_REASON)
                if (errorReason == SamsungPay.ERROR_SETUP_NOT_COMPLETED) {
                    // Display an appropriate popup message to the user
                    samsungPay.activateSamsungPay()
                } else if (errorReason == SamsungPay.ERROR_SPAY_APP_NEED_TO_UPDATE) {
                    // Display an appropriate popup message to the user
                    samsungPay.goToUpdatePage()
                } else {
                    Toast.makeText(context, "error reason: $errorReason", Toast.LENGTH_LONG).show()
                }
            }

            SamsungPay.SPAY_READY ->
                // Samsung Pay is ready
                samsungPayButton.setVisibility(View.VISIBLE)

            else ->
                // Unexpected result
                samsungPayButton.setVisibility(View.INVISIBLE)
        }
    }

    override fun onFail(errorCode: Int, bundle: Bundle) {
        samsungPayButton.setVisibility(View.INVISIBLE)
        Log.d(TAG, "checkSamsungPayStatus onFail() : $errorCode")
    }
})

Samsung Pay SDK for Flutter:

MyHomePage.samsungPaySdkFlutterPlugin.getSamsungPayStatus(StatusListener(onSuccess:(status, bundle) async {

    showStatus(status, bundle);
  
  }, onFail:(errorCode, bundle){
  
    showError(errorCode, bundle);
  
  }));