PHP code example of answear / pay-po

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

    

answear / pay-po example snippets


use Answear\PayPo\Configuration\PayPoConfiguration;
use Answear\PayPo\Request\Transaction\CreateRequest;
use Answear\PayPo\Service\Order;
//...

PayPoConfiguration::setForSandbox('clientId', 'apiKey', 'api.sandbox.paypo.pl');

$orderService = new Order();
$registerResponse = $orderService->create(new CreateRequest(...));

$redirectUrl = $registerResponse->redirectUrl;
//...

//others requests
$orderService->confirm('transaction-uuid');
$orderService->refund('transaction-uuid', 123, 'our-refund-id');
$orderService->getStatusDetails('transaction-uuid');
$orderService->cancel('transaction-uuid');

$orderService->refund('transaction-uuid', 123, $refundUuid);

$status = $orderService->getStatusDetails('transaction-uuid');

if (null === $status->refunds) {
    //extended status response disabled, refunds cannot be verified
} else {
    $status->findRefund($refundUuid);
}

use Answear\PayPo\Response\Notify;

$notify = Notify::fromRawNotify($requestPayload);

if ($notify->isSettlementNotify()) {
    $notify->settlementStatus; //null for a status not known to this library
    $notify->message;
}

use Answear\PayPo\Util\AuthenticationUtil;

AuthenticationUtil::assertSignatureValid($signature, 'POST', '/notifyUrl', $requestPayload, $merchantApiKey);

use Answear\PayPo\Exception\ApiErrorException;
use Answear\PayPo\Exception\ServiceUnavailable;

try {
    $orderService->refund('transaction-uuid', 123, $refundUuid);
} catch (ApiErrorException $exception) {
    $exception->statusCode;
    $exception->error?->message;
    $exception->error?->errors;
} catch (ServiceUnavailable $exception) {
    //retry
}