Code Examples
Common integration patterns for the PayConnect API in multiple languages.
Authentication
Create a Session Token
- cURL
- Node.js
- Python
curl -X POST https://dev.payconnect.us/api/auth/session \
-H "Authorization: Api-Key YOUR_API_KEY" \
-H "Content-Type: application/json"
const axios = require("axios");
const response = await axios.post(
"https://dev.payconnect.us/api/auth/session",
{},
{
headers: {
Authorization: "Api-Key YOUR_API_KEY",
"Content-Type": "application/json",
},
}
);
const { sessionToken } = response.data;
import requests
response = requests.post(
"https://dev.payconnect.us/api/auth/session",
headers={
"Authorization": "Api-Key YOUR_API_KEY",
"Content-Type": "application/json",
},
)
session_token = response.json()["sessionToken"]
Create a Transaction
- cURL
- Node.js
- Python
curl -X POST https://dev.payconnect.us/api/trx/payment \
-H "Authorization: Api-Key YOUR_API_KEY" \
-H "x-correlation-id: YOUR_CORRELATION_ID" \
-H "Content-Type: application/json" \
-d '{
"contact_api_id": "ct_abc123",
"transaction_amount": 50,
"order_id": "ORD-2026-001",
"account_vault_id": "av_abc123",
"type": "av",
"description": "Order #1234"
}'
const axios = require("axios");
const response = await axios.post(
"https://dev.payconnect.us/api/trx/payment",
{
contact_api_id: "ct_abc123",
transaction_amount: 50,
order_id: "ORD-2026-001",
account_vault_id: "av_abc123",
type: "av",
description: "Order #1234",
},
{
headers: {
Authorization: "Api-Key YOUR_API_KEY",
"x-correlation-id": "YOUR_CORRELATION_ID",
"Content-Type": "application/json",
},
}
);
// A token-based charge returns { transaction: {...} }; a Paya HPP flow returns
// a plain redirect URL string instead. There is no top-level `transactionId`.
if (typeof response.data === "string") {
console.log("Redirect the customer to:", response.data);
} else {
console.log("Transaction:", response.data.transaction);
}
import requests
response = requests.post(
"https://dev.payconnect.us/api/trx/payment",
headers={
"Authorization": "Api-Key YOUR_API_KEY",
"x-correlation-id": "YOUR_CORRELATION_ID",
"Content-Type": "application/json",
},
json={
"contact_api_id": "ct_abc123",
"transaction_amount": 50,
"order_id": "ORD-2026-001",
"account_vault_id": "av_abc123",
"type": "av",
"description": "Order #1234",
},
)
# A token-based charge returns {"transaction": {...}}; a Paya HPP flow returns
# a plain redirect URL string instead. There is no top-level "transactionId".
body = response.json()
if isinstance(body, str):
redirect_url = body
else:
transaction = body["transaction"]
Create an Invoice
- cURL
- Node.js
- Python
curl -X POST https://dev.payconnect.us/api/invoices \
-H "x-session-token: YOUR_SESSION_TOKEN" \
-H "x-correlation-id: YOUR_CORRELATION_ID" \
-H "Content-Type: application/json" \
-d '{
"customerId": "cust_abc123",
"amount": 150,
"description": "Consulting services - January 2025",
"dueDate": "2025-02-01"
}'
const axios = require("axios");
const response = await axios.post(
"https://dev.payconnect.us/api/invoices",
{
customerId: "cust_abc123",
amount: 150,
description: "Consulting services - January 2025",
dueDate: "2025-02-01",
},
{
headers: {
"x-session-token": "YOUR_SESSION_TOKEN",
"x-correlation-id": "YOUR_CORRELATION_ID",
"Content-Type": "application/json",
},
}
);
console.log("Invoice ID:", response.data.invoiceId);
import requests
response = requests.post(
"https://dev.payconnect.us/api/invoices",
headers={
"x-session-token": "YOUR_SESSION_TOKEN",
"x-correlation-id": "YOUR_CORRELATION_ID",
"Content-Type": "application/json",
},
json={
"customerId": "cust_abc123",
"amount": 150,
"description": "Consulting services - January 2025",
"dueDate": "2025-02-01",
},
)
invoice_id = response.json()["invoiceId"]
Create a Subscription
- cURL
- Node.js
- Python
curl -X POST https://dev.payconnect.us/api/subscriptions/v2 \
-H "x-session-token: YOUR_SESSION_TOKEN" \
-H "x-correlation-id: YOUR_CORRELATION_ID" \
-H "Content-Type: application/json" \
-d '{
"customerId": "cust_abc123",
"planId": "plan_xyz789",
"billingMode": "recurring",
"startDate": "2026-02-01"
}'
const axios = require("axios");
const response = await axios.post(
"https://dev.payconnect.us/api/subscriptions/v2",
{
customerId: "cust_abc123",
planId: "plan_xyz789",
billingMode: "recurring",
startDate: "2026-02-01",
},
{
headers: {
"x-session-token": "YOUR_SESSION_TOKEN",
"x-correlation-id": "YOUR_CORRELATION_ID",
"Content-Type": "application/json",
},
}
);
console.log("Subscription ID:", response.data.subscriptionId);
import requests
response = requests.post(
"https://dev.payconnect.us/api/subscriptions/v2",
headers={
"x-session-token": "YOUR_SESSION_TOKEN",
"x-correlation-id": "YOUR_CORRELATION_ID",
"Content-Type": "application/json",
},
json={
"customerId": "cust_abc123",
"planId": "plan_xyz789",
"billingMode": "recurring",
"startDate": "2026-02-01",
},
)
subscription_id = response.json()["subscriptionId"]
tip
All monetary amounts are in dollars. For example, 50 = $50.00.