2017 © Pedro Peláez
 

library omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

image

myonlinestore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  • Friday, June 22, 2018
  • by Sm0ke0ut
  • Repository
  • 7 Watchers
  • 3 Stars
  • 13,469 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 46 Versions
  • 49 % Grown

The README.md

NO LONGER MAINTAINED

This repository is no longer being maintained., (*1)

Omnipay: Klarna Checkout

Software License Scrutinizer Build Scrutinizer Coverage Scrutinizer, (*2)

Introduction

Omnipay is a framework agnostic, multi-gateway payment processing library for PHP 5.6+. This package implements Klarna Checkout support for Omnipay., (*3)

Installation

To install, simply add it to your composer.json file:, (*4)

$ composer require myonlinestore/omnipay-klarna-checkout

Initialization

First, create the Omnipay gateway:, (*5)

$gateway = Omnipay\Omnipay::create('\MyOnlineStore\Omnipay\KlarnaCheckout\Gateway');
// or
$gateway = new MyOnlineStore\Omnipay\KlarnaCheckout\Gateway(/* $httpClient, $httpRequest */);

Then, initialize it with the correct credentials:, (*6)

$gateway->initialize([
    'username' => $username, 
    'secret' => $secret,
    'api_region' => $region, // Optional, may be Gateway::API_VERSION_EUROPE (default) or Gateway::API_VERSION_NORTH_AMERICA
    'testMode' => false // Optional, default: true
]);
// or 
$gateway->setUsername($username);
$gateway->setSecret($secret);
$gateway->setApiRegion($region);

Usage

For general usage instructions, please see the main Omnipay repository., (*7)

General flow

  1. Create a Klarna order
  2. Update transaction (if required)
  3. Render the Iframe
  4. Respond to redirects to checkoutUrl or confirmation_url
  5. Respond to checkout callbacks
  6. Respond to the request to push_url (indicates order was completed by client) with a ackowledgement
  7. Extend authorization (if required)
  8. Update the merchant address (if required)
  9. Perform one or more capture(s), refund(s) or void operations

Authorize

To create a new order, use the authorize method:, (*8)

$data = [
    'amount' => 100,
    'tax_amount' => 20,
    'currency' => 'SEK',
    'locale' => 'SE',
    'purchase_country' => 'SE',

    'notify_url' => '', // https://developers.klarna.com/api/#checkout-api__ordermerchant_urls__validation
    'return_url' => '', // https://developers.klarna.com/api/#checkout-api__ordermerchant_urls__checkout
    'terms_url' => '', // https://developers.klarna.com/api/#checkout-api__ordermerchant_urls__terms
    'validation_url' => '', // https://developers.klarna.com/api/#checkout-api__ordermerchant_urls__validation

    'items' => [
        [
            'type' => 'physical',
            'name' => 'Shirt',
            'quantity' => 1,
            'tax_rate' => 25,
            'price' => 100,
            'unit_price' => 100,
            'total_tax_amount' => 20,
        ],
    ],
];

$response = $gateway->authorize($data)->send()->getData();

This will return the order details as well as the checkout HTML snippet to render on your site., (*9)

API documentation, (*10)

Render Iframe

Klarna Checkout requires an iframe to be rendered when authorizing payments:, (*11)

$response = $gateway->fetchTransaction(['transactionReference' => 'a5bec272-d68d-4df9-9fdd-8e35e51f92ab'])
    ->send();

echo $response->getData()['checkout']['html_snippet'];

