PHP code example of codejutsu1 / laravel-paystack-transfer

1. Go to this page and download the library: Download codejutsu1/laravel-paystack-transfer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codejutsu1 / laravel-paystack-transfer example snippets


    

    // config for Codejutsu1/LaravelPaystackTransfer
    return [
        /**
         * Public Key From Paystack Dashboard
         *
         */
        'public_key' => env('PAYSTACK_PUBLIC_KEY'),

        /**
         * Secret Key From Paystack Dashboard
         *
         */
        'secret_key' => getenv('PAYSTACK_SECRET_KEY'),

    ];

    



$transfers = [
    "amount": "37800",
    "reference": "your-unique-reference", 
    "recipient": "RCP_t0ya41mp35flk40", 
    "reason": "Holiday Flexing" 
];


 

$data = [
    "type" => "nuban", //Recipient type, either nuban, ghipps, mobile_money or bass
    "name" => "Daniel Dunu", //Recipient name
    "account_number" => "01000000010", // Recipient Account Number
    "bank_code" => "058", // Recipient bank code
    "currency" => "NGN", // Recipient Currency
];

try{
    $response = PaystackTransfer::createTransferRecipient($data);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    // Your code Logic
}


 

$data = [
    [
        "type" => "nuban", //Recipient type, either nuban, ghipps, mobile_money or bass
        "name" => "Daniel Dunu", //Recipient name
        "account_number" => "01000000010", // Recipient Account Number
        "bank_code" => "058", // Recipient bank code
        "currency" => "NGN", // Recipient Currency
    ],
    [
        "type" => "ghipps", //Recipient type, either nuban, ghipps, mobile_money or bass
        "name" => "John Doe", //Recipient name
        "account_number" => "02000000020", // Recipient Account Number
        "bank_code" => "018", // Recipient bank code
        "currency" => "NGN", // Recipient Currency
    ],
];

try{
    $response = PaystackTransfer::bulkTransferRecipient($data);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    // Your code Logic
}




try{
    $response = PaystackTransfer::listTransferRecipients();
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    // Eg of code logic
    $transferRecipients = collect($response->data);

    return $transferRecipients;
}




$queryParameters = [
    "perPage" => 30, //Integer(optional), Records per page.
    "page" => 2, //Integer(optional), exact page to retrieve.
    "from" => "2016-09-24T00:00:05.000Z", //dateTime(optional), Timestamp to start listing transfer recipient.
    "to" => "2016-09-24T00:00:05.000Z", //dateTime(optional), Timestamp to stop listing transfer recipient
];

try{
    $response = PaystackTransfer::listTransferRecipients($queryParameters);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

return $response;



try{
    $response = PaystackTransfer::fetchTransferRecipient("RCP_2x5j67tnnw1t98k");
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    // Your code logic here
}




$data = [
    'email' => '[email protected]'
];

try{
    $response = transfer()->updateTransferRecipient("RCP_2x5j67tnnw1t98k", $data);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    // Your code logic here
}




try{
    $response = transfer()->deleteTransferRecipient("RCP_2x5j67tnnw1t98k");
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    // Your code logic here
}




try{
    $response = transfer()->getBanks();
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    $banks = collect($response->data); // To a collection.

    // Your logic
}


 

$queryParameters = [
    "country" => "ghana", //String(Optional), nigeria or ghana, default is nigeria
    "perPage" => 50,  //Integer(optional), Records per page.
    //Other query parameters in the documentation.
];

try{
    $response = transfer()->getBanks($queryParameters);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

return $response;


 

try{
    $code = transfer()->getBankCode("United Bank For Africa");
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

return $code;



try{
    $response = PaystackTransfer::verifyAccountNumber(accountNumber:"2134288420", bankCode:"022");
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    //Your logic
}




$parameters = [
	"reason": "Savings",
	"amount": 300000, //NGN3000, converted to kobo. 
	"reference": "your-unique-reference",
	"recipient": "RCP_1a25w1h3n0xctjg"
];
try{
    $response = PaystackTransfer::singleTransfer($parameters);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    //Your code logic
}




try{
    $response = transfer()->finalizeTransfer(transfer_code:"TRF_vsyqdmlzble3uii", otp: "930322");
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    //Your logic
}




$transfers = [
    [
        "amount"=> 20000,
        "reference"=> "588YtfftReF355894J",
        "reason"=> "Why not?",
        "recipient"=> "RCP_2tn9clt23s7qr28",    
    ],
    [
        "amount"=> 30000,
        "reference"=> "YunoTReF35e0r4J",
        "reason"=> "Because I can",
        "recipient"=> "RCP_1a25w1h3n0xctjg",    
    ],
    [
        "amount"=> 40000,
        "reference"=> generateTransferReference(),
        "reason"=> "Go buy your mama a house",
        "recipient"=> "RCP_aps2aibr69caua7",
    ]
];

try{
    $response = PaystackTransfer::bulkTransfer($transfers);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    //Your logic
}




$transfers = [
    [
        "amount"=> 20000,
        "reference"=> "588YtfftReF355894J",
        "reason"=> "Why not?",
        "recipient"=> "RCP_2tn9clt23s7qr28",    
    ],
    [
        "amount"=> 30000,
        "reference"=> "YunoTReF35e0r4J",
        "reason"=> "Because I can",
        "recipient"=> "RCP_1a25w1h3n0xctjg",    
    ],
    [
        "amount"=> 40000,
        "reference"=> generateTransferReference(),
        "reason"=> "Go buy your mama a house",
        "recipient"=> "RCP_aps2aibr69caua7",
    ],
    //.... > 97 more arrays
];

try{
    $response = PaystackTransfer::batchTransfer($transfers);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    //Your logic
}




try{
    $response = PaystackTransfer::listTransfers();
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    //Your logic
}


$queryParameters = [
    "perPage" => 30, //Integer(optional), Records per page.
    "page" => 2, //Integer(optional), exact page to retrieve.
    "customer" => "12121", //String(optional), filter by id.
    "from" => "2016-09-24T00:00:05.000Z", //dateTime(optional), Timestamp to start listing transfer recipient.
    "to" => "2016-09-24T00:00:05.000Z", //dateTime(optional), Timestamp to stop listing transfer recipient
];

try{
    $response = PaystackTransfer::listTransfers($queryParameters);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

return $response;




try{
    $response = PaystackTransfer::fetchTransfer("14938");
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    //Your logic
}


try{
    $response = PaystackTransfer::verifyTransfer("your_reference");
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    //Your code logic
} 

bash
    php artisan paystack-transfer:install