PHP Classes

File: php/verifyPaymentPaystack.php

Recommend this page to a friend!
  Classes of bamigboye biodun   Logical Functions   php/verifyPaymentPaystack.php   Download  
File: php/verifyPaymentPaystack.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Logical Functions
General-purpose PHP and JavaScript functions
Author: By
Last change:
Date: 1 year ago
Size: 1,270 bytes
 

Contents

Class file image Download
<?php
function verifyPaymentPaystack(String $secretKey, $transactionReference)
: Array{

//The parameter after verify/ is the transaction reference to be verified
$url = 'https://api.paystack.co/transaction/verify/'.$transactionReference;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt(
 
$ch, CURLOPT_HTTPHEADER, [
   
'Authorization: Bearer '.$secretKey]
);
//send request
$request = curl_exec($ch);
//close connection
curl_close($ch);
//declare an array that will contain the result
$result = array();
if (
$request) {
 
$result = json_decode($request, true);
}else{
    return [
       
'status' => false,
       
'message' => 'data_fetch_error'
   
];
}
$status =(array_key_exists('data', $result)
&&
array_key_exists('status', $result['data'])
&& (
$result['data']['status'] === 'success'));
return
$result;
}

/*----------------------------------------------------------------
Author : Biodun Bamigboye
usage example
verifyPaymentPaystack('sk_live_eeeehjjdhfnfhhdndf776dhfhdhd',36364553545);
First Parameter is the secret key to your paystack account
Second Parameter is the transaction reference to be queried
returns an array
status key which is boolean shows the state of the transaction

*/