API ReferencePayments

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 of currency (for example 24.99 USD or 2499 JPY). Must be greater than 0, with no more decimal places than the currency has.
  • faurya_visitor_id or customer_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 same customer_id belongs 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 the faurya_visitor_id browser cookie. Links the payment to the visitor's traffic source, pages and journey.
  • faurya_session_id (string): Session ID from the faurya_session_id browser 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 for amount. Defaults to USD. Any currency Faurya has a daily exchange rate for is accepted (the European Central Bank reference set, including USD, EUR, GBP, INR, JPY, AUD, CAD, BRL and others); any other code is refused.
  • status (string): succeeded (default) or failed. 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

  • metadata must 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_id must be unique for your site. Sending it again returns 400 with "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 in errors, each with the field, a code and a message.
  • 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"
    }
  ]
}