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.
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. - Create the payment method with
account_holder_authorization: true, your statement that the buyer agreed to keep the card on file. Payra verifies the card with the processor and saves it on the customer; the method readsusage: saved. - Charge it for the order.
customer either way
and send the choice in step 3: account_holder_authorization: true to save it, or usage: "one_time" to charge it
once without saving. The payment is filed on the customer in both cases, and the buyer can change their mind without
the card fields being reset.
To check a card before the buyer buys anything, stop after step 3. No payment is created. The verification is a
small authorization that the processor voids at once (on Dhango, $1.00); it 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.
- Charge the one they pick with
POST /payments, passing itspayment_method, 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 them through the API: POST /customers
answers 403 customers_managed_by_erp.
Scopes and errors
Creating needscustomers:write; reading and listing need customers:read. The list runs newest first and
pages with limit and starting_after.