#u2ojr2-upe-fields

1 messages ยท Page 1 of 1 (latest)

eternal pine
#

Hey there. Which fields are you wanting to pass to which API? What are you trying to do?

vernal forge
#

I now need additional inputs to take user data such as their name, but I can't get it to POST to stripe

eternal pine
#

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?

vernal forge
#

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

eternal pine
#

Which Element are you using?

#

Payment Element?

vernal forge
#

Yeah

vernal forge
#

most of the example i have seen use JS

#

but I am using PHP

eternal pine
#

You'll need a JS part of your integration to facilitate capturing payment details, with Elements

vernal forge
#

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()]);
}
eternal pine
#

Not on create, no

vernal forge
#

This looks like what I am after

#

is there a downside to using these?

eternal pine
#

Downsides? Not really, no. Associates the payment with a specific Customer object which may help with reconciliation

vernal forge
#

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?

eternal pine
#

Those are the available parameters. If what you need is available then sure, you can pass them from your PHP function

vernal forge
#

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

eternal pine
#

Is there an error? Which parameters? What does your POST to your PHP function look like?

vernal forge
#

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

eternal pine
#

Is your $name var definitely defined? The PHP library will remove an empty fields so I'd guess its not set

vernal forge
#

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

brave karma
#

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.

vernal forge
#

I'll add an ID and see if that resolves it

#

Naa unfortunately not

brave karma
#

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?

vernal forge
#

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

brave karma
#

Glad to hear you found a solution, sorry I couldn't be of more assistance.