Process the payment data

Once the customer approves the payment request by verifying the selected payment method and, if applicable, the shipping option, the show() method's promise resolves and returns a PaymentResponse object, which includes the following fields:

  • methodName: String indicating the selected payment method
  • details: Object containing Samsung Pay–specific payment and credential data
  • shippingAddress: Customer's shipping address, if requested
  • shippingOption: Identifier of the selected shipping option, if requested
  • payerEmail: Payer’s email address, if requested
  • payerPhone: Payer’s telephone number, if requested
  • payerName: Payer’s name, if requested

Samsung Pay payment details

For Samsung Pay transactions, the payment data is included in the PaymentResponse.details object, which contains the following child objects:

  • paymentCredential object contains the payment credential data required by the payment gateway (PG) to authorize and process the transaction.

    In the network token mode, the paymentCredential object contains the following fields:

    • type: Credential type. For Samsung Pay network tokens, this value is always "S".
    • version: Authentication payload schema version. This value is set to 1.0.0, which corresponds to the standard 3D Secure authentication data format used by card networks (for example, Mastercard SecureCode, Verified by Visa, and American Express SafeKey).
    • data: Encrypted payload value.

    In the gateway token mode, the paymentCredential object contains the following fields:

    • reference: Token ID reference.
    • status: Transaction status, such as authorized or rejected.
  • paymentInfo object contains additional payment-related information, including:

    • card_last4digits: Last 4 digits of the card’s DPAN.

    • cardBrand: Card brand, such as MasterCard or Visa.

    • orderNumber: Merchant-defined external reference ID provided in the request.

    • billingAddress object contains the cardholder’s billing address and related attributes, which can include:

      • country: ISO 3166 alpha-2 country code (uppercase), for example, "US".
      • addressLine[n]: One or more address lines representing the most specific parts of the address, such as street name, house number, apartment number, or post office box.
      • region: Top-level administrative subdivision, such as a state or province.
      • city: City or town.
      • dependentLocality: Sublocality within a city, such as a neighborhood or district.
      • postalCode: Postal or ZIP code.
      • sortingCode: Bank sorting code, where applicable.
      • languageCode: BCP 47 language tag indicating the language used to format the address.
      • organization: Organization or company name at the address.
      • recipient: Name of the recipient or contact person.
      • phone: Phone number of the recipient or contact person.

Completing the payment flow

Once payment information is received from Samsung Pay, submit the data to the PG in accordance with the PG's integration mode and APIs. For network token integrations, you can directly pass the encrypted payload to the PG, which handles decryption as part of its processing flow. The exact handling of network tokens varies by PG. Refer to your PG’s documentation for specific requirements.

While the payment is being processed by your PG, display a loading indicator to inform the customer that the transaction is in progress. Once a response is received from the PG, call the complete() method to close the payment UI. The website can then display an order confirmation or order completion page.

The following code snippet is an example of the returned payment data and the completion of the payment flow:

request.show().then(paymentResponse => {
  var paymentData = {
    // Payment method string, e.g. "amex"
    method: paymentResponse.methodName,
    // Payment details contain payment information
    details: paymentResponse.details
    /* Request details depends on PG token mode (network - e.g., First Data; or gateway - e.g., Stripe
    ---------------------------------------------------------|------------------------------------------------------|
    * GATEWAY TOKEN MODE                                     |* NETWORK TOKEN MODE                                  |
    * "details":{                                            |*   "details:{                                        |
    *   "paymentCredential": {                               |*     "method": "3DS",                                |
    *     "reference": "tok_1ASCEoYF6yPzJ7F8SE6GRP0i",       |*     "paymentCredential": {                          |
    *     "status": "AUTHORIZED"                             |*     "type": "S",                                    |
    *   },                                                   |*     "version": "100",                               |
    *                                                        |*     "data": "long_encrypted_payload_value",         |
    *                                                        |*   },                                                |
    *--------------------------------------------------------|------------------------------------------------------|
    *   "paymentInfo": {
    *     "card_last4digits": "1489",
    *     "cardBrand": "mastercard",
    *     "orderNumber": "1233123",
    *     "billingAddress": {
    *       "country": "USA",
    *       "addressLine": ["Chhccy", "Hdyxych"],
    *       "region": "CA",
    *       "city": "Mountain View",
    *       "dependentLocality": "",
    *       "postalCode": "94043",
    *       "sortingCode": "",
    *       "languageCode": "en",
    *       "organization": "",
    *       "recipient": "",
    *       "phone": ""
    *     }
    *   }
    * }
    *
    */
  };
  return fetch('/validatePayment', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json'
    },
  body: JSON.stringify(paymentData)
  }).then(res => {
    if (res.status === 200) {
      return res.json();
    } else {
      throw 'Payment Error';
    }
  }).then(res => {
    paymentResponse.complete("success");
  }, err => {
    paymentResponse.complete("fail");
  });
  }).catch(err => {
  console.error("Error, something went wrong", err.message);
});