Example #1
0
<?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);
Example #2
0
echo "<h2><i class='fa fa-list'></i> Latest payments:</h2><hr />";
echo "<table class='table table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<td class='text-center'></td>";
echo "<td class='text-center'>Amount</td>";
echo "<td class='text-center'>Customer</td>";
echo "<td class='text-center'>Creation date</td>";
echo "<td class='text-center'>Status</td>";
echo "<td class='text-center'>Payment ID</td>";
echo "<td class='text-center'></td>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
\Payplug\Payplug::setSecretKey($secretkey);
$payments = \Payplug\Payment::listPayments(50, 0);
$payment = $payments['data'][0];
foreach ($payments['data'] as $payment) {
    $is_paid = $payment->is_paid;
    $error_code = $payment->failure->code;
    $is_refunded = $payment->is_refunded;
    $cardid = $payment->card->id;
    if ($error_code == "aborted") {
        $aborted = "true";
    } else {
        $aborted = "false";
    }
    echo "<tr>";
    echo "<td class='text-center'>";
    if ($payment->hosted_payment != null && $payment->save_card == true) {
        echo " <i class='fa fa-floppy-o'></i> ";
Example #3
0
<?php

require_once 'include/init.php';
\Payplug\Payplug::setSecretKey($secretkey);
$paymentid = htmlspecialchars($_POST['paymentid']);
if (empty($paymentid)) {
    $paymentid = htmlspecialchars($_GET['paymentid']);
}
$payment = \Payplug\Payment::abort($paymentid);
header('Location:infos.php?paymentid=' . $paymentid);
Example #4
0
// 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>";
Example #5
0
<?php

session_start();
require_once 'include/init.php';
$paymentid = htmlspecialchars($_SESSION['paymentid']);
$order_id = htmlspecialchars($_SESSION['order_id']);
$type = htmlspecialchars($_GET['type']);
\Payplug\Payplug::setSecretKey($secretkey);
$payment = \Payplug\Payment::retrieve($paymentid);
if ($type == "full") {
    $amount = $payment->amount;
    $comment = "Quick full refund";
} elseif ($type == "partial") {
    $amount = htmlspecialchars($_POST['amount_par']) * 100;
    $comment = htmlspecialchars($_POST['comment']);
}
$data = array('amount' => $amount, 'metadata' => array('reason' => $comment, 'order_id' => $order_id));
$refund = \Payplug\Refund::create($paymentid, $data);
header('Location:infos.php?paymentid=' . $paymentid);
Example #6
0
 public function testPaymentAbort()
 {
     $GLOBALS['CURLOPT_POSTFIELDS_DATA'] = null;
     $this->_requestMock->expects($this->once())->method('exec')->will($this->returnValue('{"status":"ok"}'));
     $this->_requestMock->expects($this->atLeastOnce())->method('setopt')->will($this->returnCallback(function ($option, $value = null) {
         switch ($option) {
             case CURLOPT_POSTFIELDS:
                 $GLOBALS['CURLOPT_POSTFIELDS_DATA'] = json_decode($value, true);
                 return true;
         }
         return true;
     }));
     $this->_requestMock->expects($this->any())->method('getinfo')->will($this->returnCallback(function ($option) {
         switch ($option) {
             case CURLINFO_HTTP_CODE:
                 return 200;
         }
         return null;
     }));
     $payment = Payplug\Payment::abort('a_payment_id');
     $this->assertTrue(is_array($GLOBALS['CURLOPT_POSTFIELDS_DATA']));
     $this->assertTrue($GLOBALS['CURLOPT_POSTFIELDS_DATA'] === array('abort' => true));
     $this->assertEquals('ok', $payment->status);
     unset($GLOBALS['CURLOPT_POSTFIELDS_DATA']);
 }
Example #7
0
          <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>