Skip to main content
Version: Lab (preview)

Accepting Online Payments

In this Quickstart, you will learn how to create, initiate, and test a payment.

Before you start

You will need access to your Pay Theory Sandbox. If you do not have a sandbox account, you can request one here.

Request a Sandbox

1. Importing the SDK​

In order to import your SDK, you will need to copy and paste your Import URL into the header of your code editor.

The SDK URL can be found in the Pay Theory portal under the settings tab as the SDK Import URL.

<script src={SDK Import URL}> </script>

2. Calling the Pay Theory SDK​

When you want to call a function from Pay Theory SDK you will need to use one of the following window objects: paytheory or window.paytheory


3. Add Pay Theory elements to your form​

You need to add the Pay Theory elements to your form. You can place these elements anywhere in your form and the SDK will place the hosted fields in the correct place.

javascript
<div id="pay-theory-credit-card"></div>
<div id="pay-theory-credit-card-zip"></div>

4. Set up the event listeners​

After that, before you initialize the Pay Theory fields, you would need to invoke any event listeners.

Recommended event listeners

The link below provides list of all event listeners available in the below link.

View All Event Listeners
javascript
paytheory.errorObserver(error => {
//Logic to respond to errors
})

5. Initialize the Pay Theory fields​

After you have set up all the event listeners, you can initialize the Pay Theory fields by calling the payTheoryFields function.

javascript
const API_KEY ='YOUR_API_KEY'
paytheory.payTheoryFields({
apiKey: API_KEY,
})
Finding your API Key from the Pay Theory portal
  1. Log in to your Pay Theory portal.
  2. Select the settings page from the left-hand navigation menu.
  3. Select the developer tab.
  4. Find the API Key (Public key for SDK).
  5. From here, you can copy the API key and paste it into your code editor.
paytheory API

6. Once the fields are valid, run transaction​

The only required field for the transact parameters is the amount field. You can customize the transact function more.

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

// Parameters that you will pass into the transact function. More details below.
const TRANSACTING_PARAMETERS = {
amount: AMOUNT,
// Optional. Send the same key on a retry so the payor isn't charged twice
idempotencyKey: 'order-1042'
}

let result = await paytheory.transact(TRANSACTING_PARAMETERS)

if (result.type === "SUCCESS") {
// Logic to respond to successful transaction
} else if (result.type === "FAILED") {
// Logic to respond to failed transaction
} else if (result.type === "ERROR") {
// Logic to respond to error
}
Retry without double charging

Pass an idempotencyKey with each payment. If a request times out, you can retry it or look up the original payment. See Idempotency.


Download code​

Download full code

Click below link to download the full code and project files.

Download

Next steps​

Once you are able to initiate the payment the following guides will help you get payments ready for launch.