1
votes

I got a problem with laravel cashier, when i subscribe to a product, cancel the subscription then subscribe again, it create a new payment method (whiich is the same) and make it as default. But why stripe store 2 times the same card ? If i cancel and subsribe again, i got the payment card 3 times. How can i check if the payment method already exist ?

Thank you

Here is my subscription :

$user->newSubscription($plan_name, $request->plan)->create($request->token

Here is my javascript:

const stripe = Stripe('{{ config('cashier.key') }}')

    const elements = stripe.elements()
    const cardElement = elements.create('card', {
        hidePostalCode: true
    })

    cardElement.mount('#card-element')

    const form = document.getElementById('payment-form')
    const cardBtn = document.getElementById('card-button')
    const cardHolderName = document.getElementById('card-holder-name')

    form.addEventListener('submit', async (e) => {
        e.preventDefault()

        cardBtn.disabled = true
        const { setupIntent, error } = await stripe.confirmCardSetup(
            cardBtn.dataset.secret, {
                payment_method: {
                    card: cardElement,
                    billing_details: {
                        name: cardHolderName.value
                    }
                }
            }
        )

        if(error) {
            cardBtn.disable = false
        } else {
            let token = document.createElement('input')

            token.setAttribute('type', 'hidden')
            token.setAttribute('name', 'token')
            token.setAttribute('value', setupIntent.payment_method)

            form.appendChild(token)
            form.submit();
        }
    })
1

1 Answers

0
votes

You can use the fingerprint of the new card inside the Payment Method compared against the existing Payment Methods to see if it's a duplicate, and then choose not to (re-)add it.