Skip to content

Commit fa4cee0

Browse files
Merge pull request #19 from checkout/dev
Release 1.0.3
2 parents 2260afb + 6da7e8c commit fa4cee0

File tree

16 files changed

+543
-23
lines changed

16 files changed

+543
-23
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "checkout/checkout-sdk-php",
33
"description": "Checkout.com SDK for PHP",
44
"homepage": "https://github.com/checkout/checkout-sdk-php",
5-
"version": "1.0.2",
5+
"version": "1.0.3",
66
"type": "library",
77
"license": "MIT",
88
"keywords": ["checkout.com","payment","gateway","checkout","checkoutcom","GW3","CKO", "Reboot", "SDK", "Library", "PHP", "API"],

examples/Payments/alternative_payments.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
*/
1919

2020
use Checkout\CheckoutApi;
21-
use Checkout\Models\Payments\AlipaySource;
22-
use Checkout\Models\Payments\BoletoSource;
23-
use Checkout\Models\Payments\GiropaySource;
24-
use Checkout\Models\Payments\IdealSource;
2521
use Checkout\Models\Payments\Payment;
22+
use Checkout\Models\Payments\EpsSource;
2623
use Checkout\Models\Payments\PoliSource;
24+
use Checkout\Models\Payments\IdealSource;
25+
use Checkout\Models\Payments\AlipaySource;
26+
use Checkout\Models\Payments\BoletoSource;
2727
use Checkout\Models\Payments\SofortSource;
28+
use Checkout\Models\Payments\GiropaySource;
2829

2930
/**
3031
* Create new instance of Checkout
@@ -42,7 +43,7 @@
4243

4344

4445
// iDEAL
45-
$ideal = new Payment(new IdealSource('issuer_id'), 'EUR');
46+
$ideal = new Payment(new IdealSource('bic', 'description'), 'EUR');
4647
$ideal->capture = false;
4748
$ideal->amount = 999;
4849
$payment = $checkout->payments()->request($ideal);
@@ -74,3 +75,10 @@
7475
$sofort = new Payment(new SofortSource(), 'EUR');
7576
$sofort->amount = 999;
7677
$payment = $checkout->payments()->request($sofort);
78+
79+
80+
81+
// EPS
82+
$eps = new Payment(new EpsSource(), 'EUR');
83+
$eps->amount = 999;
84+
$payment = $checkout->payments()->request($eps);

examples/Sources/klarna.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
/**
4+
* Checkout.com 2010 - 2018.
5+
* Authorised and regulated as an electronic money institution by the UK Financial Conduct Authority (FCA) under number 900816.
6+
*
7+
* Example: Create a SEPA source.
8+
*/
9+
10+
11+
/**
12+
* Include SDK
13+
*/
14+
require_once "../../checkout.php";
15+
16+
17+
/**
18+
* Use namespaces.
19+
*/
20+
21+
use Checkout\CheckoutApi;
22+
use Checkout\Models\Address;
23+
use Checkout\Models\Product;
24+
use Checkout\Models\Sources\Klarna;
25+
use Checkout\Models\Payments\Payment;
26+
use Checkout\Models\Payments\KlarnaSource;
27+
28+
/**
29+
* Create new instance of Checkout
30+
*/
31+
$checkout = new CheckoutApi('secret_key_goes_here'); // Klarna enabled sandbox account: sk_test_1dde8193-51d5-457a-8af5-1930200cd8cb
32+
33+
34+
/**
35+
* Add new Klarna source.
36+
*/
37+
38+
/* Get source */
39+
$product = new Product();
40+
$product->name = '';
41+
$product->quantity = 1;
42+
$product->unit_price = 999;
43+
$product->tax_rate = 1;
44+
$product->total_amount = 999;
45+
$product->total_tax_amount = 1;
46+
47+
$klarna = new Klarna('GB', 'GBP', 'en-GB', 999, 1, array($product));
48+
$source = $checkout->sources()->add($klarna);
49+
50+
51+
/*
52+
* [Authorize Klarna]: Pass $source->getTokenId() to Klarna JS SDK.
53+
* Learn more at https://docs.checkout.com/docs/klarna.
54+
*/
55+
56+
57+
/* Billing/Shipping */
58+
$address = new Address();
59+
$address->given_name = '';
60+
$address->family_name = '';
61+
$address->email = '';
62+
$address->title = '';
63+
$address->street_address = '';
64+
$address->street_address2 = '';
65+
$address->postal_code = '';
66+
$address->city = '';
67+
$add->region = '';
68+
$address->phone = '';
69+
$address->country = '';
70+
71+
72+
73+
74+
$source = new KlarnaSource(/* `authorization_token` from Klarna JS SDK*/, 'GB', 'en-GB', $address, 1, array($product));
75+
$payment = new Payment($source, 'GBP');
76+
$payment->amount = 999;
77+
78+
$res = $checkout->payments()->request($payment);
79+
80+
81+
82+
var_dump($details);
83+

