Skip to content

Commit ed06db3

Browse files
krmgnssotuzun
andauthored
architectural improvements (#10)
* Request\Common\RequestOptions: add constructor with array options. * Craftgate\Adapter\BaseAdapter: optimize createHttpHeaders() [array push issues]. * README: updates for RequestOptions inits. * Simplify autoload stuff [add autoload.php, drop CraftgateBootstrap.php]. * Simplify RequestOptions inits. * Add Util\Guid [drop insecure uniqid() calls]. * Move Util\AuthSignatureGenerator => Util\Signature, optimize. * Make-ups. * Add Util\Util, move & drop RequestQueryParamsBuilder into [also related test updated]. * Move lib/Craftgate => src/ [PSR compliance issue]. * Typo-fix. * Update whitelist directory. * Update all currency stuff [ISO-4217 compliance]. * Move Request\Common\RequestOptions => Options. * Doc-ups. * Apply DI stuff [also update related var names]. * Make Craftgate resource-friendly [on demand inits by related methods]. * Doc-ups [Accessor => Initializer]. * Options: add __debugInfo() & toArray() methods. * Options: add BASE_URL constant & use for $baseUrl property [also fixes default (that mentioned on README) base-URL issue]. * Move Craftgate => Client. * Move Adapter\BaseAdapter => AbstractAdapter [making abstract & dropping unneeded constructors in subs]. * Move Options => ClientOptions [proper naming]. * Doc-up. * Refactor on HTTP & cURL stuff. * Typo-fix. * Fix/optimize Curl tests. * Fix/optimize Curl tests [rework with try/catch blocks]. * Doc-ups. * Make-ups on constant names. * Adapter\PaymentAdapter: update checkout payment URL's. * Adapter: move AbstractAdapter => BaseAdapter. * ClientOptions: add SANDBOX_API_URL constant, move BASE_URL => API_URL. * Move Client,ClientOptions => Craftgate,CraftgateOptions. * Change Model\Currency::TRY => Model\Currency::TL. * Move Util\Util => Util\QueryBuilder. * Adapter\PaymentAdapter: resolve conflicts. * Changes for "optimizes imports [bb8754d]" on resolve-conflicts branch. * changes sample config and optimizes imports * adds php 8.0 to version matrix * upgrades php unit version * removes php 8.0 support for builds * reverts phpunit version * fixes search members sample request Co-authored-by: Sabri Onur Tüzün <[email protected]>
1 parent e5f0094 commit ed06db3

File tree

88 files changed

+696
-826
lines changed

Some content is hidden

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

88 files changed

+696
-826
lines changed

CraftgateBootstrap.php

Lines changed: 0 additions & 184 deletions
This file was deleted.

README.md

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,36 @@ composer require craftgate/craftgate
2020
```
2121

2222
### Manual Installation
23-
You need to download the latest [release](https://github.com/craftgate/craftgate-php-client/releases) and copy to your project. Then, include the bootstrap file as shown below. This file will autoload all the class files into your project.
23+
You need to download the latest [release](https://github.com/craftgate/craftgate-php-client/releases) and copy to your project. Then, include the autoload file as shown below. This file will autoload all related classes into your project on-demand.
2424

2525
```php
26-
require_once('/path/to/craftgate-php-client/CraftgateBootstrap.php');
26+
require '/path/to/craftgate-php-client/autoload.php';
2727
```
2828

2929
## Usage
3030
To access the Craftgate API you'll first need to obtain API credentials (e.g. an API key and a secret key). If you don't already have a Craftgate account, you can signup at [https://craftgate.io/](https://craftgate.io)
3131

32-
Once you've obtained your API credentials, you can start using Craftgate by instantiating a `Craftgate` with your credentials.
32+
Once you've obtained your API credentials, you can start using Craftgate by instantiating a `Craftgate\Craftgate` with your credentials.
3333

3434
```php
35-
36-
$options = new RequestOptions();
37-
$options->setApiKey('<YOUR API KEY>');
38-
$options->setSecretKey('<YOUR SECRET KEY>');
39-
40-
$craftgate = new Craftgate($options);
41-
...
42-
35+
$craftgate = new \Craftgate\Craftgate(array(
36+
'apiKey' => '<YOUR API KEY>',
37+
'secretKey' => '<YOUR SECRET KEY>',
38+
));
4339
```
4440

45-
By default the Craftgate client connects to the production API servers at `https://api.craftgate.io`. For testing purposes, please use the sandbox URL `https://sandbox-api.craftgate.io` using the .
41+
By default the Craftgate client connects to the production API servers at `https://api.craftgate.io`. For testing purposes, please use the sandbox URL `https://sandbox-api.craftgate.io`.
4642

4743
```php
48-
49-
$options = new RequestOptions();
50-
$options->setApiKey('<YOUR API KEY>');
51-
$options->setSecretKey('<YOUR SECRET KEY>');
52-
$options->setBaseUrl('https://sandbox-api.craftgate.io');
53-
54-
$craftgate = new Craftgate($options);
55-
44+
$craftgate = new \Craftgate\Craftgate(array(
45+
'apiKey' => '<YOUR API KEY>',
46+
'secretKey' => '<YOUR SECRET KEY>',
47+
'baseUrl' => 'https://sandbox-api.craftgate.io',
48+
));
5649
```
5750

5851
## Examples
59-
Included in the project are a number of examples that cover almost all use-cases. Refer to [the `samples/` folder](./samples)] for more info.
52+
Included in the project are a number of examples that cover almost all use-cases. Refer to [the `samples/` folder](./samples) for more info.
6053

