/omnipay-klarna

Omnipay Klarna Payments

Primary LanguagePHPGNU General Public License v3.0GPL-3.0

omnipay-klarna

Build Status Total Downloads Latest Stable Version

Klarna gateway for Omnipay payment processing library

Omnipay is a framework agnostic, multi-gateway payment processing library for PHP 7.3+. This package implements Klarna Online Payment Gateway support for Omnipay.

Requirement

  • PHP >= 7.3.x,
  • Omnipay V.3 repository,
  • PHPUnit to run tests

Autoload

You have to install omnipay V.3

composer require league/omnipay:^3

Then you have to install omnipay-payu package:

composer require alegra/omnipay-klarna

payment-klarna follows the PSR-4 convention names for its classes, which means you can easily integrate payment-klarna classes loading in your own autoloader.

Basic Usage

  • You can use /examples folder to execute examples. This folder is exists here only to show you examples, it is not for production usage.
  • First in /examples folder:
composer install

Authorize Example

  • You can check authorize.php file in /examples folder.
<?php

$loader = require __DIR__ . '/vendor/autoload.php';
$loader->addPsr4('Examples\\', __DIR__);

use Omnipay\Klarna\Message\AuthorizeResponse;
use Omnipay\Klarna\Gateway;
use Examples\Helper;

$gateway = new Gateway();

$helper = new Helper();
try {
    $params = $helper->getAuthorizeParams();

    /** @var AuthorizeResponse $response */
    $response = $gateway->authorize($params)->send();

    $result = [
        'status' => $response->isSuccessful() ?: 0,
        'message' => $response->getMessage(),
        'requestParams' => $response->getServiceRequestParams(),
        'response' => $response->getData()
    ];
} catch (Exception $e) {
    throw new \RuntimeException($e->getMessage());
}

Purchase Example

  • You can check purchase.php file in /examples folder.
<?php

$loader = require __DIR__ . '/vendor/autoload.php';
$loader->addPsr4('Examples\\', __DIR__);

use Omnipay\Klarna\Message\PurchaseResponse;
use Omnipay\Klarna\Gateway;
use Examples\Helper;

$gateway = new Gateway();

$helper = new Helper();
try {
    $params = $helper->getPurchaseParams();

    /** @var PurchaseResponse $response */
    $response = $gateway->authorize($params)->send();

    $result = [
        'status' => $response->isSuccessful() ?: 0,
        'message' => $response->getMessage(),
        'requestParams' => $response->getServiceRequestParams(),
        'response' => $response->getData()
    ];
} catch (Exception $e) {
    throw new \RuntimeException($e->getMessage());
}

Refund Example

  • You can check refund.php file in /examples folder.
<?php

$loader = require __DIR__ . '/vendor/autoload.php';
$loader->addPsr4('Examples\\', __DIR__);

use Omnipay\Klarna\Gateway;
use Examples\Helper;

$gateway = new Gateway();
$helper = new Helper();

try {
    $params = $helper->getRefundParams();
    $response = $gateway->refund($params)->send();

    $result = [
        'status' => $response->isSuccessful() ?: 0,
        'redirect' => $response->isRedirect() ?: 0,
        'message' => $response->getMessage(),
        'requestParams' => $response->getServiceRequestParams(),
        'response' => $response->getData()
    ];

    print("<pre>" . print_r($result, true) . "</pre>");
} catch (Exception $e) {
    throw new \RuntimeException($e->getMessage());
}

requestParams:

System send request to klarna api. It shows request information.