PHP code example of swedbank-pay / swedbank-pay-sdk-php

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

    

swedbank-pay / swedbank-pay-sdk-php example snippets


use SwedbankPay\Api\Client\Client;
use SwedbankPay\Api\Service\Paymentorder\V3\Request\Purchase;
use SwedbankPay\Api\Service\Paymentorder\V3\Request\TransactionCapture;

$client = new Client();
$client->setAccessToken('...')->setPayeeId('...');
$client->setApiVersion('3.1');

// Create paymentOrder
$purchase = new Purchase($paymentOrderObject);
$purchase->setClient($client);
$response = $purchase->send();

$paymentOrder = $response->getResponseResource()->getPaymentOrder();
echo $paymentOrder->getStatus();      // "Initialized" / "Paid" / "Aborted" / ...
echo $paymentOrder->getId();

$capture = new TransactionCapture($transactionObject);
$capture->setClient($client);
$capture->setPaymentOrderId($paymentOrderId);
$capture->setExpands(['financialtransactions', 'paid']);

$response = $capture->send();
$latest   = $response->getResponseResource()->getLatestFinancialTransaction();
echo $latest->getType();    // "Capture"
echo $latest->getNumber();

use SwedbankPay\Api\Service\Paymentorder\V3\Resource\Response\CallbackPayload;

$payload = new CallbackPayload($webhookBody);
$orderRef = $payload->getOrderReference();
$paymentOrderId = $payload->getPaymentOrder()->getId();