Skip to content

Commit 052e2f0

Browse files
author
Chris Gårdenberg
committed
Added Klarna Checkout-SDK.
1 parent 4cac9e9 commit 052e2f0

148 files changed

Lines changed: 28490 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.scrutinizer.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
build:
2+
nodes:
3+
analysis:
4+
dependencies:
5+
before:
6+
- composer require --dev johnpbloch/wordpress
7+
project_setup:
8+
override: true
9+
tests:
10+
override: [php-scrutinizer-run]
11+
filter:
12+
dependency_paths:
13+
- wordpress/
14+
- klarna_kco_php_4.0.0/

checkout-page.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
EDU()->write_debug($checkout);

class-edu-klarnacheckout.php

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,60 @@ public function __construct() {
1414
add_action( 'eduadmin-checkpaymentplugins', array( $this, 'intercept_booking' ) );
1515
add_action( 'eduadmin-processbooking', array( $this, 'process_booking' ) );
1616
add_action( 'wp_loaded', array( $this, 'process_klarnaresponse' ) );
17+
18+
add_shortcode( 'eduadmin-klarna-testpage', array( $this, 'test_page' ) );
19+
}
20+
21+
/**
22+
* @param int $booking_id
23+
*/
24+
public function test_page( $attributes ) {
25+
$attributes = shortcode_atts(
26+
array(
27+
'bookingid' => 0,
28+
),
29+
normalize_empty_atts( $attributes ),
30+
'test_page'
31+
);
32+
33+
$event_booking = EDUAPI()->OData->Bookings->GetItem(
34+
intval( $attributes['bookingid'] ),
35+
null,
36+
'Customer($select=CustomerId;),ContactPerson($select=PersonId;)'
37+
);
38+
$_customer = EDUAPI()->OData->Customers->GetItem( $event_booking['Customer']['CustomerId'] );
39+
$_contact = EDUAPI()->OData->Persons->GetItem( $event_booking['ContactPerson']['PersonId'] );
40+
41+
$ebi = new EduAdmin_BookingInfo( $event_booking, $_customer, $_contact );
42+
43+
do_action( 'eduadmin-processbooking', $ebi );
1744
}
1845

19-
public function intercept_booking() {
46+
/**
47+
* @param EduAdmin_BookingInfo|null $ebi
48+
*/
49+
public function intercept_booking( $ebi = null ) {
2050
if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
2151
return;
2252
}
53+
54+
if ( ! empty( $_POST['act'] ) && 'bookCourse' === $_POST['act'] ) {
55+
$ebi->NoRedirect = true;
56+
}
2357
}
2458

25-
public function process_booking() {
59+
/**
60+
* @param EduAdmin_BookingInfo|null $ebi
61+
*/
62+
public function process_booking( $ebi = null ) {
2663
if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
2764
return;
2865
}
66+
67+
$ebi->NoRedirect = true;
68+
69+
$checkout = $this->create_checkout( $ebi );
70+
include_once 'checkout-page.php';
2971
}
3072

3173
public function process_klarnaresponse() {
@@ -62,5 +104,33 @@ public function init_form_fields() {
62104
),
63105
);
64106
}
107+
108+
/**
109+
* @param EduAdmin_BookingInfo|null $ebi
110+
*
111+
* @return Klarna_Checkout_Order
112+
*/
113+
public function create_checkout( $ebi = null ) {
114+
$create = array();
115+
$create['locale'] = strtolower( str_replace( '_', '-', get_locale() ) );
116+
$create['cart'] = array();
117+
$create['cart']['items'] = array();
118+
119+
try {
120+
$connector = Klarna_Checkout_Connector::create(
121+
'',
122+
Klarna_Checkout_Connector::BASE_TEST_URL
123+
);
124+
125+
$order = new Klarna_Checkout_Order( $connector );
126+
$order->create( $create );
127+
128+
return $order;
129+
} catch ( Klarna_Checkout_ApiErrorException $ex ) {
130+
EDU()->write_debug( $ex->getMessage() );
131+
EDU()->write_debug( $ex->getPayload() );
132+
EDU()->write_debug( $create );
133+
}
134+
}
65135
}
66136
}

