Home > Blockchain >  How to add payment description during stripe checkout
How to add payment description during stripe checkout

Time:12-06

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);

CodePudding user response:

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"],
...

CodePudding user response:

If you are using the Stripe PHP library to process payments on your website, you can add a description for the payment that will be displayed to the customer during checkout. To do this, you will need to pass the description parameter to the object when you create it. The description parameter should be set to a string value that contains the payment description you want to display.

$session = $stripe->checkout->sessions->create([
  // Use the default payment method
  'payment_method_types' => ['card'],
  // Set the payment description
  'description' => 'Your payment description here',
  // Set the success and cancel URLs
  'success_url' => 'https://example.com/success',
  'cancel_url' => 'https://example.com/cancel',
  // Set the payment amount
  'line_items' => [[
    'name' => 'Your product name',
    'amount' => 1000, // The amount in cents
    'currency' => 'usd',
    'quantity' => 1
  ]]
]);
  • Related