Simple Mode Usage
Upgrading from a version before 1.0? See Migrating to 1.0.
Overview
This guide shows how to create a SimpleReverePay instance with your merchant credentials, a configuration object and your callbacks.
SimpleReverePay Initialization
To create an instance of the SimpleReverePay class, provide your merchant ID, public API key, a configuration object and the onSuccess / onError callbacks. Each parameter is described in the tables below.
Payment methods are enabled by key: add card, ach, or both. With both, the form shows one tab per method.
Example Usage
- TypeScript
- Javascript
import { SimpleReverePay } from '@revere_payments/tokenizer';
import type { SuccessResponse, ErrorResponse, Validation } from '@revere_payments/tokenizer/types';
const reverePay = new SimpleReverePay({
merchantId: 'yourMerchantId',
publicAPIKey: 'yourPublicAPIKey',
config: {
elementId: 'reverePaymentsForm',
sandbox: true,
card: {}
},
onSuccess: (data: SuccessResponse) => {
console.log('SUCCESS!', data);
},
onError: (status: number, validation: Validation, err?: ErrorResponse) => {
console.log('ERROR!', status, validation, err);
}
});import { SimpleReverePay } from 'https://esm.run/@revere_payments/tokenizer';
const reverePay = new SimpleReverePay({
merchantId: 'yourMerchantId',
publicAPIKey: 'yourAPIKey',
config: {
elementId: 'reverePaymentsForm',
sandbox: true,
card: {}
},
onSuccess: (data) => console.log('SUCCESS!', data),
onError: (status, validation, err) => console.log('ERROR!', status, validation, err)
});Card and ACH together
const reverePay = new SimpleReverePay({
merchantId: 'yourMerchantId',
publicAPIKey: 'yourPublicAPIKey',
config: {
elementId: 'reverePaymentsForm',
defaultPaymentMethod: 'card',
card: {
fields: {
cardCVV: { required: true },
email: { required: true }
}
},
ach: {
redirectURL: 'https://merchant.example.com',
submitMode: 'inner'
}
},
onSuccess: handleSuccess,
onError: handleError
});Constructor Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
merchantId | string | Yes | Your unique merchant identifier. |
publicAPIKey | string | Yes | Your public API key. |
config | SimpleConfig | Yes | Configuration settings for payment processing. |
onSuccess | Function | Yes | Fired after a successful form submission. Provides response (SuccessResponse) as an argument. |
onError | Function | Yes | Fired after a failed attempt. Provides (status, validation, error?): the HTTP status, the Validation object and an optional ErrorResponse. |
onCheckValidity | Function | No | Fired after a validity check runs on the form. Provides validity (Validation) as an argument. |
onLoaded | Function | No | Fired after the initialization process. |
Pass the callbacks to the constructor. Assigning them on the instance afterwards (for example reverePay.onSuccess = …) throws an error.
Configuration Options
Detailed settings within the config object are as follows. Set at least one of card or ach.
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
elementId | string | Yes | - | ID of the tokenizer container element. |
card | SimpleCardOptions | At least one of the two | - | Enables card payments. card: {} uses the defaults; card.fields customizes the inputs. |
ach | SimpleACHOptions | At least one of the two | - | Enables ACH payments. ach.redirectURL is required. |
defaultPaymentMethod | 'card' | 'ach' | No | 'card' if set | Which tab opens first. Must be one of the configured methods. |
sandbox | boolean | No | false | Indicates if sandbox environment should be used for testing purposes. |
strictMode | boolean | No | false | Requires the email field to enable duplication checks. |
theme | 'light' | 'dark' | No | 'light' | Sets the color theme of the tokenizer UI. |
initRequestOrigin | string | No | - | Overrides the API origin. Only accepted together with sandbox: true. |
debug | boolean | No | false | Enables debug logging. |
Unknown or misspelled options throw an error at construction time.
Response Types
For detailed information about response types and the validation object, see Types.