diff --git a/Api/Data/QuoteCreateResponseInterface.php b/Api/Data/QuoteCreateResponseInterface.php index c8e06f765..f8bc6cf6d 100644 --- a/Api/Data/QuoteCreateResponseInterface.php +++ b/Api/Data/QuoteCreateResponseInterface.php @@ -19,8 +19,6 @@ */ namespace Buckaroo\Magento2\Api\Data; -use Buckaroo\Magento2\Api\Data\BreakdownItemInterface; - interface QuoteCreateResponseInterface extends BreakdownItemInterface { /** @@ -36,4 +34,4 @@ public function getBreakdown(); * @return string */ public function getCartId(); -} \ No newline at end of file +} diff --git a/Api/IdealQuoteCreateInterface.php b/Api/IdealQuoteCreateInterface.php index e9aa88e57..3bead625c 100644 --- a/Api/IdealQuoteCreateInterface.php +++ b/Api/IdealQuoteCreateInterface.php @@ -21,9 +21,6 @@ namespace Buckaroo\Magento2\Api; -use Buckaroo\Magento2\Api\Data\QuoteCreateResponseInterface; -use Buckaroo\Magento2\Api\Data\Ideal\ShippingAddressRequestInterface; - interface IdealQuoteCreateInterface { /** @@ -31,7 +28,7 @@ interface IdealQuoteCreateInterface * * @param string $page * @param string|null $order_data - * @return QuoteCreateResponseInterface + * @return \Buckaroo\Magento2\Api\Data\QuoteCreateResponseInterface */ public function execute( string $page, diff --git a/Api/PayWithGiftcardInterface.php b/Api/PayWithGiftcardInterface.php index e6de57d84..cc3f9d729 100644 --- a/Api/PayWithGiftcardInterface.php +++ b/Api/PayWithGiftcardInterface.php @@ -23,15 +23,14 @@ use Buckaroo\Magento2\Api\Data\Giftcard\PayRequestInterface; -interface PayWithGiftcardInterface +interface PayWithGiftcardInterface { /** * Rest method for paying with giftcards * * @param string $cartId * @param string $giftcardId - * @param \Buckaroo\Magento2\Api\Data\Giftcard\PayRequestInterface $requestBody - * + * @param \Buckaroo\Magento2\Api\Data\Giftcard\PayRequestInterface $payment * @return \Buckaroo\Magento2\Api\Data\Giftcard\PayResponseInterface */ public function pay(string $cartId, string $giftcardId, PayRequestInterface $payment); diff --git a/Api/PaypalExpressQuoteCreateInterface.php b/Api/PaypalExpressQuoteCreateInterface.php index 74947cd96..053f376e0 100644 --- a/Api/PaypalExpressQuoteCreateInterface.php +++ b/Api/PaypalExpressQuoteCreateInterface.php @@ -22,7 +22,6 @@ namespace Buckaroo\Magento2\Api; use Buckaroo\Magento2\Api\Data\PaypalExpress\ShippingAddressRequestInterface; -use Buckaroo\Magento2\Api\Data\QuoteCreateResponseInterface; interface PaypalExpressQuoteCreateInterface { @@ -32,7 +31,7 @@ interface PaypalExpressQuoteCreateInterface * @param \Buckaroo\Magento2\Api\Data\PaypalExpress\ShippingAddressRequestInterface $shipping_address * @param string $page * @param string|null $order_data - * @return QuoteCreateResponseInterface + * @return \Buckaroo\Magento2\Api\Data\QuoteCreateResponseInterface */ public function execute( ShippingAddressRequestInterface $shipping_address, diff --git a/Block/Catalog/Product/View/Applepay.php b/Block/Catalog/Product/View/Applepay.php index b56485b71..5c7bbae2c 100644 --- a/Block/Catalog/Product/View/Applepay.php +++ b/Block/Catalog/Product/View/Applepay.php @@ -60,41 +60,22 @@ public function __construct( /** * @return bool */ - public function canShowButton() + public function canShowButton($page) { - $result = false; - - if ($this->cart->getSummaryQty() - && - ($this->applepayConfigProvider->getActive() != 0) - && - ($this->applepayConfigProvider->getAvailableButtons()) - && - (in_array('Cart', $this->applepayConfigProvider->getAvailableButtons())) - ) { - $result = true; - } - - return $result; + return $this->isModuleActive() && + in_array($page, $this->applepayConfigProvider->getAvailableButtons()) && + $this->applepayConfigProvider->isApplePayEnabled($this->_storeManager->getStore()); } /** + * Check if Buckaroo module is active + * * @return bool */ - public function canShowProductButton() + public function isModuleActive() { - $result = false; - - if (($this->applepayConfigProvider->getActive() != 0) - && - ($this->applepayConfigProvider->getAvailableButtons()) - && - (in_array('Product', $this->applepayConfigProvider->getAvailableButtons())) - ) { - $result = true; - } - - return $result; + $status = $this->applepayConfigProvider->getActive(); + return $status == 1 || $status == 2; } /** @@ -102,10 +83,6 @@ public function canShowProductButton() */ public function getCheckoutConfig() { - if (!$this->canShowButton()) { - return null; - } - return json_encode($this->compositeConfigProvider->getConfig(), JSON_HEX_TAG); } diff --git a/Block/Catalog/Product/View/IdealFastCheckout.php b/Block/Catalog/Product/View/IdealFastCheckout.php index b2e87188b..5647009e3 100644 --- a/Block/Catalog/Product/View/IdealFastCheckout.php +++ b/Block/Catalog/Product/View/IdealFastCheckout.php @@ -69,31 +69,12 @@ public function __construct( * * @return bool */ - public function canShowProductButton() + public function canShowButton($page) { - if ($this->isModuleActive() && $this->isButtonEnabled()){ - return $this->idealConfig->canShowButtonForPage( - 'Product', - $this->_storeManager->getStore() - ); - } - return false; - } - - /** - * Determine if the cart button can be shown - * - * @return bool - */ - public function canShowCartButton() - { - if ($this->isModuleActive() && $this->isButtonEnabled()){ - return $this->idealConfig->canShowButtonForPage( - 'Cart', - $this->_storeManager->getStore() - ); - } - return false; + return ($this->isModuleActive() && + $this->idealConfig->isFastCheckoutEnabled($this->_storeManager->getStore()) && + $this->idealConfig->canShowButtonForPage($page, $this->_storeManager->getStore()) && + $this->idealConfig->isIDealEnabled($this->_storeManager->getStore())); } /** @@ -107,19 +88,6 @@ public function isModuleActive() return $status == 1 || $status == 2; } - /** - * Check if ideal fast checkout button is enabled - * - * @return mixed - */ - public function isButtonEnabled() - { - return $this->idealConfig->isFastCheckoutEnabled( - $this->_storeManager->getStore() - ); - } - - /** * Get logo based on chosen color setting * diff --git a/Block/Catalog/Product/View/PaypalExpress.php b/Block/Catalog/Product/View/PaypalExpress.php index afb4540bd..ea1dfc567 100644 --- a/Block/Catalog/Product/View/PaypalExpress.php +++ b/Block/Catalog/Product/View/PaypalExpress.php @@ -56,26 +56,11 @@ public function __construct( $this->encryptor = $encryptor; $this->paypalConfig = $paypalConfig; } - public function canShowProductButton() + public function canShowButton($page) { - if ($this->isModuleActive()){ - return $this->paypalConfig->canShowButtonForPage( - 'Product', - $this->_storeManager->getStore() - ); - } - return false; - } - - public function canShowCartButton() - { - if ($this->isModuleActive()){ - return $this->paypalConfig->canShowButtonForPage( - 'Cart', - $this->_storeManager->getStore() - ); - } - return false; + return $this->isModuleActive() && + $this->paypalConfig->canShowButtonForPage($page, $this->_storeManager->getStore()) && + $this->paypalConfig->isPayPalEnabled($this->_storeManager->getStore()); } /** @@ -88,6 +73,7 @@ public function isModuleActive() $status = $this->configProviderAccount->getActive(); return $status == 1 || $status == 2; } + /** * Get all data required * diff --git a/Controller/Redirect/Process.php b/Controller/Redirect/Process.php index 570f78069..a78c6f241 100755 --- a/Controller/Redirect/Process.php +++ b/Controller/Redirect/Process.php @@ -330,13 +330,16 @@ private function redirectProcess() { || $paymentMethod->getConfigData('order_email', $store) === "1" ) ) { - if (!($this->hasPostData('add_initiated_by_magento', 1) && - $this->hasPostData('brq_primary_service', 'KlarnaKp') && - $this->hasPostData('add_service_action_from_magento', 'reserve') && - !empty($this->response['brq_service_klarnakp_reservationnumber']) + if (!( + ($this->hasPostData('add_initiated_by_magento', 1) && + $this->hasPostData('brq_primary_service', 'KlarnaKp') && + $this->hasPostData('add_service_action_from_magento', 'reserve') && + !empty($this->response['brq_service_klarnakp_reservationnumber'])) + || + $this->hasPostData('add_service_action_from_magento', 'payfastcheckout') )) { if ($statusCode == $this->helper->getStatusCode('BUCKAROO_MAGENTO2_STATUSCODE_SUCCESS')) { - $this->logger->addDebug(__METHOD__ . '|sendemail|'); + $this->logger->addDebug(__METHOD__ . '|sendemail| |1|'); $this->orderSender->send($this->order, true); } } diff --git a/Helper/Data.php b/Helper/Data.php index d80e6b8c0..a620f52c0 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -384,7 +384,7 @@ public function areEqualAmounts($amount1, $amount2) if ($amount2 == 0) { return $amount1 == $amount2; } else { - return abs((floatval($amount1) - floatval($amount2)) / floatval($amount2)) < 0.00001; + return abs((floatval($amount1) - floatval($amount2)) / floatval($amount2)) <= 0.01; } } diff --git a/Model/ConfigProvider/Method/Applepay.php b/Model/ConfigProvider/Method/Applepay.php index 6cfe184ae..b5b686a5a 100644 --- a/Model/ConfigProvider/Method/Applepay.php +++ b/Model/ConfigProvider/Method/Applepay.php @@ -170,4 +170,8 @@ public function getBaseAllowedCurrencies() ]; } + public function isApplePayEnabled($store = null) + { + return $this->getConfigFromXpath(self::XPATH_APPLEPAY_ACTIVE, $store); + } } diff --git a/Model/ConfigProvider/Method/Ideal.php b/Model/ConfigProvider/Method/Ideal.php index e7dab3100..d32c8d64d 100644 --- a/Model/ConfigProvider/Method/Ideal.php +++ b/Model/ConfigProvider/Method/Ideal.php @@ -173,6 +173,11 @@ public function isFastCheckoutEnabled($store = null) return $this->getConfigFromXpath(self::XPATH_IDEAL_FAST_CHECKOUT_ENABLE, $store); } + public function isIDealEnabled($store = null) + { + return $this->getConfigFromXpath(self::XPATH_IDEAL_ACTIVE, $store); + } + public function getLogoColor($store = null) { return $this->getConfigFromXpath(self::XPATH_IDEAL_FAST_CHECKOUT_LOGO, $store); diff --git a/Model/ConfigProvider/Method/Paypal.php b/Model/ConfigProvider/Method/Paypal.php index 01b399c49..f063ae685 100644 --- a/Model/ConfigProvider/Method/Paypal.php +++ b/Model/ConfigProvider/Method/Paypal.php @@ -108,7 +108,7 @@ public function getExpressMerchantId($store = null) return $this->getConfigFromXpath(self::XPATH_PAYPAL_EXPRESS_MERCHANT_ID, $store); } /** - * Test if express button is enabled for the $page + * Test if express button is enabled for the $page * * @param string $page * @@ -124,4 +124,8 @@ public function canShowButtonForPage($page, $store = null) $pages = explode(",", $buttons); return in_array($page, $pages); } + public function isPayPalEnabled($store = null) + { + return $this->getConfigFromXpath(self::XPATH_PAYPAL_ACTIVE, $store); + } } diff --git a/Model/Method/AbstractMethod.php b/Model/Method/AbstractMethod.php index 95b207980..5427c5bca 100644 --- a/Model/Method/AbstractMethod.php +++ b/Model/Method/AbstractMethod.php @@ -2124,9 +2124,20 @@ public function getArticleArrayLine( protected function getTaxCategory($order) { - $request = $this->taxCalculation->getRateRequest(null, null, null, $order->getStore()); - $taxClassId = $this->configProviderBuckarooFee->getTaxClass($order->getStore()); - $percent = $this->taxCalculation->getRate($request->setProductClassId($taxClassId)); + $shippingAddress = $order->getShippingAddress(); + $billingAddress = $order->getBillingAddress(); + $customerTaxClassId = $order->getCustomerTaxClassId(); + $storeId = $order->getStoreId(); + $taxClassId = $this->configProviderBuckarooFee->getTaxClass(); + + $request = $this->taxCalculation->getRateRequest( + $shippingAddress, + $billingAddress, + $customerTaxClassId, + $storeId + ); + $request->setProductClassId($taxClassId); + $percent = $this->taxCalculation->getRate($request); return $percent; } @@ -2725,7 +2736,7 @@ public function checkTotalGrossAmount($requestData, $payment) } //Add diff line - if (!$this->helper->areEqualAmounts($order->getGrandTotal(), $itemsTotalAmount) && !$this->payRemainder) { + if (abs($order->getGrandTotal() - $itemsTotalAmount) > 0.01) { $diff = $order->getGrandTotal() - $itemsTotalAmount; $diffLine = $this->getDiffLine($count, $diff); $requestData = array_merge($requestData, $diffLine); diff --git a/Model/Method/Ideal.php b/Model/Method/Ideal.php index 2402a8f30..bc10eb8d3 100644 --- a/Model/Method/Ideal.php +++ b/Model/Method/Ideal.php @@ -53,6 +53,14 @@ public function assignData(\Magento\Framework\DataObject $data) $this->getInfoInstance()->setAdditionalInformation('issuer', $data['additional_data']['issuer']); } + $payment = $this->getInfoInstance(); + $quote = $payment->getQuote(); + + if ($quote) { + $shippingCost = $quote->getShippingAddress()->getShippingAmount(); + $this->getInfoInstance()->setAdditionalInformation('shippingCost', $shippingCost); + } + return $this; } @@ -67,6 +75,7 @@ public function getOrderTransactionBuilder($payment) 'Name' => 'ideal', 'Action' => $this->getPayRemainder($payment, $transactionBuilder,'PayFastCheckout'), 'Version' => 2, + 'RequestParameter' => $this->getIdealFastCheckoutOrderRequestParameters($payment), ]; /** @@ -110,6 +119,20 @@ private function getOrderRequestParameters($payment): array return $parameters; } + private function getIdealFastCheckoutOrderRequestParameters($payment): array + { + $parameters = []; + + if ($this->isFastCheckout($payment) && $payment->getAdditionalInformation('shippingCost')) { + $parameters = [[ + '_' => $payment->getAdditionalInformation('shippingCost'), + 'Name' => 'shippingCost', + ]]; + } + + return $parameters; + } + protected function getRefundTransactionBuilderVersion() { return null; diff --git a/Model/Push.php b/Model/Push.php index 6c3fff0bd..140777368 100644 --- a/Model/Push.php +++ b/Model/Push.php @@ -259,10 +259,6 @@ public function receivePush() try { $response = $this->pushProcess(); - if ($this->isFastCheckout()) { - $this->updateOrderAddressesIfFastCheckout(); - } - return $response; } catch (\Throwable $e) { $this->logging->addDebug(__METHOD__ . '|Exception|' . $e->getMessage()); @@ -597,6 +593,9 @@ private function pushProcess() ); } + if ($this->isFastCheckout()) { + $this->updateOrderAddressesIfFastCheckout(); + } if (!$this->isGroupTransactionInfo()) { $this->setTransactionKey(); diff --git a/Model/Total/Quote/BuckarooAlreadyPay.php b/Model/Total/Quote/BuckarooAlreadyPay.php index c7bb6ccf5..9efb45f73 100644 --- a/Model/Total/Quote/BuckarooAlreadyPay.php +++ b/Model/Total/Quote/BuckarooAlreadyPay.php @@ -1,5 +1,4 @@ setCode('buckaroo_already_paid'); $this->priceCurrency = $priceCurrency; @@ -50,53 +66,53 @@ public function __construct( /** * Add buckaroo fee information to address * - * @param \Magento\Quote\Model\Quote $quote - * @param \Magento\Quote\Model\Quote\Address\Total $total - * @return $this + * @param Quote $quote + * @param Total $total + * @return array + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total) + public function fetch(Quote $quote, Total $total) { $orderId = $quote->getReservedOrderId(); $customTitle = []; if ($orderId) { - $items = $this->groupTransaction->getGroupTransactionItemsNotRefunded($orderId); - - foreach ($items as $giftcard) { - $foundGiftcard = $this->giftcardCollection->getItemByColumnValue( - 'servicecode', - $giftcard['servicecode'] - ); - - if ($foundGiftcard !== null || $giftcard['servicecode'] === 'buckaroovoucher') { - - - if ($giftcard['servicecode'] === 'buckaroovoucher') { - $label = __('Voucher'); - } else { - $label = $foundGiftcard['label']; + try { + $items = $this->groupTransaction->getGroupTransactionItemsNotRefunded($orderId); + + foreach ($items as $giftcard) { + $foundGiftcard = $this->giftcardCollection->getItemByColumnValue( + 'servicecode', + $giftcard['servicecode'] + ); + + if ($foundGiftcard !== null || $giftcard['servicecode'] === 'buckaroovoucher') { + if ($giftcard['servicecode'] === 'buckaroovoucher') { + $label = __('Voucher'); + } else { + $label = $foundGiftcard['label']; + } + + $customTitle[] = [ + 'label' => __('Paid with') . ' ' . $label, + 'amount' => -$giftcard['amount'], + 'servicecode' => $giftcard['servicecode'], + 'serviceamount' => $giftcard['amount'], + 'transaction_id' => $giftcard['transaction_id'], + ]; } - - $customTitle[] = [ - 'label' => __('Paid with') . ' ' . $label, - 'amount' => -$giftcard['amount'], - 'servicecode' => $giftcard['servicecode'], - 'serviceamount' => $giftcard['amount'], - 'transaction_id' => $giftcard['transaction_id'], - ]; } + } catch (\Exception $e) { + // $this->logger->error($e->getMessage()); } } - /** - * @noinspection PhpUndefinedMethodInspection - */ - $totals = [ - 'code' => $this->getCode(), + return [ + 'code' => $this->getCode(), 'title' => $customTitle ? __(json_encode($customTitle)) : $this->getLabel(), - 'value' => $this->groupTransaction->getAlreadyPaid($orderId), + 'value' => -$this->groupTransaction->getAlreadyPaid($orderId), ]; - return $totals; } /** diff --git a/Model/Total/Quote/BuckarooFee.php b/Model/Total/Quote/BuckarooFee.php index 765cf0f4e..294fb4fce 100644 --- a/Model/Total/Quote/BuckarooFee.php +++ b/Model/Total/Quote/BuckarooFee.php @@ -231,25 +231,35 @@ public function getBaseFee( $configProvider = $this->configProviderMethodFactory->get($buckarooPaymentMethodCode); $basePaymentFee = trim($configProvider->getPaymentFee($quote->getStore())); + $inclTax = $this->configProviderBuckarooFee->getPaymentFeeTax() == + Calculation::DISPLAY_TYPE_INCLUDING_TAX; + + $shippingAddress = $quote->getShippingAddress(); + $billingAddress = $quote->getBillingAddress(); + $customerTaxClassId = $quote->getCustomerTaxClassId(); + $storeId = $quote->getStoreId(); + $taxClassId = $this->configProviderBuckarooFee->getTaxClass(); + + $request = $this->taxCalculation->getRateRequest( + $shippingAddress, + $billingAddress, + $customerTaxClassId, + $storeId + ); + $request->setProductClassId($taxClassId); + $percent = $this->taxCalculation->getRate($request); if (is_numeric($basePaymentFee)) { if (in_array($buckarooPaymentMethodCode, ['billink','afterpay20','afterpay','paypal'])) { - - $inclTax = $this->configProviderBuckarooFee->getPaymentFeeTax() == - Calculation::DISPLAY_TYPE_INCLUDING_TAX; - if ($inclTax) { - $request = $this->taxCalculation->getRateRequest(null, null, null, $quote->getStore()); - $taxClassId = $this->configProviderBuckarooFee->getTaxClass($quote->getStore()); - $percent = $this->taxCalculation->getRate($request->setProductClassId($taxClassId)); if ($percent > 0) { return $basePaymentFee / (1 + ($percent / 100)); } } return $basePaymentFee; } else { - if ($inclTax) { - return $basePaymentFee; + if ($inclTax){ + return $basePaymentFee / (1 + ($percent / 100)); } /** * Payment fee is a number @@ -286,8 +296,15 @@ public function getBaseFee( $total = $address->getBaseSubtotalTotalInclTax(); break; } + $percentageFee = ($percentage / 100) * $total; - $basePaymentFee = ($percentage / 100) * $total; + if($inclTax){ + if($percent > 0){ + return $percentageFee / (1 + ($percent / 100)); + } + } else{ + return $percentageFee; + } return $basePaymentFee; } diff --git a/Model/Total/Quote/BuckarooFeeHyva.php b/Model/Total/Quote/BuckarooFeeHyva.php index 5f500bdf5..9e04a3a2d 100644 --- a/Model/Total/Quote/BuckarooFeeHyva.php +++ b/Model/Total/Quote/BuckarooFeeHyva.php @@ -217,17 +217,27 @@ public function getBaseFee( $configProvider = $this->configProviderMethodFactory->get($buckarooPaymentMethodCode); $basePaymentFee = trim($configProvider->getPaymentFee($quote->getStore())); + $inclTax = $this->configProviderBuckarooFee->getPaymentFeeTax() == + Calculation::DISPLAY_TYPE_INCLUDING_TAX; + + $shippingAddress = $quote->getShippingAddress(); + $billingAddress = $quote->getBillingAddress(); + $customerTaxClassId = $quote->getCustomerTaxClassId(); + $storeId = $quote->getStoreId(); + $taxClassId = $this->configProviderBuckarooFee->getTaxClass(); + + $request = $this->taxCalculation->getRateRequest( + $shippingAddress, + $billingAddress, + $customerTaxClassId, + $storeId + ); + $request->setProductClassId($taxClassId); + $percent = $this->taxCalculation->getRate($request); if (is_numeric($basePaymentFee)) { if (in_array($buckarooPaymentMethodCode, ['billink','afterpay20','afterpay','paypal'])) { - - $inclTax = $this->configProviderBuckarooFee->getPaymentFeeTax() == - Calculation::DISPLAY_TYPE_INCLUDING_TAX; - if ($inclTax) { - $request = $this->taxCalculation->getRateRequest(null, null, null, $quote->getStore()); - $taxClassId = $this->configProviderBuckarooFee->getTaxClass($quote->getStore()); - $percent = $this->taxCalculation->getRate($request->setProductClassId($taxClassId)); if ($percent > 0) { return $basePaymentFee / (1 + ($percent / 100)); } @@ -235,7 +245,7 @@ public function getBaseFee( return $basePaymentFee; } else { if ($inclTax) { - return $basePaymentFee; + return $basePaymentFee / (1 + ($percent / 100)); } /** * Payment fee is a number @@ -272,8 +282,15 @@ public function getBaseFee( $total = $address->getBaseSubtotalTotalInclTax(); break; } + $percentageFee = ($percentage / 100) * $total; - $basePaymentFee = ($percentage / 100) * $total; + if($inclTax){ + if($percent > 0){ + return $percentageFee / (1 + ($percent / 100)); + } + } else{ + return $percentageFee; + } return $basePaymentFee; } diff --git a/Model/Total/Quote/BuckarooRemainingAmount.php b/Model/Total/Quote/BuckarooRemainingAmount.php new file mode 100644 index 000000000..bc6eff67a --- /dev/null +++ b/Model/Total/Quote/BuckarooRemainingAmount.php @@ -0,0 +1,76 @@ +setCode('remaining_amount'); + $this->groupTransaction = $groupTransaction; + } + + /** + * Fetch remaining amount for display in the frontend + * + * @param Quote $quote + * @param Total $total + * @return array + */ + public function fetch(Quote $quote, Total $total) + { + // Fetch the already paid amount + $alreadyPaid = $this->groupTransaction->getAlreadyPaid($quote->getReservedOrderId()); + $grandTotal = $quote->getGrandTotal(); + $remainingAmount = max(0, $grandTotal - $alreadyPaid); + + return [ + 'code' => $this->getCode(), + 'title' => __('Remaining Amount'), + 'value' => $remainingAmount + ]; + } + + /** + * Get Buckaroo label + * + * @return \Magento\Framework\Phrase + */ + public function getLabel() + { + return __('Fee'); + } +} diff --git a/Service/Applepay/Add.php b/Service/Applepay/Add.php index 7b8ddd232..f9fa4263a 100644 --- a/Service/Applepay/Add.php +++ b/Service/Applepay/Add.php @@ -111,7 +111,7 @@ public function __construct( public function process($request) { $cart_hash = $request->getParam('id'); - + if($cart_hash) { $cartId = $this->maskedQuoteIdToQuoteId->execute($cart_hash); $cart = $this->cartRepository->get($cartId); @@ -121,14 +121,21 @@ public function process($request) } $product = $request->getParam('product'); + + // Check if product data is present and valid + if (!$product || !is_array($product) || !isset($product['id']) || !is_numeric($product['id'])) { + throw new \Exception('Product data is missing or invalid.'); + } + + $cart->removeAllItems(); - + try { $productToBeAdded = $this->productRepository->getById($product['id']); } catch (NoSuchEntityException $e) { throw new NoSuchEntityException(__('Could not find a product with ID "%id"', ['id' => $product['id']])); } - + $cartItem = new CartItem( $productToBeAdded->getSku(), $product['qty'] @@ -140,19 +147,19 @@ public function process($request) $cart->addProduct($productToBeAdded, $this->requestBuilder->build($cartItem)); $this->cartRepository->save($cart); - + $wallet = $request->getParam('wallet'); $shippingMethodsResult = []; if (!$cart->getIsVirtual()) { $shippingAddressData = $this->applepayModel->processAddressFromWallet($wallet, 'shipping'); - - + + $shippingAddress = $this->quoteAddressFactory->create(); $shippingAddress->addData($shippingAddressData); - $errors = $shippingAddress->validate(); - + $errors = $shippingAddress->validate(); + try { $this->shippingAddressManagement->assign($cart->getId(), $shippingAddress); } catch (\Exception $e) { @@ -161,16 +168,28 @@ public function process($request) } $this->quoteRepository->save($cart); //this delivery address is already assigned to the cart - $shippingMethods = $this->appleShippingMethod->getAvailableMethods( $cart); - foreach ($shippingMethods as $index => $shippingMethod) { + + try { + $shippingMethods = $this->appleShippingMethod->getAvailableMethods($cart); + } catch (\Exception $e) { + throw new \Exception(__('Unable to retrieve shipping methods.')); + } + + foreach ($shippingMethods as $method) { $shippingMethodsResult[] = [ - 'carrier_title' => $shippingMethod['carrier_title'], - 'price_incl_tax' => round($shippingMethod['amount'], 2), - 'method_code' => $shippingMethod['carrier_code'] . '_' . $shippingMethod['method_code'], - 'method_title' => $shippingMethod['method_title'], + 'carrier_title' => $method['carrier_title'], + 'price_incl_tax' => round($method['amount']['value'], 2), + 'method_code' => $method['carrier_code'] . '__SPLIT__' . $method['method_code'], + 'method_title' => $method['method_title'], ]; } - $cart->getShippingAddress()->setShippingMethod($shippingMethodsResult[0]['method_code']); + + if (!empty($shippingMethodsResult)) { + // Set the first available shipping method + $cart->getShippingAddress()->setShippingMethod($shippingMethodsResult[0]['method_code']); + } else { + throw new \Exception(__('No shipping methods are available for the provided address.')); + } } $cart->setTotalsCollectedFlag(false); $cart->collectTotals(); @@ -200,4 +219,4 @@ public function gatherTotals($address, $quoteTotals) 'grand_total' => $quoteTotals['grand_total']->getValue() ]; } -} \ No newline at end of file +} diff --git a/Service/Software/Data.php b/Service/Software/Data.php index b8dada996..a2923ff13 100644 --- a/Service/Software/Data.php +++ b/Service/Software/Data.php @@ -36,7 +36,7 @@ class Data const MODULE_CODE = 'Buckaroo_Magento2'; /** Version of Module */ - const BUCKAROO_VERSION = '1.50.1'; + const BUCKAROO_VERSION = '1.50.2'; /** @var ProductMetadataInterface */ private $productMetadata; diff --git a/composer.json b/composer.json index fa766e059..dfb034b7f 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "docs": "https://docs.buckaroo.io/" }, "homepage": "https://www.buckaroo.nl", - "version" : "v1.50.1", + "version" : "v1.50.2", "minimum-stability": "stable", "autoload": { "files": [ diff --git a/etc/csp_whitelist.xml b/etc/csp_whitelist.xml index 35c36e996..8aadc2928 100644 --- a/etc/csp_whitelist.xml +++ b/etc/csp_whitelist.xml @@ -18,15 +18,18 @@ list.xsd"> + https://portal.payconiq.com https://static.buckaroo.nl + wss://websocketservice-externalapi.prod.buckaroo.io https://static.buckaroo.nl wss://websockets.buckaroo.io/ https://checkout.buckaroo.nl https://testcheckout.buckaroo.nl + https://applepay.buckaroo.io diff --git a/etc/module.xml b/etc/module.xml index 9199b2144..fcd4535b7 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -20,7 +20,7 @@ */ --> - + diff --git a/etc/sales.xml b/etc/sales.xml index a884141fb..3171d1aaf 100644 --- a/etc/sales.xml +++ b/etc/sales.xml @@ -31,11 +31,16 @@ + + + + +
- +
diff --git a/view/frontend/layout/catalog_product_view.xml b/view/frontend/layout/catalog_product_view.xml index 96ba3015a..46239ee9d 100644 --- a/view/frontend/layout/catalog_product_view.xml +++ b/view/frontend/layout/catalog_product_view.xml @@ -18,6 +18,9 @@ * @license https://tldrlegal.com/license/mit-license --> + + + - \ No newline at end of file + diff --git a/view/frontend/layout/checkout_cart_index.xml b/view/frontend/layout/checkout_cart_index.xml index 17a7d2bdb..abf009c79 100644 --- a/view/frontend/layout/checkout_cart_index.xml +++ b/view/frontend/layout/checkout_cart_index.xml @@ -6,6 +6,9 @@ */ --> + + +
- - Buckaroo_Magento2/js/view/checkout/summary/grand-total - - Order Total Excl. Tax - Order Total Incl. Tax - You will be charged for - Order Total - + + + Buckaroo_Magento2/js/view/checkout/summary/remaining-amount + 250 + Remaining Amount + false + + + + Buckaroo_Magento2/js/view/checkout/summary/already-paid + 300 + Already Paid + false
diff --git a/view/frontend/templates/catalog/product/view/applepay.phtml b/view/frontend/templates/catalog/product/view/applepay.phtml index b8a329eef..47759c26d 100644 --- a/view/frontend/templates/catalog/product/view/applepay.phtml +++ b/view/frontend/templates/catalog/product/view/applepay.phtml @@ -18,9 +18,9 @@ * @license https://tldrlegal.com/license/mit-license */ ?> -canShowProductButton()): ?> -
- +canShowButton('Product')): ?> +
+
- \ No newline at end of file + diff --git a/view/frontend/templates/catalog/product/view/ideal-fast-checkout.phtml b/view/frontend/templates/catalog/product/view/ideal-fast-checkout.phtml index 17acf5b5a..a4081c320 100644 --- a/view/frontend/templates/catalog/product/view/ideal-fast-checkout.phtml +++ b/view/frontend/templates/catalog/product/view/ideal-fast-checkout.phtml @@ -1,45 +1,52 @@ canShowProductButton()): ?> - - +if ($block->canShowButton('Product')): ?> - + diff --git a/view/frontend/templates/catalog/product/view/paypal-express.phtml b/view/frontend/templates/catalog/product/view/paypal-express.phtml index 1ef90e533..13a6c7157 100644 --- a/view/frontend/templates/catalog/product/view/paypal-express.phtml +++ b/view/frontend/templates/catalog/product/view/paypal-express.phtml @@ -18,7 +18,7 @@ * @license https://tldrlegal.com/license/mit-license */ ?> -canShowProductButton()): ?> +canShowButton('Product')): ?>
@@ -38,4 +38,4 @@ }
- \ No newline at end of file + diff --git a/view/frontend/templates/checkout/cart/applepay.phtml b/view/frontend/templates/checkout/cart/applepay.phtml index 4c7a0369b..d9cdbe7ee 100644 --- a/view/frontend/templates/checkout/cart/applepay.phtml +++ b/view/frontend/templates/checkout/cart/applepay.phtml @@ -18,7 +18,7 @@ * @license https://tldrlegal.com/license/mit-license */ ?> -canShowButton()): ?> +canShowButton('Cart')): ?>
@@ -34,7 +34,7 @@ } showPayButton = function() { require(['jquery', 'buckaroo/applepay/checkout-cart'], function (jQuery, applepayPay) { - applepayPay.showPayButton(); + applepayPay.showPayButton('cart'); }); } diff --git a/view/frontend/templates/checkout/cart/ideal-fast-checkout.phtml b/view/frontend/templates/checkout/cart/ideal-fast-checkout.phtml index ba779e13c..5238981a1 100644 --- a/view/frontend/templates/checkout/cart/ideal-fast-checkout.phtml +++ b/view/frontend/templates/checkout/cart/ideal-fast-checkout.phtml @@ -1,45 +1,52 @@ canShowCartButton()): ?> - - +/** + * NOTICE OF LICENSE + * + * This source file is subject to the MIT License + * It is available through the world-wide-web at this URL: + * https://tldrlegal.com/license/mit-license + * If you are unable to obtain it through the world-wide-web, please send an email + * to support@buckaroo.nl so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please contact support@buckaroo.nl for more information. + * + * @copyright Copyright (c) Buckaroo B.V. + * @license https://tldrlegal.com/license/mit-license + */ - + diff --git a/view/frontend/templates/checkout/cart/paypal-express.phtml b/view/frontend/templates/checkout/cart/paypal-express.phtml index be7f7e673..20122de68 100644 --- a/view/frontend/templates/checkout/cart/paypal-express.phtml +++ b/view/frontend/templates/checkout/cart/paypal-express.phtml @@ -19,7 +19,7 @@ * @license https://tldrlegal.com/license/mit-license */ ?> -canShowCartButton()) : ?> +canShowButton('Cart')) : ?>
diff --git a/view/frontend/web/css/ideal-fast-checkout.css b/view/frontend/web/css/ideal-fast-checkout.css new file mode 100644 index 000000000..e107f91ac --- /dev/null +++ b/view/frontend/web/css/ideal-fast-checkout.css @@ -0,0 +1,17 @@ +#fast-checkout-ideal-btn { + height: 45px; + padding: 0; + border: none; + background: none; + display: flex; + align-items: center; + justify-content: center; + margin: 20px 0; +} + +#fast-checkout-ideal-btn img { + max-height: 100%; + max-width: 100%; + display: block; + margin: auto; +} diff --git a/view/frontend/web/js/view/checkout/applepay/checkout-cart.js b/view/frontend/web/js/view/checkout/applepay/checkout-cart.js index 42e026c20..8823a1989 100644 --- a/view/frontend/web/js/view/checkout/applepay/checkout-cart.js +++ b/view/frontend/web/js/view/checkout/applepay/checkout-cart.js @@ -32,9 +32,9 @@ define( 'use strict'; return { - showPayButton: function () { + showPayButton: function ($page) { applepayPay.setQuote(quote); - applepayPay.showPayButton('cart'); + applepayPay.showPayButton($page); applepayPay.transactionResult.subscribe( function () { diff --git a/view/frontend/web/js/view/checkout/applepay/pay.js b/view/frontend/web/js/view/checkout/applepay/pay.js index 700db28ca..ae4efa01f 100644 --- a/view/frontend/web/js/view/checkout/applepay/pay.js +++ b/view/frontend/web/js/view/checkout/applepay/pay.js @@ -392,9 +392,9 @@ define( } }.bind(this), }) - .fail(function() { - this.timeoutRedirect(); - }.bind(this)); + .fail(function() { + this.timeoutRedirect(); + }.bind(this)); return update; } else if (this.payMode == 'cart') { @@ -432,9 +432,9 @@ define( } }.bind(this), }) - .fail(function() { - this.timeoutRedirect(); - }.bind(this)); + .fail(function() { + this.timeoutRedirect(); + }.bind(this)); return update; } else { @@ -548,9 +548,9 @@ define( } }.bind(this), }) - .fail(function() { - this.timeoutRedirect(); - }.bind(this)); + .fail(function() { + this.timeoutRedirect(); + }.bind(this)); return update; @@ -607,10 +607,22 @@ define( initProductViewWatchers: function () { this.devLog('==============applepaydebug/initProductViewWatchers'); - this.productSelected.id = $('.price-box').attr('data-product-id'); - this.productSelected.qty = $('#qty').val(); - var self = this; + var productId = $('.price-box').attr('data-product-id'); + var productQty = $('#qty').val(); + + if (!productId) { + console.error('Product ID not found on the page.'); + return; + } + + if (!productQty) { + productQty = 1; + } + this.productSelected.id = productId; + this.productSelected.qty = productQty; + + var self = this; $('#qty').change(function() { self.productSelected.qty = $(this).val(); }); diff --git a/view/frontend/web/js/view/checkout/ideal-fast-checkout/pay.js b/view/frontend/web/js/view/checkout/ideal-fast-checkout/pay.js index 5235ef3d0..272012621 100644 --- a/view/frontend/web/js/view/checkout/ideal-fast-checkout/pay.js +++ b/view/frontend/web/js/view/checkout/ideal-fast-checkout/pay.js @@ -1,23 +1,49 @@ define([ - 'jquery', + 'uiComponent', 'mage/url', + 'jquery', 'Magento_Customer/js/customer-data', 'mage/translate', 'mage/storage' -], function ($, urlBuilder, customerData, $t, storage) { +], function (Component, urlBuilder, $, customerData, $t, storage) { 'use strict'; - return { - createQuoteAndPlaceOrder: function (productData) { - this.showLoader(); + return Component.extend({ + page: null, + paymentData: null, + + initialize: function (config) { + this._super(); - this.page = productData.page; - productData.order_data = this.getOrderData(); + this.page = config.page; + this.paymentData = config.paymentData; var customerDataObject = customerData.get('customer'); customerDataObject.subscribe(function (updatedCustomer) { }.bind(this)); + + $(document).on('click', '#fast-checkout-ideal-btn', function() { + this.onCheckout(); + }.bind(this)); + }, + + onCheckout: function () { + var qty = $("#qty").val(); + + var productData = { + qty: qty, + page: this.page, + paymentData: this.paymentData, + order_data: this.getOrderData() + }; + + this.createQuoteAndPlaceOrder(productData); + }, + + createQuoteAndPlaceOrder: function (productData) { + this.showLoader(); + this.processOrderFlow(productData) .then(this.onQuoteCreateSuccess.bind(this, productData)) .catch(this.onQuoteCreateFail.bind(this)); @@ -33,7 +59,7 @@ define([ getOrderData: function () { let form = $("#product_addtocart_form"); - return this.page === 'product' ? form.serialize() : null; + return this.page === "product" ? form.serialize() : null; }, onQuoteCreateSuccess: function (productData, quoteResponse) { @@ -123,5 +149,5 @@ define([ hideLoader: function () { $('body').loader('hide'); } - }; + }); }); diff --git a/view/frontend/web/js/view/checkout/summary/already-paid.js b/view/frontend/web/js/view/checkout/summary/already-paid.js new file mode 100644 index 000000000..189a9e139 --- /dev/null +++ b/view/frontend/web/js/view/checkout/summary/already-paid.js @@ -0,0 +1,42 @@ +define([ + 'Magento_Checkout/js/view/summary/abstract-total', + 'Magento_Checkout/js/model/quote', + 'Magento_Catalog/js/price-utils', + 'Magento_Checkout/js/model/totals' +], function (Component, quote, priceUtils, totals) { + 'use strict'; + + return Component.extend({ + defaults: { + template: 'Buckaroo_Magento2/checkout/summary/already-paid' + }, + isDisplayed: function () { + return this.getAlreadyPaidTotal() > 0; + }, + getValue: function () { + var alreadyPaid = this.getAlreadyPaidTotal(); + return this.getFormattedPrice(alreadyPaid); + }, + getAlreadyPaidTotal: function () { + var buckarooFeeSegment = totals.getSegment('buckaroo_already_paid'); + try { + if (buckarooFeeSegment.title) { + var items = JSON.parse(buckarooFeeSegment.title); + var total = 0; + if ((typeof items === 'object') && (items.length > 0)) { + for (var i = 0; i < items.length; i++) { + total = parseFloat(total) + parseFloat(items[i].serviceamount); + } + return parseFloat(total).toFixed(2); + } + } + } catch (e) { + } + + return parseFloat(buckarooFeeSegment.value).toFixed(2); + }, + getFormattedPrice: function (price) { + return priceUtils.formatPrice(price, quote.getPriceFormat()); + } + }); +}); diff --git a/view/frontend/web/js/view/checkout/summary/grand-total.js b/view/frontend/web/js/view/checkout/summary/grand-total.js deleted file mode 100644 index 3c1c89431..000000000 --- a/view/frontend/web/js/view/checkout/summary/grand-total.js +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -/** - * @api - */ - -define([ - 'Magento_Checkout/js/view/summary/abstract-total', - 'Magento_Checkout/js/model/quote', - 'Magento_Catalog/js/price-utils', - 'Magento_Checkout/js/model/totals' -], function (Component, quote, priceUtils, totals) { - 'use strict'; - - return Component.extend({ - defaults: { - isFullTaxSummaryDisplayed: window.checkoutConfig.isFullTaxSummaryDisplayed || false, - template: 'Buckaroo_Magento2/checkout/summary/grand-total' - }, - totals: quote.getTotals(), - isTaxDisplayedInGrandTotal: window.checkoutConfig.includeTaxInGrandTotal || false, - - /** - * @return {*} - */ - isDisplayed: function () { - return this.isFullMode(); - }, - - /** - * @return {*|String} - */ - getValue: function () { - var price = 0; - - if (this.totals()) { - price = totals.getSegment('grand_total').value; - - if(!isNaN(parseFloat(this.getAlreadyPayTotal()))){ - price = parseFloat(price) - parseFloat(this.getAlreadyPayTotal()); - } - } - - return this.getFormattedPrice(price); - }, - - /** - * @return {*|String} - */ - getBaseValue: function () { - var price = 0; - - if (this.totals()) { - price = this.totals()['base_grand_total']; - } - - return priceUtils.formatPriceLocale(price, quote.getBasePriceFormat()); - }, - - /** - * @return {*} - */ - getGrandTotalExclTax: function () { - var total = this.totals(), - amount; - - if (!total) { - return 0; - } - - amount = total['grand_total'] - total['tax_amount']; - - if (amount < 0) { - amount = 0; - } - - return this.getFormattedPrice(amount); - }, - - /** - * @return {Boolean} - */ - isBaseGrandTotalDisplayNeeded: function () { - var total = this.totals(); - - if (!total) { - return false; - } - - return total['base_currency_code'] != total['quote_currency_code']; //eslint-disable-line eqeqeq - }, - - getAlreadyPayTotal : function () { - var buckarooFeeSegment = totals.getSegment('buckaroo_already_paid'); - try { - if (buckarooFeeSegment.title) { - var items = JSON.parse(buckarooFeeSegment.title); - var total = 0; - if ((typeof items === 'object') && (items.length > 0)) { - for (var i = 0; i < items.length; i++) { - total = parseFloat(total) + parseFloat(items[i].serviceamount); - } - return parseFloat(total).toFixed(2); - } - } - } catch (e) { - // console.log(e); - } - - return parseFloat(buckarooFeeSegment.value).toFixed(2); - } - }); -}); diff --git a/view/frontend/web/js/view/checkout/summary/remaining-amount.js b/view/frontend/web/js/view/checkout/summary/remaining-amount.js new file mode 100644 index 000000000..9a12ae4f2 --- /dev/null +++ b/view/frontend/web/js/view/checkout/summary/remaining-amount.js @@ -0,0 +1,37 @@ +define([ + 'Magento_Checkout/js/view/summary/abstract-total', + 'Magento_Checkout/js/model/quote', + 'Magento_Catalog/js/price-utils', + 'Magento_Checkout/js/model/totals' +], function (Component, quote, priceUtils, totals) { + 'use strict'; + + return Component.extend({ + defaults: { + template: 'Buckaroo_Magento2/checkout/summary/remaining-amount' + }, + isDisplayed: function () { + return this.getAlreadyPaidTotal() < 0; + }, + getValue: function () { + var remainingAmount = 0; + if (totals.getSegment('remaining_amount')) { + remainingAmount = totals.getSegment('remaining_amount').value; + } + return this.getFormattedPrice(remainingAmount); + }, + getAlreadyPaidTotal: function () { + var remainingAmount = 0; + if (totals.getSegment('buckaroo_already_paid')) { + remainingAmount = totals.getSegment('buckaroo_already_paid').value; + } + return remainingAmount; + }, + getTitle: function () { + return this.title; + }, + getFormattedPrice: function (price) { + return priceUtils.formatPrice(price, quote.getPriceFormat()); + } + }); +}); diff --git a/view/frontend/web/template/checkout/summary/already-paid.html b/view/frontend/web/template/checkout/summary/already-paid.html new file mode 100644 index 000000000..41d367b5b --- /dev/null +++ b/view/frontend/web/template/checkout/summary/already-paid.html @@ -0,0 +1,11 @@ + + + + +

+ + +

+ + + diff --git a/view/frontend/web/template/checkout/summary/grand-total.html b/view/frontend/web/template/checkout/summary/grand-total.html deleted file mode 100644 index 5a324f922..000000000 --- a/view/frontend/web/template/checkout/summary/grand-total.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/view/frontend/web/template/checkout/summary/remaining-amount.html b/view/frontend/web/template/checkout/summary/remaining-amount.html new file mode 100644 index 000000000..bcba4c746 --- /dev/null +++ b/view/frontend/web/template/checkout/summary/remaining-amount.html @@ -0,0 +1,10 @@ + + + + + + + + + +