Skip to content

Commit ac0286d

Browse files
Update PHP SDK, extend notification status transition (#2)
1 parent e14d487 commit ac0286d

544 files changed

Lines changed: 16575 additions & 41677 deletions

File tree

Some content is hidden

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

upload/admin/controller/extension/payment/paynow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class ControllerExtensionPaymentPaynow extends Controller
44
{
5-
private $version = "1.0.0";
5+
private $version = "1.0.1";
66

77
private $error = array();
88
private $settings = array();

upload/catalog/controller/extension/payment/paynow.php

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ControllerExtensionPaymentPaynow extends Controller
1313
const ORDER_STATUS_CONFIRMED = 2;
1414
const ORDER_STATUS_ERROR = 10;
1515

16-
protected $version = "1.0.0";
16+
protected $version = "1.0.1";
1717
private $apiClient = null;
1818
private $isSandboxEnabled;
1919
private $apiKey;
@@ -92,8 +92,9 @@ private function sendPaymentData($orderInfo)
9292
"email" => $orderInfo["email"]
9393
]
9494
];
95+
$idempotencyKey = uniqid($orderInfo['order_id'], "_");
9596
$payment = new \Paynow\Service\Payment($this->apiClient);
96-
return $payment->authorize($payment_data);
97+
return $payment->authorize($payment_data, $idempotencyKey);
9798
}
9899

99100
public function notification()
@@ -105,16 +106,14 @@ public function notification()
105106
$headers = $this->getRequestHeaders();
106107
$notificationData = json_decode($payload, true);
107108

