forked from PaystackHQ/sample-paystack-pop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify.php
More file actions
44 lines (36 loc) · 1.23 KB
/
verify.php
File metadata and controls
44 lines (36 loc) · 1.23 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
<?php
// Confirm that reference has not already gotten value
// This would have happened most times if you handle the charge.success event.
// If it has already gotten value by your records, you may call
// perform_success()
require 'vendor/autoload.php';
$paystack = new Yabacon\Paystack('SECRET_KEY');
// the code below throws an exception if there was a problem completing the request,
// else returns an object created from the json response
$trx = $paystack->transaction->verify([
'reference'=>$_GET['reference']
]);
// status should be true if there was a successful call
if(!$trx->status){
exit($trx->message);
}
// full sample verify response is here: https://developers.paystack.co/docs/verifying-transactions
if('success' == $trx->data->status){
// use trx info including metadata and session info to confirm that cartid
// matches the one for which we accepted payment
give_value($reference, $trx);
perform_success();
}
// provide value to the customer
function give_value($reference, $trx){
// Be sure to log the reference as having gotten value
// write code to give value
}
function perform_success(){
// popup
echo json_encode(['verified'=>true]);
// standard
header('Location: /success.php');
exit();
}
?>