#GauravMavani

1 messages · Page 1 of 1 (latest)

pure jettyBOT
worthy canopy
#

hello! can you share the code snippet of how you're currently creating and attaching the payment method to the customer?

arctic dragon
#

passing client secret to card

$intent = $request->user()->createSetupIntent([
'payment_method_types' => ['card'],
'usage' => 'on_session',
]);
echo $intent->client_secret;

#

form.addEventListener('submit', async (e) => {
e.preventDefault();
cardBtn.disabled = true;
const {
setupIntent,
error
} = await stripe.confirmCardSetup(clientSecret, {
payment_method: {
card: cardElement,
billing_details: {
address: {
city: $("input[name=city]").val(),
country: $("input[name=country]").val(),
line1: $("input[name=address_line1]").val(),
line2: $("input[name=address_line2]").val(),
postal_code: $("input[name=postal_code]").val(),
state: $("input[name=state]").val()
},
email: "<?php echo Auth::user()->email; ?>",
name: "<?php echo Auth::user()->name; ?>"
}
},
});

                    if (error) {
                        cardBtn.disabled = false;
                    } else {
                        console.log(setupIntent.payment_method);
                        let paymentMethod = document.createElement('input');
                        paymentMethod.setAttribute('type', 'hidden');
                        paymentMethod.setAttribute('name', 'paymentMethod');
                        paymentMethod.setAttribute('value', setupIntent.payment_method);
                        form.appendChild(paymentMethod);
                        form.submit();
                    }
                });
#

$customer = $user->createOrGetStripeCustomer([
'email' => $user->email,
'name' => $user->name,
'address' => [
'line1' => $request->address_line1,
'line2' => $request->address_line2,
'city' => $request->city,
'country' => $request->country,
'state' =>$request->state,
'postal_code' => $request->postal_code,
],
]);

    $user->updateDefaultPaymentMethod($payment_method_id,["customer"=>$customer->id]);
        
        try{
        $subscription = $user->newSubscription($plan->name,$plan->stripe_plan)
            ->create($payment_method_id,[
                'email' => $user->email,
                'name' => $user->name,
                'on_session' => true,
        ]);

        }catch(IncompletePayment $exception){            
            return redirect()->route(
                'cashier.payment',
                [$exception->payment->id, 'redirect' => route('upgrade-success')]
            );
        }
#

this method i am using but not working for 3d secure

worthy canopy
#

can you also share the request id where you got that error message?

arctic dragon
#

i have tried many ways to solve this but no luck

worthy canopy
#

instead of attaching the PaymentMethod to a customer object later

arctic dragon
#

so first i have to create again setup intent in payment function then this line

$user->updateDefaultPaymentMethod($payment_method_id,["customer"=>$customer->id]);

#

before this i have to create setupintent?

pure jettyBOT
wary root
#

Hi there, @arctic dragon I'm taking over this thread

arctic dragon
#

now below is my current code

$customer = $user->createOrGetStripeCustomer([
'email' => $user->email,
'name' => $user->name,
'address' => [
'line1' => $request->address_line1,
'line2' => $request->address_line2,
'city' => $request->city,
'country' => $request->country,
'state' =>$request->state,
'postal_code' => $request->postal_code,
],
]);

    $setupIntent = SetupIntent::create([
        'payment_method' => $payment_method_id,
        'payment_method_types' => ['card'],
        'customer' => $customer->id,
        'usage' => 'off_session',
        'confirm' => true,
    ]);

    $user->updateDefaultPaymentMethod($payment_method_id,["customer"=>$customer->id]);
        
        try{
        $subscription = $user->newSubscription($plan->name,$plan->stripe_plan)
            ->create($payment_method_id,[
                'email' => $user->email,
                'name' => $user->name,
                'off_session' => true,
        ]);

        }catch(IncompletePayment $exception){            
            return redirect()->route(
                'cashier.payment',
                [$exception->payment->id, 'redirect' => route('upgrade-success')]
            );
        }
    }
#

getting this error now

wary root
arctic dragon
#

like this??

$paymentMethod = PaymentMethod::retrieve($payment_method_id);
$paymentMethod->attach(['customer' => $customer->id]);

    $setupIntent = SetupIntent::create([
        'payment_method' => $paymentMethod->id,
        'customer' => $customer->id,
        'usage' => 'off_session',
    ]);
#

again same error

wary root
arctic dragon
#

req_gCy2VpIieFOAVC

wary root
#

OK, based on the doc (https://support.stripe.com/questions/guide-for-saving-cards-in-india) you need to use SetupIntent to collect a payment method, and you can't attach a customer to a payment method directly.

arctic dragon
#

but this thing i have do then after i contacted you i have sent you code above

wary root
#

Do you have a SetupIntent ID that I can take a look?

arctic dragon
#

Yes wait sending clientsecret

#

seti_1N8Hg5SDJsqi3ADzSckavYN0_secret_Nu5rv4j8VhjRjp7XQdTgCffnNGnlmZr

#

client secret

#

from below code

$intent = $request->user()->createSetupIntent([
'payment_method_types' => ['card'],
]);
echo $intent->client_secret;

#

this popup is also coming after click on complete giving me error

#

pm_1N8HgiSDJsqi3ADzQg5qndhl

#

this is paymentmethod id

pm_1N8HgiSDJsqi3ADzQg5qndhl

wary root
#

What error did you see?

arctic dragon
#

payment method of type card cannot be atteched

#

as aboce

#

above*

#

let me record and send to you??

wary root
#

Which test card did you use?

arctic dragon
#

this 1st one

#

4000000000003063

this card is working

#

but not above image once

#

any luck?

wary root
#

Thanks for waiting, so you've managed to confirm a setupIntent successfully?

arctic dragon
#

customer is created successfully but while doiung this $user->updateDefaultPaymentMethod($payment_method_id,["customer"=>$customer->id]);

its giving error that PaymentMethods of type card cannot be attached to Customers directly without 3DS due to Indian payment regulations. Please instead provide the PaymentMethod and Customer alongside a SetupIntent or PaymentIntent with the setup_future_usage parameter.

wary root
#

What's the new SetupIntent ID?

arctic dragon
#

i am creatting setupintent only once while passing secret key

#

$customer = $user->createOrGetStripeCustomer([
'email' => $user->email,
'name' => $user->name,
'address' => [
'line1' => $request->address_line1,
'line2' => $request->address_line2,
'city' => $request->city,
'country' => $request->country,
'state' =>$request->state,
'postal_code' => $request->postal_code,
],
]);

    $user->updateDefaultPaymentMethod($payment_method_id,["customer"=>$customer->id]);
        
        try{
        $subscription = $user->newSubscription($plan->name,$plan->stripe_plan)
            ->create($payment_method_id,[
                'email' => $user->email,
                'name' => $user->name,
                'off_session' => true,
        ]);

        }catch(IncompletePayment $exception){            
            return redirect()->route(
                'cashier.payment',
                [$exception->payment->id, 'redirect' => route('upgrade-success')]
            );
        }
    }
#

see this is my current code

wary root
#

I just need your setupIntent ID

arctic dragon
#

okay sending wait

#

seti_1N8IN4SDJsqi3ADzTOjXQIgK

wary root
#

You haven't confirmed this setupIntent, its status is still requires_payment_method and its payment_method is null

arctic dragon
#

Yes just to give you id wait 1 minute

#

seti_1N8ISUSDJsqi3ADzzbYoM3pq

#

check for this id

#

seti_1N8IU5SDJsqi3ADzWHQoea0i

wary root
#

OK, I see that seti_1N8IU5SDJsqi3ADzWHQoea0i is succeeded . Can you try using its payment_method to create a subscription?

arctic dragon
#

seti_1N8IWESDJsqi3ADzztFdEwEX what about this one

#

for above one i got this error: PaymentMethods of type card cannot be attached to Customers directly without 3DS due to Indian payment regulations. Please instead provide the PaymentMethod and Customer alongside a SetupIntent or PaymentIntent with the setup_future_usage parameter.

wary root
#

Strange, I do see that 3DS was completed successfully.

#

Send me the ID of the request where you get this error

arctic dragon
#

sending

#

req_SLVBdToli9kKEl

wary root
#

Hmm, why don't you set the customer first when creating the SetupIntent, so that you don't need to explicity attach the payment method to a customer

arctic dragon
#

YOU WANT THAT I CREATE CUSTOMER THEN SETUP INTENT SO I CAN PASS CUSTOMER ID TO SETUP INTENT?

wary root
#

There's no need to shout. As I explained earlier, you can't attach a payment method to a customer due to India payment regulations.

#

So you should use SetupIntent to collect a payment method, and Stripe would automatically attach the payment method to the customer.

arctic dragon
#

i am not shouting by mistake capslock

pure jettyBOT
arctic dragon
#

hello

solid monolith
#

Hello

arctic dragon
#

have you checked above conversation?

solid monolith
arctic dragon
#

Yes, i have followed the steps but nothing seems to be working