PHP code example of pay-now / paynow-php-sdk

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

    

pay-now / paynow-php-sdk example snippets




use Paynow\Client;
use Paynow\Environment;
use Paynow\Exception\PaynowException;
use Paynow\Service\Payment;

$client = new Client('TestApiKey', 'TestSignatureKey', Environment::SANDBOX);
$orderReference = "success_1234567";
$idempotencyKey = uniqid($orderReference . '_');

$paymentData = [
    'amount' => '100',
    'currency' => 'PLN',
    'externalId' => $orderReference,
    'description' => 'Payment description',
    'buyer' => [
        'email' => '[email protected]'
    ]
];

try {
    $payment = new Payment($client);
    $result = $payment->authorize($paymentData, $idempotencyKey);
} catch (PaynowException $exception) {
    // catch errors
}

use Paynow\Notification;

$payload = trim(file_get_contents('php://input'));
$headers = getallheaders();
$notificationData = json_decode($payload, true);

try {
    new Notification('TestSignatureKey', $payload, $headers);
    // process notification with $notificationData
} catch (Exception $exception) {
    header('HTTP/1.1 400 Bad Request', true, 400);
}

header('HTTP/1.1 202 Accepted', true, 202);

use Paynow\Client;
use Paynow\Environment;
use Paynow\Exception\PaynowException;
use Paynow\Service\Refund;

$client = new Client('TestApiKey', 'TestSignatureKey', Environment::SANDBOX);

try {
    $refund = new Refund($client);
    $result = $refund->create('YXZA-123-ABC-A01', uniqid(), 100);
} catch (PaynowException $exception) {
    // catch errors
}

use Paynow\Client;
use Paynow\Environment;
use Paynow\Exception\PaynowException;
use Paynow\Service\Payment;

$client = new Client('TestApiKey', 'TestSignatureKey', Environment::SANDBOX);

try {
    $payment = new Payment($client);
    $paymentMethods = $payment->getPaymentMethods('PLN', 100);
    $availablePaymentMethods = $paymentMethods->getAll();
} catch (PaynowException $exception) {
    // catch errors
}
bash
$ composer 
bash
$ composer