Customer
When creating a PaymentIntent, we need to connect the customer which is responsible for paying. This is true both for Stripe and for us. On this page we will walk through the differences in creating, updating and reusing a specific customer for multiple payments.
Stripe
The stripe step-by-step for creating a payment with a customer is to first call the POST /v1/customers with the new customer data.
Upserting a customer
There is no way to upsert a customer directly, so we need to go through the steps manually to do it. Firstly check if the customer exists. Either by checking your own database, or by calling the Stripe API:
-
Customer doesn't exist we want to create a new customer:
POST /v1/customersRequest:
{ "email": "Ola.Nordmann@example.com", "name": "Ola Nordmann", "phone": "+47 123 45 678", "metadata": { // Optional: You can use this to map in your system if needed "customerReferenceID": "your-external-customer-id" } }Response:
{ "id": "cus_NffrFeUfNV2Hib" //...other properties } -
Customer already exists we might want to update the customer in that case:
POST /v1/customers/:idRequest:
{ "phone": "+47 234 56 789", }
You need to use Stripe’s customer id in their PaymentIntent-request.
Using the customer in the payment
POST /v1/payment_intents
{
// Amount
"amount": 1000,
"currency": "nok",
// Payment method
"payment_method_types": ["card"],
"capture_method": "manual",
// Customer
"customer": "cus_NffrFeUfNV2Hib",
"receipt_email": "Ola.Nordmann@example.com",
// ...other PaymentIntent-properties. See PaymentIntent.
}
See the PaymentIntent for more information regarding the general payment:
PaymentIntentPaybucky
Upserting a customer in our system is a simple task, just put in the new values in the customer-property. Our system uses your customer id instead of our internal one, so no mapping beforehand is needed.
POST /payments
{
// Amount
"grossAmount": 1000,
"currency": "NOK",
// Payment method
"paymentGateway": "creditcard",
"chargeImmediately": true,
// Customer
"customerExternalID": "your-external-customer-id",
"customer": {
"name": "John Doe",
"email": "John.Doe@example.com",
"mobilePrefix": "+47",
"mobile": "123123123",
"customerType": "Individual"
}
// ...other PaymentIntent-properties. See PaymentIntent.
}
If you don’t want to update the customer, you can omit the customer object. On the other hand, the customerExternalID -property needs to be present for every request.