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).Every field is optional.
Response
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
GET /customers/{id} reads it directly.Creating again is safe
When a customer of your workspace already has thereference 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 toPOST /customers/{id} and Payra keeps the
same record. Fields you leave out are kept; null clears one.
emailis 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.nullremoves it. Other addresses your team added to the customer in the dashboard are kept either way:emailis only the primary one.name: nullsets the name to the email the customer has after this call, or to thereference, 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.referencecannot be changed: it is your lookup key. Sending it answers400 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:POST /customerswith your user id asreference, if you have not already.- 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. - 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’spayment_methodreadsusage: saved.
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:
GET /customers?reference=…to find their customer (or use theidyou kept).- List their saved payment methods and show them.
- When they pick one on your page, confirm a session created with their
customerwith 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’spayment_methodtoPOST /paymentsinstead, andcustomerif you like.
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.
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 needcustomers:write; reading and listing need customers:read. The list runs newest first and
pages with limit and starting_after.