#u2ojr2-PaymentIntent
1 messages · Page 1 of 1 (latest)
Hi! Can you give a little more context on what you are trying to do? Are you using PaymentIntent with Payment Element to collect payments?
Sure thing 1 moment
-
So I am trying to collect billing information via additional text inputs
-
I was told to send that data through my stripe.confirmPayment (https://stripe.com/docs/js/payment_intents/confirm_payment#confirm_payment_intent-options-confirmParams-payment_method_data-billing_details)
e.preventDefault();
setLoading(true);
console.log("Testing Code is working")
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
// Make sure to change this to your payment completion page
return_url: "https://www.google.co.uk/",
payment_method_data: {
billing_details: {
name: "test"
},
metadata: {
test1: "hello123"
}
}
},
})
As you can see I have currently hardcoded them as I am just trying to focus on getting them into the order on the account.
-
From the documentation I read that "When you call stripe.confirmPayment, payment details are collected from the Element and passed to the PaymentIntents confirm endpoint as the payment_method_data parameter."
-
I don't currently have a paymentIntents confirm on my create.php file (which generates the order) and I am not sure where the confirm needs to go https://stripe.com/docs/api/payment_intents/confirm?lang=php
require $_SERVER['DOCUMENT_ROOT'] . '/Stripe/init.php';
// This is your test secret API key.
\Stripe\Stripe::setApiKey('Keyishere');
function calculateOrderAmount(array $items): int {
// Replace this constant with a calculation of the order's amount
// Calculate the order total on the server to prevent
// people from directly manipulating the amount on the client
return 1400;
}
header('Content-Type: application/json');
try {
// retrieve JSON from POST body
$jsonStr = file_get_contents('php://input');
$jsonObj = json_decode($jsonStr);
// Create a PaymentIntent with amount and currency
$paymentIntent = \Stripe\PaymentIntent::create(
[
'amount' => calculateOrderAmount($jsonObj->items),
'currency' => 'eur',
'automatic_payment_methods' => [
'enabled' => true,
],
'description' => 'test@test.com | Product: test x1',
]
);
$output = [
'clientSecret' => $paymentIntent->client_secret,
];
echo json_encode($output);
} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}```
This is what my order create.php looks like
Does what I am trying to do make sense to you?
Got it! And how do you collect payment information? Are you using Payment Element?
Yeah
So the flow would be something like this:
- Create the PaymentIntent on the backend
- Retrieve the client secret of the PaymentIntent
- Use the client secret on the frontend to create the Payment Element
- The user enters their payment information
- When the user submits the form, call
confirmPayment
Note that by default the Payment Element, for some payment method, will automatically ask for billing details. So there's nothing to do on your end for this.
Okay so I currently have all of this in place
I am just not able to capture and send additional information in that stripe.ConfirmPayment
Wait is this all done automatically? "When you call stripe.confirmPayment, payment details are collected from the Element and passed to the PaymentIntents confirm endpoint as the payment_method_data parameter."
Well, it depends! What exactly do you mean by "additional information"?
Things like "payment_method_data"
and everything encompassed in that
eg metadata
If the Payment Element is asking for billing details (note that some payment method don't), then these values will be automatically sent to Stripe when calling confirmPayment.
I understand that
but I will be making my own fields such as "First Name"
that will always go into those parameters
but it's not appearing when I submit?
True, if you add your own custom filed, then you need to manage that yourself. Where do you want to store the first name? On the customer object? On the metadata of the Payment Intent? Somewhere else?
I want to send it through with the confirmPayment as metadata
But currently what I send through doesnt* actually appear with the order
e.preventDefault();
setLoading(true);
console.log("Testing Code is working")
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
// Make sure to change this to your payment completion page
return_url: "https://www.google.co.uk/",
payment_method_data: {
billing_details: {
name: "test"
},
metadata: {
test1: "hello123"
},
},
},
})```
So this triggers when the submit button is clicked
You would expect to see in the meta data for the order a field called "test1" and it should have the value of "hello123"
However when I do a test order the meta data is empty
As you can see here I just did a test
and the metadata is empty
You can't pass metadata in the confirmPayment() call.
So if you want to update the metadata of the PaymentIntent, that's something that you'll have to do yourself from your backend server.
Yes, you can see the exhaustive list of parameters in our documentation here: https://stripe.com/docs/js/payment_intents/confirm_payment