eduadmin-wp-klarna-checkout.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ public function __construct() {
5252
}
5353

5454
public function init() {
55+
if ( ! class_exists( 'Klarna_Checkout_Connector' ) ) {
56+
require_once __DIR__ . '/klarna_kco_php_4.0.0/src/Klarna/Checkout.php';
57+
}
58+
5559
if ( class_exists( 'EDU_Integration' ) ) {
60+
5661
require_once __DIR__ . '/class-edu-klarnacheckout.php';
5762

5863
add_filter( 'edu_integrations', array( $this, 'add_integration' ) );
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
coverage_clover: data/tmp/coverage.xml
2+
json_path: data/tmp/coveralls-upload.json

klarna_kco_php_4.0.0/.travis.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
language: php
2+
php:
3+
- 5.6
4+
- 5.5
5+
- 5.4
6+
- 5.3
7+
- hhvm
8+
9+
matrix:
10+
allow_failures:
11+
- php: 5.6
12+
- php: hhvm
13+
14+
branches:
15+
only:
16+
- /^v\d\.\d/
17+
cache:
18+
directories:
19+
- vendor
20+
21+
before_script:
22+
- composer install --dev --no-interaction
23+
24+
script:
25+
- ant -f misc/ant/build.xml tests
26+
27+
after_script:
28+
- php vendor/bin/coveralls

klarna_kco_php_4.0.0/CHANGELOG

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
===========================
2+
Klarna Checkout PHP library
3+
===========================
4+
5+
v4.0.0
6+
----------------
7+
Date: 2015-06-01
8+
9+
Christer G. <support@klarna.com>
10+
Update resource constructors. Only allow creation with IDs instead of full URIs
11+
12+
v3.0.2, v3.0.1
13+
----------------
14+
Date: 2015-05-21
15+
16+
Matthias F. <support@klarna.com>
17+
Remove short hand array syntax for PHP 5.3.
18+
19+
v3.0.0
20+
----------------
21+
Date: 2015-05-21
22+
23+
Matthias F. <support@klarna.com>
24+
Adding support for recurring orders.
25+
26+
v2.0.0
27+
---------------
28+
Date: 2015-03-18
29+
30+
David K. <support@klarna.com>
31+
Add ability to set accept header.
32+
33+
v1.2.2
34+
----------------
35+
Date: 2014-10-03
36+
37+
Christer G. <support@klarna.com>
38+
Updating checkout and create examples to ensure a cart is always created
39+
40+
v1.2.1
41+
----------------
42+
Date: 2014-09-05
43+
44+
Christer G. <support@klarna.com>
45+
Updating code examples
46+
47+
v1.2.0
48+
----------------
49+
Date: 2014-03-27
50+
51+
Christer G. <support@klarna.com>
52+
Verify SSL host and peer
53+
Enable setting custom cURL options
54+
Show cURL error message in Klarna_Checkout_ConnectionErrorException
55+
56+
v1.1.1
57+
----------------
58+
Date: 2013-09-12
59+
60+
Christer G. <support@klarna.com>
61+
Adding CURLOPT_TIMEOUT with the same timeout as CURLOPT_CONNECTTIMEOUT
62+
63+
v1.1.0
64+
----------------
65+
Date: 2013-03-15
66+
67+
Majid G. <support@klarna.com>
68+
Increasing http timeout to 10 seconds
69+
Adding capability to change the timeout from connector
70+
71+
v1.0.0
72+
----------------
73+
Date: 2012-11-21
74+
75+
Klarna <support@klarna.com>
76+
Initial release.

klarna_kco_php_4.0.0/README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
## Klarna Checkout PHP library
2+
3+
[![Packagist Version][packagist-shield]](https://packagist.org/packages/klarna/checkout)
4+
[![Build Status][travis-shield]](https://travis-ci.org/klarna/kco_php)
5+
[![Coverage Status][coveralls-shield]](https://coveralls.io/r/klarna/kco_php)
6+
7+
Klarna Checkout is a revolutionary new payment solution that is changing the way
8+
people shop online. First, consumers verify their purchase with a minimal
9+
amount of information through intelligent identification, securing your order
10+
immediately, and then complete their payment afterwards – separating buying
11+
from paying and dramatically increasing conversion. Klarna Checkout also allows
12+
merchants to offer all payment methods through one supplier, minimizing
13+
administration, costs and integration time.
14+
15+
## About Klarna
16+
Klarna was founded in Stockholm in 2005 with the idea of providing a
17+
zero-friction online payment solution that would allow consumers and merchants
18+
to interact with each other as safely and simply as possible. We do this by
19+
letting the consumer receive the goods first and pay afterwards, while we assume
20+
the credit and fraud risks for the merchants. Today, Klarna is one of Europe's
21+
fastest growing companies. In just 8 years, we've grown to 800 employees
22+
operating in 7 European countries with over 8 million consumers. But we are not
23+
satisfied with that. Our goal is to become market leaders within invoice-based
24+
payments worldwide and change the way the world shops online.
25+
26+
## Documentation
27+
Documentation and more examples can be found at
28+
[developers.klarna.com](https://developers.klarna.com).
29+
30+
## How to contribute
31+
At Klarna, we strive toward achieving the highest possible quality for our
32+
products. Therefore, we require you to follow these guidelines if you wish
33+
to contribute.
34+
35+
To contribute, the following criteria needs to be fulfilled:
36+
* Description regarding what has been changed and why
37+
* Pull requests should implement a boxed change
38+
* All code and documentation must follow the
39+
[PEAR coding standards](http://pear.php.net/manual/en/standards.php)
40+
* All classes must follow the [PSR-0 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md)
41+
* New features and bug fixes must have accompanying unit tests:
42+
* Positive tests
43+
* Negative tests
44+
* Boundary tests (if possible)
45+
* No less than 90% decision coverage
46+
* All unit tests should pass
47+
48+
## Questions and feedback
49+
If you have any questions concerning this product or the implementation,
50+
please contact [integration@klarna.com](mailto:integration@klarna.com).
51+
52+
## Acknowledgements
53+
* David Keijser
54+
* Rickard Dybeck
55+
* Majid Garmaroudi
56+
* Magnus Nordlander
57+
* Christer Gustavsson
58+
* Fredrik Liljegren
59+
* Jan Kohlhof
60+
* Maksim Kotlyar
61+
* Matthias Feist
62+
63+
## License
64+
The Klarna Checkout PHP library is released under
65+
[Apache License, Version 2.0](http://www.apache.org/LICENSE-2.0)
66+
67+
[packagist-shield]: https://img.shields.io/packagist/v/klarna/checkout.svg?style=flat
68+
[travis-shield]: https://img.shields.io/travis/klarna/kco_php/v4.0.svg?style=flat
69+
[coveralls-shield]: https://img.shields.io/coveralls/klarna/kco_php/v4.0.svg?style=flat

klarna_kco_php_4.0.0/composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "klarna/checkout",
3+
"description": "Wrapper for the Klarna Checkout API",
4+
"homepage": "http://developers.klarna.com",
5+
"license": "Apache-2.0",
6+
"type": "library",
7+
"require": {
8+
"php": ">=5.3.0",
9+
"ext-curl": "*"
10+
},
11+
"require-dev": {
12+
"phpunit/phpunit": "~4.6",
13+
"phpmd/phpmd": "~2.2",
14+
"squizlabs/php_codesniffer": "~2.3",
15+
"satooshi/php-coveralls": "~0.6"
16+
},
17+
"autoload": {
18+
"psr-0": {
19+
"Klarna": "src"
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)