#Mr.Medi

1 messages ยท Page 1 of 1 (latest)

opal jacinthBOT
jovial egret
#

do you have more context like an exact error message and request ID req_xxxx?

solar salmon
#

yes, req_jXu1A2LlXP4ZkA

#

that is my request error

#

The error is "Invalid token id: pm_1NR97MJKetCvGTPaMxVMmyNI",

jovial egret
#

that request makes no sense unfortunately, you already have a PaymentMethod object, you should just use that directly.

#

for whatever reason you are acting as though you have a Token (tok_xxx)and need toconvert it to a PaymentMehtod, but you already have the PaymentMethod(with the ID pm_xxx)

solar salmon
#

Oh I see, is there any way in django to createOrgetCustomer function like in laravel?

jovial egret
#

I don;'t know anything about Django or the library you're using

solar salmon
#

so, the problem is that the customer already have a payment method?

jovial egret
#

no, the problem is that you created a PaymentMethod pm_xxx and for some reason you are passing it to code that is expecting to have a tok_xxx and needs to convert it to a pm_xxx

solar salmon
#

what is tok used for?

#

I guess the problem lies in ```python
customer = stripe.Customer.create(
email=request.user.email
)

            payment_method = stripe.PaymentMethod.create(
            type="card",
            card={
                "token": token,
            },
            )
            stripe.PaymentMethod.attach(payment_method.id, customer=customer.id, )
jovial egret
#

yes

solar salmon
#

token is the pm that you mention

jovial egret
solar salmon
#

i have a setupintent as well in stripe elements in the frontend

jovial egret
#

ok. Then either way, you need to not be doing this call to stripe.PaymentMethod.create if your frontend code is already creating PaymentMethods and not tokens

#

presumably you have this code from some old legacy thing you're upgrading that used to use tokens

solar salmon
#

i will try, but the customer dont have any payment method

jovial egret
#

I mean of course not?

#

the code that would do the attachment crashed with an error, which is what we're talking about here ๐Ÿ™‚

solar salmon
#

Sorry for asking a lot of questions, but I remove that lines i get this error This customer has no attached payment source or default payment method. Please consider adding a default payment method. For more information, visit https://stripe.com/docs/billing/subscriptions/payment-methods-setting#payment-method-priority. with req_id req_9HROJA6iQ1xt2t

#

Is the front supposed to create it?

jovial egret
#

depends how you built this

#

what guides are you using?

solar salmon
#
    var stripe = Stripe('{{stripe_publishable_key}}');
    var style = {
          base: {
            color: "#32325d",
            fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
            fontSmoothing: "antialiased",
            fontSize: "16px",
            "::placeholder": {
              color: "#aab7c4"
            }
          },
          invalid: {
            color: "#fa755a",
            iconColor: "#fa755a"
          }
        };
    const elements = stripe.elements()
    const cardElement = elements.create('card', {style:style});
    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();
        }
    })
#

this is my front, I just add the token in the form when the user click the button to purchase it

jovial egret
#

or you need to attach it later after the SI succeeds (which your code you showed earlier tries to do perhaps but fails due to the issue explained)

solar salmon
#

Thank you!

#

Im following the guide, but in the frontend says that Your code called confirmPayment() but you passed a client_secret associated with a SetupIntent. Did you mean to call confirmSetup() instead? Do I have to call it or is that error because the customer already exists?

jovial egret
#

no, it means you're not really following the guide correctly

#

you wouldn't use a SetupIntent at all here ,you'd use the Invoice's PaymentIntent

solar salmon
#

I see, when the user makes the GET request to the plan im passing the setupintent

#

there is no way to create the customer and subscription once the user buys it?

jovial egret
#

not really following

#

but yes if you want to do it the other way where you create the Subscription after the PaymentMethod is created, you 'can' but it's highly recommended against. The recommended approach is https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements (you create the Subscription first when the customer visits the "sign up" page, then use the Invoice's PaymentIntent on the frontend, which accepts the card, saves it, charges it and activates the subscription all in one step)

solar salmon
jovial egret
#

that's an internal part of the integration but sure, that's normal

solar salmon
#

Yeah, in the stripe js, right? Thank you very much for your help ๐Ÿ™‚ i will follow with the guide

opal jacinthBOT