#u2ojr2-customer
1 messages · Page 1 of 1 (latest)
hi! can you clarify overall what your goal is?
But generally it's just that you call the Customer Create API first, and then the PaymentIntent API, passing the ID of the created Customer. There's an example at https://stripe.com/docs/payments/save-during-payment?platform=web for instance
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?
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
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?
seems ok, you should test it out by running the code
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?
can you share the ID pi_xxx of that payment?
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();
did you save the file and deploy the code?
Yeah
the code is fine but you're not making API requests that match it
you can see from your logs https://dashboard.stripe.com/test/logs that you're not making any calls to /v1/customers
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
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?
no, they're separate fields, the customer name and the cardholder name can be different
Alright so I am guessing I would need to set the customer name when the object is created?
you can but you don't really need to. Depends what your goal is
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
hmm, at a high level it's possible I suppose, but it's really hard to give an in-depth answer
Is there a guide on stripe possibly or some docs that explain it?
Not sure how to answer that, I don't really understand the exact question yet
Do you know what "One Click Up-sells" are?
sure, like you want to have the success page after the Checkout page offer a button to charge the customer again.
yes. No there's no specific guide. You should use Checkout to charge the customer and save their details (make sure to pass https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-setup_future_usage )
Then on your success page you can have a button that then results in you creating a PaymentInent that passes the customer and payment_method and confirm parameters to attempt a payment on the saved details
Brilliant I will check this out and see how it goes