Skip to content

Commit

Permalink
Merge pull request #19 from checkout/dev
Browse files Browse the repository at this point in the history
Release 1.0.3
  • Loading branch information
aquila-freitas-cko committed May 10, 2019
2 parents 2260afb + 6da7e8c commit fa4cee0
Show file tree
Hide file tree
Showing 16 changed files with 543 additions and 23 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "checkout/checkout-sdk-php",
"description": "Checkout.com SDK for PHP",
"homepage": "https://github.com/checkout/checkout-sdk-php",
"version": "1.0.2",
"version": "1.0.3",
"type": "library",
"license": "MIT",
"keywords": ["checkout.com","payment","gateway","checkout","checkoutcom","GW3","CKO", "Reboot", "SDK", "Library", "PHP", "API"],
Expand Down
18 changes: 13 additions & 5 deletions examples/Payments/alternative_payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
*/

use Checkout\CheckoutApi;
use Checkout\Models\Payments\AlipaySource;
use Checkout\Models\Payments\BoletoSource;
use Checkout\Models\Payments\GiropaySource;
use Checkout\Models\Payments\IdealSource;
use Checkout\Models\Payments\Payment;
use Checkout\Models\Payments\EpsSource;
use Checkout\Models\Payments\PoliSource;
use Checkout\Models\Payments\IdealSource;
use Checkout\Models\Payments\AlipaySource;
use Checkout\Models\Payments\BoletoSource;
use Checkout\Models\Payments\SofortSource;
use Checkout\Models\Payments\GiropaySource;

/**
* Create new instance of Checkout
Expand All @@ -42,7 +43,7 @@


// iDEAL
$ideal = new Payment(new IdealSource('issuer_id'), 'EUR');
$ideal = new Payment(new IdealSource('bic', 'description'), 'EUR');
$ideal->capture = false;
$ideal->amount = 999;
$payment = $checkout->payments()->request($ideal);
Expand Down Expand Up @@ -74,3 +75,10 @@
$sofort = new Payment(new SofortSource(), 'EUR');
$sofort->amount = 999;
$payment = $checkout->payments()->request($sofort);



// EPS
$eps = new Payment(new EpsSource(), 'EUR');
$eps->amount = 999;
$payment = $checkout->payments()->request($eps);
83 changes: 83 additions & 0 deletions examples/Sources/klarna.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

/**
* Checkout.com 2010 - 2018.
* Authorised and regulated as an electronic money institution by the UK Financial Conduct Authority (FCA) under number 900816.
*
* Example: Create a SEPA source.
*/


/**
* Include SDK
*/
require_once "../../checkout.php";


/**
* Use namespaces.
*/

use Checkout\CheckoutApi;
use Checkout\Models\Address;
use Checkout\Models\Product;
use Checkout\Models\Sources\Klarna;
use Checkout\Models\Payments\Payment;
use Checkout\Models\Payments\KlarnaSource;

/**
* Create new instance of Checkout
*/
$checkout = new CheckoutApi('secret_key_goes_here'); // Klarna enabled sandbox account: sk_test_1dde8193-51d5-457a-8af5-1930200cd8cb


/**
* Add new Klarna source.
*/

/* Get source */
$product = new Product();
$product->name = '';
$product->quantity = 1;
$product->unit_price = 999;
$product->tax_rate = 1;
$product->total_amount = 999;
$product->total_tax_amount = 1;

$klarna = new Klarna('GB', 'GBP', 'en-GB', 999, 1, array($product));
$source = $checkout->sources()->add($klarna);


/*
* [Authorize Klarna]: Pass $source->getTokenId() to Klarna JS SDK.
* Learn more at https://docs.checkout.com/docs/klarna.
*/


/* Billing/Shipping */
$address = new Address();
$address->given_name = '';
$address->family_name = '';
$address->email = '';
$address->title = '';
$address->street_address = '';
$address->street_address2 = '';
$address->postal_code = '';
$address->city = '';
$add->region = '';
$address->phone = '';
$address->country = '';




$source = new KlarnaSource(/* `authorization_token` from Klarna JS SDK*/, 'GB', 'en-GB', $address, 1, array($product));
$payment = new Payment($source, 'GBP');
$payment->amount = 999;

$res = $checkout->payments()->request($payment);



var_dump($details);

7 changes: 5 additions & 2 deletions examples/Sources/sepa.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
*/

use Checkout\CheckoutApi;
use Checkout\Models\Sources\BillingAddress;
use Checkout\Models\Sources\Sepa;
use Checkout\Models\Sources\SepaData;
use Checkout\Models\Sources\SepaAddress;

/**
* Create new instance of Checkout
Expand All @@ -32,7 +32,10 @@
/**
* Add new SEPA source.
*/
$address = new BillingAddress('address_line_1', 'address_line_2', 'city', 'state', 'post_code', 'country_code');


//$address = new BillingAddress('address_line_1', 'address_line_2', 'city', 'state', 'post_code', 'country_code'); @note: deprecated
$address = new SepaAddress('address_line_1', 'city', 'post_code', 'country_code');
$data = new SepaData('first_name', 'surname', 'iban', 'bic', 'descriptor', 'mandate');
$source = new Sepa($address, $data);
$details = $checkout->sources()->add($source);
Expand Down
10 changes: 5 additions & 5 deletions src/CheckoutApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class CheckoutApi
*
* @var string
*/
const VERSION = '1.0.2';
const VERSION = '1.0.3';

