How to add payment description during stripe checkout

Advertisements

I was wondering how to add the payment description at the stripe checkout session, so that when I export the payment details into an excel file at the stripe dashboard, it will be easier for me to filter the payment data.
enter image description here

Code for stripe checkout session

<?php
session_start();
require 'vendor/autoload.php';
include("conn_db.php");
$total_amount = $_POST["total-amount"];
$total_amount = (int)($total_amount  * 100);
$stripe = new Stripe\StripeClient("sk_test_51MBGiuHGbqwDRBAKP9yCcv2q4EltFvPh5UbpMCRCpn7PkS2diEAlKfoe4ZHsRJYLnHZt0qKExGlbb1UI962x70cn00mLE1tInW");
header('Content-Type', 'application/json');
    
    $store_query = "SELECT * FROM store WHERE store_id = (SELECT store_id FROM cart WHERE user_id = {$_SESSION['user_id']} GROUP BY user_id)";
    $store_arr = $mysqli->query($store_query)->fetch_array();
    $store_id = $store_arr["store_id"];
    $store_name = $store_arr["store_name"];
    
    $query = "SELECT c.*, m.*, u.* FROM user u INNER JOIN cart c ON u.user_id = c.user_id INNER JOIN mitem m ON c.mitem_id = m.mitem_id WHERE c.user_id = {$_SESSION['user_id']} AND c.store_id = {$store_id};";
    $result = $mysqli->query($query);
    $line_items_array = [];
    
    while ($row = $result->fetch_object()) {
        array_push(
            $line_items_array,
            [
                'price_data' => [
                    'product_data' => [
                        'name' => $row->mitem_name,
                        'description' => $store_name,
                        'metadata' => [
                            'pro_id' => $row->mitem_id
                        ]
                    ],
                    'unit_amount' => (int)($row->mitem_price  * 100),
                    'currency' => "myr",
                ],
                'quantity' => $row->cart_amount
            ]
        );
    }
    
    
    print_r($line_items_array);
    
    
    $session = $stripe->checkout->sessions->create([
        "success_url" => ADD_URL . '?response=1&session_id={CHECKOUT_SESSION_ID}',
        "cancel_url" => FAILED_URL,
        "payment_method_types" => ['card'],
        "mode" => 'payment',
        "line_items" => $line_items_array,
        
    ]);
    header("Location: " . $session->url);

>Solution :

https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-description

...
"payment_method_types" => ['card'],
"mode" => 'payment',
"payment_intent_data" => ["description" => "My description of the payment"],
...

Leave a Reply Cancel reply