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

ParameterTypeRequiredDefaultDescription
resourcesStringOptionalpaymentfields,applepayA 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.
publicApiKeyStringRequiredNoneAn active public API key, such as pub_test_xxxxxxxxxxxxxxxx. A private key fails. See API keys.
merchantIdStringRequired when resources includes applepay or googlepayNoneThe 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 resources

If you omit resources, the loader uses paymentfields,applepay. That loads the deprecated PaymentFields script and Apple Pay, so merchantId becomes required.

Resources

ValueLoadsRequires merchantIdGuide
paymentelementsPaymentElements, as Preczn.PaymentElementsNoCollect payment details with PaymentElements
3dsThe 3D Secure challenge client, as Preczn.ThreeDSecureNoAdd 3D Secure to checkout
applepayThe Apple Pay client, as Preczn.ApplePay. It also loads Apple's Apple Pay JavaScript SDK when your page doesn't already include it.YesAccept Apple Pay
googlepayThe Google Pay client, as Preczn.GooglePayYesAccept Google Pay
paymentfieldsThe deprecated PaymentFields script, as Preczn.PaymentFields. Use paymentelements for new integrations.NoNone

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:

MessageCause
Invalid API KeypublicApiKey is missing, isn't a public key, or isn't active.
Invalid Merchant IDresources 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.

Did this page help you?