PHP code example of nigel / contipay-php

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

    

nigel / contipay-php example snippets



use Contipay\Core\Contipay;
use Contipay\Helpers\Payload\PayloadGenerator;

www.contipay.co.zw/api/success";
$cancelUrl = "https://www.contipay.co.zw/api/cancel";
$merchantCode = 00;
$phone = "2637****340";
$amount = (float) 10;

$contipay = new Contipay(
    'token-here', // copy from .env or paste directly
    'secret-here', // copy from .env or paste directly
);


$payload = (new PayloadGenerator($merchantCode, $webhookUrl))
    ->setUpProviders('InnBucks', 'IB')
    ->simpleDirectPayload(
        $amount,
        $phone,
    );

$res = $contipay->setAppMode("DEV")
    ->setPaymentMethod()
    ->process($payload);

header('Content-type: application/json');

echo $res;


$payload = (
    new PayloadGenerator(
        $merchantCode,
        $webhookUrl,
        $successUrl,
        $cancelUrl
    )
)->simpleRedirectPayload(
        $amount,
        $phone
    );

$res = $contipay->setAppMode("DEV")
    ->setPaymentMethod('redirect')
    ->process($payload);

header('Content-type: application/json');

echo $res;


$payload = (
    new PayloadGenerator(
        $merchantCode,
        $webhookUrl
    )
)->setUpCustomer('Nigel', 'Jaure', $phone, 'ZW', '[email protected]')
    ->setUpProviders('Ecocash', 'EC')
    ->setUpAccountDetails($phone, 'Nigel Jaure')
    ->setUpTransaction($amount, "USD")
    ->directPayload();

$res = $contipay
    ->setAppMode("DEV")
    ->setPaymentMethod()
    ->process($payload);

header('Content-type: application/json');

echo $res;

$payload = (
    new PayloadGenerator(
        $merchantCode,
        $webhookUrl,
        $successUrl,
        $cancelUrl
    )
)->setUpCustomer('Nigel', 'Jaure', $phone, 'ZW', '[email protected]')
    ->setUpTransaction($amount, "USD")
    ->redirectPayload();

$res = $contipay->setAppMode("DEV")
    ->setPaymentMethod('redirect')
    ->process($payload);

header('Content-type: application/json');

echo $res;;


$privateKey = <<<EOD
-----BEGIN PRIVATE KEY-----
     YOUR KEY HERE 
-----END PRIVATE KEY-----
EOD;

$payload = (
    new PayloadGenerator(
        $merchantCode,
        $webhookUrl
    )
)->setUpCustomer('Nigel', 'Jaure', $phone, 'ZW', '[email protected]')
    ->setUpProviders('Transfer', 'TF')
    ->setUpAccountDetails($phone, 'Nigel Jaure')
    ->setUpTransaction($amount, "USD")
    ->directPayload();

$res = $contipay
    ->setAppMode("DEV")
    ->setPaymentMethod()
    ->disburse($payload, $privateKey);

header('Content-type: application/json');

echo $res;

$contipay = new Contipay(
    'token-here', // copy from .env or paste directly
    'secret-here', // copy from .env or paste directly
);

// Update URLs if necessary
$contipay->updateURL('dev-url', 'live-url');

// Process payment with the updated URLs
$res = $contipay
    ->setAppMode("DEV")  // LIVE as another option
    ->setPaymentMethod()
    ->process($payload);

header('Content-type: application/json');

echo $res;
bash
composer