Skip to content

nirmalsunny/klarna-payments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Klarna Payments Library

The payments API is used to create a session to offer Klarna's payment methods as part of your checkout. As soon as the purchase is completed the order should be read and handled using the [Order Management API].

Most files of this PHP package was automatically generated by the Swagger Codegen project:

  • API version: 1.0.0
  • Build package: io.swagger.codegen.v3.generators.php.PhpClientCodegen

Important changes have been made for this package to be useful.

Added new classes and fixed existing ones.

Requirements

PHP 5.5 and later

Installation & Usage

Composer

Run composer install to install all the dependenices

Manual Installation

Download the files and include autoload.php:

    require_once('/path/to/klarna-Payments/vendor/autoload.php');

Or, you already have a project?

  • Download the repository
  • Create a new folder called nirmalsunny under your vendor folder
  • Create another folder called klarna-payments and add the lib folder there.
  • Add these to your composer.json:
"autoload": {
       "psr-4": { "nirmalsunny\\KlarnaPayments\\" : "vendor/nirmalsunny/klarna-payments/lib/" }
   }
  • Add these if not already added in your composer.json
"require": {
       "guzzlehttp/guzzle": "^6.2"
   }
  • run composer update

Tests

To do

Getting Started

Please follow the installation procedure and then run the following:

<?php

require_once(__DIR__ . '/vendor/autoload.php');

use \nirmalsunny\KlarnaPayments\ApiException;

$config = \nirmalsunny\KlarnaPayments\Configuration::getDefaultConfiguration();
$config->setUsername('');
$config->setPassword('');
$config->setHost(\nirmalsunny\KlarnaPayments\KlarnaPlaygroundEndpoint::$EUROPE);

$apiInstance = new nirmalsunny\KlarnaPayments\Api\OrdersApi($config,
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client()
);
$authorization_token = "authorization_token_example"; // string | 

try {
    $apiInstance->cancelAuthorization($authorization_token);
} catch (ApiException $e) {
    //print_r($e->getResponseHeaders());
}

$apiInstance = new nirmalsunny\KlarnaPayments\Api\OrdersApi($config,
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client()
);
$authorization_token = "authorization_token_example"; // string | 
$body = new \nirmalsunny\KlarnaPayments\Model\CreateOrderRequest(); // \nirmalsunny\KlarnaPayments\Model\CreateOrderRequest | 

try {
    $result = $apiInstance->createOrder($authorization_token, $body);
    print_r($result);
} catch (ApiException $e) {
    //print_r($e->getResponseHeaders());
}

$apiInstance = new nirmalsunny\KlarnaPayments\Api\OrdersApi($config,
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client()
);
$authorization_token = "authorization_token_example"; // string | 
$body = new \nirmalsunny\KlarnaPayments\Model\CustomerTokenCreationRequest(); // \nirmalsunny\KlarnaPayments\Model\CustomerTokenCreationRequest | 

try {
    $result = $apiInstance->purchaseToken($authorization_token, $body);
    print_r($result);
} catch (ApiException $e) {
    //print_r($e->getResponseHeaders());
}
?>

Example

session.php is an example on how to create a session which is the first step in the flow.

Documentation for API Endpoints

All URIs are relative to https://api.klarna.com

Class Method HTTP request Description
OrdersApi cancelAuthorization DELETE /payments/v1/authorizations/{authorizationToken} Cancel an existing authorization
OrdersApi createOrder POST /payments/v1/authorizations/{authorizationToken}/order Create a new order
OrdersApi purchaseToken POST /payments/v1/authorizations/{authorizationToken}/customer-token Generate a consumer token
SessionsApi createCreditSession POST /payments/v1/sessions Create a new credit session
SessionsApi readCreditSession GET /payments/v1/sessions/{session_id} Read an existing credit session
SessionsApi updateCreditSession POST /payments/v1/sessions/{session_id} Update an existing credit session

Documentation For Models

Documentation For Authorization

All endpoints require authorization.

The Authorization header is created and sent automatically.

TODO

  • Documentation
  • Tests

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages