#fazilhussain015

1 messages · Page 1 of 1 (latest)

stoic skyBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

raven depot
#

Hey there

uneven plover
#

could you please help me with this

raven depot
#

If you confirm client-side, then you do want to use a Webhook

uneven plover
#

okay let me check this link first

#

how i can confirm on my own server ?

raven depot
#

Well I thought that is what you said above

#

Mostly you don't want to confirm on your server

#

We recommend confirming client-side

uneven plover
#

look at my scenario
i want to allow customer to put there amount and than go with payment method for this
i created an intent with dummy amount and after this i send the payment request to my backend which create again intent with new amount provided by the customer.
when request submit to the backend i want to get the all data releated to the payment and than want to return to customer to return url

raven depot
#

Yeah you shouldn't create a PaymentIntent with a "dummy amount"

uneven plover
#

i think im using already defferred flow

#

const options = {
mode: 'payment',
amount: 1099,
currency: 'usd',
// Fully customizable with appearance API.
appearance: {/.../},
};

// Set up Stripe.js and Elements to use in checkout form
const elements = stripe.elements(options);

// Create and mount the Payment Element
const paymentElement = elements.create('payment');
paymentElement.mount('#payment-element');

#

i took this snippet from the differet flow page

#

here you can see that a intent is going to be created first to load the payment methods ui

#

after completing again
creating the intent in backedn code
here is the code snipet from your mentioned page
<?php
$stripe = new \Stripe\StripeClient("");
$intent = $stripe->paymentIntents->create(
[
'amount' => 1099,
'currency' => 'usd',
// In the latest version of the API, specifying the automatic_payment_methods parameter is optional because Stripe enables its functionality by default.
'automatic_payment_methods' => ['enabled' => true],
]
);
echo json_encode(array('client_secret' => $intent->client_secret));
?>

raven depot
#

Oh then why are you creating a "dummy PaymentIntent"

#

And please redact your secret key above

#

Never share that -- even your test mode one

#

As it allows access to your account

uneven plover
#

yeah this key is already publicly open for the test in the stripe documentation

#

its not from my dashboard

raven depot
#

Ah okay

uneven plover
#

could you please help me with this as i have provided you the complete scenario please read it carefully and suggest me what i need to do

raven depot
#

To be clear... when you sign into your account, the docs populate with your key

uneven plover
#

surpirised

raven depot
#

You want to use Webhooks here since you are confirming client-side

#

So you listen for payment_intent.succeeded

#

Then you can expand the latest_charge and look at the payment_method_details

#

That will give you all the data you want

uneven plover
#

okay if its possible within the payment creation that will be greate

raven depot
uneven plover
#

i think it will take lot of time to implement the the manual code as mentioned in the code

#

in the first case for the webhook

#

i created a webhok for the event payment.successed

#

in this im getting payment details but im unable to get the customer details such as card last 4 digit name and address could you please explain me how i can do this
as i ask this question above but you just send the document link and im unable to get my point from the document

raven depot
#

When you receive the payment_intent.succeeded webhook you retrieve the PaymentIntent using https://stripe.com/docs/api/payment_intents/retrieve and when you do that you expand the latest_charge. Then in the response you can inspect the latest_charge.payment_method_details for the data you want.

uneven plover
#

okay one point more in the deferred intent flow
how many times we need to send the request to stripe ?

raven depot
#

Send what request?

uneven plover
#

first we load the UI for the payment methods im right ?

#

to load the payment methods UI what we need to do is we need to run this code

#

const options = {
mode: 'payment',
amount: 1099,
currency: 'usd',
// Fully customizable with appearance API.
appearance: {/.../},
};

// Set up Stripe.js and Elements to use in checkout form
const elements = stripe.elements(options);

#

what this code does ?

raven depot
#

Yes that creates your elements instance which is then used to render Payment Element

uneven plover
#

yes with amount option

#

again we send the request by using this code
<?php
$stripe = new \Stripe\StripeClient("sk_test_51NwYwSLYxS9gopqXCGqio9dk8QCOgBFoJ9E04mvi8rY1XE7tpPn1fVD1q3cqXGKC0pOTfNoIAw060kb1a258bEZA00KWS0yF5i");
$intent = $stripe->paymentIntents->create(
[
'amount' => 1099,
'currency' => 'usd',
// In the latest version of the API, specifying the automatic_payment_methods parameter is optional because Stripe enables its functionality by default.
'automatic_payment_methods' => ['enabled' => true],
]
);
echo json_encode(array('client_secret' => $intent->client_secret));
?>

raven depot
#

That is how you create a PaymentIntent, yes.

uneven plover
#

okay as i sad i want to give option to the customer to decided for the payment so why we are provding amount in the options and again sedning it through backend code as mentioned in the last

raven depot
#

The amount dictates which Payment Method Types would be supported

#

Some of them have limitations

uneven plover
#

could you please more elborate this point

#

as I'm deciding the payment after UI loaded its means im passsing the dummy amount in the options

raven depot
#

It is required to pass currency/amount on the frontend so the correct payment method type options render in the UI

#

If you don't know the amount yet then yeah you could use a "dummy amount" and then you can update it when your customer indicates the amount.

#

Or, you can wait to render Payment Element until your customer indicates amount

uneven plover
#

okay

#

in this process webhook runs two time

#

when it calls api first time with dummy amount and second again when submit the customer request

#

because both time we are creating the request

#

so this issues with exact data fetching when it will runs two time webhook for one payment

raven depot
#

Not sure what "runs two time" means... you want to only listen for payment_intent.succeeded -- are you also listening for payment_intent.created ?

uneven plover
#

for both times it runs an event with
payment_intent.succeeded

raven depot
#

Are you sure you aren't creating a duplicate payment?

#

Do you have an example you can provide of 2 Event IDs that I can look at?

uneven plover
#

yes i can provide you

raven depot
#

Can you share the Event ID for those two

#

Looks like evt_xxxx

uneven plover
#

"id": "evt_3OMVLtLYxS9gopqX0kUQpyhk",

#

"id": "evt_3OMVFWLYxS9gopqX0si4KDPr",

raven depot
#

Okay so those are Events for two different PaymentIntents

#

So looks like you are creating and confirming two differnet PaymentIntents in your flow

#

Which means you have a bug somewhere

#

And you need to ensure that on each submission you only create/confirm a single PaymentIntent

uneven plover
#

okay can i share my code with you

raven depot
#

You can but that really won't help. What you need to do is add logs throughout your code to see why your create endpoint server-side and your confirmPayment() method client-side are being called two times.

uneven plover
#

okay

#

thanks for your time