Home > other >  Stripe accessing the metadata within a PHP script
Stripe accessing the metadata within a PHP script

Time:02-10

I'm trying to retrieve a line of metadata (order_no) within Stripe's checkout.session.completed event but I don't know how to go about it. I'm using PHP. I don't know how to query the event to retrieve the checkout.session object from within a PHP script, so I can read the metadata. Could someone please show by example how to achieve that without installing addons such as Slim, etc. I have looked at multiple examples on this site but have not been able to understand them. Thanks in advance for any help you can give.

header('Content-Type: application/json');

$order = $mysqli->escape_string(md5(rand(0,20)));
$amt = '299';

$checkout_session = \Stripe\Checkout\Session::create(

[
'payment_intent_data'=>['description' =>'my purchases'],        
'metadata' => [
    'order_id' => $order
],
'line_items' => [
    [
        'name' => 'My Products',
        'description' => 'My online products',
        'currency' => 'gbp',
        'amount' => $amt,
        'quantity' => 1 
  ]],
    'success_url' => $MySite.'success.php',
    'cancel_url' => $MySite.'cancel.html'
]);

header("HTTP/1.1 303 See Other");
header("Location: " . $checkout_session->url);
}

CodePudding user response:

  •  Tags:  
  • Related