#u2ojr2-customer

1 messages · Page 1 of 1 (latest)

night steeple
wind fractal
#

I see alright, bare with me going to have a quick read through this

#

So all I have to do is put this $customer = \Stripe\Customer::create(); before my payment intent triggers?

night steeple
#

well not just that, since you have to then use $customer in the subsequent call to create the PaymentIntent, but that's the idea yes

wind fractal
#

I see yeah adding 'customer' => $customer->id, to my payment intent

#

okay 1 sec just gonna try this out

#

hmm not so sure what I have done wrong but my payment still sent through but as a "Guest"

#
    // retrieve JSON from POST body
    $jsonStr = file_get_contents('php://input');
    $jsonObj = json_decode($jsonStr);

    $customer = \Stripe\Customer::create();

    // Create a PaymentIntent with amount and currency
    $paymentIntent = \Stripe\PaymentIntent::create(
        [
            'customer' => $customer->id,
            'amount' => calculateOrderAmount($jsonObj->items),
            'currency' => 'gbp',
            'automatic_payment_methods' => [
                'enabled' => true,
            ],
            'description' => 'Biotic Advanced Pro Blend x1',
            'metadata' => [
                'product_name' => 'Biotic Advanced',
                'product_id' => 'SN040',
                'quantity' => 1,
            ]
        ]
    );

    

    $output = [
        'clientSecret' => $paymentIntent->client_secret,
    ];


    echo json_encode($output);
} catch (Error $e) {
    http_response_code(500);
    echo json_encode(['error' => $e->getMessage()]);
}```
#

Does that look right to you?

#

Hello?

night steeple
#

seems ok, you should test it out by running the code

wind fractal
#

Yeah I did but it didn't work

#

It came through as a Guest for some reason?

#

I will try another test

#

getting this still?

night steeple
#

can you share the ID pi_xxx of that payment?

wind fractal
#

pi_3KixK1JsPTNcs2HQ1AerSNvX

#

"customer": null, in the event data for some reason?

#

Does anything need to be sent when making the customer object?

$customer = \Stripe\Customer::create();

night steeple
#

did you save the file and deploy the code?

wind fractal
#

Yeah

night steeple
#

the code is fine but you're not making API requests that match it

wind fractal
#

I will try again 1 moment

#

But I am sure it is being deployed alright

night steeple
#

so you likely are not running the code you think you are. Try adding some logging/print statements/breakpoints to step through the code and see what's actually running

wind fractal
#

I've added a meta tag to the payment intent saying "Deployed" and the time of deployment

#

Okay yeah looks like the code isn;t running

#

1 moment I will try and figure this out

#

Okay I got that working

#

is there a way to set the customer name as the payment method name?

night steeple
#

no, they're separate fields, the customer name and the cardholder name can be different

wind fractal
#

Alright so I am guessing I would need to set the customer name when the object is created?

night steeple
#

you can but you don't really need to. Depends what your goal is

wind fractal
#

Well from a visual point of view for the payments

#

I will leave it for now, come back to it later...

#

I do have another question though if you could point me in the right direction

#

Say I have the following funnel

Cart Page (with stripe on)

I then redirect them to a page with a product on is it possible to have an instant purchase button that will use the card details they previously entered on the cart page

night steeple
#

hmm, at a high level it's possible I suppose, but it's really hard to give an in-depth answer

wind fractal
#

Is there a guide on stripe possibly or some docs that explain it?

night steeple
#

Not sure how to answer that, I don't really understand the exact question yet

wind fractal
#

Do you know what "One Click Up-sells" are?

night steeple
#

sure, like you want to have the success page after the Checkout page offer a button to charge the customer again.

wind fractal
#

Yeah exactly

#

Is that possible with Stripe?

night steeple
wind fractal
#

Brilliant I will check this out and see how it goes