dayhaysoos/use-shopping-cart

Subscription not working

Closed this issue · 2 comments

Hi everyone.

I have an error somewhere where the mode is not passed along to Stripe.
I have

<CartProvider
        cartMode='client-only'
        mode='subscription'
        currency='NOK'
        stripe='pk_test_xxxxx'
        successUrl='http://localhost:3000?status=success'
        cancelUrl='http://localhost:3000?status=cancel'
    >
    {children}
</CartProvider>

I use the simple client-only flow so no back-end here. This is the relevant code from my cart component (that is a child of the Provider):

import {useShoppingCart} from 'use-shopping-cart'

...

const {
       ...,
        redirectToCheckout
    } = useShoppingCart()

...

<button onClick={redirectToCheckout} ...>

and the cart is working fine until checkout where the call to https://api.stripe.com/v1/payment_pages has mode=payment and gets an HTTP 400 with

{
  "error": {
    "message": "You specified `payment` mode but passed a recurring price. Either switch to `subscription` mode or use only one-time prices.",
    "param": "items[0]",
    "type": "invalid_request_error"
  }
}

I can't find where I should put this subscription except in the CartProvider. Am I missing something?

EDIT: also tried <button onClick={() => redirectToCheckout()} ...>

EDIT2: Might it be coming from

?

The PR I created fixes my issue but I'm not sure if I'm breaking something else...

Hey, sorry I took so long to respond @osnodegeoffrey ! I'll check out your PR tonight.