PHP code example of payintohq / payinto-php-sdk

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

    

payintohq / payinto-php-sdk example snippets


use Payinto\Client;

$payinto = new Client([
    'secretKey' => $_ENV['PAYINTO_LIVE_SECRET_KEY'],
    'publicKey' => $_ENV['PAYINTO_LIVE_PUBLIC_KEY'] ?? null,
    'webhookSecret' => $_ENV['PAYINTO_LIVE_WEBHOOK_SECRET'] ?? null,
]);

use Payinto\Client;

public function show(Client $payinto): array
{
    return $payinto->business->whoami()->raw();
}

$response = $payinto->business->whoami();
$business = $response->data();
$response->status(); $response->message(); $response->timestamp();
$response->raw(); // complete decoded envelope

use Payinto\Exception\ValidationException;

try {
    // amount_control is 
        'merchant_reference' => 'ORDER-1',
    ]);
} catch (ValidationException $exception) {
    // Read the API message: "One or more of the given data has an error."
    $message = $exception->getMessage();

    // Read field-level errors, for example: ["The amount control field is 

// Check that the Business API is available.
$payinto->business->status();

// Resolve the business and environment associated with the secret key.
$payinto->business->whoami();

// Query the status of a Business API transaction by reference.
$payinto->transactions->status('merchant-reference');

// List accounts for the business.
$payinto->accounts->list([
    'page' => 1,
    'per_page' => 25,
]);

// Retrieve the business's main account.
$payinto->accounts->main();

// Retrieve transactions belonging to the main account.
$payinto->accounts->mainTransactions([
    'page' => 1,
    'per_page' => 50,
]);

// Retrieve a specific account.
$payinto->accounts->get($accountId);

// Retrieve transactions belonging to a specific account.
$payinto->accounts->transactions($accountId);

// Create an individual customer.
$customer = $payinto->customers->createIndividual([
    'first_name' => 'Ada',
    'last_name' => 'Example',
    'gender' => 'female',
    'date_of_birth' => '1990-01-15',
    'email' => '[email protected]',
    'phone_number' => '+2348000000000',
    'country_code' => 'NG',
    'bvn' => '12345678901',
    'nin' => '12345678901', // optional
    'address' => [
        'address_line1' => '1 Example Street',
        'city' => 'Lagos',
        'state' => 'Lagos',
        'country' => 'NG',
    ],
]);

// Search or list customers.
$payinto->customers->list([
    'search' => 'Ada',
    'page' => 1,
    'per_page' => 25,
]);

// Retrieve a customer by ID.
$payinto->customers->get($customer->data()['id']);

// Update permitted customer fields. All update fields are optional, so send
// only the values that need to change.
//
// Important: once a customer's identity has been verified, identity/profile
// data and identification information cannot be changed. This includes
// names, gender, date of birth, BVN, NIN, and other verified identity data.
// Make those corrections before identity verification, where permitted.
$updatedCustomer = $payinto->customers->update($customer->data()['id'], [
    // Non-identity contact fields may be updated when allowed by the API.
    'email' => '[email protected]',
    'phone_number' => '+2348000000000',
    'country_code' => 'NG',
    'metadata' => [
        'source' => 'web',
    ],
]);

// Create a business customer.
$payinto->customers->createBusiness([
    'business_name' => 'Example Ltd',
    'business_registration_type' => 'limited',
    'business_registration_number' => 'RC123456',
    'business_registration_date' => '2020-01-15',
    'first_name' => 'Ada',
    'last_name' => 'Example',
    'gender' => 'female',
    'date_of_birth' => '1990-01-15',
    'email' => '[email protected]',
    'phone_number' => '+2348000000000',
    'country_code' => 'NG',
    'bvn' => '12345678901',
    'nin' => '12345678901', // optional
    'address' => [
        'address_line1' => '1 Example Street',
        'city' => 'Lagos',
        'state' => 'Lagos',
        'country' => 'NG',
    ],
]);

// Upload a customer photo as a multipart request.
$payinto->customers->uploadPhoto($customer->data()['id'], file_get_contents('photo.jpg'), 'photo.jpg');

// Verify customer identity without an OTP flow.
$payinto->customers->verifyIdentity($customer->data()['id'], [
    'type' => 'BVN', // use BVN or NIN
]);

// Start an OTP-based customer identity verification.
$identityChallenge = $payinto->customers->initiateIdentity($customer->data()['id'], [
    'type' => 'BVN', // use BVN or NIN
]);

// Complete an OTP-based customer identity verification.
$payinto->customers->validateIdentity($customer->data()['id'], [
    'type' => 'BVN',
    'reference' => $identityChallenge->data()['reference'],
    'otp' => '123456',
]);

// List virtual accounts.
$payinto->virtualAccounts->list();

// Create a reusable static virtual account for an existing customer.
// customer_id and merchant_reference are   'amount' => 5000,
    'merchant_reference' => 'DATA-ORDER-1', // optional but recommended
]);

