Skip to content

Instantly share code, notes, and snippets.

@prestigegodson
Last active November 26, 2018 22:14
Show Gist options
  • Save prestigegodson/1f571d24504c528394a236a6617cd8d1 to your computer and use it in GitHub Desktop.
Save prestigegodson/1f571d24504c528394a236a6617cd8d1 to your computer and use it in GitHub Desktop.
public function transaction_charge(){
log_message('debug','Event charge.success from paystack');
// Retrieve the request's body
$input = @file_get_contents("php://input");
// only a post with paystack signature header gets our attention
if ((strtoupper($_SERVER['REQUEST_METHOD']) != 'POST' ) || !array_key_exists('HTTP_X_PAYSTACK_SIGNATURE', $_SERVER) ){
exit();
}
define('PAYSTACK_SECRET_KEY',$this->private_key);
// validate event do all at once to avoid timing attack
if($_SERVER['HTTP_X_PAYSTACK_SIGNATURE'] !== hash_hmac('sha512', $input, PAYSTACK_SECRET_KEY)){
exit();
}
http_response_code(200);
// parse event (which is json string) as object
// Do something - that will not take long - with $event
$event = json_decode($input);
//update transaction status
//update users payment status
if($event->event == "charge.success"){
log_message('debug','Entered successs');
//TODO: get transaction reference and work with it
$reference = $event->data->reference;
//with the transaction $reference, check if the transaction has already been marked as successful,
// if not, then credit agent wallet and mark as successful.
}
exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment