JavaScript SDK
Shopify provides Shop Pay button and Shop Pay Login Web Components that you can add to your store.
Use the following code to load the script into your webpage from the CDN and embed the components.
Anchor to [object Object], parametersconfigure parameters
configure parameters| Parameter | Type | Description |
|---|---|---|
shopId | Number | A required parameter. This is the ID for the shop. The shopId (integer) can be retrieved from the shop object in the Admin API. |
clientId | String | A required parameter. This is the unique identifier for the client. The clientId is provided by Shopify. |
debug | Boolean | An optional parameter. When set to true, it enables debug mode, which will console log additional information that can be useful for development and troubleshooting. This should be omitted in production environments. |
onAnalyticsEvent | Function | An optional parameter. This is a callback function that will be invoked with specific Event objects. This can be useful for monitoring user interactions and gathering data. See below for supported events. |
locale | ShopPayLocale | An optional parameter. Specifies the desired locale for the checkout experience. Expects a valid ISO language code, optionally followed by an ISO country code. Defaults to English (en). For a list of supported locales, see the Supported Locales List section. |
discountCodeField | Boolean | An optional parameter. When set to false, the discount code input field is hidden on Shop Pay checkout. Defaults to true. |
Anchor to AnalyticsAnalytics
The following events are currently supported:
-
loginpromptdisplayed: This event is triggered when the Shop Pay login modal prompt is displayed. -
windowopened: This event is triggered when the Shop Pay popup checkout window is opened. -
windowclosed: This event is triggered when the Shop Pay popup checkout window is closed.Here's an example of how you might handle these events in your
onAnalyticsEventcallback:
Anchor to Shop Pay LoginShop Pay Login
Anchor to [object Object], parameterscreateLogin parameters
createLogin parameters| Parameter | Type | Description |
|---|---|---|
emailInputId | String | A required parameter. The unique identifier of the email input element to listen to. This is also used to anchor the login modal to an element. |
| Parameter | Type | Description |
|---|---|---|
buyWith | Boolean | An optional parameter. If true, displays the "Buy with" variant of the button. Defaults to false. |
Anchor to CSS PropertiesCSS Properties
| Name | Description | Constraints |
|---|---|---|
--shop-pay-button-width | The width of the button. | Default: 262px Minimum: 120px Minimum ( buy-with): 193px |
--shop-pay-button-height | The height of the button. | Default: 42px Minimum: 40px |
--shop-pay-button-border-radius | The border radius of the button. | Default: 4px |
The following example styles the button with the default height of 42 pixels, a width of 200 pixels, and a border radius of 0 pixels:
Upon invoking the .render method, the button is optimistically rendered while an HTTP request is dispatched to Shopify to check the availability of Shop Pay in the configured shop. If the Shopify Payments setup is incomplete or Shop Pay is deactivated in the payment settings, the button element is removed from the DOM.
Upon invoking the .render method, the button is optimistically rendered while an HTTP request is dispatched to Shopify to check the availability of Shop Pay in the configured shop. If the Shopify Payments setup is incomplete or Shop Pay is deactivated in the payment settings, the button element is removed from the DOM.
If you need to disable and re-enable the Shop Pay button for specific user interactions or other conditions in your application, you can use the following methods.
Example: Disable the Shop Pay button until a valid variant is selected