Skip to main content
Version: Lab (preview)

Payment Button

button starts a payment session from the checkoutDetails you pass and mounts a button in the pay-theory-checkout-button hosted field. When the payor clicks it, a Pay Theory checkout page opens in a pop-up where they pick a payment method and pay.


button​

// Amount in cents
const AMOUNT = 1000

const PAYMENT_METADATA = {
"student-name": "Pat Theodore"
};

// Configures the checkout page that opens when the payor clicks the button
const CHECKOUT_DETAILS = {
amount: AMOUNT,
paymentName: "School Technology Fees",
paymentDescription: "Technology fee for the 2026-2027 school year",
requirePhone: true,
callToAction: paytheory.DONATE,
acceptedPaymentMethods: paytheory.ONLY_CARD,
payorId: "ptl_pay_2NM2STwd3pWznLo1hGnUSc",
metadata: PAYMENT_METADATA,
feeMode: paytheory.MERCHANT_FEE,
accountCode: "code-123456789",
invoiceId: "ptl_inv_2O0yTY3k5AIyDc8NQ2SvhC",
}

// Styles the button
const STYLE_OBJECT = {
color: paytheory.WHITE,
callToAction: paytheory.DONATE,
pill: true,
height: 48
}

const OPTIONS = {
apiKey: "YOUR_API_KEY",
checkoutDetails: CHECKOUT_DETAILS,
style: STYLE_OBJECT,
onReady: () => {},
onClick: () => {},
onError: error => {},
onCancel: () => {},
onSuccess: result => {},
onBarcode: barcode => {}
}

paytheory.button(OPTIONS)

Pass button one object with these keys.

Required

Keytypedescription
apiKeyStringYour Pay Theory API Key, from the Pay Theory portal.
checkoutDetailsCheckout detailsWhat the checkout page charges and shows.

Optional

Keytypedescription
styleStyle objectHow the button looks.
onReadyFunctionCalled with true when the button is ready to click.
onClickFunctionCalled when the payor clicks the button.
onErrorFunctionCalled with an error string. The string starts with one of the error codes.
onCancelFunctionCalled when the payor closes the pop-up without paying.
onSuccessFunctionCalled with the success response when the payment succeeds.
onBarcodeFunctionCalled with the barcode response when the payor creates a cash barcode and closes the pop-up.

button returns a Promise. If a parameter is invalid, it resolves to false and sends the error to onError.


Checkout details​

Required

Keytypedescription
amountIntAmount of the payment, in cents.
paymentNameStringName shown on the checkout page. It's also saved as the transaction's reference.

Optional

Keytypedescription
paymentDescriptionStringDescription shown on the checkout page.
requirePhoneBooleanPass true to make the payor enter a phone number.
callToActionStringCall to action for the checkout. Defaults to paytheory.PAY. See call to action.
acceptedPaymentMethodsStringPayment methods the page offers. Defaults to paytheory.ALL. See accepted payment methods.
payorIdStringID of an existing payor. If you leave it out, Pay Theory creates a new payor.
metadataObjectKey-value data stored with the transaction.
feeModeStringpaytheory.MERCHANT_FEE (default) or paytheory.SERVICE_FEE.
accountCodeStringCode for tracking a payment or group of payments.
invoiceIdStringID of the invoice this payment pays. Don't combine with recurringId.
recurringIdStringID of the recurring payment this payment pays. The amount must be a multiple of the recurring amount per payment.
healthExpenseTypeStringHealthcare category: HEALTHCARE, RX, VISION, CLINICAL, COPAY, DENTAL or TRANSIT.
level3DataSummaryLevel 3 data summaryLevel 3 summary data for the transaction.

Style object​

style is optional. If you pass it, include all four keys. Without it, the button is purple, says "Pay with", has square corners and is 48 pixels tall.

Keytypedescription
colorStringButton color. See color.
callToActionStringText on the button. See call to action.
pillBooleanPass true for a pill shape.
heightIntButton height in pixels.

Success response​

onSuccess receives this object.

Keytypedescription
receipt_numberStringThe transaction ID.
amountIntAmount charged, in cents. Includes the service fee.
service_feeIntService fee, in cents.
last_fourStringLast four digits of the card or account number.
brandStringCard brand.
created_atStringWhen the transaction was created.
stateStringStatus of the transaction.
metadataObjectThe metadata you passed.
payor_idStringID of the payor.
payment_method_idStringID of the payment method token.

Barcode response​

onBarcode receives this object.

Keytypedescription
barcodeUrlStringURL of the barcode image.
mapUrlStringURL of a map of retail locations that accept the barcode.

Call to action​

ValueButton text, followed by the Pay Theory logoConstant
PAYPay withpaytheory.PAY
DONATEDonate withpaytheory.DONATE
BOOKBook withpaytheory.BOOK

Accepted payment methods​

ValueThe page acceptsConstant
ALLCard, ACH and cashpaytheory.ALL
ONLY_CARDCardpaytheory.ONLY_CARD
ONLY_ACHACHpaytheory.ONLY_ACH
ONLY_CASHCashpaytheory.ONLY_CASH
NOT_CARDACH and cashpaytheory.NOT_CARD
NOT_ACHCard and cashpaytheory.NOT_ACH
NOT_CASHCard and ACHpaytheory.NOT_CASH

Color​

ValueConstant
purplepaytheory.PURPLE
whitepaytheory.WHITE
blackpaytheory.BLACK
greypaytheory.GREY