Send multiple SKU’s and Quantities to stripe from php

I have built a shopping cart and want to send multiple items to stripe. The page is populated using php and mysql.

I want to take each of the listed SKU’s and associated quantities from the table see below;

$sql = "SELECT * FROM cart WHERE sess_id = '$sess_id'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {  
    echo "<table class='table table-striped'>";
    echo "<thead>";
    echo "<tr>";
    echo "<th>Product Name</th><th>Product SKU</th><th>Quantity</th><th>Price</th><th>Remove</th>";
    echo "</tr>";
        echo "<tr>";
        echo "
        <td><a href='delete.php?record=".$row["id"]."' class='btn btn-danger'>Delete</a></td>";
        echo "</tr>";
    echo "</tbody>";
    echo "</table>";
} else {
    echo "<h3>Thankyou for visiting. You have no items in your cart.</h3><p>Return to the shop <a href='shop.php'>Click here</a></p>";

and I want to insert them in the items array below. Everything works fine when I remove the comments and enter manually but of course carts change;


    var stripe = Stripe('pk_test_XXxxxxxxxxxxxxxxxxxxxxx');

    document.getElementById('checkout').addEventListener('click', e => {
            var items = <?php echo json_encode($items); ?>; // Pulls items from php varia
        items: [//**I want to insert results here like they do below**
         //  {sku: 'sku_GKmcmMKCbgntH9', quantity: 1},
         //  {sku: 'sku_GKmZw6apqDvusM', quantity: 1},
          // {sku: 'sku_GJW8ks9YMQ51au', quantity: 1},

    successUrl: 'https:/',
    cancelUrl: '',
  }).then(function (result) {
    // If `redirectToCheckout` fails due to a browser or network
    // error, display the localized error message to your customer
    // using `result.error.message`.


Thank you in advance for your help.

Leave a Reply

Your email address will not be published. Required fields are marked *