HomeGuidesReference
Log In

Initialize Forage JS

Forage(ForageConfig)

Forage(ForageConfig) creates a Forage instance. A Forage instance interacts with the Forage server. You need a Forage instance before you can create an EBT Element and perform EBT checkout operations.

The constructor requires a ForageConfig object as its only parameter.

ForageConfig fields

FieldTypeDescription
merchantId

required

stringA unique Merchant ID that Forage provides during onboarding onboarding preceded by "mid/". For example, mid/123ab45c67. The Merchant ID can be found in the Forage Sandbox or Production Dashboard.
sessionToken

required

stringThe session token that your backend generates to authenticate your app against the Forage Payments API. The token expires after 15 minutes.
customerId

required

stringA unique ID for the end customer making the payment.

If you use your internal customer ID, then we recommend that you hash the value before sending it on the payload.
appearance?objectA set of global styles that is applied to every EBT Element. Supported values include:

* variables (parent key):
- borderRadius
- boxShadow
- colorBackground
- colorPlaceholderText
- colorText
- fontFamily
- fontLineHeight
- fontSizeBase
- fontWeightNormal
- padding

Since session tokens expire after 15 minutes, you can use authentication tokens to simplify your development experience

Authentication tokens should only be used on the client side during testing and development.

Example: Create a Forage instance

const forage = Forage({
  merchantId: 'mid/123ab45c67',
  sessionToken:
    'sandbox_eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhIjo0MiwiZXhwIjoxNjc2OTg2ODM1fQ.7KLvDpM9WHRD4pKCYr0rOy2kM0hVf3bwtZEAOZJrJ1w',
  // NOTE: The following line is for testing purposes only and should not be used in production.
  // Please replace this line with a real hashed customer ID value.
  customerId: btoa(Math.random().toString()),
  appearance: {
    variables: {
      borderRadius: '8px'
    }
  }
})