Harpreet Singh
Harpreet Singh

Reputation: 99

stripe.confirmCardPayment is not a function

when i am creating subscription through stripe it gives err message As i am doing subscription through stripe i am also giving some msg about authentication in dashboard like 3d secure authenticatio. and my cvc_check is unavailable in showing dashboard 1.first issue is 3d secure authentication. 2.cvc check unavailbel in India. My account is also india

TypeError: stripe.confirmCardPayment is not a function

my code is pls what i am doing wrong

stripe.customers.create(
            {
                name: name,
                email: email,
                phone: reqObj.phone,
                address: { "city": reqObj.address, "country": "IN",
     "line1": "", "line2": "", "state":"India" },
            },
            function (err, customer) {
                if (err) {res.json({ "status": false, "error": err })
                    console.log(err)
                }else {
                customer_id=customer.id;
    stripe.tokens.create(
        {
            card: {
                number: reqObj.card_no,
                exp_month: reqObj.exp_month,
                exp_year: reqObj.exp_year,
                cvc: reqObj.cvc
            },
        },
        function (err, token) {
            if (err) {
                res.json({ "status": false, "errorT": err})
            } else {
                // stripe.customers.createSource(
                //     customer_id,
                //     { source: token.id },
                    // function (err, card) {
                        // if (err) {
                            // res.json({ status: "false", "error": err })
                        // }else {
                            stripe.plans.list(
                                { product: "prod_IMGu6PI2mJbBCi", active: true },
                                function (err, plans) {
                                    if (!err) {
                            for(i in plans.data){
                                if(plans.data[i].amount==reqObj.amount){
                                    var myId=plans.data[i].id
                   stripe.paymentMethods.create({
                        type: 'card',
                        card: {
                            number: reqObj.card_no,
                            exp_month: reqObj.exp_month,
                            exp_year: reqObj.exp_year,
                            cvc: reqObj.cvc
                        },
                        },function(err,result){
                        // console.log(err,result) 
                        stripe.paymentMethods.attach(result.id, {
                            customer: customer_id,
                          },function(err,result1){ 
                            //   console.log(err,"result1",result1)
                          stripe.customers.update(
                            customer_id,
                            {
                              invoice_settings: {
                                default_payment_method: result.id,
                              },
                            },function(err,res2){ 
                                // console.log(err,"res2")
                            stripe.subscriptions.create({
                                customer: customer_id,
                                items: [{ price: myId}],
                                expand: ['latest_invoice.payment_intent'],
                              },function(err,res3){ 
                                  console.log(err,"res3",
    res3.latest_invoice.payment_intent.client_secret)
                          a=res3.latest_invoice.payment_intent.client_secret
                      stripe.confirmCardPayment(
    res3.latest_invoice.payment_intent.client_secret,
    function(err,paymentIntent)
                        {
                            console.log(err,"paymentIntent",paymentIntent)
                        }
                            )}
                              );
                            } );
                        });
                    });

                    
            }
        });
                }
                // asynchronously called
            });

Upvotes: 1

Views: 3981

Answers (1)

koopajah
koopajah

Reputation: 25552

Your code is mixing up client-side and server-side code together which will not work. The stripe.confirmCardPayment() method comes from Stripe.js and should be called client-side in Javascript inside the browser, not server-side with Node.js.

The beginning of your code is updating a Customer with the right default payment method id. Then it's creating a Subscription. And then, if the creation fails to have the first invoice paid, for example if the card is declined or requires 3D Secure, you have to then go back to the client, in the browser, to run the next step which is to confirm the PaymentIntent associated with the Subscription's Invoice.

So you need to go back to the client, where you originally created the PaymentMethod id pm_123456 that you passed in result.id and then try to confirm the PaymentIntent.

Upvotes: 2

Related Questions