Skip to content

Commit

Permalink
Intial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aquila-freitas-cko committed Jan 31, 2019
0 parents commit 3966cfa
Show file tree
Hide file tree
Showing 137 changed files with 9,041 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = 1f
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea
.DS_Store
composer.lock
vendor/
nbproject/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 CKOTech

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<p align="center"><img src="https://www.checkout.com/static/img/checkout-logo/logo.svg" width="380"></p>


The **Checkout SDK for PHP** enables developers to easily work with Checkout.com APIs.
It requires PHP 5.6.

## Getting Help

If you encounter a bug with Checkout SDK for PHP please search the existing issues and try to make sure your problem doesn’t already exist before opening a new issue.
The GitHub issues are intended for bug reports and feature requests. For help and questions with using Checkout SDK for PHP please contact our integration support team.

For full usage details, see the [Wiki](https://github.com/checkout/checkout-sdk-php/wiki).


## Installation

### Installation with Composer (Recommended)
Either run the following command in the root directory of your project:
```bash
composer require checkout/checkout-php-api
```

Or require the Checkout.com package inside the composer.json file of your project:
```php
"require": { "php": ">=5.6", "checkout/checkout-sdk-php": "1.0.0"}.
```

### Clone repository
Alternatively you can clone the repository from GitHub with git clone
```bash
git clone [email protected]:checkout/checkout-sdk-php.git
```

## Quickstart

Include a `checkout-sdk-php/checkout.php` to access the operations for each API:

```php
use Checkout\CheckoutApi;
use Checkout\Models\Tokens\Card;
use Checkout\Models\Payments\TokenSource;
use Checkout\Models\Payments\Payment;

// Set the secret key
$secretKey = 'sk_test_key';

// Initialize the Checkout API
$checkout = new CheckoutApi($secretKey);


// Create a Card token
$card = new Card('4242424242424242', 12, 2020);
$card->cvv = 100;
$token = $checkout->tokens()->request($card);


// Create a payment method instance with card details
$method = new TokenSource($token->getId());

// Prepare the payment parameters
$payment = new Payment($method, 'GBP');
$payment->amount = 1000; // = 10.00

// Send the request and retrieve the response
$response = $checkout->payments()->request($payment);
```


## Tests
Install PHPUnit by running `composer require --dev phpunit/phpunit` and execute the tests with `./vendor/bin/phpunit`.
75 changes: 75 additions & 0 deletions checkout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* Auto load Checkout SDK
*/
final class Checkout
{

/**
* @var string
*/
const CHK_DIR = "Checkout";

/**
* Hold registration status
*
* @var bool
*/
private static $registered = false;

/**
* Register autoload to
*/
public static function register()
{
if (!static::$registered) {
spl_autoload_register(array(__CLASS__, 'load'), true);
static::$registered = true;
}
}

/**
* Load class
*
* @param string $class
* @return boolean
*/
public static function load($class)
{
$file = static::find($class);
if ($file) {
include_once $file;
}

return (bool) $file;
}

/**
* Find class file
*
* @param string $class
* @return string
*/
public static function find($class)
{
$file = '';
$arr = explode('\\', $class);

if ($arr[0] === static::CHK_DIR) {
$arr[0] = 'src';

$file = __DIR__;
foreach ($arr as &$value) {
$file .= DIRECTORY_SEPARATOR . $value;
}

$file .= '.php';
if (!file_exists($file)) {
$file = '';
}
}

return $file;
}
} Checkout::register();
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "checkout/checkout-sdk-php",
"description": "Checkout.com SDK for PHP",
"homepage": "https://github.com/checkout/checkout-sdk-php",
"version": "1.0.0",
"type": "library",
"license": "MIT",
"keywords": ["checkout.com","payment","gateway","checkout","checkoutcom","GW3","CKO", "Reboot", "SDK", "Library", "PHP", "API"],
"authors": [
{
"name": "Checkout.com",
"homepage": "https://github.com/checkout/checkout-sdk-php/graphs/contributors",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.4.0"
},
"autoload": {
"psr-4": {
"Checkout\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Checkout\\tests\\": "tests/"
}
},
"require-dev": {
"phpunit/phpunit": "^4.0"
}
}
32 changes: 32 additions & 0 deletions examples/Events/list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* Checkout.com 2010 - 2018.
* Authorised and regulated as an electronic money institution by the UK Financial Conduct Authority (FCA) under number 900816.
*
* Example: Retrieve all events from the API.
*/

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


/**
* Used namespaces.
*/
use Checkout\CheckoutApi;

/**
* Create new instance of Checkout
*/
$checkout = new CheckoutApi('secret_key_goes_here');


/**
* Get all events
*/
$events = $checkout->events()->retrieve();

var_dump($events);
32 changes: 32 additions & 0 deletions examples/Events/load.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

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

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


/**
* Used namespaces.
*/
use Checkout\CheckoutApi;

/**
* Create new instance of Checkout
*/
$checkout = new CheckoutApi('secret_key_goes_here');


/**
* Load a specific event.
*/
$event = $checkout->events()->load('event_id_goes_here');

var_dump($event);
32 changes: 32 additions & 0 deletions examples/Events/notification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* Checkout.com 2010 - 2018.
* Authorised and regulated as an electronic money institution by the UK Financial Conduct Authority (FCA) under number 900816.
*
* Example: Load notification of an event.
*/

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


/**
* Used namespaces.
*/
use Checkout\CheckoutApi;

/**
* Create new instance of Checkout
*/
$checkout = new CheckoutApi('secret_key_goes_here');


/**
* Get all types
*/
$notification = $checkout->events()->notification('event_id_goes_here', 'notification_id_goes_here');

var_dump($notification);
32 changes: 32 additions & 0 deletions examples/Events/types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

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

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


/**
* Used namespaces.
*/
use Checkout\CheckoutApi;

/**
* Create new instance of Checkout
*/
$checkout = new CheckoutApi('secret_key_goes_here');


/**
* Get all types
*/
$types = $checkout->events()->types();

varnotification($types);
32 changes: 32 additions & 0 deletions examples/Events/webhook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

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

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


/**
* Used namespaces.
*/
use Checkout\CheckoutApi;

/**
* Create new instance of Checkout
*/
$checkout = new CheckoutApi('secret_key_goes_here');


/**
* Retry all webhooks for this event.
*/
$details = $checkout->events()->webhook('event_id_goes_here');

var_dump($details);
Loading

0 comments on commit 3966cfa

Please sign in to comment.