Add Samsung Pay button to the Clover iframe

North America—United States and Canada

Your merchants can accept payments through Samsung Pay® using the Clover iframe integrations on their ecommerce websites. For general details on supported transaction types, merchant eligibility, and payment flow, see Samsung Pay integration for Clover Ecommerce.

Prerequisites

  1. Set up the Clover iframe payment form—Complete the steps to create a payment form and include the Clover iframe SDK in your webpage:
    • Sandbox: https://checkout.sandbox.dev.clover.com/sdk.js
    • Production: https://checkout.clover.com/sdk.js
  2. Check supported browsers—Samsung Pay is compatible with most modern browsers, except Mozilla Firefox.

Add a button for Samsung Pay transactions

  1. On the Clover iframe, use the paymentRequestButton element (PAYMENT_REQUEST_BUTTON_SAMSUNG_PAY) to add a button for Samsung Pay transactions.
  2. Add a <div> container for the button in your HTML (for example, <div id="payment-request-button-samsung-pay"></div>) and define its dimensions in CSS:
    • Values for max-width and max-height are controlled by the <div> container where you mount the button (for example, width: 300px; height: 60px;).
  3. Initialize the Clover SDK with your public key and merchantId, define samsungPayRequestData, and create and mount the PAYMENT_REQUEST_BUTTON_SAMSUNG_PAY element:
// Initialize Clover SDK
const clover = new Clover('{YOUR_PAKMS_PUBLIC_KEY}', {
  merchantId: '{YOUR_MERCHANT_ID}'
});
const elements = clover.elements();

// Configure initial Samsung Pay request data
const initialAmount = document.getElementById('amount').value || '1';

const samsungPayRequestData = {
  orderNumber: '{ORDER_NUMBER}',
  merchant: {
    name: 'Virtual Shop',
    url: 'virtualshop.com',
    id: '{SAMSUNG_MERCHANT_ID}',
    countryCode: 'US'
  },
  amount: {
    option: 'FORMAT_TOTAL_ESTIMATED_AMOUNT',
    currency: 'USD',
    total: initialAmount
  },
  options: {
    totalPriceStatus: 'ESTIMATED',
    buttonStyle: 'black',
    environment: 'PRODUCTION'
  }
};

// Create PAYMENT_REQUEST_BUTTON_SAMSUNG_PAY and mount to <div> container
const samsungPaymentRequestButton = elements.create('PAYMENT_REQUEST_BUTTON_SAMSUNG_PAY', {
  samsungPayRequestData
});
samsungPaymentRequestButton.mount('#payment-request-button-samsung-pay');
  1. (Optional) If the payment amount changes during the checkout session, call clover.updatePaymentRequest() with the updated samsungPayRequest:
const handleInputChange = (event) => {
  const newAmountRaw = event.target.value;

  clover.updatePaymentRequest({
    samsungPayRequest: {
      ...samsungPayRequestData,
      amount: {
        ...samsungPayRequestData.amount,
        total: newAmountRaw
      }
    }
  });
};

document.getElementById('amount').addEventListener('input', handleInputChange);

Handle Samsung Pay events

Attach event listeners to the samsungPaymentRequestButton element to manage the Samsung Pay payment flow and update the payment status:

samsungPaymentRequestButton.addEventListener('paymentMethodStart', (ev) => {
  console.log(ev);
});

samsungPaymentRequestButton.addEventListener('paymentMethod', (ev) => {
  console.log(ev);
});

samsungPaymentRequestButton.addEventListener('paymentMethodEnd', (ev) => {
  console.log(ev);
  clover.updateSamsungPaymentStatus('REJECTED');
});

The addEventListener method supports the following events:

  • paymentMethodStart: Fires when the Samsung Pay payment flow starts.
  • paymentMethod: Fires when the customer approves the payment and returns payment information.
  • paymentMethodEnd: Fires when the Samsung Pay flow ends. Use clover.updateSamsungPaymentStatus() to report the resulting payment status (for example, 'REJECTED').

Complete HTML example

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" allow="payment">
    <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    <title>Clover iframe Samsung Pay</title>

    <script src="https://checkout.sandbox.dev.clover.com/sdk.js"></script>
    <style>
      body {
        background-color: #192130;
        margin: 0 auto;
        width: 300px;
        font-family: Roboto, "Open Sans", sans-serif;
      }

      .container {
        background-color: #FFFFFF;
        border-top-left-radius: 15px;
        border-top-right-radius: 15px;
        box-shadow: 0 0 6px 0 rgba(141, 151, 158, 0.2);
        padding: 24px;
      }

      .container * {
        font-size: 16px;
      }

      #payment-request-button-samsung-pay {
        width: 300px;
        height: 60px;
        margin: 0 auto;
        padding-bottom: 12px;
      }

      @media (min-width: 300px) {
        body {
          width: auto;
        }
      }
    </style>
  </head>
  <body>
    <div class="container">
      <input id="amount" type="number" placeholder="Enter amount here" value="1" />
      <div id="payment-request-button-samsung-pay"></div>
    </div>

    <script>
      // Initialize Clover SDK
      const clover = new Clover('{YOUR_PAKMS_PUBLIC_KEY}', {
        merchantId: '{YOUR_MERCHANT_ID}'
      });
      const elements = clover.elements();

      // 1. Initial state configuration
      const initialAmount = document.getElementById('amount').value || '1';

      const samsungPayRequestData = {
        orderNumber: '{ORDER_NUMBER}',
        merchant: {
          name: 'Virtual Shop',
          url: 'virtualshop.com',
          id: '{SAMSUNG_MERCHANT_ID}',
          countryCode: 'US'
        },
        amount: {
          option: 'FORMAT_TOTAL_ESTIMATED_AMOUNT',
          currency: 'USD',
          total: initialAmount
        },
        options: {
          totalPriceStatus: 'ESTIMATED',
          buttonStyle: 'black',
          environment: 'PRODUCTION'
        }
      };

      // 2. Element mount
      const samsungPaymentRequestButton = elements.create('PAYMENT_REQUEST_BUTTON_SAMSUNG_PAY', {
        samsungPayRequestData
      });
      samsungPaymentRequestButton.mount('#payment-request-button-samsung-pay');

      // 3. Amount update
      const handleInputChange = (event) => {
        const newAmountRaw = event.target.value;

        clover.updatePaymentRequest({
          samsungPayRequest: {
            ...samsungPayRequestData,
            amount: {
              ...samsungPayRequestData.amount,
              total: newAmountRaw
            }
          }
        });
      };

      // 4. Event listeners
      document.getElementById('amount').addEventListener('input', handleInputChange);

      samsungPaymentRequestButton.addEventListener('paymentMethod', (ev) => console.log(ev));
      samsungPaymentRequestButton.addEventListener('paymentMethodStart', (ev) => console.log(ev));
      samsungPaymentRequestButton.addEventListener('paymentMethodEnd', (ev) => {
        console.log(ev);
        clover.updateSamsungPaymentStatus('REJECTED');
      });
    </script>
  </body>
</html>

Related topics


Did this page help you?