centarro / kco_rest
Community maintained Klarna PHP SDK
Installs: 151 381
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 65
Open Issues: 1
Requires
- php: >=8.1
- guzzlehttp/guzzle: ~6.0 || ^7.0
Requires (Dev)
- apigen/apigen: 4.1.*
- klarna/apigen-theme: 2.1.0
- php-coveralls/php-coveralls: ^2.1
- phpmd/phpmd: 2.1.*
- phpunit/phpunit: ~10.0
- squizlabs/php_codesniffer: ^3.0
- v4.x-dev
- v4.2.6
- v4.2.5
- v4.2.4
- v4.2.3
- v4.2.2
- v4.2.1
- v4.2.0
- v4.1.x-dev
- v4.1.5
- v4.1.4
- v4.1.3
- v4.1.2
- v4.1.1
- v4.1.0
- v4.0.x-dev
- v4.0.0
- v3.0.x-dev
- v3.0.1
- v3.0.0
- v2.2.x-dev
- v2.2.0
- v2.1.x-dev
- v2.1.0
- v2.0.x-dev
- v2.0.0
- v1.0.x-dev
- v1.0.1
- v1.0.0
- dev-improve-header-methods
- dev-use-github-actions
- dev-release_4.2.3
- dev-ps4_autoload_definition
- dev-code_snippets
This package is auto-updated.
Last update: 2024-10-14 09:29:13 UTC
README
Introduction
This is an unofficial, community maintained fork of the deprecated official Klarna PHP SDK.
Shop now. Pay later.
Shop at your favorite stores today and experience the freedom to pay later with Klarna.
Getting started
SDK covers all of Klarna API: https://developers.klarna.com/api/
Prerequisites
- PHP 8.1 or above
- API credentials
- Composer (optional)
API Credentials
Before getting a production account you can get a playground one. Register here to be able to test your SDK integration before go live:
- https://playground.eu.portal.klarna.com/developer-sign-up - for EU countries
- https://playground.us.portal.klarna.com/developer-sign-up - for the US
PHP SDK Installation and Usage
Install via Composer
To install the PHP SDK from the Central Composer repository use composer:
composer require centarro/kco_rest
Highly recommended to use version tag when installing SDK.
composer require centarro/kco_rest:1.2.3.4
Detailed information about the PHP SDK package and a list of available versions can be found here: https://packagist.org/packages/klarna/kco_rest
Include the SDK into your PHP file using the Composer autoloader:
<?php require('vendor/autoload.php');
Manual installation
To install the PHP SDK manually you need to clone the repo to any folder on your machine:
git clone git@github.com:centarro/kco_rest_php.git /path/to/some/folder/kco_rest_php
Include the SDK into your PHP file using the SDK autoloader:
<?php require('/path/to/some/folder/kco_rest_php/src/autoload.php');
⚠️Warning: Using manually installed SDK requires you to use the CURLTransport instance to send HTTP requests.
Read more about How to use HTTP Transport
Documentation and Examples
Klarna API documentation: https://developers.klarna.com/api/
SDK References: https://klarna.github.io/kco_rest_php/
Example files can be found in the docs/ directory.
Additional documentation can be found at https://developers.klarna.com.
Logging and Debugging
PHP SDK logs information to STDOUT/STDERR. To enable debug mode, set DEBUG_SDK environment variable:
$ DEBUG_SDK=true php <your_program.php>
or
$ export DEBUG_SDK=1 $ php <your_program.php>
Another way to enable Debugging Mode is define
the DEBUG_SDK inside your script:
<?php // some code here define('DEBUG_SDK', true); // some code here
Be aware, the SDK just checks if the DEBUG_SDK
is defined! It means you will see the debug information
by using define('DEBUG_SDK', false);
or export DEBUG_SDK=no
More information about the DEBUG_SDK flag can be found here: klarna#32
The output will look like:
DEBUG MODE: Request
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
GET : https://api.playground.klarna.com/customer-token/v1/tokens/TOKEN
Headers : {"User-Agent":["Library\/Klarna.kco_rest_php_3.1.0 (Guzzle\/6.3.3; curl\/7.54.0) OS\/Darwin_17.5.0 Language\/PHP_5.6.37"]}
Body :
DEBUG MODE: Response
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Headers : {"Content-Type":["application\/json"],"Date":["Wed, 15 Aug 2018 15:55:53 GMT"],"Klarna-Correlation-Id":["ABC-123"],"Server":["openresty"],"Content-Length":["62"],"Connection":["keep-alive"]}
Body : {
"status" : "ACTIVE",
"payment_method_type" : "INVOICE"
}