108-
$payment = $this->model_extension_payment_paynow->getLastPaymentStatus($notificationData["paymentId"]);
109-
110-
if (!$payment) {
111-
$this->model_extension_payment_paynow->log("Order for payment not exists - " . $notificationData["paymentId"]);
112-
header('HTTP/1.1 400 Bad Request', true, 400);
113-
exit;
114-
}
115-
116109
try {
117110
new \Paynow\Notification($this->signatureKey, $payload, $headers);
111+
$payment = $this->model_extension_payment_paynow->getLastPaymentStatus($notificationData["paymentId"]);
112+
if (!$payment) {
113+
$this->model_extension_payment_paynow->log("Order for payment not exists - " . $notificationData["paymentId"]);
114+
header('HTTP/1.1 400 Bad Request', true, 400);
115+
exit;
116+
}
118117
} catch (\Exception $exception) {
119118
$this->model_extension_payment_paynow->log($exception->getMessage() . " - " . $notificationData["paymentId"]);
120119
header('HTTP/1.1 400 Bad Request', true, 400);
@@ -130,28 +129,29 @@ private function updateOrderState($payment, $notificationData)
130129
{
131130
$orderInfo = $this->model_checkout_order->getOrder($payment["id_order"]);
132131
if ($orderInfo) {
133-
if ($this->isCorrectStatus($payment['status'], $notificationData['status'])) {
134-
switch ($notificationData['status']) {
135-
case self::PAYNOW_PAYMENT_STATUS_PENDING:
136-
break;
137-
case self::PAYNOW_PAYMENT_STATUS_REJECTED:
138-
$this->model_checkout_order->addOrderHistory($orderInfo['order_id'], self::ORDER_STATUS_REJECTED, "Paynow: " . $payment["id_payment"] . "- " . $notificationData['status']);
139-
break;
140-
case self::PAYNOW_PAYMENT_STATUS_CONFIRMED:
141-
$this->model_checkout_order->addOrderHistory($orderInfo['order_id'], self::ORDER_STATUS_CONFIRMED, "Paynow: " . $payment["id_payment"] . "- " . $notificationData['status']);
142-
break;
143-
case self::PAYNOW_PAYMENT_STATUS_ERROR:
144-
$this->model_checkout_order->addOrderHistory($orderInfo['order_id'], self::ORDER_STATUS_ERROR, "Paynow: " . $payment["id_payment"] . "- " . $notificationData['status']);
145-
break;
146-
}
147-
148-
$this->model_extension_payment_paynow->storePaymentState(
149-
$notificationData['paymentId'],
150-
$notificationData['status'],
151-
$orderInfo["order_id"],
152-
(new DateTime($notificationData['modifiedAt']))->format('Y-m-d H:i:s')
153-
);
132+
if (!$this->isCorrectStatus($payment['status'], $notificationData['status'])) {
133+
throw new Exception('Order status transition is incorrect ' . $payment['status'] . ' - ' . $notificationData['status'] . ' for order ' . $orderInfo['order_id']);
134+
}
135+
switch ($notificationData['status']) {
136+
case self::PAYNOW_PAYMENT_STATUS_PENDING:
137+
break;
138+
case self::PAYNOW_PAYMENT_STATUS_REJECTED:
139+
$this->model_checkout_order->addOrderHistory($orderInfo['order_id'], self::ORDER_STATUS_REJECTED, "Paynow: " . $payment["id_payment"] . "- " . $notificationData['status']);
140+
break;
141+
case self::PAYNOW_PAYMENT_STATUS_CONFIRMED:
142+
$this->model_checkout_order->addOrderHistory($orderInfo['order_id'], self::ORDER_STATUS_CONFIRMED, "Paynow: " . $payment["id_payment"] . "- " . $notificationData['status']);
143+
break;
144+
case self::PAYNOW_PAYMENT_STATUS_ERROR:
145+
$this->model_checkout_order->addOrderHistory($orderInfo['order_id'], self::ORDER_STATUS_ERROR, "Paynow: " . $payment["id_payment"] . "- " . $notificationData['status']);
146+
break;
154147
}
148+
149+
$this->model_extension_payment_paynow->storePaymentState(
150+
$notificationData['paymentId'],
151+
$notificationData['status'],
152+
$orderInfo["order_id"],
153+
(new DateTime($notificationData['modifiedAt']))->format('Y-m-d H:i:s')
154+
);
155155
}
156156
}
157157

@@ -162,7 +162,7 @@ private function isCorrectStatus($previousStatus, $nextStatus)
162162
self::PAYNOW_PAYMENT_STATUS_PENDING => [self::PAYNOW_PAYMENT_STATUS_CONFIRMED, self::PAYNOW_PAYMENT_STATUS_REJECTED],
163163
self::PAYNOW_PAYMENT_STATUS_REJECTED => [self::PAYNOW_PAYMENT_STATUS_CONFIRMED],
164164
self::PAYNOW_PAYMENT_STATUS_CONFIRMED => [],
165-
self::PAYNOW_PAYMENT_STATUS_ERROR => []
165+
self::PAYNOW_PAYMENT_STATUS_ERROR => [self::PAYNOW_PAYMENT_STATUS_CONFIRMED, self::PAYNOW_PAYMENT_STATUS_REJECTED]
166166
];
167167
$previousStatusExists = isset($paymentStatusFlow[$previousStatus]);
168168
$isChangePossible = in_array($nextStatus, $paymentStatusFlow[$previousStatus]);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor
2+
/composer.lock
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
language: php
2+
3+
php:
4+
# - 5.3 # requires old distro, see below
5+
- 5.4
6+
- 5.5
7+
- 5.6
8+
- 7.0
9+
- 7.1
10+
- 7.2
11+
- hhvm # ignore errors, see below
12+
13+
# lock distro so new future defaults will not break the build
14+
dist: trusty
15+
16+
matrix:
17+
include:
18+
- php: 5.3
19+
dist: precise
20+
allow_failures:
21+
- php: hhvm
22+
23+
install:
24+
- composer install --no-interaction
25+
26+
script:
27+
- vendor/bin/phpunit --coverage-text
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Changelog
2+
3+
## 1.4.1 (2019-04-09)
4+
5+
* Fix: Check if the function is declared before declaring it.
6+
(#23 by @Niko9911)
7+
8+
* Improve test suite to also test against PHP 7.2 and
9+
add test for base64 encoding and decoding filters.
10+
(#22 by @arubacao and #25 by @Nyholm and @clue)
11+
12+
## 1.4.0 (2017-08-18)
13+
14+
* Feature / Fix: The `fun()` function does not pass filter parameter `null`
15+
to underlying `stream_filter_append()` by default
16+
(#15 by @Nyholm)
17+
18+
Certain filters (such as `convert.quoted-printable-encode`) do not accept
19+
a filter parameter at all. If no explicit filter parameter is given, we no
20+
longer pass a default `null` value.
21+
22+
```php
23+
$encode = Filter\fun('convert.quoted-printable-encode');
24+
assert('t=C3=A4st' === $encode('täst'));
25+
```
26+
27+
* Add examples and improve documentation
28+
(#13 and #20 by @clue and #18 by @Nyholm)
29+
30+
* Improve test suite by adding PHPUnit to require-dev,
31+
fix HHVM build for now again and ignore future HHVM build errors,
32+
lock Travis distro so new future defaults will not break the build
33+
and test on PHP 7.1
34+
(#12, #14 and #19 by @clue and #16 by @Nyholm)
35+
36+
## 1.3.0 (2015-11-08)
37+
38+
* Feature: Support accessing built-in filters as callbacks
39+
(#5 by @clue)
40+
41+
```php
42+
$fun = Filter\fun('zlib.deflate');
43+
44+
$ret = $fun('hello') . $fun('world') . $fun();
45+
assert('helloworld' === gzinflate($ret));
46+
```
47+
48+
## 1.2.0 (2015-10-23)
49+
50+
* Feature: Invoke close event when closing filter (flush buffer)
51+
(#9 by @clue)
52+
53+
## 1.1.0 (2015-10-22)
54+
55+
* Feature: Abort filter operation when catching an Exception
56+
(#10 by @clue)
57+
58+
* Feature: Additional safeguards to prevent filter state corruption
59+
(#7 by @clue)
60+
61+
## 1.0.0 (2015-10-18)
62+
63+
* First tagged release

upload/system/storage/vendor/paynow/guzzlehttp/guzzle/LICENSE renamed to upload/system/storage/vendor/paynow/clue/stream-filter/LICENSE

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
Copyright (c) 2011-2015 Michael Dowling, https://github.com/mtdowling <mtdowling@gmail.com>
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Christian Lück
24

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

10-
The above copyright notice and this permission notice shall be included in
11-
all copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
1214

1315
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1416
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

0 commit comments

Comments
 (0)