Skip to content

Commit

Permalink
Update PHP SDK, extend notification status transition (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilleszczak2 authored Dec 9, 2019
1 parent e14d487 commit ac0286d
Show file tree
Hide file tree
Showing 544 changed files with 16,575 additions and 41,677 deletions.
2 changes: 1 addition & 1 deletion upload/admin/controller/extension/payment/paynow.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class ControllerExtensionPaymentPaynow extends Controller
{
private $version = "1.0.0";
private $version = "1.0.1";

private $error = array();
private $settings = array();
Expand Down
64 changes: 32 additions & 32 deletions upload/catalog/controller/extension/payment/paynow.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ControllerExtensionPaymentPaynow extends Controller
const ORDER_STATUS_CONFIRMED = 2;
const ORDER_STATUS_ERROR = 10;

protected $version = "1.0.0";
protected $version = "1.0.1";
private $apiClient = null;
private $isSandboxEnabled;
private $apiKey;
Expand Down Expand Up @@ -92,8 +92,9 @@ private function sendPaymentData($orderInfo)
"email" => $orderInfo["email"]
]
];
$idempotencyKey = uniqid($orderInfo['order_id'], "_");
$payment = new \Paynow\Service\Payment($this->apiClient);
return $payment->authorize($payment_data);
return $payment->authorize($payment_data, $idempotencyKey);
}

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

$payment = $this->model_extension_payment_paynow->getLastPaymentStatus($notificationData["paymentId"]);

if (!$payment) {
$this->model_extension_payment_paynow->log("Order for payment not exists - " . $notificationData["paymentId"]);
header('HTTP/1.1 400 Bad Request', true, 400);
exit;
}

