Ok, I'm trying to convert from another payment processor to stripe. The call to Stripe goes like this and this demo works:
$session = \Stripe\Checkout\Session::create([
"success_url" => "https://www.domain.com/stripesuccess.php?sid={CHECKOUT_SESSION_ID}",
"cancel_url" => "https://www.domain.com/cart.php",
"mode" => 'payment',
"line_items" => [
[
"price_data" =>[
"currency" =>"usd",
"product_data" =>[
"name"=> "WIDGETB",
"description" => "Blue Widget"
],
"unit_amount" => 5000
],
"quantity" => 1
],
[
"price_data" =>[
"currency" =>"usd",
"product_data" =>[
"name"=> "WIDGETG",
"description" => "Green Widget"
],
"unit_amount" => 2000
],
"quantity" => 2
]
]);
The problem is I'm pulling the line items from a DB. How to format these line items in a loop and format it properly? (Newbie here... not even clear whether the above is an object or array or what), but I know I can't just throw a loop in the middle to add my dynamic line items.
// Pulling shopping cart from a DB into $row array. Holds cart info. price, qty,sku and description
/ Mysql fetchAll here
foreach ($resultID as $row) {
$line_items_array = array(
"price" => $row['price'],
"quantity" => $row['qty'],
"sku" => $row['sku'],
"description" = $row['description']
);
}
How do I put this array of multiple items into the Stripe code and preserve the formatting in the first example?
I know this is a very vague question, but hoping someone will understand what I'm trying to do.
Thanks