Skip to main content
A customer is one of your workspace’s customers: the same record your team sees under Customers in the Payra dashboard. Payment methods saved on a customer can be charged again without the buyer typing the card, and payments made with them are filed on that customer in the dashboard. Create each buyer as a customer from your server, with your own id for them (your user id, for example) as reference. You can keep Payra’s id with your user, or skip that and look the customer up by reference whenever you need it.
1

Create the customer

Call it when the buyer signs up, or the first time they pay with you. Calling it again later is safe (see below).
Response
Every field is optional. reference is your id for the buyer, up to 100 characters, unique in your workspace. phone is in E.164 format (+1 and ten digits for a US number). name is the name the dashboard shows; when you leave it out, the email is used as the name, or the reference when there is no email either, and name returns that.
2

Find the customer again by your id

The list holds that one customer, or none. With Payra’s id, GET /customers/{id} reads it directly.

Creating again is safe

When a customer of your workspace already has the reference you send, POST /customers creates nothing: it returns that customer, unchanged, with 200 instead of 201, and ignores the other fields you sent. So you can call it at every sign-up or checkout without looking the buyer up first, and a retry after a timeout, or two requests arriving at the same time, never makes a second customer. Without a reference, every call creates a new customer.

Updating a customer

When a buyer edits their profile in your store, send the new details to POST /customers/{id} and Payra keeps the same record. Fields you leave out are kept; null clears one.
The response is the customer with the new values. The change shows in the Payra dashboard at once.
  • email is where Payra sends the customer’s receipts and the address that signs in to the customer portal, so the new address takes over both from then on: the previous one can no longer sign in. Payra does not confirm the new address with the buyer; verify it in your store before you send it. null removes it. Other addresses your team added to the customer in the dashboard are kept either way: email is only the primary one.
  • name: null sets the name to the email the customer has after this call, or to the reference, the way a create without a name does; a later email change does not rename them again. On a customer with neither, it is refused.
  • reference cannot be changed: it is your lookup key. Sending it answers 400 parameter_invalid, as does any field the endpoint does not know.

Saving and reusing a card

A new buyer, or one paying with a new card:
  1. POST /customers with your user id as reference, if you have not already.
  2. Create a payment method session with that customer, and let Elements collect the card. Saving needs the billing postal code: collect it on your page and pass it when Elements confirms the session.
  3. Charge the session for the order, in one call, with save_payment_method: true: your statement that the buyer agreed to keep the card on file. Once the charge succeeds, Payra keeps the card on the customer, and the payment’s payment_method reads usage: saved.
If your checkout lets the buyer choose whether to keep the card, create the session with their customer either way and send the choice in step 3: save_payment_method: true to keep it, or leave it out to charge the card once. The payment is filed on the customer in both cases, and the buyer can change their mind without the card fields being reset. To save a card before the buyer buys anything (an “add a card” page), create the payment method from the session with account_holder_authorization: true instead of charging it. No payment is created; Payra verifies the card with a small authorization that the processor voids at once (up to $1.00), which may still show on the buyer’s statement as pending for a short while. A returning buyer:
  1. GET /customers?reference=… to find their customer (or use the id you kept).
  2. List their saved payment methods and show them.
  3. When they pick one on your page, confirm a session created with their customer with it, and charge the session (payment_method_session): the payment is the buyer’s own, so their bank can verify them with 3-D Secure where Payra runs it. A charge made with nobody on your page (a renewal, an auction that closed) passes the card’s payment_method to POST /payments instead, and customer if you like.
A buyer who deletes a card in your store: detach it, so it can no longer be charged and leaves their file in the dashboard. Buyers who already had an account with you before you started using Payra need nothing done in advance. The first time one pays by card, POST /customers with their user id creates their customer on the spot, and they enter the card once. Cards saved with a previous processor stay with that processor.

What else comes with a customer

  • Receipts from Payra. When the customer has an email and the workspace’s Email payment receipts to customers setting is on, charging one of their saved payment methods emails them Payra’s payment receipt. Turn the setting off if you send your own. See Payments.
  • The dashboard. Your team sees the customer, their saved cards and their payments, and can remove a card there too; its payment method then reads detached.
  • No environment. Customers belong to the workspace, not to sandbox or live: a sandbox key and a live key read the same ones. Payment methods do belong to one environment, so a customer’s sandbox cards are never listed or charged with a live key.
Customers created in the dashboard, or synced from an ERP, can be read and listed too; their reference is null. A workspace whose customers come from an ERP integration cannot create or update them through the API: the call answers 403 customers_managed_by_erp. An update that sends no field to change only returns the customer.

Scopes and errors

Creating and updating need customers:write; reading and listing need customers:read. The list runs newest first and pages with limit and starting_after.