try {
new \Paynow\Notification($this->signatureKey, $payload, $headers);
$payment = $this->model_extension_payment_paynow->getLastPaymentStatus($notificationData["paymentId"]);
if (!$payment) {
$this->model_extension_payment_paynow->log("Order for payment not exists - " . $notificationData["paymentId"]);
header('HTTP/1.1 400 Bad Request', true, 400);
exit;
}
} catch (\Exception $exception) {
$this->model_extension_payment_paynow->log($exception->getMessage() . " - " . $notificationData["paymentId"]);
header('HTTP/1.1 400 Bad Request', true, 400);
Expand All @@ -130,28 +129,29 @@ private function updateOrderState($payment, $notificationData)
{
$orderInfo = $this->model_checkout_order->getOrder($payment["id_order"]);
if ($orderInfo) {
if ($this->isCorrectStatus($payment['status'], $notificationData['status'])) {
switch ($notificationData['status']) {
case self::PAYNOW_PAYMENT_STATUS_PENDING:
break;
case self::PAYNOW_PAYMENT_STATUS_REJECTED:
$this->model_checkout_order->addOrderHistory($orderInfo['order_id'], self::ORDER_STATUS_REJECTED, "Paynow: " . $payment["id_payment"] . "- " . $notificationData['status']);
break;
case self::PAYNOW_PAYMENT_STATUS_CONFIRMED:
$this->model_checkout_order->addOrderHistory($orderInfo['order_id'], self::ORDER_STATUS_CONFIRMED, "Paynow: " . $payment["id_payment"] . "- " . $notificationData['status']);
break;
case self::PAYNOW_PAYMENT_STATUS_ERROR:
$this->model_checkout_order->addOrderHistory($orderInfo['order_id'], self::ORDER_STATUS_ERROR, "Paynow: " . $payment["id_payment"] . "- " . $notificationData['status']);
break;
}

$this->model_extension_payment_paynow->storePaymentState(
$notificationData['paymentId'],
$notificationData['status'],
$orderInfo["order_id"],
(new DateTime($notificationData['modifiedAt']))->format('Y-m-d H:i:s')
);
if (!$this->isCorrectStatus($payment['status'], $notificationData['status'])) {
throw new Exception('Order status transition is incorrect ' . $payment['status'] . ' - ' . $notificationData['status'] . ' for order ' . $orderInfo['order_id']);
}
switch ($notificationData['status']) {
case self::PAYNOW_PAYMENT_STATUS_PENDING:
break;
case self::PAYNOW_PAYMENT_STATUS_REJECTED:
$this->model_checkout_order->addOrderHistory($orderInfo['order_id'], self::ORDER_STATUS_REJECTED, "Paynow: " . $payment["id_payment"] . "- " . $notificationData['status']);
break;
case self::PAYNOW_PAYMENT_STATUS_CONFIRMED:
$this->model_checkout_order->addOrderHistory($orderInfo['order_id'], self::ORDER_STATUS_CONFIRMED, "Paynow: " . $payment["id_payment"] . "- " . $notificationData['status']);
break;
case self::PAYNOW_PAYMENT_STATUS_ERROR:
$this->model_checkout_order->addOrderHistory($orderInfo['order_id'], self::ORDER_STATUS_ERROR, "Paynow: " . $payment["id_payment"] . "- " . $notificationData['status']);
break;
}

$this->model_extension_payment_paynow->storePaymentState(
$notificationData['paymentId'],
$notificationData['status'],
$orderInfo["order_id"],
(new DateTime($notificationData['modifiedAt']))->format('Y-m-d H:i:s')
);
}
}

Expand All @@ -162,7 +162,7 @@ private function isCorrectStatus($previousStatus, $nextStatus)
self::PAYNOW_PAYMENT_STATUS_PENDING => [self::PAYNOW_PAYMENT_STATUS_CONFIRMED, self::PAYNOW_PAYMENT_STATUS_REJECTED],
self::PAYNOW_PAYMENT_STATUS_REJECTED => [self::PAYNOW_PAYMENT_STATUS_CONFIRMED],
self::PAYNOW_PAYMENT_STATUS_CONFIRMED => [],
self::PAYNOW_PAYMENT_STATUS_ERROR => []
self::PAYNOW_PAYMENT_STATUS_ERROR => [self::PAYNOW_PAYMENT_STATUS_CONFIRMED, self::PAYNOW_PAYMENT_STATUS_REJECTED]
];
$previousStatusExists = isset($paymentStatusFlow[$previousStatus]);
$isChangePossible = in_array($nextStatus, $paymentStatusFlow[$previousStatus]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor
/composer.lock
27 changes: 27 additions & 0 deletions upload/system/storage/vendor/paynow/clue/stream-filter/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
language: php

php:
# - 5.3 # requires old distro, see below
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- hhvm # ignore errors, see below

# lock distro so new future defaults will not break the build
dist: trusty

matrix:
include:
- php: 5.3
dist: precise
allow_failures:
- php: hhvm

install:
- composer install --no-interaction

script:
- vendor/bin/phpunit --coverage-text
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Changelog

## 1.4.1 (2019-04-09)

* Fix: Check if the function is declared before declaring it.
(#23 by @Niko9911)

* Improve test suite to also test against PHP 7.2 and
add test for base64 encoding and decoding filters.
(#22 by @arubacao and #25 by @Nyholm and @clue)

## 1.4.0 (2017-08-18)

* Feature / Fix: The `fun()` function does not pass filter parameter `null`
to underlying `stream_filter_append()` by default
(#15 by @Nyholm)

Certain filters (such as `convert.quoted-printable-encode`) do not accept
a filter parameter at all. If no explicit filter parameter is given, we no
longer pass a default `null` value.

```php
$encode = Filter\fun('convert.quoted-printable-encode');
assert('t=C3=A4st' === $encode('täst'));
```

* Add examples and improve documentation
(#13 and #20 by @clue and #18 by @Nyholm)

* Improve test suite by adding PHPUnit to require-dev,
fix HHVM build for now again and ignore future HHVM build errors,
lock Travis distro so new future defaults will not break the build
and test on PHP 7.1
(#12, #14 and #19 by @clue and #16 by @Nyholm)

## 1.3.0 (2015-11-08)

* Feature: Support accessing built-in filters as callbacks
(#5 by @clue)

```php
$fun = Filter\fun('zlib.deflate');

$ret = $fun('hello') . $fun('world') . $fun();
assert('helloworld' === gzinflate($ret));
```

## 1.2.0 (2015-10-23)

* Feature: Invoke close event when closing filter (flush buffer)
(#9 by @clue)

## 1.1.0 (2015-10-22)

* Feature: Abort filter operation when catching an Exception
(#10 by @clue)

* Feature: Additional safeguards to prevent filter state corruption
(#7 by @clue)

## 1.0.0 (2015-10-18)

* First tagged release
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
Copyright (c) 2011-2015 Michael Dowling, https://github.com/mtdowling <[email protected]>
The MIT License (MIT)

Copyright (c) 2015 Christian Lück

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:
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 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,
Expand Down
Loading

0 comments on commit ac0286d

Please sign in to comment.