#cgourmelon

1 messages · Page 1 of 1 (latest)

cosmic adderBOT
hybrid wasp
#

Hi there

#

Are you referring to the billing details of a PaymentMethod or a Customer?

slow beacon
#

In the payment_method_data

#

knowing that my var line1 and line2 are already used

hybrid wasp
#

There is a specific param for name

slow beacon
#

(I'm using the checkout.js file to pass post inputs to my webhook.php file in order to create a new order)

#

Name is already used for the name of the client

#

And I need another fied to pass his surname information

#

For the billing I need name + surname + company name + adress 1 + adress 2 + city + codepost + country 😅

hybrid wasp
#

Okay in that case you want to use metadata

#

As there won't be another param here really

#

You could associate a Customer with the PaymentMethod and then set the name on the Customer

#

All depends on what you want this data for

slow beacon
#

This is how I proceed :In my checkout file I have the following input :
<input type="text" name="nom" id="nom" value="" />

In the checkout.js I pass it in the handleSubmit function like this :
confirmParams: {payment_method_data : {billing_details : {name : form.nom.value}}}

And in the webhook.php file I retrieve the data like this :
$paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntent
$billing_details = $paymentIntent['charges']->data[0]->billing_details;
$pff_fleurs_commandes_client_nom = $billing_details->name;

So far I've managed to create an order like that but there are some inputs that I need such as the firstname or the comany name that I don't know how to push to the webhook.
Am I doing it right ? Is there a way to pass custom inputs like this ?

hybrid wasp
#

Yeah I mean that works fine overall. But if you need more data then you want to pass it directly to your server instead of relying solely on the webhook.

#

Like you are calling your backend any way here to create your PaymentIntent right?

#

Just pass the name and other stuff when you do that

#

Then you can store that data either in your database or associate it to a Customer or handle as you desire

slow beacon
#

You mean on the create.php file ?

hybrid wasp
#

Not sure -- I don't know what your codebase looks like.

#

At what point are you creating your PaymentIntent?

slow beacon
#

I followed this piece of code :

#

// Fetches a payment intent and captures the client secret
async function initialize() {
const { clientSecret } = await fetch("/create.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ items }),
}).then((r) => r.json());

elements = stripe.elements({ clientSecret });

const paymentElementOptions = {
layout: "tabs",
};

const paymentElement = elements.create("payment", paymentElementOptions);
paymentElement.mount("#payment-element");
}

#

I am following this tutorial :

hybrid wasp
#

Ah okay gotcha so yeah the only issue here is that you are doing this on page-load so that will be before you have the business name (I assume)

slow beacon
#

To better understand what I'm trying to do, this is the ecommerce link :

#

Just add any flower to your basket then click on the following link to go to the Stripe checkout :

#

(Sorry it's in french 😅 )

hybrid wasp
#

I understand what you are trying to do. It is more that you need to pass the business name to the server separately from your submit handler.

#

So just like you send data to your backend when you fetch("/create.php" you would do the same when you call your submit handler on "pay"

slow beacon
#

If I understand correctely, I would have to create my order on the same file where the paymentintent is created ?

#

In my case in the create.php file where the following code is present :

#

// Create a PaymentIntent with amount and currency
$paymentIntent = \Stripe\PaymentIntent::create([
'amount' => $total_panier,
'currency' => 'eur',
'automatic_payment_methods' => [
'enabled' => false,
],
]);

hybrid wasp
#

Are you storing this data in your own database after you ingest it with your webhook endpoint? Or are you just relying on storing it within Stripe?

slow beacon
#

So far I was creating the order on our MySQL database on the webhook.php file

hybrid wasp
#

okay great

slow beacon
#

But I think I undersant now that I need to do that before

#

*understand

#

But I need the order to be created when the client presses the payment button. Can I do that thks to the create.php file ?

#

He will have in stored thks to POST all my inputs of the checkout form ?

hybrid wasp
#

Ah okay so it actually looks like you are redirecting to your payment page after you collect this name

#

So yeah this does make it easy

#

So all you need to do is pass the name when you fetch create.php and then you can pass it as metadata on the PaymentIntent

#

So like you are doing above:

        'amount' => $total_panier,
        'currency' => 'eur',
        'automatic_payment_methods' => [
            'enabled' => false,
        ],
        `metadata` => [
            biz_name: $biz_name
        ]
    ]);```
#

Then that metadata will be present in your payment_intent.succeeded webhook

#

And you can store it in your database at that point

slow beacon
#

Would this work if I define $biz_name = $_POST['biz_name']; ?

#

(Having the input bizname in the checkout file of course)

#

biz_name input sorry

hybrid wasp
#

Yep

#

As long as you pass it in your fetch body

#

Like right now it looks like you are passing items

#

As you have async function initialize() { const { clientSecret } = await fetch("/create.php", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ items }), }).then((r) => r.json());

#

Whatever you put in your items variable there is going to get sent to your server

slow beacon
#

Ok, very enligntening

#

Thank you a lot @hybrid wasp , I'm going to make some changes to see if it works.

hybrid wasp
#

Sounds good!

slow beacon
#

Can I come back in this chat if I have more questions ?

#

Or I would need to create another feed

hybrid wasp
#

Threads get archived after a period of inactivity but you can always post in the main channel and someone will be around to help