SDK Programming Guide
  • 3.3.1 Checking Samsung Pay status
  • Partner apps: Merchant, Issuer

    The first step in implementing the Samsung Pay SDK within your partner app is to create the SamsungPay instance and check Samsung Pay status on the device to determine its support for Samsung Pay (or lack thereof) and whether or not to display the Samsung Pay button to the user for selection as a payment option. The Samsung Pay button also lets issuer apps add a card to Samsung Pay. In both instances, the partner app must have valid PartnerInfo to pass to SamsungPay for caller verification.

    To set its PartnerInfo, the partner app passes its service ID (SID) and Service Type, both of which are assigned by the Samsung Pay Developers portal during onboarding. Used for checking blocked list and version control between the Samsung Pay SDK and Samsung Pay app, you must set their Service Type in PartnerInfo when calling any APIs.

    You must also set the API level they are using. See Understanding the Debug API Key and API Level for additional details.

  • Bundle bundle = new Bundle();
    bundle.putString(SamsungPay.PARTNER_SERVICE_TYPE, 
    SamsungPay.ServiceType.INAPP_PAYMENT.toString());
    		
    PartnerInfo partnerInfo = new PartnerInfo(serviceId, bundle);
    
    • Note
    • The SID should not be confused with the App ID; the two are mutually distinct.
  • After setting PartnerInfo, the partner app can now call getSamsungPayStatus(). This method of the SamsungPay class must be called before using any other feature in the Samsung Pay SDK.
  • void getSamsungPayStatus(StatusListener callback)
    
  • The result is delivered to StatusListener, and provides the following events:
    • onSuccess() - Called when the requested operation is successful. It provides the status of the request, as well as extra bundle data related to the request.
    • onFail() - Called when the request operation fails. It returns the error code and extra bundle data related to the request.
  • The Samsung Pay status code returned will be one of the following:
    • SPAY_NOT_SUPPORTED - indicates Samsung Pay is not supported on this device; typically returned if the device is incompatible with Samsung Pay or if the Samsung Pay app is not installed.
    • SPAY_NOT_READY - indicates Samsung Pay is not completely activated; usually returned if the user did not complete a mandatory update or if the user has not signed in with a valid Samsung Account. In which case, the partner app can activate or update the Samsung Pay app on the device per the EXTRA_ERROR_REASON bundle keys below.
    • ERROR_SPAY_SETUP_NOT_COMPLETE - tells the partner app to display an appropriate popup message to the user while calling activateSamsungPay() to activate Samsung Pay app.
    • ERROR_SPAY_APP_NEED_TO_UPDATE - tells the partner app to display an appropriate popup message to the user and call goToUpdatePage() to open the update page.
    • ERROR_PARTNER_SDK_API_LEVEL - tells the partner app it has an error about API level. To resolve the error condition, the partner app must set a valid API level.
    • ERROR_PARTNER_SERVICE_TYPE - tells the partner app it did not set Service Type or the Service Type it did set is invalid. Service Type is set in PartnerInfo.
    • SPAY_READY - indicates that Samsung Pay is activated and ready to use; typically returned after the user completes all mandatory updates and signs in.
    • Extra bundle data can have the following values:
    • EXTRA_COUNTRY_CODE - for both onSuccess() and onFailure(), this is the current device’s country code (ISO 3166-1 alpha-2) set by Samsung Pay. If the partner app is not supported in this particular country, the partner app can decide not to display Samsung Pay button.
    • EXTRA_ERROR_REASON - for onFailure(), this is the reason for failure set by Samsung Pay.
  • When the returned status code is SPAY_READY, the partner app can safely display the Samsung Pay button for user selection as a payment option, card provisioning, et al.
  • Sample code showing how to use the getSamsungPayStatus() API method looks like this:
  • Bundle bundle = new Bundle();
    bundle.putString(SamsungPay.PARTNER_SERVICE_TYPE, SamsungPay.ServiceType.INAPP_PAYMENT.toString());
    PartnerInfo partnerInfo = new PartnerInfo(serviceId, bundle);
    
    SamsungPay samsungPay = new SamsungPay(context, partnerInfo);
    /*
     * Method to get the Samsung Pay status on the device.
     * Partner (Issuers, Merchants, Wallet providers, and so on) applications must call this Method to
     * check the current status of Samsung Pay before doing any operation.
     */
    samsungPay.getSamsungPayStatus(new StatusListener() {
        @Override
        public void onSuccess(int status, Bundle bundle) {
            switch (status) {
    				case SamsungPay.SPAY_NOT_SUPPORTED: 
    						// Samsung Pay is not supported
    						samsungPayButton.setVisibility(View.INVISIBLE);
    						break;
    				case SamsungPay.SPAY_NOT_READY: 
    						// Activate Samsung Pay or update Samsung Pay, if needed
    						samsungPayButton.setVisibility(View.INVISIBLE);
    						break;
    				case SamsungPay.SPAY_READY: 
    						// Samsung Pay is ready
    						samsungPayButton.setVisibility(View.VISIBLE);
    						break;
    				default: 
    						// Not expected result
    						samsungPayButton.setVisibility(View.INVISIBLE);
    						break;
    		     }
        }
    
        @Override
        public void onFail(int errorCode, Bundle bundle) {
    			samsungPayButton.setVisibility(View.INVISIBLE);
    			Log.d(TAG, "checkSamsungPayStatus onFail() : " + errorCode);
        }
    });