After submitting the form within the iframe, Klarna will redirect the client to the provided confirmation_url (success) or checkout_url (failure)`., (*12)

Update transaction

While an order has not been authorized (completed) by the client, it may be updated:, (*13)

$response = $gateway->updateTransaction([
    'transactionReference' => 'a5bec272-d68d-4df9-9fdd-8e35e51f92ab',
    'amount'           => 200,
    'tax_amount'       => 40,
    'currency'         => 'SEK',
    'locale'           => 'SE',
    'purchase_country' => 'SE',
    'items' => [/*...*/],
])->send();

The response will contain the updated order data., (*14)

API documentation, (*15)

Extend authorization

Klarna order authorization is valid until a specific date, and may be extended (up to a maximum of 180 days). The updated expiration date may then be retrieved with a fetch request, (*16)

if ($gateway->extendAuthorization(['transactionReference' => 'a5bec272-d68d-4df9-9fdd-8e35e51f92ab'])->send()->isSuccessful()) {
    $expiration = new \DateTimeImmutable(
        $gateway->fetchTransaction(['transactionReference' => 'a5bec272-d68d-4df9-9fdd-8e35e51f92ab'])
            ->send()
            ->getData()['management']['expires_at']
    );
}

API documentation, (*17)

Capture

$success = $gateway->capture([
    'transactionReference' => 'a5bec272-d68d-4df9-9fdd-8e35e51f92ab',
    'amount' => '995',
])->send()
->isSuccessful();

API documentation, (*18)

Fetch

A Klarna order is initially available through the checkout API. After it has been authorized, it will be available through the Order management API (and will, after some time, no longer be available in the checkout API). This fetch request will first check whether the order exitst in the checkout API. If that is not the case, or the status indicates the order is finished, it will also fetch the order from the order management API, (*19)

$response = $gateway->fetchTransaction(['transactionReference' => 'a5bec272-d68d-4df9-9fdd-8e35e51f92ab'])
    ->send();

$success = $response->isSuccessful();
$checkoutData = $response->getData()['checkout'] ?? [];
$managementData = $response->getData()['management'] ?? [];

API documentation | Checkout | Order management, (*20)

Acknowlegde

Acknowledge a completed order, (*21)

$success = $gateway->acknowledge(['transactionReference' => 'a5bec272-d68d-4df9-9fdd-8e35e51f92ab'])
    ->send()
    ->isSuccessful();

API documentation, (*22)

Refund

$success = $gateway->refund([
    'transactionReference' => 'a5bec272-d68d-4df9-9fdd-8e35e51f92ab',
    'amount' => '995',
])->send()
->isSuccessful();

API documentation, (*23)

Void

You may release the remaining authorized amount. Specifying a specific amount is not possible., (*24)

$success = $gateway->void(['transactionReference' => 'a5bec272-d68d-4df9-9fdd-8e35e51f92ab'])
    ->send()
    ->isSuccessful();

API documentation, (*25)

Update customer address

This may be used when updating customer address details after the order has been authorized. Success op this operation is subject to a risk assessment by Klarna. Both addresses are required parameters., (*26)

$success = $gateway->refund([
    'transactionReference' => 'a5bec272-d68d-4df9-9fdd-8e35e51f92ab',
    'shipping_address' => [
        'given_name'=> 'Klara',
        'family_name'=> 'Joyce',
        'title'=> 'Mrs',
        'street_address'=> 'Apartment 10',
        'street_address2'=> '1 Safeway',
        'postal_code'=> '12345',
        'city'=> 'Knoxville',
        'region'=> 'TN',
        'country'=> 'us',
        'email'=> 'klara.joyce@klarna.com',
        'phone'=> '1-555-555-5555'
    ],
    'billing_address' => [
        'given_name'=> 'Klara',
        'family_name'=> 'Joyce',
        'title'=> 'Mrs',
        'street_address'=> 'Apartment 10',
        'street_address2'=> '1 Safeway',
        'postal_code'=> '12345',
        'city'=> 'Knoxville',
        'region'=> 'TN',
        'country'=> 'us',
        'email'=> 'klara.joyce@klarna.com',
        'phone'=> '1-555-555-5555'
    ],
])->send()
->isSuccessful();

API documentation, (*27)

Update merchant reference(s)

If an order has been authorized by the client, its merchant references may be updated:, (*28)

$response = $gateway->updateMerchantReferences([
    'merchant_reference1' => 'foo',
    'merchant_reference2' => 'bar',
])->send();

API documentation, (*29)

Units

Klarna expresses amounts in minor units as described here., (*30)

The Versions

22/06 2018

dev-master

9999999-dev https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

22/06 2018

v2.0.0

2.0.0.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

21/06 2018

dev-update-core-packages

dev-update-core-packages https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

30/05 2018

v1.0.31

1.0.31.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

30/05 2018

dev-release-3.0

dev-release-3.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

29/05 2018

dev-fix-exclude-empty-values

dev-fix-exclude-empty-values https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

24/05 2018

v1.0.30

1.0.30.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

11/05 2018

v1.0.29

1.0.29.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

01/05 2018

v1.0.28

1.0.28.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

01/05 2018

dev-add-update-customer-request

dev-add-update-customer-request https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

23/04 2018

dev-purchase_country-to-string

dev-purchase_country-to-string https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

16/04 2018

v1.0.27

1.0.27.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

13/04 2018

v1.0.26

1.0.26.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

09/04 2018

v1.0.25

1.0.25.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

05/04 2018

v1.0.24

1.0.24.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

22/03 2018

dev-add-response-status-code-succesfull-checks

dev-add-response-status-code-succesfull-checks https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

15/03 2018

v1.0.23

1.0.23.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

15/03 2018

v1.0.22

1.0.22.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

14/03 2018

v1.0.21

1.0.21.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

13/03 2018

v1.0.20

1.0.20.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

12/03 2018

v1.0.19

1.0.19.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

06/03 2018

v1.0.18

1.0.18.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

26/02 2018

v1.0.17

1.0.17.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

26/02 2018

dev-hotfix-tax-rate-rounding

dev-hotfix-tax-rate-rounding https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

22/02 2018

v1.0.16

1.0.16.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

20/02 2018

v1.0.15

1.0.15.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

16/02 2018

1.0.14

1.0.14.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

13/02 2018

1.0.13

1.0.13.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

01/02 2018

1.0.12

1.0.12.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

01/02 2018

dev-orderline-type

dev-orderline-type https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

30/01 2018

1.0.11

1.0.11.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

29/01 2018

dev-add-extend-authorization-request

dev-add-extend-authorization-request https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

29/01 2018

1.0.10

1.0.10.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

20/12 2017

1.0.9

1.0.9.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

22/11 2017

v1.0.8

1.0.8.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

21/09 2017

v1.0.7

1.0.7.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

21/09 2017

v1.0.6

1.0.6.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

21/09 2017

v1.0.5

1.0.5.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

20/09 2017

v1.0.4

1.0.4.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

20/09 2017

v1.0.3

1.0.3.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

12/09 2017

v1.0.2

1.0.2.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

11/09 2017

v1.0.1

1.0.1.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

05/05 2017

v1.0

1.0.0.0 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

05/05 2017

dev-MWW-5458

dev-MWW-5458 https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

31/03 2017

dev-capture-request

dev-capture-request https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout

31/03 2017

dev-authorize-request

dev-authorize-request https://github.com/MyOnlineStore/omnipay-klarna-checkout

Klarna Checkout gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

omnipay klarna checkout