#u2ojr2-upe-fields
1 messages ยท Page 1 of 1 (latest)
Hey there. Which fields are you wanting to pass to which API? What are you trying to do?
So I have a cart page here https://bodyxtr.com/Testing/order/order
Using stripe elements I have injected the payment section in and the data all goes to my stripe fine
I now need additional inputs to take user data such as their name, but I can't get it to POST to stripe
How do you want to persist that data? What is your intention of it? Just for billing details, or do you want a Customer to associate the payment to?
Mainly just for billing details and so we have a record (say if they want to refund ect)
I had tried doing a $POST with the name but this doesn't work
Yeah
You could pass them to confirmPayment with Stripe.js: https://stripe.com/docs/js/payment_intents/confirm_payment#confirm_payment_intent-options-confirmParams-payment_method_data-billing_details
I originally used https://stripe.com/docs/payments/quickstart to get what I have set up
most of the example i have seen use JS
but I am using PHP
You'll need a JS part of your integration to facilitate capturing payment details, with Elements
Is it not possible to capture and send this data via a payment intent in php?
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',
'metadata' => [
'products' => 'test x1',
'email' => 'test@test.com',
'name' => $name,
'first_name' => 'Jack',
'last_name' => 'Test',
],
]
);
$output = [
'clientSecret' => $paymentIntent->client_secret,
];
echo json_encode($output);
} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}
Not on create, no
Not unless you want to use Customer objects: https://stripe.com/docs/billing/customer
Downsides? Not really, no. Associates the payment with a specific Customer object which may help with reconciliation
So just to reiterate, there is no way I can pass additional form fields to the create.php which can be used as parameters in my paymentIntent?
Well it depends which fields they are: https://stripe.com/docs/api/payment_intents/create
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Those are the available parameters. If what you need is available then sure, you can pass them from your PHP function
Yeah so the ones I need are there, but I just don't understand how to get them from my Form to that PHP file
What would traditionally work, isn't working
Is there an error? Which parameters? What does your POST to your PHP function look like?
So this is the form
you can see the field called Name
It posts the the create.php file
The create.php then posts that field to the payment intent
However
this is missing when I check stripe
Is your $name var definitely defined? The PHP library will remove an empty fields so I'd guess its not set
Can you see what I am doing wrong for it to not be set?
To me that looks fine for PHP
I can't see why $name would be empty
I will do a few more tests and see what I can find
Looks like for some reason the POST isn't capturing the name from the form field
Hi ๐ jumping in as my teammate needed to step away. The one thing that is standing out to me about your input field is that it doesn't have an id attribute, though I'm not certain that will resolve the behavior you're seeing of the content not being in the post body.
How are you checking the contents of the post body? Are you just dumping the outputs on the PHP side or are you actually sniffing the request?
I think I have figured out a way to do this without using Post and instead parsing the data into the Javascript file which is then read by the create.php
Thank you for the help anyway
Glad to hear you found a solution, sorry I couldn't be of more assistance.