JezK
Edit File: process_payment_old_without3D_working.php
<?php session_start(); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); include 'db_connection.php'; include '../membership/email.php'; require_once('stripe_lib/vendor/autoload.php'); include '../membership/vendor/autoload.php'; $first_name = trim($_POST['first_name']); $last_name = trim($_POST['last_name']); $position = trim($_POST['position']); $company_name = trim($_POST['company_name']); $city = trim($_POST['city']); $country = trim($_POST['country']); $vat_number = trim($_POST['vat_number']); $email = trim($_POST['email']); $countryCode = trim($_POST['countryCode']); $mobile = trim($_POST['mobile']); //$food_items = json_encode($_POST['food_items']); $food_items = isset($_POST['food_items']) ? json_encode($_POST['food_items']) : '[]'; $comments = trim($_POST['comments']); $coupon_code = trim($_POST['coupon_code']); $date = date("Y-m-d"); $event_id = trim($_POST['event_id']); $event_name = trim($_POST['event_name']); $sql = "SELECT MAX(id) AS max_id FROM payments"; $result = $conn->query($sql); $data = $result->fetch_assoc(); $Unique_ID = $data['max_id']+1; $unique_id = "REIA-B00".$Unique_ID; $amount = $_POST['event_price']; if($amount!=0) { //\Stripe\Stripe::setApiKey('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'); \Stripe\Stripe::setApiKey('sk_test_51HqxNhLB5kw3RTIUhauZZsIPMfsAcXCvdUdIjIF9b99Xlcpjf831CmqNB9Y0mCwcBU2iGFiwe571HERp2zZXtStk0003TA8OwV'); $token = $_POST['stripe-token']; $amount = $_POST['event_price']; try { //$stripe = new \Stripe\StripeClient('sk_test_51HqxNhLB5kw3RTIUhauZZsIPMfsAcXCvdUdIjIF9b99Xlcpjf831CmqNB9Y0mCwcBU2iGFiwe571HERp2zZXtStk0003TA8OwV'); // $pay=$stripe->paymentIntents->create([ // 'amount' => $amount*100, // 'currency' => 'eur', // 'automatic_payment_methods' => ['enabled' => true], // ]); //print_r($pay); exit; $charge = \Stripe\Charge::create([ 'amount' => $amount*100, 'currency' => 'eur', 'source' => $token, 'description' => 'Event booking', ]); //print_r($charge); exit; // $paymentIntent = \Stripe\PaymentIntent::create([ // 'amount' => $amount * 100, // 'currency' => 'eur', // 'payment_method' => $token, // 'confirmation_method' => 'manual', // 'confirm' => true, // 'description' => 'Event booking', // 'payment_method_options' => [ // 'card' => [ // 'request_three_d_secure' => 'any', // ], // ], // ]); // print_r($paymentIntent); exit; if (!empty($charge) && $charge->status == 'succeeded') { $transaction_id = $charge->id; $paid_amount = $charge->amount; $paid_currency = $charge->currency; $payment_status = $charge->status; $new_price = $paid_amount/100; $sqlQ ="INSERT INTO `payments` (`booking_id`,`first_name`,`last_name`,`position`,`company_name`,`city`,`country`, `vat_number`, `email`, `countryCode`, `mobile`, `food_items`, `comments`,`coupon_code`,`gdpr`,`transaction_id`,`payment_status`,`date`,`event_id`,`price`,`currency`) VALUES ('$unique_id','$first_name','$last_name','$position','$company_name','$city','$country','$vat_number', '$email', '$countryCode', '$mobile', '$food_items', '$comments','$coupon_code','1', '$transaction_id', '$payment_status','$date', '$event_name', '$new_price','$paid_currency')"; if ($conn->query($sqlQ) === TRUE) { $last_id = $conn->insert_id; $sql_last = "SELECT * FROM `payments` WHERE `id` = '$last_id' ORDER BY `id` DESC"; $result_last = $conn->query($sql_last); $row = $result_last->fetch_assoc(); $name = $row['first_name']; $booking_id = $row['booking_id']; $transaction_id = $row['transaction_id']; $price = $row['price']; $event_id = $row['event_id']; $date = $row['date']; send_payment_confirmation_email($email,$name,$booking_id,$transaction_id,$price,$event_id,$date); send_payment_confirmation_client($email,$name,$booking_id,$transaction_id,$price,$event_id,$date); header('Location:payment_success.php?trans_id='.$transaction_id); } } } catch (\Stripe\Exception\CardException $e) { // Handle card payment errors // echo "Error: " . $e->getMessage(); exit; if ($e->getError()->payment_intent->status === 'requires_action') { // The payment requires further user action, redirect to the 3DS authentication URL $redirect_url = $e->getError()->payment_intent->next_action->redirect_to_url->url; header("Location: $redirect_url"); exit; } else { echo "Error: " . $e->getMessage(); exit; } } } else { $sqlQ ="INSERT INTO `payments` (`booking_id`,`first_name`,`last_name`,`position`,`company_name`,`city`,`country`, `vat_number`, `email`, `countryCode`, `mobile`, `food_items`, `comments`,`coupon_code`,`gdpr`,`transaction_id`,`payment_status`,`date`,`event_id`,`price`,`currency`) VALUES ('$unique_id','$first_name','$last_name','$position','$company_name','$city','$country','$vat_number', '$email', '$countryCode', '$mobile', '$food_items', '$comments','$coupon_code','1', '', 'succeeded','$date', '$event_name', '0','euro')"; if ($conn->query($sqlQ) === TRUE) { $last_id = $conn->insert_id; $sql_last = "SELECT * FROM `payments` WHERE `id` = '$last_id' ORDER BY `id` DESC"; $result_last = $conn->query($sql_last); $row = $result_last->fetch_assoc(); $booking_id = $row['booking_id']; $name = $row['first_name']; $lname = $row['last_name']; $position = $row['position']; $company_name = $row['company_name']; $city = $row['city']; $country = $row['country']; $vat_number = $row['vat_number']; $countryCode = $row['countryCode']; $mobile = $row['mobile']; $mobile = $row['mobile']; $transaction_id = $row['transaction_id']; $price = $row['price']; $event_id = $row['event_id']; $date = $row['date']; $payment_status = $row['payment_status']; $currency = $row['currency']; send_zero_payment_confirmation_email($email,$name,$booking_id,$transaction_id,$price,$event_id,$date); send_zero_payment_confirmation_client($email,$name,$booking_id,$transaction_id,$price,$event_id,$date); $_SESSION['receipt_id']=$last_id; header('Location:receipt.php'); } }