-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpay.php
97 lines (83 loc) · 2.48 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
91
92
93
94
95
96
97
<?php
if (!isset($_SESSION['user'])) {
header('location:index.php')
}
include('Userc.php');
$object=new Userc;
//recall from class
$transid=$_SESSION['trans_id'];
if (isset($_SESSION['trans_id'])) {
$return=$object->gettransdetails($transid);
}
if (isset($_SESSION['user'])) {
$cust_data=$object->getCustomer($_SESSION['user']);
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style type="text/css">
.height{
height:80vh;
}
</style>
<body>
<?php include('header2.php'); ?>
<div class="container">
<div class="row justify-content-center align-items-center height">
<div class="col-md-6 text-center">
<div class="card p-4">
<div class="card-body">
<h2 class="py-2">You are paying : <b><?php echo number_format($return['grand_total'] ,2);?></b></h2>
<h2 class="py-2">Your transaction number is: <b><?php echo $return['trans_no']; ?></b></h2>
<form id="paymentForm">
<script src="https://js.paystack.co/v1/inline.js"></script>
<button class="btn btn-warning py-2 my-2" type="submit" onclick="payWithPaystack(event)">Make Payment</button>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
include('footer.php');
?>
<script>
// const paymentForm = document.getElementById('paymentForm');
// paymentForm.addEventListener("submit", payWithPaystack(), false);
const api="pk_test_303bebb4a1c34e2f6245f1204a2cab2498142fd3";
function payWithPaystack(e) {
e.preventDefault();
var handler = PaystackPop.setup({
key: api,
email: '<?php echo $cust_data['cust_email']; ?>' ,
amount: '<?php echo $return['grand_total'] ; ?>' * 100,
firstname: '<?php echo $cust_data['cust_fname'];?>',
lastname: '<?php echo $cust_data['cust_lname'];?>',
ref: '<?php echo $return['trans_no']; ?>', // generates a pseudo-unique reference. Please replace with a reference you generated. Or remove the line entirely so our API will generate one for you
// label: "Optional string that replaces customer email"
onClose: function(){
alert('Window closed.');
},
callback: function(response){
let message = 'Payment complete! Reference: ' + response.reference;
alert(message);
console.log(response);
}
});
handler.openIframe();
//using json
// $data=json_encode(['email'=>$cust_data['email'], 'amount'=>$return['grand_total']]);
// $.ajax({
// url:'thankyou.php',
// data:$data,
// success:function(resp){
// $('row').html(resp);
// }
// })
}
</script>
</body>
</html>