-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayment.php
More file actions
46 lines (41 loc) · 1.57 KB
/
payment.php
File metadata and controls
46 lines (41 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
$secretkey = "yourprivatekeytest";
$email = htmlspecialchars($_POST['email']);
$firstname = htmlspecialchars($_POST['firstname']);
$lastname = htmlspecialchars($_POST['lastname']);
$token = $_POST['payplugToken'];
// $amountc = $_SESSION['amount'];
$amountc = $_POST['amount'];
require_once("payplug-php/lib/init.php");
\Payplug\Payplug::setSecretKey($secretkey);
try {
$payment = \Payplug\Payment::create(array(
'amount' => $amountc*100,
'currency' => 'EUR',
'payment_method' => $token,
'customer' => array(
'email' => $email,
'first_name' => $firstname,
'last_name' => $lastname
),
'notification_url' => 'https://ppjs.rico.solutions/notifications.html'
));
} catch (\Payplug\Exception\ConnectionException $e) {
echo "Connection with the PayPlug API failed.";
} catch (\Payplug\Exception\InvalidPaymentException $e) {
echo "Payment object provided is invalid.";
} catch (\Payplug\Exception\UndefinedAttributeException $e) {
echo "Requested attribute is undefined.";
} catch (\Payplug\Exception\HttpException $e) {
echo "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>Thanks " . $payment->customer->email . ", your payment has been accepted.</strong></div>";
} else {
var_dump($e);
echo "<div><strong>Error !</strong><br />". $payment->failure->message ." (" . $payment->failure->code . ").</div>";
}