-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
pay.php
90 lines (70 loc) · 2.06 KB
/
pay.php
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!--
-- Developed by Nnaemeka Nweke.
-- I am a software engineer open for freelance work.
-- You can reach on Twitter @codegenty
-- I am also avalibale on linkedin // https://www.linkedin.com/in/nnaemekanweke
-- My email address nnaemeka.nweke2@gmail.com
-->
<?php
// Get form data from the frontend
if(isset($_POST['pay']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$plan = $_POST['options'];
//Payment processor parameters
$request = [
"tx_ref" => 'FLW |'.time(),
"amount" => $plan,
"currency" =>"NGN",
"redirect_url" =>"http://localhost:5000/confirmPayment.php",
"payment_options" =>"card,banktransfer",
"meta" =>[
"consumer_id" =>23,
"consumer_mac" =>"92a3-912ba-1192a",
"price" => $plan
],
"customer" =>[
"email" => $email,
"phone_number" =>"080****4528",
"name" => $name
],
"customizations" =>[
"title" => "Pied Piper Payments",
"description" => "Middleout isn't free. Pay the price",
"logo" => "https://th.bing.com/th/id/R32be9fd5280ac7a66de9032638beb97b?rik=14frGejks3IxYw&pid=ImgRaw"
]
];
}
// Send payment to flutterwave for processing
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.flutterwave.com/v3/payments',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode($request),
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer {SECRETE_KEY}', //Get your Secrete key from flutterwave dashboard.
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
// echo '<pre>';
// echo $response;
// echo '</pre>';
curl_close($curl);
$res = json_decode($response);
// Redirect to payment validation
if ($res->status === 'success') {
$link = $res->data->link;
header('Location: '.$link);
}
else{
echo "We can't process your payment";
}
?>