-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
paymentpage.php
156 lines (129 loc) · 5.77 KB
/
paymentpage.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
session_start();
require("functions.php"); //file which has required functions
?>
<html>
<head><title>Payment Page </title>
</head>
<body bgcolor="white">
<?php
$key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; //replace ur 32 bit secure key , Get your secure key from your Reseller Control panel
//This filter removes data that is potentially harmful for your application. It is used to strip tags and remove or encode unwanted characters.
$_GET = filter_var_array($_GET, FILTER_SANITIZE_STRING);
//Below are the parameters which will be passed from foundation as http GET request
$paymentTypeId = $_GET["paymenttypeid"]; //payment type id
$transId = $_GET["transid"]; //This refers to a unique transaction ID which we generate for each transaction
$userId = $_GET["userid"]; //userid of the user who is trying to make the payment
$userType = $_GET["usertype"]; //This refers to the type of user perofrming this transaction. The possible values are "Customer" or "Reseller"
$transactionType = $_GET["transactiontype"]; //Type of transaction (ResellerAddFund/CustomerAddFund/ResellerPayment/CustomerPayment)
$invoiceIds = $_GET["invoiceids"]; //comma separated Invoice Ids, This will have a value only if the transactiontype is "ResellerPayment" or "CustomerPayment"
$debitNoteIds = $_GET["debitnoteids"]; //comma separated DebitNotes Ids, This will have a value only if the transactiontype is "ResellerPayment" or "CustomerPayment"
$description = $_GET["description"];
$sellingCurrencyAmount = $_GET["sellingcurrencyamount"]; //This refers to the amount of transaction in your Selling Currency
$accountingCurrencyAmount = $_GET["accountingcurrencyamount"]; //This refers to the amount of transaction in your Accounting Currency
$redirectUrl = $_GET["redirecturl"]; //This is the URL on our server, to which you need to send the user once you have finished charging him
$checksum = $_GET["checksum"]; //checksum for validation
//Other variables.
$name = $_GET['name'];
$company = $_GET['company'];
$emailAddr = $_GET['emailAddr'];
$address1 = $_GET['address1'];
$address2 = $_GET['address2'];
$address3 = $_GET['address3'];
$city = $_GET['city'];
$state = $_GET['state'];
$country = $_GET['country'];
$zip = $_GET['zip'];
$telNoCc = $_GET['telNoCc'];
$telNo = $_GET['telNo'];
$faxNoCc = $_GET['faxNoCc'];
$faxNo = $_GET['faxNo'];
$resellerEmail = $_GET['resellerEmail'];
$resellerURL = $_GET['resellerURL'];
$resellerCompanyName = $_GET['resellerCompanyName'];
if(verifyChecksum($paymentTypeId, $transId, $userId, $userType, $transactionType, $invoiceIds, $debitNoteIds, $description, $sellingCurrencyAmount, $accountingCurrencyAmount, $key, $checksum))
{
//YOUR CODE GOES HERE
/**
* since all these data has to be passed back to foundation after making the payment you need to save these data
*
* You can make a database entry with all the required details which has been passed from foundation.
*
* OR
*
* keep the data to the session which will be available in postpayment.php as we have done here.
*
* It is recommended that you make database entry.
**/
$_SESSION['redirecturl']=$redirectUrl;
$_SESSION['transid']=$transId;
$_SESSION['sellingcurrencyamount']=$sellingCurrencyAmount;
$_SESSION['accountingcurencyamount']=$accountingCurrencyAmount;
//Insert the values into the database.
/*if ($conn = mysqli_connect("DBHost", "username", "password", "table"))
// replace the DB parameters with yours
{
if ($query = mysqli_query($conn, "INSERT INTO records (paymenttypeid, transid, userid, usertype, transactiontype, invoiceids, debitnoteids, description, sellingcurrencyamount, accountingcurrencyamount, redirecturl, checksum) VALUES('$paymentTypeId', '$transId', '$userId', '$userType', '$transactionType', '$invoiceIds', '$debitNoteIds', '$description', '$sellingCurrencyAmount', '$accountingCurrencyAmount', '$redirectUrl', '$checksum')"))
{
//Do nothing it worked.
}
else
{
die("Failed to record data".mysqli_error($conn));
}
}
else
{
die("Could not connect to mysql");
}*/
?>
<script src="https://js.paystack.co/v1/inline.js"></script>
<script type="text/javascript">
function payWithPaystack(){
var handler = PaystackPop.setup({
key: 'pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
email: '<?php $emailAddr = $_GET['emailAddr']; echo $emailAddr; ?>',
amount: '<?php $sellingCurrencyAmount = $_GET["sellingcurrencyamount"]; $sellingCurrencyAmountInNaira = $sellingCurrencyAmount * 100; echo $sellingCurrencyAmountInNaira; ?>',
ref: '<?php $transId = $_GET["transid"]; echo $transId; ?>', // best to comment out and use Paystacks automatic random ref generated number while testing your integration, else you'll get a duplicate Ref error from Paystack
metadata: {
custom_fields: [
{
display_name: "Customer Name",
variable_name: "custom_name",
value: '<?php $name = $_GET['name']; echo $name; ?>',
}
]
},
callback: function(response) {
var data = response.reference;
window.location = "postpayment.php?status=" + data;
},
onClose: function closeCurrentWindow() {
window.close();
}
});
handler.openIframe();
}
window.onload = function()
{
payWithPaystack();
};
</script>
<?php
}
else
{
/**This message will be dispayed in any of the following case
*
* 1. You are not using a valid 32 bit secure key from your Reseller Control panel
* 2. The data passed from foundation has been tampered.
*
* In both these cases the customer has to be shown error message and shound not
* be allowed to proceed and do the payment.
*
**/
echo "Checksum mismatch !";
}
?>
</body>
</html>