examples/Sources/sepa.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
*/
2020

2121
use Checkout\CheckoutApi;
22-
use Checkout\Models\Sources\BillingAddress;
2322
use Checkout\Models\Sources\Sepa;
2423
use Checkout\Models\Sources\SepaData;
24+
use Checkout\Models\Sources\SepaAddress;
2525

2626
/**
2727
* Create new instance of Checkout
@@ -32,7 +32,10 @@
3232
/**
3333
* Add new SEPA source.
3434
*/
35-
$address = new BillingAddress('address_line_1', 'address_line_2', 'city', 'state', 'post_code', 'country_code');
35+
36+
37+
//$address = new BillingAddress('address_line_1', 'address_line_2', 'city', 'state', 'post_code', 'country_code'); @note: deprecated
38+
$address = new SepaAddress('address_line_1', 'city', 'post_code', 'country_code');
3639
$data = new SepaData('first_name', 'surname', 'iban', 'bic', 'descriptor', 'mandate');
3740
$source = new Sepa($address, $data);
3841
$details = $checkout->sources()->add($source);

src/CheckoutApi.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ final class CheckoutApi
4747
*
4848
* @var string
4949
*/
50-
const VERSION = '1.0.2';
50+
const VERSION = '1.0.3';
5151

5252
/**
5353
* Channel section.
@@ -147,14 +147,14 @@ final class CheckoutApi
147147
* Initialise Checkout API SDK.
148148
*
149149
* @param string $secret
150-
* @param int $sandbox
150+
* @param boolean $sandbox
151151
* @param string $public
152-
* @param string $path Path to custom configuration.
152+
* @param mixed $config Path or array of custom configuration.
153153
*/
154-
public function __construct ($secret = '', $sandbox = -1, $public = '', $path = __DIR__ . DIRECTORY_SEPARATOR . 'config.ini')
154+
public function __construct ($secret = '', $sandbox = -1, $public = '', $config = __DIR__ . DIRECTORY_SEPARATOR . 'config.ini')
155155
{
156156

157-
$configs = Utilities::loadConfig($path);
157+
$configs = Utilities::loadConfig($config);
158158

159159
$this->loadChannel($configs, $secret, $sandbox, $public);
160160
$this->loadLogs($configs);

src/Library/HttpHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ protected function handleError($curl)
324324

325325
$code = $this->getCode();
326326
if ($code >= 400) {
327-
$ex = (new CheckoutHttpException('The endpoint did not accepted the request.', $code))->setBody($this->response);
327+
$ex = (new CheckoutHttpException('The endpoint did not accept the request.', $code))->setBody($this->response);
328328
}
329329

330330
return $ex;

src/Library/Model.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,16 @@ public function isSuccessful()
227227
return $this->getValue('http_code') < 400;
228228
}
229229