// Pay a cable TV bill.
$payinto->vas->payCableTv([
    'biller_id' => $cableBillerId,
    'product_id' => $cableProductId,
    'smart_card_number' => '1234567890',
    'amount' => 5000,
    'merchant_reference' => 'CABLE-ORDER-1', // optional but recommended
]);

// Pay an electricity bill.
$payinto->vas->payElectricity([
    'biller_id' => $electricityBillerId,
    'product_id' => $electricityProductId,
    'meter_number' => '1234567890123',
    'amount' => 50000,
    'merchant_reference' => 'ELECTRICITY-ORDER-1', // optional but recommended
]);

// Pay a betting account.
$payinto->vas->payBetting([
    'biller_id' => $bettingBillerId,
    'product_id' => $bettingProductId,
    'customer_id' => '123456789',
    'amount' => 5000,
    'merchant_reference' => 'BETTING-ORDER-1', // optional but recommended
]);

// Create an OTP challenge.
$otp = $payinto->addons->createOtp([
    'sender' => 'Payinto',
    'length' => 6,
    'expiry' => 10, // minutes accepted by the API: 5 to 60
    'channel' => ['sms'], // sms, whatsapp, email, or a combination
    'recipient' => [
        'phone_number' => '+2348000000000',
        'phone_number_country_code' => 'NG',
    ],
]);

// Validate an OTP challenge.
$payinto->addons->validateOtp($otp->data()['reference'], [
    'reference' => $otp->data()['reference'],
    'otp' => '123456',
]);

// Run a customer credit check.
$payinto->addons->creditCheck([
    'type' => 'individual',
    'bvn' => '12345678901',
    'credit_bureau' => 'CRC',
]);

// Calculate the credit-check fee.
$payinto->addons->creditCheckFee([
    'type' => 'individual',
    'credit_bureau' => 'CRC',
]);

// Verify a Bank Verification Number.
$payinto->addons->bvnVerification([
    'bvn' => '12345678901',
]);

// Retrieve the BVN verification fee.
$payinto->addons->bvnVerificationFee();

// Initialize a server-side Checkout session.
$initialized = $payinto->checkout->initialize([
    'amount' => 150000,
    'currency' => 'NGN',
    'merchant_reference' => 'ORDER-1',
    'customer' => [
        'name' => 'Ada Example', // optional
        'email' => '[email protected]', // 

// Query the final status of a Checkout payment from the server.
$result = $payinto->checkout->transactionStatus('ORDER-1');
if ($result->data()['payment_status'] === 'successful') { /* fulfil order */ }

use Illuminate\Http\Request;
use Payinto\Client;

public function webhook(Request $request, Client $payinto): array
{
    // Verify the request before trusting or processing its payload.
    $valid = $payinto->webhooks->verifyRequest($request);

    abort_unless($valid, 401, 'Invalid webhook signature.');

    return $request->json()->all();
}

use Payinto\Client;

$payinto = new Client([
    'secretKey' => $_ENV['PAYINTO_LIVE_SECRET_KEY'],
    'webhookSecret' => $_ENV['PAYINTO_LIVE_WEBHOOK_SECRET'],
    'webhookTimestampTolerance' => 300,
]);

$rawBody = (string) file_get_contents('php://input');
$signatureHeader = $_SERVER['HTTP_X_PAYINTO_SIGNATURE'] ?? '';

// Verify the raw body and Payinto signature before decoding JSON.
if (! $payinto->webhooks->verify($rawBody, $signatureHeader)) {
    http_response_code(401);
    exit('Invalid webhook signature.');
}

$payload = json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR);

// Call an endpoint that does not yet have a dedicated SDK method.
$payinto->request('GET', 'business/new-endpoint', ['query'=>['page'=>1]]);
bash
composer 
bash
php artisan vendor:publish --tag=payinto-config