Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
zuk3975 committed Jun 12, 2024
1 parent 4271164 commit f4aaea2
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 6 deletions.
12 changes: 12 additions & 0 deletions saferpayofficial.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
3 changes: 3 additions & 0 deletions src/Config/SaferPayConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class SaferPayConfig
self::PAYMENT_KLARNA,
self::PAYMENT_WLCRYPTOPAYMENTS,
self::PAYMENT_WECHATPAY,
self::PAYMENT_ACCOUNTTOACCOUNT,
];

const PAYMENT_ALIPAY = 'ALIPAY';
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/DTO/Request/Initialize/InitializeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 6 additions & 0 deletions src/Entity/SaferPayOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class SaferPayOrder extends ObjectModel
*/
public $authorized;

/**
* @var bool
*/
public $pending;

/**
* @var array
*/
Expand All @@ -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'],
],
];
}
3 changes: 2 additions & 1 deletion src/EntityBuilder/SaferPayOrderBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Install/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions src/Processor/CheckoutProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions upgrade/install-1.2.3.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit f4aaea2

Please sign in to comment.