Moving from Stripe
A business that billed its customers at Stripe before it used Palbase already has them there: their Stripe customer, their saved cards, the card their invoices are charged to. adoptCustomer brings such a customer over as one of your payers: nobody enters a card again, nothing is charged, and from then on Palbase charges the payer's invoices to the cards it brought.
Every call here takes the project's secret key (createServer().payments in palbase/server, Palbase.payments in palbase/backend).
Bringing a customer over
The customer must be one of the channel's Stripe account, in the channel's mode: a live channel brings over a live customer (cus_… of the live account), a test channel a test one.
import { createServer } from "palbase/server";
const server = createServer({ url: process.env.PALBASE_URL!, secretKey: process.env.PALBASE_SECRET_KEY! });
const { data: adopted } = await server.payments.adoptCustomer({
path: { customer_id: "acme" },
body: {
channel: "stripe_live",
provider_customer: "cus_Q8x2LmN4pR7sTv",
// default_method: "pm_…" names the default card; left out, the card Stripe charges the customer's invoices to
},
});
// adopted.customer: the payer's profile; adopted.methods: its cards, each channel's default first (is_default)
| What comes over | How |
|---|---|
| The customer's cards | Each card the Stripe customer holds is listed as the payer's (listCustomerMethods), and each is told as payments.method.saved. |
| The default card | default_method when you name one; else the card Stripe charges the customer's invoices to; else the oldest. |
| The profile | A payer with no profile here takes the Stripe customer's name, email, address and tax number. A payer that has one keeps it, and it is written on the Stripe customer. |
customer_id is a payer you name, as for any payer: a new one is made by the adoption, an existing one takes the Stripe customer as its record on that channel. Asked again for the same customer, the call answers the payer as it is; a refused adoption keeps nothing, the payer included.
What stays at Stripe
- Subscriptions. A subscription the customer has at Stripe is not brought over: it goes on renewing there, billed by Stripe as before. End it at Stripe when Palbase bills the customer in its place.
- What was paid before. A dispute or a refund of a charge made at Stripe before the adoption is not told (
payments.dispute.opened,payments.refund.succeeded): Palbase tells of the payments it made, and those stay Stripe's to answer, in Stripe's dashboard.
One customer, one payer
The Stripe customer is marked as the payer's and the project's (its palbase_customer and palbase_project metadata). A customer another payer holds is refused, and so is one another project on the same Stripe account holds.
| Answer | When |
|---|---|
404 provider_customer_not_found | The channel's Stripe account has no such customer: one of another account, or of the other mode. |
409 provider_customer_deleted | Stripe deleted the customer. |
409 provider_customer_taken | The customer is another payer's record. |
409 customer_has_provider_record | The payer has a Stripe customer of its own on the channel already. |
422 default_method_not_found | default_method is none of the customer's cards. |
422 adopt_not_supported | The channel is iyzico's: iyzico keeps no customer record. |
412 no_payment_channel | No active channel of that key. |
503 provider_unavailable | Stripe could not be reached; asking again is safe. |
A channel connected with a restricted key needs Customers: Write and Payment Methods: Write on the key (Stripe).
From the CLI
palbase payments:payers:adopt acme --channel stripe_live --provider-customer cus_Q8x2LmN4pR7sTv
palbase payments:payers:adopt acme --channel stripe_live --provider-customer cus_Q8x2LmN4pR7sTv --default-card pm_1Q8x…
It asks before it changes anything (the environment's developer role; on a production environment it asks first), and prints the cards it brought with the default marked.
Related
- Payers & Invoices — the payer's cards and its taxed invoices
- Stripe — keys, the Stripe App, and permissions
- Server & Backend SDK