Skip to main content
Version: Lab (preview)

QR Code

This guide will show you how to generate QR codes that will take users to your checkout. This function initializes a payment session based on the checkoutDetails you pass in. This QR Code will open a hosted checkout page that will allow the user to select a payment method and complete the payment.

Before you start

In order to use QR Codes you need be set up to accept online payments. Accepting Online Payments


Prepare the QR Code​

Use the code below to generate your QR Code.

javascript
//Amount passed in is in cents
const AMOUNT = 1000

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

// Parameters that you will pass in to configure the checkout page that opens when the qrCode is scanned.
const CHECKOUT_DETAILS = {
amount: AMOUNT,
paymentName: "School Technology Fees",
acceptedPaymentMethods: paytheory.ONLY_CARD,
payorId: "ptl_pay_5Q860Z2ouH3KKLnWfNpyxd",
metadata: PAYMENT_METADATA,
recurringId: "ptl_rec_64ImZH6LpufCQddDXX2OYH",
}


const OPTIONS = {
apiKey: "PT_API_KEY",
checkoutDetails: CHECKOUT_DETAILS,
size: 150,
onReady: () => {},
onError: () => {},
onSuccess: () => {}
}
paytheory.qrCode(OPTIONS)

Use either invoiceId or recurringId in checkoutDetails, not both.


Customizing your QR code​

The following parameters can be passed into the qrCode function to customize the payment session. You will pass a single object into the function with the following keys.

Required parameters:​

Keytypedescription
apiKeystringThe API key for your Pay Theory account. You can find this in your Pay Theory Portal.
checkoutDetailsobjectThe details for the checkout page that opens when the qrCode is scanned. Details Below.

Optional parameters​

Keytypedescription
sizeintThis is the size, height and width, of the qrCode in pixels. Defaults to 128 and must be above 128 and below 300.
onReadyfunctionA function that will be called when the qrCode is ready to be displayed.
onErrorfunctionA function that will be called when an error occurs. It is passed an error string.
onSuccessfunctionA function that will be called when the payment is successful. It is passed the success response.

Customizing checkout details​

The following parameters can be passed into the checkoutDetails object to customize the checkout page that opens when the qrCode is scanned.

Required parameters:​

Keytypedescription
amountintThe amount of the payment in cents.
paymentNamestringThe name of the payment that will be displayed on the checkout page. Will also be passed in to the reference field of the transaction.

Optional parameters:​

Keytypedescription
acceptedPaymentMethodsstring
  • The payment methods that will be accepted for the payment. Defaults to paytheory.ALL.
  • Constants are available from the SDK.
  • Available options are paytheory.ONLY_CARD, paytheory.ONLY_ACH, paytheory.ONLY_CASH, paytheory.NOT_CARD, paytheory.NOT_ACH, paytheory.NOT_CASH, and paytheory.ALL.
payorIdstringThe Pay Theory id for the payor that will be used for the payment. If this is not passed in, a new payor will be created.
metadataJSONThe metadata that will be passed into the transaction.
recurring IDstring
  • The Pay Theory recurring ID to use for the payment. Allows for users to assign a payment to a recurring payment.
  • If you pass in a recurring ID, the transaction amount must be an interval of the recurring payments amount per payment.

Next Steps​

You may also make reference to various payment methods like ACH and Cash capability.