# Elements SDK

### Quick demo

Check out our demo page to see the flow in action.

{% embed url="<https://js.sandbox.sensepass.com/sp-ecom-elements-sdk.html>" %}

{% hint style="info" %}
This is a checkout page example with the Elements SDK.
{% endhint %}

***

<figure><img src="https://3556089516-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbqMA3Kf8t2xEX9F6y9%2Fuploads%2Fb8I4i09dwSOcai0I4ANy%2Fd36c90c66e21916818bbba6bd75d17a0f5165ffe3da1ad99a0ef7cef5a67a6ce.jpg?alt=media&#x26;token=30fb3681-4d06-4f59-a1a2-41ac678c9266" alt="" width="375"><figcaption></figcaption></figure>

### Configuration

{% hint style="info" %}
You can copy-paste the (relevant) following HTML code to your checkout page to get going.

* Note that the current widget configuration is set up to use the mock client-id - and replace it with yours.
  {% endhint %}

{% code lineNumbers="true" expandable="true" %}

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SensePass Elements SDK</title>
    <!-- Set the SensePass SDK script -->
    <script src="https://js.sensepass.com/scripts/sensepass-front-end@1.1.1.sdk.js"></script>
</head>
<body style="width: 25rem; margin: 0 auto">
    <!-- Top Payment Button -->
    <button id="primary-payment-button" onclick="handlePaymentButtonClick()">Complete Payment (primary)</button>
    <!-- SensePass Elements Container -->
    <div id="sensepass-front-end"></div>
    <!-- Bottom Payment Button -->
    <button id="secondary-payment-button" onclick="handlePaymentButtonClick()">Complete Payment (secondary)</button>
    <script>
        // Configure the SDK
        const spClient = SensePassFrontEndSDK.config({
            mode: "sandbox", // "sandbox" | "production"
            debug: true,
            clientId: "SensePassSDKGeneralClientId",
            methodType: "manual_capture", // "manual_capture" | "authorize" | "tokenize"
            theme: {
                paymentMethodGrid: "vertical" // "horizontal" | "vertical" | "vertical-b"
            },
            payButtonId: ['primary-payment-button', 'secondary-payment-button'], // Array of button IDs
        });
        // Initialize the SDK
        const sensepass = spClient.init();
        // Event: Payment method selected
        sensepass.paymentSelected(payload => console.log('Payment method selected:', payload));
        // Event: Payment in progress
        sensepass.paying(payload => console.log('Payment in progress:', payload));
        // Event: Payment method validation status
        sensepass.paymentMethodValidationStatus(payload => console.log('Payment validation status:', payload));
        // Event: Error occurred
        sensepass.error(payload => console.error('SDK Error:', payload));

        function handlePaymentButtonClick() {
            // Call the pay method when button is clicked
            sensepass.pay(payload => console.log('Payment result:', payload),
                {
                    amount: 1299, // Amount in cents (12.99 USD)
                    currency: "USD",
                    billingAddress: {
                        city: "New York",
                        email: "demo@example.com",
                        firstName: "John",
                        lastName: "Doe",
                        street: "123 Demo St",
                        state: "NY",
                        zipcode: "10001",
                        mobilePhone: "5551234567",
                        country: "US"
                    }
                }
            );
        }
    </script>
</body>
</html>
```

{% endcode %}

***

### Payment Data

{% hint style="info" %}
Example of the SDK's "pay" callback payload (sets the payment for commit)
{% endhint %}

{% code lineNumbers="true" expandable="true" %}

```json
{
  "TransactionNumber": "7f943e53476a3efcc263d0f975a01c45a6118fc55852efde8dad7227",
  "status": 20
}
```

{% endcode %}

### Customization

{% hint style="info" %}
This code sample demonstrates how to customize the appearance of the Elements Widget's payment buttons/elements. \
Set this object in our SDK configuration to apply your custom theme.

Download and edit the following themes you wish to style on your own:

1. Material theme: <https://pay.sandbox.sensepass.com/publicAssets/themes/material.theme.css>
2. SensePass theme: [https://pay.sandbox.sensepass.com/publicAssets/themes/ecommerce.theme.css](https://pay.sandbox.sensepass.com/publicAssets/themes/material.theme.css)
3. Save your themes in a hosting site of your choosing and set their URL in the config JSON.
4. Use the [SDK Theme Config Model](https://docs.sensepass.com/sensepay/transaction-api/models/sdk-theme-config-model) to set you custom text and other UI configurations.
   {% endhint %}

{% code lineNumbers="true" %}

```javascript
SensePassFrontEndSDK.config({
   // ...,
   theme: { // optional theme for various packages
	/** angular material provides extensive documentation on customizing their theme
	* you can find it at: https://material.angular.io/guide/theming */
	material: "https://pay.sandbox.sensepass.com/publicAssets/themes/custom-sample-material.theme.css", // sample for a customized material theme
	sensepassEcommerce: "https://pay.sandbox.sensepass.com/publicAssets/themes/custom-sample-ecommerce.theme.css", // sample for a customized sensepass theme
	paymentMethodGrid: "horizontal", // horizontal | vertical style of the payment options
	config: {} // a configuration object for specific payment methods text/animations
   }
})
```

{% endcode %}
