Skip to content

Commit 980b109

Browse files
Merge pull request #59 from checkout/dev
Abstract IdempotencyKey.
2 parents 93093be + 2a7ce1b commit 980b109

File tree

9 files changed

+127
-78
lines changed

9 files changed

+127
-78
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<p align="center"><img src="https://www.checkout.com/static/img/checkout-logo/logo.svg" width="380"></p>
1+
<p align="center"><img src="https://www.checkout.com/static/img/logos/cko/logos/checkout.svg" width="380"></p>
22

33

44
The **Checkout SDK for PHP** enables developers to easily work with Checkout.com APIs.

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.11",
5+
"version": "1.0.12",
66
"type": "library",
77
"license": "MIT",
88
"keywords": ["checkout.com","payment","gateway","checkout","checkoutcom","GW3","CKO", "Reboot", "SDK", "Library", "PHP", "API"],

src/CheckoutApi.php

Lines changed: 1 addition & 1 deletion
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.11';
50+
const VERSION = '1.0.12';
5151

5252
/**
5353
* Channel section.

src/Controllers/PaymentController.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function refund(Refund $refund, $mode = HttpHandler::MODE_EXECUTE)
8383
{
8484
$response = $this->requestAPI($refund->getEndpoint())
8585
->setBody($refund->getValues())
86-
->setIdempotencyKey($payment->getIdempotencyKey());
86+
->setIdempotencyKey($refund->getIdempotencyKey());
8787

8888
return $this->response($response, Refund::QUALIFIED_NAME, $mode, $refund->id);
8989
}
@@ -129,7 +129,7 @@ public function void(Voids $void, $mode = HttpHandler::MODE_EXECUTE)
129129
{
130130
$response = $this->requestAPI($void->getEndpoint())
131131
->setBody($void->getValues())
132-
->setIdempotencyKey($payment->getIdempotencyKey());
132+
->setIdempotencyKey($void->getIdempotencyKey());
133133

134134
return $this->response($response, Voids::QUALIFIED_NAME, $mode, $void->id);
135135
}
@@ -145,7 +145,7 @@ public function capture(Capture $capture, $mode = HttpHandler::MODE_EXECUTE)
145145
{
146146
$response = $this->requestAPI($capture->getEndpoint())
147147
->setBody($capture->getValues())
148-
->setIdempotencyKey($payment->getIdempotencyKey());
148+
->setIdempotencyKey($capture->getIdempotencyKey());
149149

150150
return $this->response($response, Capture::QUALIFIED_NAME, $mode, $capture->id);
151151
}
@@ -165,34 +165,34 @@ public function request(Payment $payment, $mode = HttpHandler::MODE_EXECUTE)
165165

166166
return parent::response($response, Payment::QUALIFIED_NAME, $mode);
167167
}
168-
168+
169169
/**
170170
* Extra methods.
171171
*/
172-
172+
173173
/**
174174
* Retrieve supported banks.
175-
*
175+
*
176176
* @param string $class Qualified name of the class.
177177
* @return Response
178178
*/
179179
public function banks($class, $mode = HttpHandler::MODE_EXECUTE)
180-
{
181-
180+
{
181+
182182
$banks = new Response();
183183
$url = $class::MODEL_REQUEST_BANKS_URL;
184-
184+
185185
if($url) {
186186
$response = $this->requestAPI($url);
187187
$banks = $this->response($response, Response::QUALIFIED_NAME, $mode);
188188
}
189-
189+
190190
return $banks;
191191
}
192-
192+
193193
/**
194194
* Retrieve supported issuers. Alias for $this->banks().
195-
*
195+
*
196196
* @param string $model
197197
* @return array
198198
*/

src/Models/Payments/Capture.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
namespace Checkout\Models\Payments;
1919

2020
use Checkout\Library\HttpHandler;
21-
use Checkout\Library\Model;
2221
use Checkout\Library\Utilities;
2322

2423
/**
@@ -30,7 +29,7 @@
3029
* @license https://opensource.org/licenses/mit-license.html MIT License
3130
* @link https://docs.checkout.com/
3231
*/
33-
class Capture extends Model
32+
class Capture extends Idempotency
3433
{
3534

3635
/**

src/Models/Payments/Idempotency.php

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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 <[email protected]>
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\Library\Model;
21+
22+
/**
23+
* Parent class for Source and Destination.
24+
*
25+
* @category SDK
26+
* @package Checkout.com
27+
* @author Platforms Development Team <[email protected]>
28+
* @license https://opensource.org/licenses/mit-license.html MIT License
29+
* @link https://docs.checkout.com/
30+
*/
31+
abstract class Idempotency extends Model
32+
{
33+
34+
/**
35+
* Qualified name of the class.
36+
*
37+
* @var string
38+
*/
39+
const QUALIFIED_NAME = __CLASS__;
40+
41+
/**
42+
* Method type.
43+
*
44+
* @var string
45+
*/
46+
const METHOD_TYPE = '';
47+
48+
/**
49+
* Idempotency key.
50+
*
51+
* @var string
52+
*/
53+
protected $idempotency = '';
54+
55+
56+
/**
57+
* Setters and Getters
58+
*/
59+
60+
/**
61+
* Get all field values.
62+
*
63+
* @return array $values
64+
*/
65+
public function getValues()
66+
{
67+
$values = parent::getValues();
68+
unset($values['idempotency']);
69+
return $values;
70+
}
71+
72+
/**
73+
* Set Idempotency key.
74+
*
75+
* @note Be cautious when using idempotency keys.
76+
* If we detect concurrent requests with the same idempotency key,
77+
* only one request will be processed and the other requests
78+
* will return a 429 - Too Many Requests response.
79+
* @param string $key
80+
* @return self $this
81+
*/
82+
public function setIdempotencyKey($key)
83+
{
84+
$this->idempotency = $key;
85+
return $this;
86+
}
87+
88+
/**
89+
* Get Idempotency key.
90+
*
91+
* @return string $key
92+
*/
93+
public function getIdempotencyKey()
94+
{
95+
return $this->idempotency;
96+
}
97+
98+
/**
99+
* Remove idempotency key from the object.
100+
*
101+
* @return void
102+
*/
103+
public function removeIdempotencyKey()
104+
{
105+
unset($this->idempotency);
106+
}
107+
108+
}

src/Models/Payments/Payment.php

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
namespace Checkout\Models\Payments;
1919

2020
use Checkout\Library\HttpHandler;
21-
use Checkout\Library\Model;
2221
use Checkout\Library\Utilities;
2322
use Checkout\Models\Response;
2423

@@ -31,7 +30,7 @@
3130
* @license https://opensource.org/licenses/mit-license.html MIT License
3231
* @link https://docs.checkout.com/
3332
*/
34-
class Payment extends Model
33+
class Payment extends Idempotency
3534
{
3635

3736
/**
@@ -62,13 +61,6 @@ class Payment extends Model
6261
*/
6362
const MODEL_REQUEST_METHOD = HttpHandler::METHOD_POST;
6463

65-
/**
66-
* Idempotency key.
67-
*
68-
* @var string
69-
*/
70-
protected $idempotency = '';
71-
7264

7365
/**
7466
* Magic Methods
@@ -191,54 +183,6 @@ protected static function arrayToModel(
191183
* Setters and Getters
192184
*/
193185

194-
/**
195-
* Get all field values.
196-
*
197-
* @return array $values
198-
*/
199-
public function getValues()
200-
{
201-
$values = parent::getValues();
202-
unset($values['idempotency']);
203-
return $values;
204-
}
205-
206-
/**
207-
* Set Idempotency key.
208-
*
209-
* @note Be cautious when using idempotency keys.
210-
* If we detect concurrent requests with the same idempotency key,
211-
* only one request will be processed and the other requests
212-
* will return a 429 - Too Many Requests response.
213-
* @param string $key
214-
* @return self $this
215-
*/
216-
public function setIdempotencyKey($key)
217-
{
218-
$this->idempotency = $key;
219-
return $this;
220-
}
221-
222-
/**
223-
* Get Idempotency key.
224-
*
225-
* @return string $key
226-
*/
227-
public function getIdempotencyKey()
228-
{
229-
return $this->idempotency;
230-
}
231-
232-
/**
233-
* Remove idempotency key from the object.
234-
*
235-
* @return void
236-
*/
237-
public function removeIdempotencyKey()
238-
{
239-
unset($this->idempotency);
240-
}
241-
242186
/**
243187
* Get redirection of payment response.
244188
*

src/Models/Payments/Refund.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
namespace Checkout\Models\Payments;
1919

2020
use Checkout\Library\HttpHandler;
21-
use Checkout\Library\Model;
2221
use Checkout\Library\Utilities;
2322

2423
/**
@@ -30,7 +29,7 @@
3029
* @license https://opensource.org/licenses/mit-license.html MIT License
3130
* @link https://docs.checkout.com/
3231
*/
33-
class Refund extends Model
32+
class Refund extends Idempotency
3433
{
3534

3635
/**

src/Models/Payments/Voids.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
namespace Checkout\Models\Payments;
1919

2020
use Checkout\Library\HttpHandler;
21-
use Checkout\Library\Model;
2221
use Checkout\Library\Utilities;
2322

2423
/**
@@ -30,7 +29,7 @@
3029
* @license https://opensource.org/licenses/mit-license.html MIT License
3130
* @link https://docs.checkout.com/
3231
*/
33-
class Voids extends Model
32+
class Voids extends Idempotency
3433
{
3534

3635
/**

0 commit comments

Comments
 (0)