230+
/**
231+
* Get error type.
232+
*
233+
* @return string
234+
*/
235+
public function getErrorType()
236+
{
237+
return $this->getValue('error_type');
238+
}
239+
230240
/**
231241
* Get list of errors.
232242
*

src/Library/Utilities.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,18 @@ public static function getLastElementPointer(array &$arr)
115115
/**
116116
* Load configuration file.
117117
*
118-
* @param string $path
118+
* @param mixed $config
119119
* @return array
120120
*/
121-
public static function loadConfig($path)
121+
public static function loadConfig($config = array())
122122
{
123-
$config = array();
124-
if (is_readable($path)) {
125-
$config = parse_ini_file($path, true);
123+
124+
if (is_string($config) && is_readable($config)) {
125+
$config = parse_ini_file($config, true);
126126
}
127127

128128
return $config;
129+
129130
}
130131

131132
/**

src/Models/Payments/EpsSource.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
/**
4+
* Checkout.com
5+
* Authorised and regulated as an electronic money institution
6+
* by the UK Financial Conduct Authority (FCA) under number 900816.
7+
*
8+
* PHP version 7
9+
*
10+
* @category SDK
11+
* @package Checkout.com
12+
* @author Platforms Development Team <platforms@checkout.com>
13+
* @copyright 2010-2019 Checkout.com
14+
* @license https://opensource.org/licenses/mit-license.html MIT License
15+
* @link https://docs.checkout.com/
16+
*/
17+
18+
namespace Checkout\Models\Payments;
19+
20+
use Checkout\Models\Address;
21+
22+
/**
23+
* Payment method EPS.
24+
*
25+
* @category SDK
26+
* @package Checkout.com
27+
* @author Platforms Development Team <platforms@checkout.com>
28+
* @license https://opensource.org/licenses/mit-license.html MIT License
29+
* @link https://docs.checkout.com/
30+
*/
31+
class EpsSource extends IdSource
32+
{
33+
34+
/**
35+
* Qualified name of the class.
36+
*
37+
* @var string
38+
*/
39+
const QUALIFIED_NAME = __CLASS__;
40+
41+
/**
42+
* Qualified namespace of the class.
43+
*
44+
* @var string
45+
*/
46+
const QUALIFIED_NAMESPACE = __NAMESPACE__;
47+
48+
/**
49+
* Name of the model.
50+
*
51+
* @var string
52+
*/
53+
const MODEL_NAME = 'eps';
54+
55+
56+
/**
57+
* Magic Methods
58+
*/
59+
60+
/**
61+
* Initialise payment
62+
*
63+
* @param string $token A description of the payment.
64+
*/
65+
public function __construct($purpose)
66+
{
67+
$this->type = static::MODEL_NAME;
68+
$this->purpose = $purpose;
69+
}
70+
}

src/Models/Payments/KlarnaSource.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
/**
4+
* Checkout.com
5+
* Authorised and regulated as an electronic money institution
6+
* by the UK Financial Conduct Authority (FCA) under number 900816.
7+
*
8+
* PHP version 7
9+
*
10+
* @category SDK
11+
* @package Checkout.com
12+
* @author Platforms Development Team <platforms@checkout.com>
13+
* @copyright 2010-2019 Checkout.com
14+
* @license https://opensource.org/licenses/mit-license.html MIT License
15+
* @link https://docs.checkout.com/
16+
*/
17+
18+
namespace Checkout\Models\Payments;
19+
20+
use Checkout\Models\Address;
21+
22+
/**
23+
* Payment method Klarna.
24+
*
25+
* @category SDK
26+
* @package Checkout.com
27+
* @author Platforms Development Team <platforms@checkout.com>
28+
* @license https://opensource.org/licenses/mit-license.html MIT License
29+
* @link https://docs.checkout.com/
30+
*/
31+
class KlarnaSource extends IdSource
32+
{
33+
34+
/**
35+
* Qualified name of the class.
36+
*
37+
* @var string
38+
*/
39+
const QUALIFIED_NAME = __CLASS__;
40+
41+
/**
42+
* Qualified namespace of the class.
43+
*
44+
* @var string
45+
*/
46+
const QUALIFIED_NAMESPACE = __NAMESPACE__;
47+
48+
/**
49+
* Name of the model.
50+
*
51+
* @var string
52+
*/
53+
const MODEL_NAME = 'klarna';
54+
55+
56+
/**
57+
* Magic Methods
58+
*/
59+
60+
/**
61+
* Initialise payment
62+
*
63+
* @param string $token Klarna authentication token, obtained by the merchant during client transaction authorization.
64+
* @param string $currency The currency in which the payment is being made (three-letter ISO 4217 code)
65+
* @param string $locale The customer's locale (RFC 1766 code).
66+
* @param Address $billing Customer's billing address.
67+
* @param integer $tax Total tax amount of the order.
68+
* @param Product[] $products This object is passed directly to Klarna as order_lines.
69+
*/
70+
public function __construct($token, $country, $locale, Address $billing, $tax, array $products)
71+
{
72+
$this->type = static::MODEL_NAME;
73+
$this->authorization_token = $token;
74+
$this->billing_address = $billing;
75+
$this->purchase_country = $country;
76+
$this->locale = $locale;
77+
$this->tax_amount = $tax;
78+
$this->products = $products;
79+
}
80+
}

0 commit comments

Comments
 (0)