PHP code example of alexasomba / paystack-php

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

    

alexasomba / paystack-php example snippets


$config = Configuration::getDefaultConfiguration()
    ->setAccessToken($_ENV['PAYSTACK_SECRET_KEY']);



lexasomba\Paystack\Api\TransactionApi;
use Alexasomba\Paystack\Configuration;
use Alexasomba\Paystack\Model\TransactionInitialize;
use GuzzleHttp\Client;

$config = Configuration::getDefaultConfiguration()
    ->setAccessToken($_ENV['PAYSTACK_SECRET_KEY']);

$api = new TransactionApi(new Client(), $config);
$response = $api->transactionInitialize(
    new TransactionInitialize([
        'email' => '[email protected]',
        'amount' => 5000,
    ])
);

echo $response->getData()->getAuthorizationUrl() . PHP_EOL;

use Alexasomba\Paystack\Extras\HttpClientFactory;
use Alexasomba\Paystack\Extras\Paystack;

$config = Paystack::createConfiguration($_ENV['PAYSTACK_SECRET_KEY']);
$client = HttpClientFactory::create([
    'timeoutSeconds' => 30,
    'idempotency' => ['enabled' => true, 'auto' => true],
]);

$response = $transactionApi->transactionInitialize(
    new TransactionInitialize(['email' => '[email protected]', 'amount' => 5000])
);

$verified = $transactionApi->transactionVerify('ref_123');

$chargeApi->chargeCreate(new ChargeCreateRequest(['email' => '[email protected]']));

$bulkChargeApi->bulkChargeInitiate([
    new BulkChargeInitiate(['authorization' => 'AUTH_xxx', 'amount' => 5000, 'reference' => 'bulk-ref-1']),
]);

$subaccountApi->subaccountCreate(new SubaccountCreate(['business_name' => 'Acme Stores']));

$splitApi->splitCreate(new SplitCreate(['name' => 'Main split', 'type' => 'percentage', 'currency' => 'NGN']));

$terminals = $terminalApi->terminalList();

$virtualTerminalApi->virtualTerminalCreate(new VirtualTerminalCreate(['name' => 'Web checkout terminal']));

$customerApi->customerCreate(new CustomerCreate(['email' => '[email protected]']));

$directDebitApi->directdebitInitialize(new DirectDebitInitializeRequest(['email' => '[email protected]']));

$dedicatedVirtualAccountApi->dedicatedAccountAssign(new DedicatedVirtualAccountAssign(['customer' => 12345]));

$applePayApi->applePayRegisterDomain(new ApplePayParam(['domain_name' => 'example.com']));

$planApi->planCreate(new PlanCreate(['name' => 'Starter', 'amount' => 500000, 'interval' => 'monthly']));

$subscriptionApi->subscriptionCreate(new SubscriptionCreate(['customer' => 'CUS_xxx', 'plan' => 'PLN_xxx']));

$transferRecipientApi->transferrecipientCreate(new TransferRecipientCreate(['name' => 'Ada Lovelace', 'type' => 'nuban']));

$transferApi->transferCreate(new TransferInitiate(['source' => 'balance', 'amount' => 5000, 'recipient' => 'RCP_xxx']));

$transferApi->transferEnableOtp();

$balance = $balanceApi->balanceFetch();

$paymentRequestApi->paymentRequestCreate(new PaymentRequestCreate(['amount' => 5000, 'description' => 'Consulting invoice']));

$resolved = $bankApi->bankResolveAccountNumber('0001234567', '057');

$productApi->productCreate(new ProductCreate(['name' => 'T-shirt', 'price' => 5000, 'currency' => 'NGN']));

$storefronts = $storefrontApi->storefrontList();

$orderApi->orderCreate(new OrderCreate(['customer' => 'CUS_xxx']));

$pageApi->pageCreate(new PageCreate(['name' => 'Event Ticket', 'amount' => 5000]));

$settlements = $settlementApi->settlementList();

$timeout = $integrationApi->integrationFetchPaymentSessionTimeout();

$integrationApi->integrationUpdatePaymentSessionTimeout(20);

$refundApi->refundCreate(new RefundCreate(['transaction' => 123456789, 'amount' => 5000]));

$disputes = $disputeApi->disputeList();

$banks = $bankApi->bankList('nigeria');

$countries = $miscellaneousApi->miscellaneousListCountries();