POST Payment
Record revenue from any payment provider and attribute it to a customer and visitor.
If you have connected your payment provider, you don't need this endpoint: Faurya already records those payments. Sending the same payment here as well would count it twice.
POST Payment
POST https://api.faurya.com/api/v1/payments
Record a payment and attribute it to the customer and visitor who made it. The payment appears in your revenue reports and dashboards alongside payments from connected providers. Requires Bearer Token authentication.
Example request
const response = await fetch("https://api.faurya.com/api/v1/payments", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.FAURYA_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
transaction_id: "payment_456",
amount: 2499,
currency: "INR",
customer_id: user.id,
email: user.email,
name: user.name,
faurya_visitor_id: req.cookies.faurya_visitor_id,
faurya_session_id: req.cookies.faurya_session_id,
metadata: {
plan: "starter",
provider: "custom_checkout",
},
}),
});
const result = await response.json();Success response
{
"message": "Payment accepted",
"status": "accepted",
"transaction_id": "payment_456",
"amount_usd": 29.99,
"currency": "USD"
}A 200 means the payment passed validation and is queued; it is recorded within moments. amount_usd is the amount valued at today's exchange rate, for your reference. Faurya stores the payment in the currency you sent and converts it for each report.
Here's an example of how to add payment data and attribute revenue using this API endpoint.
Request body
Send a JSON object with the following fields.
Required fields
transaction_id(string): Unique ID of the payment in your system. At most 255 characters.amount(number): Payment amount in major units ofcurrency(for example24.99USD or2499JPY). Must be greater than0, with no more decimal places than the currency has.faurya_visitor_idorcustomer_id: send at least one, and both whenever you can.
Who paid
customer_id(string): Your own ID for the paying user. Every payment with the samecustomer_idbelongs to one customer, whichever device or session it came from, including server-side renewals that have no browser cookie.faurya_visitor_id(string): Visitor ID from thefaurya_visitor_idbrowser cookie. Links the payment to the visitor's traffic source, pages and journey.faurya_session_id(string): Session ID from thefaurya_session_idbrowser cookie, when available.email(string): The customer's email address.name(string): The customer's name.
Send customer_id with every payment. Without it, the same person paying from
two devices appears as two customers. email and name are stored on the
customer for display; they are never used to match customers.
Payment details
currency(string): Three-letter ISO 4217 code foramount. Defaults toUSD. Any currency Faurya has a daily exchange rate for is accepted (the European Central Bank reference set, includingUSD,EUR,GBP,INR,JPY,AUD,CAD,BRLand others); any other code is refused.status(string):succeeded(default) orfailed. Failed payments appear in failed-transaction reports and never count as revenue.occurred_at(string): When the payment happened, as an ISO 8601 date-time. Defaults to the time Faurya receives the request. Use it when reporting past payments.metadata(object): Extra attributes stored with the payment.
Metadata rules
metadatamust be a JSON object with at most 10 entries.- Keys are 1-64 characters.
- Values must be a string (at most 500 characters), number, boolean or
null. Objects and arrays are refused.
Rules
transaction_idmust be unique for your site. Sending it again returns400with"error": "DUPLICATE_TRANSACTION", including while the first request is still being recorded.- A deleted transaction cannot be recorded again (
"error": "TRANSACTION_DELETED"). - The visitor does not need to exist yet. A payment made moments after the visitor's first page view is recorded immediately, and linked to the visitor as soon as the visit is processed.
- Payments do not count toward your account's event limit.
Response
200 OK: Payment accepted.400 Bad Request: The request is invalid, the currency is unsupported, or the transaction already exists. Invalid requests list every problem inerrors, each with thefield, acodeand amessage.401 Unauthorized: Missing or invalid API key.
{
"message": "Invalid payment request",
"errors": [
{
"field": "amount",
"code": "TOO_MANY_DECIMALS",
"message": "USD amounts have at most 2 decimal places"
}
]
}