6154
### Running the Examples
6255
If you've cloned this repo on your development machine and wish to run the examples you can run an example with the command `./vendor/bin/phpunit`
@@ -67,12 +60,11 @@ Let's quickly review an example where we implement a credit card payment scenari
6760
> For more examples covering almost all use-cases, check out the [examples in the `samples/` folder](./samples)
6861
6962
```php
70-
$options = new RequestOptions();
71-
$options->setApiKey('<YOUR API KEY>');
72-
$options->setSecretKey('<YOUR SECRET KEY>');
73-
$options->setBaseUrl('https://sandbox-api.craftgate.io');
74-
75-
$craftgate = new Craftgate($options);
63+
$craftgate = new \Craftgate\Craftgate(array(
64+
'apiKey' => '<YOUR API KEY>',
65+
'secretKey' => '<YOUR SECRET KEY>',
66+
'baseUrl' => 'https://sandbox-api.craftgate.io',
67+
));
7668

7769
$request = array(
7870
'price' => 100,
@@ -91,17 +83,17 @@ $request = array(
9183
),
9284
'items' => array(
9385
array(
94-
'externalId' => uniqid(),
86+
'externalId' => \Craftgate\Util\Guid::generate(),
9587
'name' => 'Item 1',
9688
'price' => 30
9789
),
9890
array(
99-
'externalId' => uniqid(),
91+
'externalId' => \Craftgate\Util\Guid::generate(),
10092
'name' => 'Item 2',
10193
'price' => 50
10294
),
10395
array(
104-
'externalId' => uniqid(),
96+
'externalId' => \Craftgate\Util\Guid::generate(),
10597
'name' => 'Item 3',
10698
'price' => 20
10799
)
@@ -110,18 +102,17 @@ $request = array(
110102

111103
$response = $craftgate->payment()->createPayment($request);
112104

113-
print_r($response);
114-
105+
var_dump($response);
115106
```
116107

117108
### Advanced Usage: Adapters
118-
In reality, the `Craftgate` class serves as a collection of adapters that integrates with different parts of the API. While the intended usage for most use-cases is to instantiate a `Craftgate` instance (as illustrated in the examples above) and use its adapter accessors (e.g. `payment()`), you can also manually import a certain adapter class and instantiate it.
109+
In reality, the `Craftgate` class serves as a provider of adapters that integrates with different parts of the API. While the intended usage for most use-cases is to instantiate a `Craftgate` instance (as illustrated in the examples above) and use its adapter initializers (e.g. `payment()`).
119110

120111
**Note:** When instantiating an adapter, you can use the same options as you would when instantiating a `Craftgate`
121112

122-
For all adapters in the `Craftgate`, their purposes, accessors, as well as direct import paths, refer to the list below:
113+
All adapters in the `Craftgate` have their purposes and initializers that listed below:
123114

124-
| Adapter Name | Purpose | Accessor |
115+
| Adapter Name | Purpose | Initializer |
125116
|--------------|---------|----------|
126117
| `InstallmentAdapter` | Retrieving per-installment pricing information based on installment count or BIN number | `installment()` |
127118
| `OnboardingAdapter` | Conducting CRUD operations on buyers and sub merchants | `onboarding()` |

autoload.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Craftgate;
4+
5+
spl_autoload_register(function ($name) {
6+
if (strpos($name, __NAMESPACE__) === 0) {
7+
$name = substr($name, strlen(__NAMESPACE__) + 1);
8+
$name = strtr($name, '\\', DIRECTORY_SEPARATOR);
9+
($file = realpath(
10+
__DIR__ . DIRECTORY_SEPARATOR
11+
. 'src' . DIRECTORY_SEPARATOR
12+
. $name . '.php'
13+
)) && require $file;
14+
}
15+
});

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
"ext-json": "*"
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit": "~4.0",
24-
"satooshi/php-coveralls": "~0.6.1"
23+
"phpunit/phpunit": "~4.0"
2524
},
2625
"autoload": {
2726
"psr-4": {
28-
"Craftgate\\": "lib/Craftgate/"
27+
"Craftgate\\": "src/"
2928
}
3029
},
3130
"autoload-dev": {

lib/Craftgate/Adapter/BaseAdapter.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)