#sxe-session-webhook
1 messages ยท Page 1 of 1 (latest)
Hi.
if ($event->type == 'payment_intent.payment_failed')
{
$amount_received = $payment_intent['amount_received'];
$currency = $payment_intent['currency'];
$description = $payment_intent['description'];
$stmt2 = $con->prepare("INSERT INTO Table (UserID, Payment, Currency) VALUES (?, ?, ?)");
$stmt2->bind_param("iss", $_SESSION['ID'], $intent_id, $currency);
$stmt2->execute();
}
I want to insert to the table, $_Session['id']
But webhook is being submitted by Stripe server.
I'm thinking, instead of that, maybe I can create metadatas on create intent
What do you think?
create metadata of "UserIDPaid" => $_SESSION['ID']
Then, on webhook script, retrieve the metadata 'UserIDPaid'
Sorry I don't follow
Are you trying to store session ID in your database?
Yes.
But session ID won't be ever set on webhook page,
Because the datas are being sent from stripe's server.
Not by user's side.
That's why I'm thinking, to set metadatas on create intent, when user is submitting a payment,
because datas are being sent by user's side to stripe server.
and I can save user's session id in a metadata
Apologies I'm still not clear on your use-case here
Can you give me an example of the flow you're trying to build?
Sorry for delay.
Can you help me to create metadatas?
$paymentIntent = \Stripe\PaymentIntent::create([
'amount' => $Price*100,
'currency' => 'ron',
'payment_method_types' => ['card'],
'description' => ''.$_SESSION['ID'].'',
]);
How metadatas should look like?
yup give me a moment
metadatas for
WhatUserIDPaid = $_SESSION['ID'];
AddressOfUser = $_SESSION['Address'];
Then I can understand how metadatas would look like
and I create more of them
you'd likely want it to be an array
so something like
'metadata' => [
'WhatUserIDPaid' => $_SESSION['ID'],
'AddressOfUser' => $_SESSION['Address']
]
When you say alter, do you mean change it later? If so, Yes
You'd update the PaymentIntent with the new metadata by calling the endpoing
https://stripe.com/docs/api/payment_intents/update#update_payment_intent-metadata
And also, on webhook, how can I retrieve the metadata?
what event are you looking at right now?
No, I mean, if other people beside me, can they alter the metadatas?
I will set 'WhatUserIDPaid' the session id.
I want to remain it fixed.
So no one can modify it.
Or alter it.
Ah okay
so you'd create the PaymentIntent server-side using your private keys
So no, no one should be able to alter it
I've created the payment intent.
Now I'm at webhook.
I'm retrieving the payment intent.
$intent_id = $event->data->object->id;
$stripe = new \Stripe\StripeClient(
'x'
);
$payment_intent = $stripe->paymentIntents->retrieve($intent_id,
['expand' => ['payment_method']]
);
$whopaid = $payment_intent['metadata']['WhatUserIDPaid'];
Is that correct?
try it out ๐ looks fine but only one way to know for sure
try to print out just the response i.e. $payment_intent and see if you can spot metadata on it
How can I print it? the output is being realised on a webhook.php page
and payment is realised on index.php
and webhook.php is not included in index.php
My mistake.
Instead of WhoPaid I put WhatUserPaid
Let me try it again.
Yes, works fine!
I have a question too.
Can I get charge infos as payment intent?
I'm trying to get brand, last 4, expre month, exprie year
On the failed payments.