bjdodo
bjdodo

Reputation: 361

Creating stripe customer with subscription and anchor via checkout

I am using PHP in the backend (but my problem is not language dependent).

I'd like to create a stripe customer with a subscription and an anchor date for invoicing dates, and a card payment method. The anchor is giving me a headache.

I believe the general steps are: on server side I can create a customer, then a session, then in the browser code I call stripe.redirectToCheckout() where I pass in the session id. This works without the anchor, subscription and card are created ok.

However I do not know where to specify the anchor. At https://stripe.com/docs/api/checkout/sessions/create I found no input argument for anchor date.

As the session create function has an input argument for a subscription, I have tried to create a customer, then a subscription, then a session. However creating the subscription fails with the reason that the customer does not have a paymentmethod.

If I do the working steps: create customer, session, call redirectToCheckout() then I cannot change the anchor of the subscription (except for changing it to now which is not what I want) so I need a way to create a subscription with the anchor.

Could someone please let me know what I missed?

Thank you

Upvotes: 2

Views: 774

Answers (2)

xyres
xyres

Reputation: 21744

billing_cycle_anchor can be set via the Checkout session since since 26 April, 2023. See docs.

Example:

$stripe->checkout->sessions->create([
  'mode' => 'subscription',
  'subscription_data' => [
    'billing_cycle_anchor' => 1682985600
  ]
]);

Upvotes: 0

Jonathan Steele
Jonathan Steele

Reputation: 1938

When creating the Checkout Session, you can pass subscription specific parameters using the subscription_data hash. Unfortunately the billing_cycle_anchor parameter can not be used when creating a Checkout Session.

As a workaround, you could use a trial period as a way to fix the billing anchor to the specific date you require.

Upvotes: 2

Related Questions