-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddfund.php
More file actions
56 lines (46 loc) · 1.49 KB
/
addfund.php
File metadata and controls
56 lines (46 loc) · 1.49 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
47
48
49
50
51
52
53
54
55
56
<?php
require 'config.php';
$curl = curl_init();
$reference = isset($_GET['reference']) ? $_GET['reference'] : '';
if(!$reference){
die('No reference supplied');
}
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.paystack.co/transaction/verify/" . rawurlencode($reference),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"accept: application/json",
"authorization: Bearer " . PAYSTACK_SECRET,
"cache-control: no-cache"
],
));
$response = curl_exec($curl);
$err = curl_error($curl);
if($err){
// there was an error contacting the Paystack API
die('Curl returned error: ' . $err);
}
$tranx = json_decode($response);
if(!$tranx->status){
// there was an error from the API
die('API returned error: ' . $tranx->message);
}
if('success' == $tranx->data->status){
// transaction was successful...
// please check other things like whether you already gave value for this ref
// if the email matches the customer who owns the product etc
// Give value
header("content-type: application/json");
// uncomment this line if you want to see the payment data
//echo $response;
//die();
if ( $tranx->data->customer->email == $_SESSION['user']['email']) {
// update the user wallet
$user = $_SESSION['user']['id'];
$amount = $tranx->data->amount / 100;
$sql = "UPDATE `wallets` SET amount = amount + '$amount' WHERE user = $user";
$stmt = $db->query($sql);
// redirect to wallet
header("Location:index.php");
}
}