Browser client reference
Load PaymentElements, 3D Secure, Apple Pay, and Google Pay on your page with one Preczn script tag.
Load Preczn's browser resources, such as PaymentElements, Apple Pay, Google Pay, and 3D Secure, with one script tag. The loader, preczn.min.js, reads its query string, checks your public API key, and adds a script element for each resource you name to your page's head.
This page describes the loader only. To use a resource after it loads, see its guide in the Resources section.
Script URL
Add the loader to your page's head:
<script src="https://api.preczn.com/v1/clients/preczn.min.js?resources=paymentelements&publicApiKey=pub_test_xxxxxxxxxxxxxxxx"></script>Test mode and Live mode use the same URL. The publicApiKey you pass decides the mode: a key that starts with pub_test_ works in Test mode, and a key that starts with pub_ works in Live mode. See Live vs. test mode.
Query parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
resources | String | Optional | paymentfields,applepay | A comma-separated list of resources to load. Each value must be one in the Resources table. Values are case-insensitive, spaces around a value are ignored, and a repeated value loads once. |
publicApiKey | String | Required | None | An active public API key, such as pub_test_xxxxxxxxxxxxxxxx. A private key fails. See API keys. |
merchantId | String | Required when resources includes applepay or googlepay | None | The ID of the merchant the page takes payments for. The merchant must belong to the same platform as publicApiKey. Resources that don't need it ignore it. |
Always set
resourcesIf you omit
resources, the loader usespaymentfields,applepay. That loads the deprecated PaymentFields script and Apple Pay, somerchantIdbecomes required.
Resources
| Value | Loads | Requires merchantId | Guide |
|---|---|---|---|
paymentelements | PaymentElements, as Preczn.PaymentElements | No | Collect payment details with PaymentElements |
3ds | The 3D Secure challenge client, as Preczn.ThreeDSecure | No | Add 3D Secure to checkout |
applepay | The Apple Pay client, as Preczn.ApplePay. It also loads Apple's Apple Pay JavaScript SDK when your page doesn't already include it. | Yes | Accept Apple Pay |
googlepay | The Google Pay client, as Preczn.GooglePay | Yes | Accept Google Pay |
paymentfields | The deprecated PaymentFields script, as Preczn.PaymentFields. Use paymentelements for new integrations. | No | None |
Load several resources
To load several resources with one script tag, list them in resources, separated by commas. Pass merchantId when the list includes applepay or googlepay.
The following tag loads PaymentElements, 3D Secure, Apple Pay, and Google Pay:
<script src="https://api.preczn.com/v1/clients/preczn.min.js?resources=paymentelements,3ds,applepay,googlepay&publicApiKey=pub_test_xxxxxxxxxxxxxxxx&merchantId=mid_test_xxxxxxxxxxxxxxxx"></script>Replace pub_test_xxxxxxxxxxxxxxxx with your public API key and mid_test_xxxxxxxxxxxxxxxx with the merchant's ID.
The loader adds one script element for each resource to the page's head, in the order you list them. Each element has an integrity attribute with a SHA-512 hash and crossorigin="anonymous", so the browser runs the script only if its content matches the hash.
Cache-busting
The loader adds a ts query parameter to every resource URL it writes. Its value is the time Preczn served the loader, in milliseconds since the Unix epoch. Each page load gets a new value, so the browser fetches current copies of each resource. You don't set ts yourself.
Loader errors
If any check fails, the loader loads no resources. Instead, it throws an error in the browser console that starts with Errors occurred loading the Preczn client: and lists each problem:
| Message | Cause |
|---|---|
Invalid API Key | publicApiKey is missing, isn't a public key, or isn't active. |
Invalid Merchant ID | resources includes applepay or googlepay, and merchantId is missing, doesn't match a merchant, or belongs to another platform. |
Unsupported resource(s): <values> | resources includes a value that isn't in the Resources table. |
Updated 8 days ago
