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.
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.
//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:
| Key | type | description |
|---|---|---|
| apiKey | string | The API key for your Pay Theory account. You can find this in your Pay Theory Portal. |
| checkoutDetails | object | The details for the checkout page that opens when the qrCode is scanned. Details Below. |
Optional parameters
| Key | type | description |
|---|---|---|
| size | int | This is the size, height and width, of the qrCode in pixels. Defaults to 128 and must be above 128 and below 300. |
| onReady | function | A function that will be called when the qrCode is ready to be displayed. |
| onError | function | A function that will be called when an error occurs. It is passed an error string. |
| onSuccess | function | A 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:
| Key | type | description |
|---|---|---|
| amount | int | The amount of the payment in cents. |
| paymentName | string | The 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:
| Key | type | description |
|---|---|---|
| acceptedPaymentMethods | string |
|
| payorId | string | The 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. |
| metadata | JSON | The metadata that will be passed into the transaction. |
| recurring ID | string |
|