Init the library

Initialize the library by calling paygreenjs.init() with a configuration object.

paygreenjs.init({
  paymentOrder: {
    id: "po_xxxxxxxxxxxxxxxxxxx",
    objectSecret: "xxxxxxxxxxxx"
  },
  publicKey: "pk_xxxxxxxxxxx",
  mode: "payment",
});

Required parameters

NameTypeWhen requiredDescription
publicKeyStringAlwaysPublic key of your Paygreen shop. Find or create one here.
modeStringAlways (defaults to payment)Defines how the library works. payment mode runs a payment. instrument mode creates a reusable instrument.
paymentOrderObject { id, objectSecret }In payment modeThe Payment Order id and its single-use object secret (returned once in the response of POST createPaymentOrder).
paymentMethodStringIn instrument modeWhich method to use. Optional in payment mode — if omitted, PaygreenJS lists all methods available on the Payment Order.

Optional parameters

NameTypeDefaultDescription
instrumentObject { id }{ id: null }Pay with an existing saved instrument (one-click).
buyerObject { id }{ id: null }Buyer information used to link an instrument.
langStringBrowser language, fallback enUI language. Supported: en, fr, de, es, it.
modeOptionsObject{}Additional options depending on the selected mode. See below.
styleObjectnullCustom styles applied to the iframes of the payment form. See Customization.
displayObjectSee belowCard/CVV icon display and 3DS presentation mode.
👍

buyer.id is required when:

  • mode: instrument with authorizedInstrument: true.
  • Without it, init() throws with Buyer is required for authorized instrument....

display object

Sub-fieldTypeDefaultDescription
cardIconBooleantrueShow the card-brand icon next to the PAN field.
cvvIconBooleanfalseShow a help icon next to the CVV field.
authenticationString'inline'How 3DS is presented: 'inline' (inside #paygreen-container) or 'modal' (centered overlay).

modeOptions ( Only in instrument mode)

Sub-fieldTypeDefaultDescription
authorizedInstrumentBooleantrue for bank_card, amex, swile, restoflash. false otherwise.Create the instrument and authorize it in one call (with 3DS if required).
shopIdString (sh_…)nullMarketplace setup: link the created instrument to a specific sub-shop while authenticating with the marketplace public key.

Full example

paygreenjs.init({
  publicKey: "pk_xxxxxxxxxxx",
  mode: "payment",
  paymentMethod: "bank_card",
  paymentOrder: {
    id: "po_xxxxxxxxxxxxxxxxxxx",
    objectSecret: "xxxxxxxxxxxx",
  },
  lang: "en",
  style: {
    input: { base: { color: "#111827", fontSize: "16px" } },
  },
  display: {
    cardIcon: true,
    cvvIcon: true,
    authentication: "modal",
  },
});