Jump to content

Lowie

New Members
  • Posts

    1
  • Joined

  • Last visited

Lowie's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm currently working on a school project and I'm using Stripe as a payment method for my 'webshop'. To create a PaymentIntent you need an Array where you put the product information (Price, amount, etc.). This wasn't a problem first but now I'm trying to create a pdf (using FPDF) with the same products that I put in the Array. Currently I was thinking of creating a seperate file where I create the Array and than Include it in the files that require it. It worked perfectly when I loaded the exact page but once I included it and loaded a different page the Array was empty. Is there something I'm looking over or a better way to do it, it would be very helpfull to lmk. <?php require_once '../../vendor/autoload.php'; include '../header.php'; $products = \Stripe\Product::all(); $producten = array(); foreach ($products->data as $product) { $price = \Stripe\Price::retrieve($product->default_price); $amount = isset($_POST['amount'][$product->id]) ? $_POST['amount'][$product->id] : 0; echo $product. '<br>'; if ($amount > 0) { $producten[] = array( 'price' => $price->id, 'quantity' => $amount ); } } var_dump($producten); if (isset($_POST['submit'])) { Header ('Location: payment.php'); } ?> $customer = \Stripe\Customer::retrieve($_SESSION['stripeId']); // echo $customer->email; $orders = \Stripe\PaymentIntent::all(['customer' => $_SESSION['stripeId']]); // var_dump($orders); echo '<form method="post" action="betaling.php">'; foreach ($products->data as $product) { if ($product->active) { $price = \Stripe\Price::retrieve($product->default_price); echo ' <div class="max-w-md mx-auto bg-white rounded-xl shadow-md overflow-hidden md:max-w-2xl m-4"> <div class="md:flex"> <div class="md:shrink-0"> <img class="h-48 w-full object-cover md:h-full md:w-48" src="../../assets/spaghetti.jpg"> </div> <div class="p-8"> <div class="uppercase tracking-wide text-sm text-sky-900 font-semibold">'.$product->name.'</div> <p class="mt-2 text-lg font-medium">'.$product->description.'</p> <p class="mt-2">€'.$price->unit_amount / 100 .'</p> <div class="flex items-center"> <label for="amount_'.$product->id.'" class="block text-gray-700 text-sm font-bold pr-4 ">Aantal: </label> <input max="20" min="0" type="number" value="0" name="amount['.$product->id.']" id="amount_'.$product->id.'" class="shadow appearance-none border rounded py-2 px-3 text-gray-700 leading-tight mt-2"> <input type="hidden" name="id" value="'.$product->id.'"> </div> </div> </div> </div>'; } }; echo '<div class="flex items-center"><button name="afrekenen" type="submit" class="mx-auto bg-sky-800 hover:bg-blue-900 text-white font-bold py-2 px-4 rounded">Afrekenen</button></div>'; echo '</form>'; - Lowie
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.