Last active
July 30, 2019 07:40
-
-
Save voidnerd/e46a0bc4afa65673ffa8be9770ee2d2c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function verify($reference) { | |
| $result = array(); | |
| //The parameter after verify/ is the transaction reference to be verified | |
| //you have to get reference from callback url if you are using paystack standard | |
| $url = 'https://api.paystack.co/transaction/verify/'. $reference; | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_URL, $url); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
| curl_setopt( | |
| $ch, CURLOPT_HTTPHEADER, [ | |
| 'Authorization: Bearer '. env('PAYSTACK_SECRET_KEY')] | |
| ); | |
| $request = curl_exec($ch); | |
| if(curl_error($ch)){ | |
| echo 'error:' . curl_error($ch); | |
| } | |
| curl_close($ch); | |
| if ($request) { | |
| $result = json_decode($request, true); | |
| } | |
| if (array_key_exists('data', $result) && array_key_exists('status', $result['data']) && ($result['data']['status'] === 'success')) { | |
| //transaction was successful | |
| $paid_amount = $result['data']['amount'] / 100; | |
| return response()->json($result['data']); | |
| }else{ | |
| //we could not verify this transaction | |
| return response()->json([ | |
| 'message' => 'Transaction was unsuccessful', | |
| 'success' => false | |
| ], 401); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment