Skip to content

Instantly share code, notes, and snippets.

@ibrahimlawal
Last active December 17, 2020 13:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibrahimlawal/011693d6edf79552b4796ce557dbbfd6 to your computer and use it in GitHub Desktop.
Save ibrahimlawal/011693d6edf79552b4796ce557dbbfd6 to your computer and use it in GitHub Desktop.
Initializing a Paystack Transaction for 20 naira // And verifying it. // Uses Paystack Class : https://github.com/yabacon/paystack-class
<?php
// Get this from https://github.com/yabacon/paystack-class
require 'Paystack.php';
$paystack = new Paystack('sk_test_xxx');
// 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->initialize(
[
'amount'=>'2000', /* 20 naira */
'reference'=>'0832uhdo8sd0', /* Must be unique per transaction, not required */
'email'=>'xxxxx@gmail.com',
'callback_url'=>'http://example.com/verify.php'
/* sample verify code in the other file,
paystack will redirect to this file after the
transaction */
]
);
// status should be true if there was a successful call
if(!$trx->status){
exit($trx->message);
}
// full sample initialize response is here: https://developers.paystack.co/docs/initialize-a-transaction
// Get the user to click link to start payment or simply redirect to the url generated
echo $trx->data->authorization_url;
<?php
require 'Paystack.php';
$paystack = new Paystack('sk_test_xxx');
$reference = filter_input(INPUT_GET, 'reference');
$trx = $paystack->transaction->verify(
[
'reference'=>$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
echo $trx->data->status;
@zaacwilliam1
Copy link

Please how do I get customers display name and customer ID

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment