PHP code example of sonawap / paystack

1. Go to this page and download the library: Download sonawap/paystack 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/ */

    

sonawap / paystack example snippets




use Sonawap\Paystack\Transaction\Transaction;
use Sonawap\Paystack\Transaction\Plan;
use Sonawap\Paystack\Transaction\Product;
use Sonawap\Paystack\Transaction\Invoice;
use Sonawap\Paystack\Customer\Customer;

$transaction = new Transaction();
$customer = new Customer();
$plan = new Plan();
$product = new Product();
$invoice = new Invoice();

/// initialize a transaction

$transaction->initializeTransaction($fields); //$fields as to be array

<!-- Example -->

$transaction->initializeTransaction(
    $fields = [
        'email' => "[email protected]",
        'amount' => "20000",
    ]
);

/// Charge Authorization

$transaction->chargeAuthorization(array); //$field as to be array

/// Check Authorization

$transaction->checkAuthorization(array); //$field as to be array

/// Partial_debits

$transaction->partial_debit(array); //$field as to be array

$transaction->transactionTotal([
    'perPage' => 5,
    'page' => 1
]); 


// List transactions carried out on your integration

$transaction->transactionTotal(array); //$field as to be array

// Get details of a transaction carried out on your integration.

$transaction->transactionTotal(array); //$field as to be array

/// Verify Transaction

$transaction->verifyTransaction(reference); // passing the reference gotten from the initialization of the transaction


// Create a Customer
$customer->createCustomer(); // $field must be array


// Example
$result = $customer->createCustomer(
    $fields = [
        'first_name' => '',
        'last_name' => '',
        'email' => "[email protected]"
    
    ]
);

// Desactivate Authorisation

$customer->deAuth(array);

// List Customers

$customer->listCustomers([
    'perPage' => 5,
    'page' => 1
]); 

// Fetch Customer

$customer->fetchCustomer("email"); ;

// Update Customer

$customer->updateCustomer(array);

// Validate Customer

$customer->validateCustomer(array);

// Whitelist/Blacklist Customer

$customer->wnbCustomer(array);


// Create Plan

$plan->createPlan(array);

// Example 
$plan->createPlan(
    $fields = [

		'name' => "Monthly retainer",

		'interval' => "monthly", 
	
		'amount' => "500000"
    
    ]
);

// Fetch Plan

$plan->fetchPlan(idOrCode);

// List Plans

$plan->listPlans(perPage, Page);

// Update Plan

$plan->updatePlan(code, array);


// Create Product

$product->createProduct(array);

// Example 
$product->createProduct(
    $fields = [
        'description' => "Product Six Description",
        'name' => "Product Six",
        'price' => 500000,
        'currency' => "USD",
        'limited' => false,
        'quantity' => 100,
    ]
);

// Fetch Product

$product->fetchProduct(idOrCode);

// List Products

$product->listProducts(perPage, Page);

// Update Product

$product->updateProduct(code, array);


// Create Product

$invoice->createInvoice(array);

// Example 
$invoice->createInvoice(
    $fields = [

        "description" => "a test invoice",
        "line_items"=> [
            {
                "name" => "item 1", 
                "amount" => 20000
            },

            {
                "name" => "item 2", 
                "amount" => 20000
            }
        ],
        "tax" => [
            {
                "name" => "VAT", 
                "amount" => 2000
            }
        ],
        "customer" => "CUS_xwaj0txjryg393b",
        "due_date" => "2020-07-08"

    ];
);

// Send Nofication

$invoice->sendNotification($fields = []);

// Archive Invoice

$invoice->archiveInvoice($fields = []);

// Total Invoice

$invoice->totalInvoice();

// List Invoices

$invoice->listInvoices() ;  //perPage = 5, customer = Customer_id

// View Invoice

$invoice->fetchInvoice($idOrCode) ;  

// View Invoice

$invoice->finalizeInvoice() ; 

// Verify Invoice

$invoice->verifyInvoice($idOrCode) ;  

// Archive Invoice

$invoice->verifyInvoice($idOrCode) ;  

// Update Product

$invoice->updateInvoice(code, array);