To request a payment using a custom payment sheet, use the startInAppPayWithCustomSheet() and updateSheet() methods, provided by either the PaymentManager class (for the Samsung Pay SDK for Android) or the SamsungPaySdkFlutter class (for the Samsung Pay SDK for Flutter):
startInAppPayWithCustomSheet() initiates the payment request with a custom payment sheet. The payment sheet persists for 5 minutes after you call the API. If the time limit expires, the transaction fails.
updateSheet() updates the current payment sheet, for example, after the customer has selected the card they want to use or modified their shipping address. As of API level 1.5, your app can also update the custom sheet with a custom error message. For more information, see Samsung Pay SDK for Android sample app.
To request payment:
Call the startInAppPayWithCustomSheet() method. Your custom payment sheet is displayed on your app screen and the customer can select a card in Samsung Wallet for payment and change the billing and shipping addresses, as necessary.
The customer can select their card, change the shipping or billing address, and authorize the payment.
The method result is delivered to the CustomSheetTransactionInfoListener interface, which provides the following events:
onCardInfoUpdated(): Called when the customer changes their payment card. Use the updateSheet() method in this callback to update the current payment sheet.
onSuccess(): Called when the payment request operation is successfully completed and Samsung Pay confirms the payment. This event returns the CustomSheetPaymentInfo object and the paymentCredential JSON string:
CustomSheetPaymentInfo is used for the current transaction. This object contains transaction details, such as amount, shippingAddress, merchantId, merchantName, and orderNumber. You can use the following methods within this callback to access transaction details:
getPaymentCardLast4DPAN(): Returns the last 4 digits of the customer's digitized personal/primary identification number (DPAN).
getPaymentCardLast4FPAN(): Returns the last 4 digits of the customer's funding personal/primary identification number (FPAN).
getPaymentCardBrand(): Returns the brand of the card used for the transaction.
getPaymentCurrencyCode(): Returns the ISO currency code in which the transaction is valued.
getPaymentShippingAddress(): Returns the shipping/delivery address for the transaction.
getPaymentShippingMethod(): Returns the shipping method for the transaction.
paymentCredential contains the payment credentials that you must deliver to your payment gateway (PG):
If your PG uses direct network tokens, paymentCredential is a JSON object containing an encrypted cryptogram which you can pass to the PG directly.
If your PG uses indirect gateway tokens, paymentCredential is a JSON object containing reference (token ID generated by the PG) and status (AUTHORIZED, PENDING, CHARGED, or REFUNDED).
onFailure(): Called when the payment request operation fails.
The following code snippet is an example of using the startInAppPayWithCustomSheet() and updateSheet() methods:
Samsung Pay SDK for Android:
/*
* CustomSheetTransactionInfoListener is for listening callback events of the custom sheet payment.
* This is invoked when the card is changed by the customer on the custom payment sheet,
* and with the success or failure of the payment request.
*/
private val transactionListener = object : CustomSheetTransactionInfoListener {
// This callback is received when the customer changes their card on the custom payment sheet in Samsung Pay
override fun onCardInfoUpdated(selectedCardInfo: CardInfo, customSheet: CustomSheet) {
/*
* Called when the customer changes their card in Samsung Pay.
* Newly selected cardInfo is passed so your app can update the transaction amount
* based on different card (if needed)
*/
val amountBoxControl =
customSheet.getSheetControl(AMOUNT_CONTROL_ID) as AmountBoxControl
amountBoxControl.updateValue(PRODUCT_ITEM_ID, 1000.0) //item price
amountBoxControl.updateValue(PRODUCT_TAX_ID, 50.0) // sales tax
amountBoxControl.updateValue(PRODUCT_SHIPPING_ID, 10.0) // Shipping fee
amountBoxControl.updateValue(PRODUCT_FUEL_ID, 0.0, "Pending") // additional item status
amountBoxControl.setAmountTotal(
1060.0,
AmountConstants.FORMAT_TOTAL_PRICE_ONLY
) // Grand total
customSheet.updateControl(amountBoxControl)
// Call updateSheet() with AmountBoxControl; mandatory
try {
paymentManager.updateSheet(customSheet)
} catch (e: java.lang.IllegalStateException) {
e.printStackTrace()
} catch (e: java.lang.NullPointerException) {
e.printStackTrace()
}
}
/*
* This callback is received when the payment is approved by the customer and the transaction payload
* is generated. Payload can be an encrypted cryptogram (network token) or the PG's token
* reference ID (gateway token).
*/
override fun onSuccess(response: CustomSheetPaymentInfo, paymentCredential: String, extraPaymentData: Bundle) {
/*
* Called when Samsung Pay creates the transaction cryptogram, which your app then sends
* to your server or PG to complete the payment
*/
try {
val DPAN = response.cardInfo.cardMetaData.getString(SpaySdk.EXTRA_LAST4_DPAN, "")
val FPAN = response.cardInfo.cardMetaData.getString(SpaySdk.EXTRA_LAST4_FPAN, "")
Toast.makeText(context, "DPAN: " + DPAN + "FPAN: " + FPAN, Toast.LENGTH_LONG).show()
} catch (e: java.lang.NullPointerException) {
e.printStackTrace()
}
Toast.makeText(context, "Transaction : onSuccess", Toast.LENGTH_LONG).show()
}
override fun onFailure(errorCode: Int, errorData: Bundle) {
// Called when an error occurs during cryptogram generation
Toast.makeText(context, "Transaction : onFailure : $errorCode", Toast.LENGTH_LONG)
.show()
}
}
private fun startInAppPayWithCustomSheet() {
// Show custom payment sheet
try {
val bundle = Bundle()
bundle.putString(
SamsungPay.PARTNER_SERVICE_TYPE,
SpaySdk.ServiceType.INAPP_PAYMENT.toString()
)
val partnerInfo = PartnerInfo(serviceId, bundle)
paymentManager = PaymentManager(context, partnerInfo)
// Request payment using Samsung Pay
paymentManager.startInAppPayWithCustomSheet(
makeCustomSheetPaymentInfo(),
transactionListener
)
} catch (e: IllegalStateException) {
e.printStackTrace()
} catch (e: NumberFormatException) {
e.printStackTrace()
} catch (e: NullPointerException) {
e.printStackTrace()
} catch (e: IllegalArgumentException) {
e.printStackTrace()
}
}
During the payment request operation, if an address is provided by Samsung Wallet, the onAddressUpdated() event is triggered whenever the customer updates the address information in the custom payment sheet. Use the updateSheet() method to update the shipping fee or any other relevant information in the payment sheet. Set the ErrorCode to signal whether the address provided by Samsung Wallet is invalid, out of delivery area, or does not exist.
For example, if you do not support product delivery to the designated location or the billing address from Samsung Wallet is not valid for tax recalculation, call the updateSheet() method with one of the following error codes:
We use cookies to improve your experience on our website and to show you relevant
advertising. Manage you settings for our cookies below.
Essential Cookies
These cookies are essential as they enable you to move around the website. This
category cannot be disabled.
Company
Domain
Samsung Electronics
developer.samsung.com, .samsung.com
Analytical/Performance Cookies
These cookies collect information about how you use our website. for example which
pages you visit most often. All information these cookies collect is used to improve
how the website works.
Company
Domain
Samsung Electronics
.samsung.com
Functionality Cookies
These cookies allow our website to remember choices you make (such as your user name, language or the region your are in) and
tailor the website to provide enhanced features and content for you.
Company
Domain
Samsung Electronics
developer.samsung.com, google.account.samsung.com
Preferences Submitted
You have successfully updated your cookie preferences.