Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This user isn’t a Stripe customer #28

Closed
handplant opened this issue Oct 10, 2024 · 1 comment
Closed

This user isn’t a Stripe customer #28

handplant opened this issue Oct 10, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@handplant
Copy link

I'm logged into Craft CMS and making a checkout using the following code:

{{ tag('a', {
  href: stripeCheckoutUrl(
    cartItems,
    currentUser ?? false,
    'thank-you?session={CHECKOUT_SESSION_ID}',
    '/?cancelled=true',
    {}
  ),
  text: 'Checkout',
  class: 'btn btn--xl',
}) }}

I’m wondering why the user is recorded as a guest in Stripe, and in the Craft backend, it shows "This user isn’t a Stripe customer." Shouldn’t this be linked? Or have I overlooked something?

Webhooks are running with the Stripe CLI.

Image

Thank you!

Additional info

  • Craft version: Craft Pro 5.4.7.1
  • PHP version: 8.2.21
  • Plugins & versions: Stripe 1.1.0
@handplant handplant added the bug Something isn't working label Oct 10, 2024
@i-just
Copy link
Contributor

i-just commented Oct 10, 2024

Hi, thanks for reaching out!

It looks like the product you purchased is a one-off product, not a recurring one (not a subscription). By default, when purchasing a one-off product, Stripe will create a guest customer. As per https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-customer_creation, you can change that behaviour in 2 different ways:

  • you could set customer_creation to always
    for example:
{% set params = {} %}
{% if not currentUser %}
  {% set params = params|merge({'customer_creation': 'always'}) %}
{% endif %}
{{ tag('a', {
  href: stripeCheckoutUrl(
    items,
    currentUser ?? false,
    craft.app.request.getAbsoluteUrl() ~ '?session={CHECKOUT_SESSION_ID}&test=value',
    craft.app.request.getAbsoluteUrl(),
    params
  ),
  text: 'Checkout',
  class: 'btn btn--xl',
}) }}
  • or have the post-purchase invoices enabled, in which case a Customer will be created even for the one-off purchases; you’d do that by setting invoice_creation.enabled to true;
    in this case, the params would be:
{
  'invoice_creation': {
    'enabled': true
  }
}

Please note that some parameters are only allowed in certain modes. For example the invoice_creation parameter is only allowed when making a one-off purchase and will throw an error when used when purchasing a recurring one (when purchasing both one-off and a recurring product in a single checkout, the mode is set to subscription).

I hope this clarifies things!

I'll close this now, but feel free to reach out if you run into any further issues.

@i-just i-just closed this as completed Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants