// The PayPlug API secret key: require_once 'include/init.php'; $email = htmlspecialchars($_POST['email']); $token = $_POST['payplugToken']; $cart = '8.20'; $my_order_id = uniqid('fb', false); $savethecard = htmlspecialchars($_POST['savethecard']); if ($savethecard == "yes") { $save_opt = true; } else { $save_opt = false; } $amount = $cart * 100; \Payplug\Payplug::setSecretKey($secretkey); try { $payment = \Payplug\Payment::create(array('amount' => $amount, 'currency' => 'EUR', 'payment_method' => $token, 'save_card' => $save_opt, 'customer' => array('email' => $email, 'first_name' => 'John', 'last_name' => 'Doe'), 'notification_url' => $notification_url, 'metadata' => array('order_id' => $my_order_id))); } catch (\Payplug\Exception\ConnectionException $e) { // Connection with the PayPlug API failed. } catch (\Payplug\Exception\InvalidPaymentException $e) { // Payment object provided is invalid. } catch (\Payplug\Exception\UndefinedAttributeException $e) { // Requested attribute is undefined. } catch (\Payplug\Exception\HttpException $e) { // Http errors. } catch (\Payplug\Exception\PayplugException $e) { echo 'Failure code: ' . $e->getMessage(); } catch (Exception $e) { echo 'Caught exception: ' . $e->getMessage(); } if ($payment->is_paid == true) { echo "<div><strong><i class='fa fa-thumbs-o-up'></i> Thanks " . $payment->customer->email . ", your payment has been accepted.</strong></div>";
<?php session_start(); require_once 'include/init.php'; $firstname = htmlspecialchars($_SESSION['firstname']); $lastname = htmlspecialchars($_SESSION['lastname']); $email = htmlspecialchars($_SESSION['email']); $amount = htmlspecialchars($_SESSION['amount']); $cardid = htmlspecialchars($_SESSION['cardid']); $my_order_id = uniqid(fb, more_entropy); \Payplug\Payplug::setSecretKey($secretkey); $payment = \Payplug\Payment::create(array('amount' => $amount * 100, 'currency' => 'EUR', 'payment_method' => $cardid, 'customer' => array('email' => $email, 'first_name' => $firstname, 'last_name' => $lastname), 'notification_url' => $notification_url . '?order_id=' . $my_order_id . '&edom=' . $mode, 'metadata' => array('customer_id' => $my_order_id))); session_unset($_SESSION['firstname']); session_unset($_SESSION['lastname']); session_unset($_SESSION['email']); session_unset($_SESSION['amount']); session_unset($_SESSION['cardid']); header('Location:infos.php?paymentid=' . $payment->id);
<div class='col-md-12'> <?php require_once 'include/init.php'; $firstname = htmlspecialchars($_POST['firstname']); $lastname = htmlspecialchars($_POST['lastname']); $email = htmlspecialchars($_POST['email']); $amount = htmlspecialchars($_POST['amount']); $my_order_id = uniqid('fb', false); $savethecard = htmlspecialchars($_POST['savethecard']); if ($savethecard == "yes") { $save_opt = true; } else { $save_opt = false; } \Payplug\Payplug::setSecretKey($secretkey); $payment = \Payplug\Payment::create(array('amount' => $amount * 100, 'currency' => 'EUR', 'save_card' => $save_opt, 'customer' => array('email' => $email, 'first_name' => $firstname, 'last_name' => $lastname), 'hosted_payment' => array('return_url' => $return_url . '?order_id=' . $my_order_id, 'cancel_url' => $cancel_url . '?order_id=' . $my_order_id), 'notification_url' => $notification_url . '?edom=' . $mode . '&order_id=' . $my_order_id, 'metadata' => array('order_id' => $my_order_id))); $ppurl = $payment->hosted_payment->payment_url; $paymentid = $payment->id; echo "<h3><i class='fa fa-thumbs-o-up'></i> Successfully create a {$amount} € payment for {$firstname} {$lastname} !</h3>"; echo "<div>Payment ID is <strong>{$paymentid}</strong></div>"; echo "<div>Payment url is <strong><a href='{$ppurl}'>{$ppurl}</a></strong></div>"; echo "<div>Order ID is <strong>{$my_order_id}</strong></div>"; ?> </div> <div class='col-md-12'> <?php echo "<br /><a href='{$ppurl}' class='btn btn-primary btn-lg btn-block' role='button'>Pay now !</a>"; ?> </div> </div> </div>