#sxe-session-webhook

1 messages ยท Page 1 of 1 (latest)

timid wren
#

Hello ๐Ÿ‘‹
Can you provide more context? What is the use-case here?

torpid oak
#

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'

timid wren
#

Sorry I don't follow
Are you trying to store session ID in your database?

torpid oak
#

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

timid wren
#

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?

torpid oak
#

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?

timid wren
#

yup give me a moment

torpid oak
#

metadatas for
WhatUserIDPaid = $_SESSION['ID'];
AddressOfUser = $_SESSION['Address'];

#

Then I can understand how metadatas would look like

#

and I create more of them

timid wren
#

you'd likely want it to be an array

#

so something like

  'metadata' => [
      'WhatUserIDPaid' => $_SESSION['ID'],
      'AddressOfUser' => $_SESSION['Address']
   ]
torpid oak
#

Can metadatas be altered?

#

And also, on webhook, how can I retrieve the metadata?

timid wren
#

And also, on webhook, how can I retrieve the metadata?
what event are you looking at right now?

torpid oak
#

I will set 'WhatUserIDPaid' the session id.

#

I want to remain it fixed.

#

So no one can modify it.

#

Or alter it.

timid wren
#

Ah okay
so you'd create the PaymentIntent server-side using your private keys
So no, no one should be able to alter it

torpid oak
#

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']; 
timid wren
#

try it out ๐Ÿ˜„ looks fine but only one way to know for sure

torpid oak
#

Hmm

#

I don't think it works.

#

No php errors tho.

#

But my query is not being ran.

timid wren
#

try to print out just the response i.e. $payment_intent and see if you can spot metadata on it

torpid oak
#

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.