/**
* Channel section.
Expand Down Expand Up @@ -147,14 +147,14 @@ final class CheckoutApi
* Initialise Checkout API SDK.
*
* @param string $secret
* @param int $sandbox
* @param boolean $sandbox
* @param string $public
* @param string $path Path to custom configuration.
* @param mixed $config Path or array of custom configuration.
*/
public function __construct ($secret = '', $sandbox = -1, $public = '', $path = __DIR__ . DIRECTORY_SEPARATOR . 'config.ini')
public function __construct ($secret = '', $sandbox = -1, $public = '', $config = __DIR__ . DIRECTORY_SEPARATOR . 'config.ini')
{

$configs = Utilities::loadConfig($path);
$configs = Utilities::loadConfig($config);

$this->loadChannel($configs, $secret, $sandbox, $public);
$this->loadLogs($configs);
Expand Down
2 changes: 1 addition & 1 deletion src/Library/HttpHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ protected function handleError($curl)

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

return $ex;
Expand Down
10 changes: 10 additions & 0 deletions src/Library/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ public function isSuccessful()
return $this->getValue('http_code') < 400;
}

/**
* Get error type.
*
* @return string
*/
public function getErrorType()
{
return $this->getValue('error_type');
}

/**
* Get list of errors.
*
Expand Down
11 changes: 6 additions & 5 deletions src/Library/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,18 @@ public static function getLastElementPointer(array &$arr)
/**
* Load configuration file.
*
* @param string $path
* @param mixed $config
* @return array
*/
public static function loadConfig($path)
public static function loadConfig($config = array())
{
$config = array();
if (is_readable($path)) {
$config = parse_ini_file($path, true);

if (is_string($config) && is_readable($config)) {
$config = parse_ini_file($config, true);
}

return $config;

}

/**
Expand Down
70 changes: 70 additions & 0 deletions src/Models/Payments/EpsSource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/**
* Checkout.com
* Authorised and regulated as an electronic money institution
* by the UK Financial Conduct Authority (FCA) under number 900816.
*
* PHP version 7
*
* @category SDK
* @package Checkout.com
* @author Platforms Development Team <platforms@checkout.com>
* @copyright 2010-2019 Checkout.com
* @license https://opensource.org/licenses/mit-license.html MIT License
* @link https://docs.checkout.com/
*/

namespace Checkout\Models\Payments;

use Checkout\Models\Address;

/**
* Payment method EPS.
*
* @category SDK
* @package Checkout.com
* @author Platforms Development Team <platforms@checkout.com>
* @license https://opensource.org/licenses/mit-license.html MIT License
* @link https://docs.checkout.com/
*/
class EpsSource extends IdSource
{

/**
* Qualified name of the class.
*
* @var string
*/
const QUALIFIED_NAME = __CLASS__;

/**
* Qualified namespace of the class.
*
* @var string
*/
const QUALIFIED_NAMESPACE = __NAMESPACE__;

/**
* Name of the model.
*
* @var string
*/
const MODEL_NAME = 'eps';


/**
* Magic Methods
*/

/**
* Initialise payment
*
* @param string $token A description of the payment.
*/
public function __construct($purpose)
{
$this->type = static::MODEL_NAME;
$this->purpose = $purpose;
}
}
80 changes: 80 additions & 0 deletions src/Models/Payments/KlarnaSource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

/**
* Checkout.com
* Authorised and regulated as an electronic money institution
* by the UK Financial Conduct Authority (FCA) under number 900816.
*
* PHP version 7
*
* @category SDK
* @package Checkout.com
* @author Platforms Development Team <platforms@checkout.com>
* @copyright 2010-2019 Checkout.com
* @license https://opensource.org/licenses/mit-license.html MIT License
* @link https://docs.checkout.com/
*/

namespace Checkout\Models\Payments;

use Checkout\Models\Address;

/**
* Payment method Klarna.
*
* @category SDK
* @package Checkout.com
* @author Platforms Development Team <platforms@checkout.com>
* @license https://opensource.org/licenses/mit-license.html MIT License
* @link https://docs.checkout.com/
*/
class KlarnaSource extends IdSource
{

/**
* Qualified name of the class.
*
* @var string
*/
const QUALIFIED_NAME = __CLASS__;

/**
* Qualified namespace of the class.
*
* @var string
*/
const QUALIFIED_NAMESPACE = __NAMESPACE__;

/**
* Name of the model.
*
* @var string
*/
const MODEL_NAME = 'klarna';


/**
* Magic Methods
*/

/**
* Initialise payment
*
* @param string $token Klarna authentication token, obtained by the merchant during client transaction authorization.
* @param string $currency The currency in which the payment is being made (three-letter ISO 4217 code)
* @param string $locale The customer's locale (RFC 1766 code).
* @param Address $billing Customer's billing address.
* @param integer $tax Total tax amount of the order.
* @param Product[] $products This object is passed directly to Klarna as order_lines.
*/
public function __construct($token, $country, $locale, Address $billing, $tax, array $products)
{
$this->type = static::MODEL_NAME;
$this->authorization_token = $token;
$this->billing_address = $billing;
$this->purchase_country = $country;
$this->locale = $locale;
$this->tax_amount = $tax;
$this->products = $products;
}
}

0 comments on commit fa4cee0

Please sign in to comment.