Retrieve a card list from the Samsung Wallet app

To confirm that the card the customer wants to enroll is not yet present in Samsung Wallet, use the getAllCards() method, provided by the CardManager (for the Samsung Pay SDK for Android) or SamsungPaySdkFlutter (for the Samsung Pay SDK for Flutter) class. As there is no need to call this method every time your app resumes, place the method within the onCreate() method rather than the onResume() method.

The getAllCards() method requests a list of all cards in the Samsung Wallet app on the same customer device where your app is running:

  1. Make sure you have checked the Samsung Pay status on the customer's device and the returned status is SPAY_READY.

  2. For the Samsung Pay SDK for Android only, create a CardManager instance with the same PartnerInfo object you used for checking the Samsung Pay status. The Samsung Pay SDK for Android uses the PartnerInfo object for caller verification.

  3. If you are using an API level earlier than 1.4, set your issuer name or names (depending on your app or the requirements of your token service provider) in a cardFilter (for the Samsung Pay SDK for Android) or EXTRA_ISSUER_NAME (for the Samsung Pay SDK for Flutter) parameter. The parameter narrows the card list returned by Samsung Wallet to the specified issuers only. Only complete matches are returned.

    Since the API level 1.4, the issuer names you have registered in the Samsung Pay Portal are automatically retrieved and the cardFilter parameter is ignored.

  4. Call the getAllCards() method. The result is delivered to the GetCardListener interface, which provides the following events:

    • onSuccess(): Called when the operation is successful and returns cardId, cardStatus, and extra cardInfo data for all filtered cards.
    • onFail(): Called when the operation fails.

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

Samsung Pay SDK for Android:

val cardFilter = Bundle()
// Since API level 1.4, cardFilter param is ignored.
// The data is retrieved from the Samsung Pay Portal
cardFilter.putString(CardManager.EXTRA_ISSUER_NAME, issuerName)
cardManager.getAllCards(null, object : GetCardListener{
    override fun onSuccess(cards: MutableList<Card>?) {
        // Getting card status succeeded
        if (cards == null || cards.isEmpty()) {
            Log.e(TAG, "No card is found")
            return
        } else {
            // Perform operations with card data
            for (s in cards) {
                Log.d(TAG, "CardId: " + s.cardId + "CardStatus " + s.cardStatus)
                // Get extra card data
                if (s.cardInfo != null) {
                    val cardId = s.cardId // Since API level 2.13, ID comes from the card network
                    val last4FPan = s.cardInfo.getString(CardManager.EXTRA_LAST4_FPAN)
                    val last4DPan = s.cardInfo.getString(CardManager.EXTRA_LAST4_DPAN)
                    val cardType = s.cardInfo.getString(CardManager.EXTRA_CARD_TYPE)
                    val cardIssuerName =
                        s.cardInfo.getString(CardManager.EXTRA_ISSUER_NAME)
                    Log.d(
                        TAG,
                        "last4FPan:$last4FPan last4DPan:$last4DPan CardId: $cardId"
                    )
                }
            }
        }
    }
    override fun onFail(errorCode: Int, errorData: Bundle?) {
        // Getting card status failed
    }
})

Samsung Pay SDK for Flutter:

samsungPaySdkFlutterPlugin.getAllCards(GetCardListener(onSuccess:(list){
      showCardList(list);
    }, onFail:(errorCode, bundle){
      showError(errorCode, bundle);
    }));