1. Go to this page and download the library: Download kofi/ngpayments 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/ */
public function boot(){
//Create configuration
$payment_provider_config = [
"provider" => "paystack", //If the provider is not set, default is Paystack
"public_key" => config("services.paystack.public_key"),
"secret_key" => config("services.paystack.private_key"),
"app_env" => config("app.env")
];
//Tell the package to use this configuration
PaymentProviderFactory::setPaymentProviderConfig($payment_provider_config);
}
PaymentProviderFactory::enableHttpExceptions();
$bill = new Bill("[email protected]", 3000); //The Bill class always works with amounts in naira.
$payment_reference = $bill->charge()->getPaymentReference();
savePaymentReference($payment_reference); // save the generated reference to your database
$payment_page_url = $bill->getPaymentPageUrl();
header("Location: " . $payment_page_url); //redirect to Paystack's checkout page
$bill = new Bill();
$bill->customer_email = "[email protected]";
$bill->reference = "unique_reference";
$bill->callback_url = $callback_url;
//if you are working with Paystack,
//set the amount in kobo,
//if you want to work with naira amounts (with Paystack)
//set the naira_amount property instead like so:
$bill->amount = 40000;
$bill->naira_amount = 400;
$payment_page_url = $bill->charge()->getPaymentPageUrl()
//Redirect to the payment page.
//If you are using a framework, use your framework's redirect method
header("Location: ". $payment_page_url);
$bill = new Bill($customer_email, 7000);
$reference = $bill->charge()->getPaymentReference(); //make sure to call the charge() method on bill first
savePaymentReferenceToDB($reference);
$payment_page_url = $bill->getPaymentPageUrl();
header("Location: ". $payment_page_url);
$reference = getPaymentReferenceFromSomewhere();
if(Bill::isPaymentValid($reference, 7000)){
//send product to customer or activate account etc.
}
$bill = new Bill($customer_email, 7000);
$reference = $bill->charge()->getPaymentReference();
$payment_page_url = $bill->getPaymentPageUrl();
redirect_to_url($payment_page_url) //if you are using a framework, use your framework's redirect method
$authorization_code = Bill::getPaymentAuthorizationCode($reference, 7000); //This method validates the payment made by the customer and returns the authorization code (token) if the payment is valid
$auth_bill = new AuthBill($authorization_code, $customer_email, 3000);
$reference = $auth_bill->charge(); //if the payment is successful, this returns a reference, if it fails, it returns null
$subaccount = new Subaccount($business_name, $settlement_bank, $account_number, $percentage_charge);
//the save method will create a subaccount
//with your payment provider
//and return the id or code of the created subaccount
$subaccount_id = $subaccount->save();
saveSubaccountIdToDatabase($subaccount_id)
$plan = new Plan("My Plan", 3000, "weekly");
$plan_id = $plan->save();
$bill = new Bill($customer_email, 3000); //the plan amount will always override the bill amount in this case
$reference = $bill->subscribe($plan_id)->getPaymentReference();
$payment_page_url = $bill->getPaymentPageUrl();
header("Location: " . $payment_page_url); //redirect to the payment page
class Subaccount implements ApiDataMapperInterface
{
...
public function __construct(
$business_name = null,
string $settlement_bank = null,
string $account_number = null,
$percentage_charge = null
){...}
...