From f4aaea2ff99d24355a9ada990e8292b8287a567a Mon Sep 17 00:00:00 2001 From: Julius Zukauskas Date: Wed, 12 Jun 2024 18:20:25 +0300 Subject: [PATCH] wip --- saferpayofficial.php | 12 ++++++++++++ src/Config/SaferPayConfig.php | 3 +++ src/DTO/Request/Initialize/InitializeRequest.php | 4 +++- src/Entity/SaferPayOrder.php | 6 ++++++ src/EntityBuilder/SaferPayOrderBuilder.php | 3 ++- src/Install/Installer.php | 1 + src/Processor/CheckoutProcessor.php | 4 ++++ upgrade/install-1.2.3.php | 9 +++++---- 8 files changed, 36 insertions(+), 6 deletions(-) diff --git a/saferpayofficial.php b/saferpayofficial.php index 88910a53..c37f9f52 100755 --- a/saferpayofficial.php +++ b/saferpayofficial.php @@ -116,6 +116,18 @@ public function getService($service) return $containerProvider->getService($service); } + public function hookDisplayOrderConfirmation($params) + { + if (empty($params['order'])) { + return ''; + } + + //@todo: get saferpay order, check if pending and only then show custom message + //@todo: translate and move to template when requirements are clear + return 'Your payment is still being processed by your bank. This can take up to 5 days (120 hours). Once we receive the final status, we will notify you immediately. +Thank you for your patience!'; + } + public function hookActionObjectOrderPaymentAddAfter($params) { if (!isset($params['object'])) { diff --git a/src/Config/SaferPayConfig.php b/src/Config/SaferPayConfig.php index b057cb5b..c6649a1a 100755 --- a/src/Config/SaferPayConfig.php +++ b/src/Config/SaferPayConfig.php @@ -78,6 +78,7 @@ class SaferPayConfig self::PAYMENT_KLARNA, self::PAYMENT_WLCRYPTOPAYMENTS, self::PAYMENT_WECHATPAY, + self::PAYMENT_ACCOUNTTOACCOUNT, ]; const PAYMENT_ALIPAY = 'ALIPAY'; @@ -271,6 +272,7 @@ public static function supportsOrderCapture(string $paymentMethod): bool //payments that DOES NOT SUPPORT capture $unsupportedCapturePayments = [ self::PAYMENT_WECHATPAY, + self::PAYMENT_ACCOUNTTOACCOUNT, ]; return !in_array($paymentMethod, $unsupportedCapturePayments); @@ -281,6 +283,7 @@ public static function supportsOrderCancel(string $paymentMethod): bool //payments that DOES NOT SUPPORT order cancel $unsupportedCancelPayments = [ self::PAYMENT_WECHATPAY, + self::PAYMENT_ACCOUNTTOACCOUNT, ]; return !in_array($paymentMethod, $unsupportedCancelPayments); diff --git a/src/DTO/Request/Initialize/InitializeRequest.php b/src/DTO/Request/Initialize/InitializeRequest.php index 90d9d05f..07269cd0 100755 --- a/src/DTO/Request/Initialize/InitializeRequest.php +++ b/src/DTO/Request/Initialize/InitializeRequest.php @@ -177,7 +177,9 @@ public function getAsArray() ], 'Payment' => [ 'Amount' => [ - 'Value' => $this->payment->getValue(), + //@todo: don't forget this. Its for testing/debugging. https://docs.saferpay.com/home/integration-guide/testing-and-go-live#account-to-account-payments +// 'Value' => $this->payment->getValue(), + 'Value' => 4030030, 'CurrencyCode' => $this->payment->getCurrencyCode(), ], 'OrderId' => $this->payment->getOrderReference(), diff --git a/src/Entity/SaferPayOrder.php b/src/Entity/SaferPayOrder.php index 2bac92c9..81bd09e0 100755 --- a/src/Entity/SaferPayOrder.php +++ b/src/Entity/SaferPayOrder.php @@ -90,6 +90,11 @@ class SaferPayOrder extends ObjectModel */ public $authorized; + /** + * @var bool + */ + public $pending; + /** * @var array */ @@ -109,6 +114,7 @@ class SaferPayOrder extends ObjectModel 'canceled' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'], 'refunded' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'], 'authorized' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'], + 'pending' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'], ], ]; } diff --git a/src/EntityBuilder/SaferPayOrderBuilder.php b/src/EntityBuilder/SaferPayOrderBuilder.php index 4018db98..7da44046 100755 --- a/src/EntityBuilder/SaferPayOrderBuilder.php +++ b/src/EntityBuilder/SaferPayOrderBuilder.php @@ -35,7 +35,7 @@ class SaferPayOrderBuilder { //TODO to pass $body as InitializeBody. - public function create($body, $cartId, $customerId, $isTransaction) + public function create($body, $cartId, $customerId, $isTransaction, $status = null) { if (method_exists('Order', 'getIdByCartId')) { $orderId = Order::getIdByCartId($cartId); @@ -51,6 +51,7 @@ public function create($body, $cartId, $customerId, $isTransaction) $saferPayOrder->id_customer = $customerId; $saferPayOrder->redirect_url = $this->getRedirectionUrl($body); $saferPayOrder->is_transaction = $isTransaction; + $saferPayOrder->add(); return $saferPayOrder; diff --git a/src/Install/Installer.php b/src/Install/Installer.php index 8e5c9534..00974406 100755 --- a/src/Install/Installer.php +++ b/src/Install/Installer.php @@ -96,6 +96,7 @@ private function registerHooks() $this->module->registerHook('actionAdminControllerSetMedia'); $this->module->registerHook('actionOrderHistoryAddAfter'); $this->module->registerHook('actionObjectOrderPaymentAddAfter'); + $this->module->registerHook('displayOrderConfirmation'); } private function installConfiguration() diff --git a/src/Processor/CheckoutProcessor.php b/src/Processor/CheckoutProcessor.php index eac6cc4a..061f66bb 100644 --- a/src/Processor/CheckoutProcessor.php +++ b/src/Processor/CheckoutProcessor.php @@ -210,6 +210,10 @@ private function processAuthorizedOrder(CheckoutData $data, Cart $cart) } elseif ($data->getOrderStatus() === 'CAPTURED') { $order->setCurrentState(_SAFERPAY_PAYMENT_COMPLETED_); $saferPayOrder->captured = 1; + } elseif ($data->getOrderStatus() === 'PENDING') { + $order->setCurrentState(_SAFERPAY_PAYMENT_AUTHORIZED_); + $saferPayOrder->authorized = 1; + $saferPayOrder->pending = 1; } $saferPayOrder->update(); diff --git a/upgrade/install-1.2.3.php b/upgrade/install-1.2.3.php index b8af0277..bac6152c 100644 --- a/upgrade/install-1.2.3.php +++ b/upgrade/install-1.2.3.php @@ -27,10 +27,11 @@ if (!defined('_PS_VERSION_')) { exit; } + function upgrade_module_1_2_3(SaferPayOfficial $module) { - Configuration::updateValue(RequestHeader::SPEC_VERSION, SaferPayConfig::API_VERSION); - Configuration::updateValue(RequestHeader::SPEC_REFUND_VERSION, SaferPayConfig::API_VERSION); - - return true; + return Db::getInstance()->execute('ALTER TABLE ' . _DB_PREFIX_ . 'saferpay_order ADD COLUMN `pending` TINYINT(1) DEFAULT 0') && + $module->registerHook('displayOrderConfirmation') && + Configuration::updateValue(RequestHeader::SPEC_VERSION, SaferPayConfig::API_VERSION) && + Configuration::updateValue(RequestHeader::SPEC_REFUND_VERSION, SaferPayConfig::API_VERSION); }