Skip to content

Commit

Permalink
Supporting changes to allow paypal express in cart on Hyva themes (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-onufriichuk authored Jul 1, 2024
1 parent 90e3f31 commit 36fc99e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Model/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ public function getConfig()

$items[Method::PAYMENT_TITLE_PREFIX . $method['name']]['use_place_order_styling'] = (bool)
$this->config->getPaypalBlockStyling(ConfigInterface::XML_PATH_USE_PLACE_ORDER_STYLING);

$items[Method::PAYMENT_TITLE_PREFIX . $method['name']]['is_express'] =
$this->isExpressPaymentCart($quote);
}
}

Expand Down
22 changes: 17 additions & 5 deletions Model/ProcessOrder/Cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rvvup\Payments\Model\ProcessOrder;

use Magento\Framework\Event\ManagerInterface as EventManager;
use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderManagementInterface;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -86,7 +87,8 @@ public function __construct(
public function execute(OrderInterface $order, array $rvvupData, string $origin): ProcessOrderResultInterface
{
$this->validateIdExists($rvvupData);
$this->validateStatusAllowed($rvvupData['payments'][0], $this->allowedStatuses);
$payment = $rvvupData['payments'][0];
$this->validateStatusAllowed($payment, $this->allowedStatuses);
$this->validateOrderPayment($order);

if (!$order->canCancel()) {
Expand Down Expand Up @@ -116,8 +118,8 @@ public function execute(OrderInterface $order, array $rvvupData, string $origin)
'payment_process_type' => self::TYPE,
'payment_process_result' => $result,
'event_message' => $result
? 'Rvvup Payment has status ' . $rvvupData['payments'][0]['status']. '.'
: 'Rvvup Payment has status ' . $rvvupData['payments'][0]['status']
? 'Rvvup Payment has status ' . $payment['status']. '.'
: 'Rvvup Payment has status ' . $payment['status']
. ' but failed to cancel the Magento order.',
'order_id' => $order->getEntityId(),
'rvvup_id' => $rvvupData['id']
Expand All @@ -128,9 +130,19 @@ public function execute(OrderInterface $order, array $rvvupData, string $origin)
$processOrderResult = $this->processOrderResultFactory->create();
$processOrderResult->setResultType(ProcessOrderResultInterface::RESULT_TYPE_ERROR);
$processOrderResult->setRedirectPath(In::FAILURE);
$message = 'Payment ' . ucfirst(mb_strtolower($rvvupData['payments'][0]['status']));
$processOrderResult->setCustomerMessage($message);
if ($order->getPayment()->getMethod() === Method::PAYMENT_TITLE_PREFIX . 'PAYPAL') {
if ($payment['status'] == 'DECLINED') {
if ($payment['declineReason'] == 'INVALID_AUTHORIZATION') {
$message = 'Total order value exceeds amount authorised on PayPal, ' . PHP_EOL;
$message .= 'please re-authorise with PayPal or choose another payment method';
$processOrderResult->setCustomerMessage($message);
return $processOrderResult;
}
}
}

$message = 'Payment ' . ucfirst(mb_strtolower($payment['status']));
$processOrderResult->setCustomerMessage($message);
return $processOrderResult;
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"guzzlehttp/guzzle": ">=6",
"magento/module-catalog": "^103.0 || ^104.0",
"magento/module-grouped-product": ">=100.1",
"rvvup/sdk": "1.1.0",
"rvvup/sdk": "1.2.3",
"ext-json": "*",
"php": "^7.3 || ^8.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ define([
$(document).on('click', 'a#' + this.getCancelExpressPaymentLinkId(), (e) => {
e.preventDefault();

if (!rvvupMethodProperties.getIsExpressPaymentCheckout()) {
if (!window.checkoutConfig.payment[this.index].is_express) {
return;
}

Expand Down Expand Up @@ -467,7 +467,7 @@ define([
* @return {boolean}
*/
shouldDisplayPayPalButton() {
return this.isPayPalComponent() && !rvvupMethodProperties.getIsExpressPaymentCheckout();
return this.isPayPalComponent() && !window.checkoutConfig.payment[this.index].is_express;
},

/**
Expand All @@ -476,7 +476,7 @@ define([
* @return {false}
*/
shouldDisplayCancelExpressPaymentLink() {
return rvvupMethodProperties.getIsExpressPaymentCheckout();
return window.checkoutConfig.payment[this.index].is_express;
},

/**
Expand Down

0 comments on commit 36fc99e

Please sign in to comment.