diff --git a/.github/workflows/icons.yml b/.github/workflows/icons.yml index 0b3c9df64..aad12a079 100644 --- a/.github/workflows/icons.yml +++ b/.github/workflows/icons.yml @@ -22,7 +22,7 @@ jobs: - name: Copy payment method icons run: | cd "${{ github.workspace }}/Media/Payment methods/SVG/" - rm -f ideal-qr.svg knaken.svg paylink.svg paybybank.svg pos-nfc.svg riverty.svg + rm -f ideal-qr.svg knaken.svg paylink.svg paybybank.svg pos-nfc.svg cd ${{ github.workspace }}/Media cp -R "Payment methods/SVG/." ${{ github.workspace }}/view/base/web/images/svg/ - name: Copy creditcards icons diff --git a/Api/PaypalExpressQuoteCreateInterface.php b/Api/PaypalExpressQuoteCreateInterface.php index 948873ee0..74947cd96 100644 --- a/Api/PaypalExpressQuoteCreateInterface.php +++ b/Api/PaypalExpressQuoteCreateInterface.php @@ -22,6 +22,7 @@ namespace Buckaroo\Magento2\Api; use Buckaroo\Magento2\Api\Data\PaypalExpress\ShippingAddressRequestInterface; +use Buckaroo\Magento2\Api\Data\QuoteCreateResponseInterface; interface PaypalExpressQuoteCreateInterface { @@ -31,8 +32,8 @@ interface PaypalExpressQuoteCreateInterface * @param \Buckaroo\Magento2\Api\Data\PaypalExpress\ShippingAddressRequestInterface $shipping_address * @param string $page * @param string|null $order_data - * @return \Buckaroo\Magento2\Api\Data\PaypalExpress\QuoteCreateResponseInterface - */ + * @return QuoteCreateResponseInterface + */ public function execute( ShippingAddressRequestInterface $shipping_address, string $page, diff --git a/Block/Info.php b/Block/Info.php index fe76fec66..5a2f0e08f 100644 --- a/Block/Info.php +++ b/Block/Info.php @@ -94,8 +94,8 @@ public function getPayPerEmailMethod() public function getPaymentLogo(string $method): string { $mappings = [ - "afterpay2" => "svg/afterpay.svg", - "afterpay20" => "svg/afterpay.svg", + "afterpay2" => "svg/riverty.svg", + "afterpay20" => "svg/riverty.svg", "capayablein3" => "svg/in3.svg", "capayablepostpay" => "svg/in3.svg", "creditcard" => "svg/creditcards.svg", diff --git a/Block/Widget/Button/Toolbar.php b/Block/Widget/Button/Toolbar.php index dcf916306..058ddb6f3 100644 --- a/Block/Widget/Button/Toolbar.php +++ b/Block/Widget/Button/Toolbar.php @@ -62,7 +62,8 @@ class Toolbar 'buckaroo_magento2_wechatpay', 'buckaroo_magento2_p24', 'buckaroo_magento2_trustly', - 'buckaroo_magento2_pospayment' + 'buckaroo_magento2_pospayment', + 'buckaroo_magento2_blik', ]; /** diff --git a/Controller/Redirect/Process.php b/Controller/Redirect/Process.php index 1f7619410..570f78069 100755 --- a/Controller/Redirect/Process.php +++ b/Controller/Redirect/Process.php @@ -23,6 +23,7 @@ use Buckaroo\Magento2\Logging\Log; use Buckaroo\Magento2\Model\Config\Source\InvoiceHandlingOptions; use Magento\Framework\App\Request\Http as Http; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Sales\Api\Data\TransactionInterface; use Magento\Sales\Api\Data\OrderPaymentInterface; use Buckaroo\Magento2\Model\Method\AbstractMethod; @@ -466,6 +467,10 @@ protected function setPaymentOutOfTransit(OrderPaymentInterface $payment) ->setAdditionalInformation(AbstractMethod::BUCKAROO_PAYMENT_IN_TRANSIT, false) ->save(); } + + /** + * @throws NoSuchEntityException + */ protected function handleFailed($statusCode) { $this->logger->addDebug(__METHOD__ . '|7|'); @@ -476,7 +481,7 @@ protected function handleFailed($statusCode) $this->removeAmastyGiftcardOnFailed(); if (!$this->getSkipHandleFailedRecreate()) { - if (!$this->quoteRecreate->recreate($this->quote)) { + if (!$this->quoteRecreate->recreate($this->quote, $this->response)) { $this->logging->addError('Could not recreate the quote.'); } } @@ -489,35 +494,25 @@ protected function handleFailed($statusCode) */ // StatusCode specified error messages - $statusCodeAddErrorMessage = []; - $statusCodeAddErrorMessage[$this->helper->getStatusCode('BUCKAROO_MAGENTO2_ORDER_FAILED')] = - 'Unfortunately an error occurred while processing your payment. Please try again. If this' . - ' error persists, please choose a different payment method.'; - $statusCodeAddErrorMessage[$this->helper->getStatusCode('BUCKAROO_MAGENTO2_STATUSCODE_FAILED')] = - 'Unfortunately an error occurred while processing your payment. Please try again. If this' . - ' error persists, please choose a different payment method.'; - $statusCodeAddErrorMessage[$this->helper->getStatusCode('BUCKAROO_MAGENTO2_STATUSCODE_REJECTED')] = - 'Unfortunately an error occurred while processing your payment. Please try again. If this' . - ' error persists, please choose a different payment method.'; - $statusCodeAddErrorMessage[ - $this->helper->getStatusCode('BUCKAROO_MAGENTO2_STATUSCODE_CANCELLED_BY_USER') - ] = 'According to our system, you have canceled the payment. If this' . - ' is not the case, please contact us.'; - - $this->addErrorMessage( - __( - $statusCodeAddErrorMessage[$statusCode] - ) - ); - - //skip cancel order for PPE + $statusCodeAddErrorMessage = [ + $this->helper->getStatusCode('BUCKAROO_MAGENTO2_ORDER_FAILED') => 'Unfortunately an error occurred while processing your payment. Please try again. If this error persists, please choose a different payment method.', + $this->helper->getStatusCode('BUCKAROO_MAGENTO2_STATUSCODE_FAILED') => 'Unfortunately an error occurred while processing your payment. Please try again. If this error persists, please choose a different payment method.', + $this->helper->getStatusCode('BUCKAROO_MAGENTO2_STATUSCODE_REJECTED') => 'Unfortunately an error occurred while processing your payment. Please try again. If this error persists, please choose a different payment method.', + $this->helper->getStatusCode('BUCKAROO_MAGENTO2_STATUSCODE_CANCELLED_BY_USER') => 'According to our system, you have canceled the payment. If this is not the case, please contact us.' + ]; + + $this->addErrorMessage(__($statusCodeAddErrorMessage[$statusCode] ?? 'An error occurred while processing your payment.')); + + // Skip cancel order for PPE if (isset($this->response['add_frompayperemail'])) { return $this->redirectFailure(); } + // Cancel the order and log an error if it fails if (!$this->cancelOrder($statusCode)) { $this->logger->addError('Could not cancel the order.'); } + $this->logger->addDebug(__METHOD__ . '|8|'); return $this->redirectFailure(); } @@ -778,7 +773,7 @@ public function setSkipHandleFailedRecreate($value) /** * Remove coupon from failed order if magento enterprise - * + * * @return void */ protected function removeCoupon() @@ -789,7 +784,7 @@ protected function removeCoupon() if (!(is_object($couponFactory) && method_exists($couponFactory, 'load'))) { return; } - + $coupon = $couponFactory->load($couponCode, 'code'); $resourceModel = $this->_objectManager->get(\Magento\SalesRule\Model\Spi\CouponResourceInterface::class); if (!(is_object($resourceModel) && method_exists($resourceModel, 'delete'))) { diff --git a/Helper/Data.php b/Helper/Data.php index 06e5ace99..d80e6b8c0 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -453,6 +453,7 @@ public function getPaymentMethodsList() ['value' => 'transfer', 'label' => __('Bank Transfer')], ['value' => 'trustly', 'label' => __('Trustly')], ['value' => 'wechatpay', 'label' => __('WeChatPay')], + ['value' => 'blik', 'label' => __('Blik')], ]; } diff --git a/Model/Config/Source/PaymentMethods/AfterExpiry.php b/Model/Config/Source/PaymentMethods/AfterExpiry.php index 72f6f8e1f..661e8016e 100644 --- a/Model/Config/Source/PaymentMethods/AfterExpiry.php +++ b/Model/Config/Source/PaymentMethods/AfterExpiry.php @@ -54,6 +54,7 @@ public function toOptionArray() ['value' => 'wechatpay', 'label' => __('WeChatPay')], ['value' => 'p24', 'label' => __('P24')], ['value' => 'trustly', 'label' => __('Trustly')], + ['value' => 'blik', 'label' => __('Blik')], ]; return $options; diff --git a/Model/Config/Source/PaymentMethods/PayLink.php b/Model/Config/Source/PaymentMethods/PayLink.php index 00a008c66..7de64040d 100644 --- a/Model/Config/Source/PaymentMethods/PayLink.php +++ b/Model/Config/Source/PaymentMethods/PayLink.php @@ -54,6 +54,7 @@ public function toOptionArray() ['value' => 'wechatpay', 'label' => __('WeChatPay')], ['value' => 'p24', 'label' => __('P24')], ['value' => 'trustly', 'label' => __('Trustly')], + ['value' => 'blik', 'label' => __('Blik')], ]; return $options; diff --git a/Model/Config/Source/PaymentMethods/PayPerEmail.php b/Model/Config/Source/PaymentMethods/PayPerEmail.php index a84fb8378..f191f7d0a 100644 --- a/Model/Config/Source/PaymentMethods/PayPerEmail.php +++ b/Model/Config/Source/PaymentMethods/PayPerEmail.php @@ -149,6 +149,11 @@ public function toOptionArray() 'value' => 'trustly', 'label' => __('Trustly'), 'code' => 'buckaroo_magento2_trustly' + ], + [ + 'value' => 'blik', + 'label' => __('Blik'), + 'code' => 'buckaroo_magento2_blik' ] ]; diff --git a/Model/ConfigProvider/Method/Blik.php b/Model/ConfigProvider/Method/Blik.php new file mode 100644 index 000000000..8ea414eec --- /dev/null +++ b/Model/ConfigProvider/Method/Blik.php @@ -0,0 +1,87 @@ +getBuckarooPaymentFeeLabel( + \Buckaroo\Magento2\Model\Method\Blik::PAYMENT_METHOD_CODE + ); + + return [ + 'payment' => [ + 'buckaroo' => [ + 'blik' => [ + 'paymentFeeLabel' => $paymentFeeLabel, + 'subtext' => $this->getSubtext(), + 'subtext_style' => $this->getSubtextStyle(), + 'subtext_color' => $this->getSubtextColor(), + 'allowedCurrencies' => $this->getAllowedCurrencies(), + ], + ], + ], + ]; + } + + /** + * @param null|int $storeId + * + * @return float + */ + public function getPaymentFee($storeId = null) + { + $paymentFee = $this->scopeConfig->getValue( + self::XPATH_BLIK_PAYMENT_FEE, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + $storeId + ); + + return $paymentFee ? $paymentFee : false; + } +} diff --git a/Model/Method/Blik.php b/Model/Method/Blik.php new file mode 100644 index 000000000..6cf882733 --- /dev/null +++ b/Model/Method/Blik.php @@ -0,0 +1,103 @@ +transactionBuilderFactory->get('order'); + + $services = [ + 'Name' => 'blik', + 'Action' => 'Pay', + 'Version' => 0, + ]; + + /** + * @noinspection PhpUndefinedMethodInspection + */ + $transactionBuilder->setOrder($payment->getOrder()) + ->setServices($services) + ->setMethod('TransactionRequest'); + + return $transactionBuilder; + } + + /** + * {@inheritdoc} + */ + public function getCaptureTransactionBuilder($payment) + { + return false; + } + + /** + * {@inheritdoc} + */ + public function getAuthorizeTransactionBuilder($payment) + { + return false; + } + + /** + * {@inheritdoc} + */ + public function getVoidTransactionBuilder($payment) + { + return true; + } + + /** + * @param \Magento\Sales\Api\Data\OrderPaymentInterface|\Magento\Payment\Model\InfoInterface $payment + * + * @return bool|string + */ + public function getPaymentMethodName($payment) + { + return 'blik'; + } + + protected function getRefundTransactionBuilderChannel() + { + return 'Web'; + } +} diff --git a/Model/Method/Giropay.php b/Model/Method/Giropay.php index 4ecb70377..69a7318ab 100644 --- a/Model/Method/Giropay.php +++ b/Model/Method/Giropay.php @@ -101,4 +101,9 @@ public function getPaymentMethodName($payment) { return $this->buckarooPaymentMethodCode; } + + protected function getRefundTransactionBuilderChannel() + { + return 'Web'; + } } diff --git a/Model/Service/CreateInvoice.php b/Model/Service/CreateInvoice.php index 9854719ae..1a6be2e9c 100644 --- a/Model/Service/CreateInvoice.php +++ b/Model/Service/CreateInvoice.php @@ -135,6 +135,8 @@ public function createInvoiceGeneralSetting(Order $order, array $invoiceItems): $transactionSave->save(); + $this->registry->unregister('current_invoice'); + $payment = $invoice->getOrder()->getPayment(); $transactionKey = (string)$payment->getAdditionalInformation( @@ -225,4 +227,4 @@ public function addTransactionData($payment, $transactionKey = false, $datas = f return $payment; } -} \ No newline at end of file +} diff --git a/Model/Total/Quote/BuckarooAlreadyPay.php b/Model/Total/Quote/BuckarooAlreadyPay.php index 2dea6e756..d9f0024e5 100644 --- a/Model/Total/Quote/BuckarooAlreadyPay.php +++ b/Model/Total/Quote/BuckarooAlreadyPay.php @@ -47,6 +47,46 @@ public function __construct( $this->giftcardCollection = $giftcardCollection; } + /** + * Collect grand total address amount + * + * @param \Magento\Quote\Model\Quote $quote + * @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment + * @param \Magento\Quote\Model\Quote\Address\Total $total + * @return $this + * + * @throws \LogicException + */ + public function collect( + \Magento\Quote\Model\Quote $quote, + \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, + \Magento\Quote\Model\Quote\Address\Total $total + ) { + parent::collect($quote, $shippingAssignment, $total); + + // Ensure that shipping assignment has items, otherwise skip processing. + if (!$shippingAssignment->getItems()) { + return $this; + } + + $orderId = $quote->getReservedOrderId(); + $alreadyPaidAmount = $this->groupTransaction->getAlreadyPaid($orderId); + + // Ensure totals are properly initialized. + $total->setTotalAmount($this->getCode(), 0); + $total->setBaseTotalAmount($this->getCode(), 0); + + // Adjust the grand total only if the already paid amount is greater than zero. + if ($alreadyPaidAmount > 0) { + $total->addTotalAmount($this->getCode(), -$alreadyPaidAmount); + $total->addBaseTotalAmount($this->getCode(), -$alreadyPaidAmount); + + } + + return $this; + } + + /** * Add buckaroo fee information to address * @@ -61,7 +101,7 @@ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Qu $customTitle = []; if ($orderId) { $items = $this->groupTransaction->getGroupTransactionItemsNotRefunded($orderId); - + foreach ($items as $giftcard) { $foundGiftcard = $this->giftcardCollection->getItemByColumnValue( 'servicecode', @@ -70,7 +110,7 @@ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Qu if ($foundGiftcard !== null || $giftcard['servicecode'] === 'buckaroovoucher') { - + if ($giftcard['servicecode'] === 'buckaroovoucher') { $label = __('Voucher'); } else { diff --git a/Model/Total/Quote/BuckarooFee.php b/Model/Total/Quote/BuckarooFee.php index cd26ff588..1d0bba1c6 100644 --- a/Model/Total/Quote/BuckarooFee.php +++ b/Model/Total/Quote/BuckarooFee.php @@ -68,11 +68,14 @@ class BuckarooFee extends \Magento\Quote\Model\Quote\Address\Total\AbstractTotal protected $logging; /** - * @param ConfigProviderAccount $configProviderAccount + * @param ConfigProviderAccount $configProviderAccount * @param ConfigProviderBuckarooFee $configProviderBuckarooFee - * @param Factory $configProviderMethodFactory - * @param PriceCurrencyInterface $priceCurrency - * @param Data $catalogHelper + * @param Factory $configProviderMethodFactory + * @param PriceCurrencyInterface $priceCurrency + * @param Data $catalogHelper + * @param PaymentGroupTransaction $groupTransaction + * @param Log $logging + * @param TaxModelCalculation $taxCalculation */ public function __construct( ConfigProviderAccount $configProviderAccount, @@ -112,7 +115,11 @@ public function collect( \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total ) { + parent::collect($quote, $shippingAssignment, $total); + if (!$shippingAssignment->getItems()) { + return $this; + } /** * @noinspection PhpUndefinedMethodInspection */ @@ -123,14 +130,14 @@ public function collect( $total->setBaseBuckarooFee(0); $orderId = $quote->getReservedOrderId(); - if ($this->groupTransaction->getAlreadyPaid($orderId) > 0) { - return $this; - } - if (!$shippingAssignment->getItems()) { - return $this; + // Check if already paid amount is affecting the calculation + if ($this->groupTransaction->getAlreadyPaid($orderId) > 0) { + // Optionally, you could log or debug here to ensure no early returns affect the fee calculation. + $this->logging->addDebug('Already paid detected, but continuing to add fee.'); } + // Ensure payment method is set correctly $paymentMethod = $quote->getPayment()->getMethod(); if (!$paymentMethod || strpos($paymentMethod, 'buckaroo_magento2_') !== 0) { return $this; @@ -141,9 +148,8 @@ public function collect( return $this; } - $basePaymentFeeOLD = $this->getBaseFee($methodInstance, $quote); - $basePaymentFee = $total->getBaseBuckarooFeeInclTax() - $total->getBuckarooFeeBaseTaxAmount(); - + // Calculate the base payment fee using the getBaseFee method + $basePaymentFee = $this->getBaseFee($methodInstance, $quote); if ($basePaymentFee < 0.01) { return $this; } diff --git a/Model/Total/Quote/BuckarooFeeHyva.php b/Model/Total/Quote/BuckarooFeeHyva.php new file mode 100644 index 000000000..a86321ca0 --- /dev/null +++ b/Model/Total/Quote/BuckarooFeeHyva.php @@ -0,0 +1,336 @@ +setCode('buckaroo_fee_hyva'); + + $this->configProviderAccount = $configProviderAccount; + $this->configProviderBuckarooFee = $configProviderBuckarooFee; + $this->configProviderMethodFactory = $configProviderMethodFactory; + $this->priceCurrency = $priceCurrency; + $this->catalogHelper = $catalogHelper; + + $this->groupTransaction = $groupTransaction; + $this->logging = $logging; + $this->taxCalculation = $taxCalculation; + $this->configProvider = $configProvider; + } + + /** + * Collect grand total address amount + * + * @param \Magento\Quote\Model\Quote $quote + * @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment + * @param \Magento\Quote\Model\Quote\Address\Total $total + * @return $this + * + * @throws \LogicException + */ + public function collect( + \Magento\Quote\Model\Quote $quote, + \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, + \Magento\Quote\Model\Quote\Address\Total $total + ) { + if (!$this->configProvider->isHyvaCheckoutEnabled()) { + return $this; + } + + parent::collect($quote, $shippingAssignment, $total); + + // Ensure that shipping assignment has items, otherwise skip processing. + if (!$shippingAssignment->getItems()) { + return $this; + } + + $orderId = $quote->getReservedOrderId(); + + // Check if already paid amount is affecting the calculation + if ($this->groupTransaction->getAlreadyPaid($orderId) > 0) { + // Optionally, you could log or debug here to ensure no early returns affect the fee calculation. + $this->logging->addDebug('Already paid detected, but continuing to add fee.'); + } + + // Ensure payment method is set correctly + $paymentMethod = $quote->getPayment()->getMethod(); + if (!$paymentMethod || strpos($paymentMethod, 'buckaroo_magento2_') !== 0) { + return $this; + } + + $methodInstance = $quote->getPayment()->getMethodInstance(); + if (!$methodInstance instanceof \Buckaroo\Magento2\Model\Method\AbstractMethod) { + return $this; + } + + // Calculate the base payment fee using the getBaseFee method + $basePaymentFee = $this->getBaseFee($methodInstance, $quote); + if ($basePaymentFee < 0.01) { + return $this; + } + + // Convert the fee to the store's currency + $paymentFee = $this->priceCurrency->convert($basePaymentFee, $quote->getStore()); + + // Add fee amounts using addTotalAmount to ensure proper accumulation with other totals + $total->addTotalAmount('buckaroo_fee_hyva', $paymentFee); + $total->addBaseTotalAmount('buckaroo_fee_hyva', $basePaymentFee); + + // Set the fee on the total object for further calculations + $total->setBuckarooFee($paymentFee); + $total->setBaseBuckarooFee($basePaymentFee); + $total->setGrandTotal($total->getGrandTotal() + $paymentFee); + + return $this; + } + + /** + * Add buckaroo fee information to address + * + * @param Quote $quote + * @param Total $total + * @return array + */ + public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total) + { + // Determine whether to include tax in the fee value based on your configuration settings + $includeTax = $this->configProviderBuckarooFee->getPaymentFeeTax() == \Buckaroo\Magento2\Model\Config\Source\TaxClass\Calculation::DISPLAY_TYPE_INCLUDING_TAX; + + // Calculate the value based on the settings (either including or excluding tax) + $value = $includeTax ? $total->getBuckarooFeeInclTax() : $total->getBuckarooFee(); + + return [ + 'code' => $this->getCode(), + 'title' => $this->getLabel(), + 'value' => $value + ]; + } + + /** + * @param \Buckaroo\Magento2\Model\Method\AbstractMethod $methodInstance + * @param \Magento\Quote\Model\Quote $quote + * @param bool $inclTax + * + * @return bool|false|float + * @throws \Buckaroo\Magento2\Exception + */ + public function getBaseFee( + \Buckaroo\Magento2\Model\Method\AbstractMethod $methodInstance, + \Magento\Quote\Model\Quote $quote, + $inclTax = false + ) { + $buckarooPaymentMethodCode = $methodInstance->buckarooPaymentMethodCode; + if (!$this->configProviderMethodFactory->has($buckarooPaymentMethodCode)) { + return false; + } + + $configProvider = $this->configProviderMethodFactory->get($buckarooPaymentMethodCode); + $basePaymentFee = trim($configProvider->getPaymentFee($quote->getStore())); + + 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; + } + /** + * Payment fee is a number + */ + return $this->getFeePrice($basePaymentFee); + } + + } elseif (strpos($basePaymentFee, '%') === false) { + /** + * Payment fee is invalid + */ + return false; + } + + /** + * Payment fee is a percentage + */ + $percentage = floatval($basePaymentFee); + if ($quote->getShippingAddress()) { + $address = $quote->getShippingAddress(); + } else { + $address = $quote->getBillingAddress(); + } + + $total = 0; + + $feePercentageMode = $this->configProviderAccount->getFeePercentageMode($quote->getStore()); + + switch ($feePercentageMode) { + case 'subtotal': + $total = $address->getBaseSubtotal(); + break; + case 'subtotal_incl_tax': + $total = $address->getBaseSubtotalTotalInclTax(); + break; + } + + $basePaymentFee = ($percentage / 100) * $total; + + return $basePaymentFee; + } + + /** + * Get payment fee price with correct tax + * + * @param float $price + * @param null $priceIncl + * + * @param \Magento\Framework\DataObject|null $pseudoProduct + * + * @return float + * @throws \Buckaroo\Magento2\Exception + */ + public function getFeePrice($price, $priceIncl = null, \Magento\Framework\DataObject $pseudoProduct = null) + { + if ($pseudoProduct === null) { + $pseudoProduct = new \Magento\Framework\DataObject(); + } + + $pseudoProduct->setTaxClassId($this->configProviderBuckarooFee->getTaxClass()); + + /** + * @noinspection PhpUndefinedMethodInspection + */ + if ($priceIncl === null + && $this->configProviderBuckarooFee->getPaymentFeeTax() == Calculation::DISPLAY_TYPE_INCLUDING_TAX + ) { + $priceIncl = true; + } else { + $priceIncl = false; + } + + $price = $this->catalogHelper->getTaxPrice( + $pseudoProduct, + $price, + false, + null, + null, + null, + null, + $priceIncl + ); + + return $price; + } + + /** + * Get Buckaroo label + * + * @return \Magento\Framework\Phrase + */ + public function getLabel() + { + return __('Fee'); + } +} diff --git a/Observer/RestoreQuote.php b/Observer/RestoreQuote.php index d7c80b676..132ce4900 100644 --- a/Observer/RestoreQuote.php +++ b/Observer/RestoreQuote.php @@ -24,68 +24,30 @@ use Magento\Checkout\Model\Session; use Buckaroo\Magento2\Model\Service\Order; use Buckaroo\Magento2\Model\Method\Payconiq; -use Buckaroo\Magento2\Model\Method\Giftcards; use Magento\Quote\Api\CartRepositoryInterface; use Buckaroo\Magento2\Model\ConfigProvider\Account; use Buckaroo\Magento2\Helper\PaymentGroupTransaction; use Buckaroo\Magento2\Model\Giftcard\Remove as GiftcardRemove; -use Buckaroo\Magento2\Model\Method\AbstractMethod; -use Buckaroo\Magento2\Service\Sales\Quote\Recreate as QuoteRecreate; +use Magento\Framework\Event\Observer; +use Magento\Framework\Event\ObserverInterface; +use Magento\Quote\Model\Quote; -class RestoreQuote implements \Magento\Framework\Event\ObserverInterface +class RestoreQuote implements ObserverInterface { - /** - * @var \Magento\Checkout\Model\Session - */ private $checkoutSession; - - /** - * @var \Buckaroo\Magento2\Model\ConfigProvider\Account - */ protected $accountConfig; - - /** - * @var \Buckaroo\Magento2\Helper\Data - */ - private \Buckaroo\Magento2\Helper\Data $helper; - - - - /** - * @var \Magento\Quote\Api\CartRepositoryInterface - */ + private $helper; protected $quoteRepository; - - /** - * @var \Buckaroo\Magento2\Model\Service\Order - */ protected $orderService; - - /** - * @var \Buckaroo\Magento2\Model\Giftcard\Remove - */ protected $giftcardRemoveService; - - /** - * @var \Buckaroo\Magento2\Helper\PaymentGroupTransaction - */ protected $groupTransaction; - - /** - * @param Session $checkoutSession - * @param Account $accountConfig - * @param Data $helper - * @param QuoteRecreate $quoteRecreate - * @param CartRepositoryInterface $quoteRepository - * @param Order $orderService - */ public function __construct( - \Magento\Checkout\Model\Session $checkoutSession, - \Buckaroo\Magento2\Model\ConfigProvider\Account $accountConfig, - \Buckaroo\Magento2\Helper\Data $helper, - \Magento\Quote\Api\CartRepositoryInterface $quoteRepository, - \Buckaroo\Magento2\Model\Service\Order $orderService, + Session $checkoutSession, + Account $accountConfig, + Data $helper, + CartRepositoryInterface $quoteRepository, + Order $orderService, GiftcardRemove $giftcardRemoveService, PaymentGroupTransaction $groupTransaction ) { @@ -101,10 +63,10 @@ public function __construct( /** * Restore Quote and Cancel LastRealOrder * - * @param \Magento\Framework\Event\Observer $observer + * @param Observer $observer * @return void */ - public function execute(\Magento\Framework\Event\Observer $observer) + public function execute(Observer $observer) { $this->helper->addDebug(__METHOD__ . '|1|' . var_export($this->checkoutSession->getData(), true)); @@ -112,9 +74,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) $previousOrderId = $lastRealOrder->getId(); if ($payment = $lastRealOrder->getPayment()) { - if ($this->shouldSkipFurtherEventHandling() - || strpos($payment->getMethod(), 'buckaroo_magento2') === false - || in_array($payment->getMethod(), [Payconiq::PAYMENT_METHOD_CODE])) { + if ($this->shouldSkipFurtherEventHandling() || $this->isPayconiqPaymentMethod($payment)) { $this->helper->addDebug(__METHOD__ . '|10|'); return; } @@ -122,29 +82,19 @@ public function execute(\Magento\Framework\Event\Observer $observer) if ($this->accountConfig->getCartKeepAlive($lastRealOrder->getStore())) { $this->helper->addDebug(__METHOD__ . '|20|'); - if ($this->checkoutSession->getQuote() - && $this->checkoutSession->getQuote()->getId() - && ($quote = $this->quoteRepository->getActive($this->checkoutSession->getQuote()->getId())) - ) { - $this->helper->addDebug(__METHOD__ . '|25|'); - $shippingAddress = $quote->getShippingAddress(); - if (!$shippingAddress->getShippingMethod()) { - $this->helper->addDebug(__METHOD__ . '|35|'); - $shippingAddress->load($shippingAddress->getAddressId()); - } + $quote = $this->getActiveQuote(); + if ($quote) { + $this->processShippingAddress($quote); } - - - if ( - ( - $this->helper->getRestoreQuoteLastOrder() && - ($lastRealOrder->getData('state') === 'new') && - ($lastRealOrder->getData('status') === 'pending') && - $payment->getMethodInstance()->usesRedirect - ) || $this->canRestoreFailedFromSpam() - ) { + + if ($this->shouldRestoreQuote($lastRealOrder, $payment)) { $this->helper->addDebug(__METHOD__ . '|40|'); $this->checkoutSession->restoreQuote(); + + if ($this->isFastCheckout($payment)) { + $this->clearRestoredQuoteAddresses($this->checkoutSession->getQuote()); + } + $this->rollbackPartialPayment($lastRealOrder->getIncrementId()); $this->setOrderToCancel($previousOrderId); } @@ -159,10 +109,126 @@ public function execute(\Magento\Framework\Event\Observer $observer) } /** - * Check if order has failed from max spam payment attempts + * Get the active quote from the checkout session. * - * @return boolean + * @return Quote|null */ + private function getActiveQuote() + { + $quote = null; + if ($this->checkoutSession->getQuote() && $this->checkoutSession->getQuote()->getId()) { + try { + $quote = $this->quoteRepository->getActive($this->checkoutSession->getQuote()->getId()); + } catch (\Exception $e) { + $this->helper->addError(__METHOD__ . '|Error fetching active quote: ' . $e->getMessage()); + } + } + return $quote; + } + + /** + * Process the shipping address of the quote. + * + * @param Quote $quote + */ + private function processShippingAddress($quote) + { + $this->helper->addDebug(__METHOD__ . '|25|'); + $shippingAddress = $quote->getShippingAddress(); + if ($shippingAddress && !$shippingAddress->getShippingMethod()) { + $this->helper->addDebug(__METHOD__ . '|35|'); + try { + $shippingAddress->load($shippingAddress->getAddressId()); + } catch (\Exception $e) { + $this->helper->addError(__METHOD__ . '|Error loading shipping address: ' . $e->getMessage()); + } + } + } + + /** + * Check if the quote should be restored. + * + * @param $lastRealOrder + * @param $payment + * @return bool + */ + private function shouldRestoreQuote($lastRealOrder, $payment) + { + return ( + ($this->helper->getRestoreQuoteLastOrder() && + ($lastRealOrder->getData('state') === 'new') && + ($lastRealOrder->getData('status') === 'pending') && + $payment->getMethodInstance()->usesRedirect) || $this->canRestoreFailedFromSpam() + ); + } + + /** + * Clear addresses after quote restoration to ensure they are not unintentionally restored. + * + * @param Quote $quote + */ + private function clearRestoredQuoteAddresses($quote) + { + if ($quote && $quote->getId()) { + $quote->setCustomerEmail(null); + + // Remove existing addresses if they exist + $this->clearAddress($quote, $quote->getBillingAddress()); + $this->clearAddress($quote, $quote->getShippingAddress()); + + // Save the modified quote to ensure addresses are cleared + try { + $this->quoteRepository->save($quote); + $this->helper->addDebug(__METHOD__ . '|Addresses cleared after restoreQuote()'); + } catch (\Exception $e) { + $this->helper->addDebug(__METHOD__ . '|Error clearing addresses: ' . $e->getMessage()); + } + } + } + + + /** + * Clear address data and remove the address object from the quote. + * + * @param Quote $quote + * @param $address + */ + private function clearAddress($quote, $address) + { + if ($address) { + // Remove the address from the quote + $quote->removeAddress($address->getId()); + + // Optionally clear address data if needed to reset but keep structure intact + $address->addData([]); + } + } + + /** + * Check if the payment method is fastcheckout. + * + * @param $payment + * @return bool + */ + private function isFastCheckout($payment) + { + return $payment->getMethod() === 'buckaroo_magento2_ideal' && + isset($payment->getAdditionalInformation()['issuer']) && + $payment->getAdditionalInformation()['issuer'] === 'fastcheckout'; + } + + /** + * Check if the payment method should be skipped. + * + * @param $payment + * @return bool + */ + private function isPayconiqPaymentMethod($payment) + { + return strpos($payment->getMethod(), 'buckaroo_magento2') === false || + in_array($payment->getMethod(), [Payconiq::PAYMENT_METHOD_CODE]); + } + public function canRestoreFailedFromSpam() { return $this->helper->getRestoreQuoteLastOrder() && @@ -174,18 +240,11 @@ public function shouldSkipFurtherEventHandling() return false; } - /** - * Set previous order id on the payment object for the next payment - * - * @param int $previousOrderId - * - * @return void - */ private function setOrderToCancel($previousOrderId) { $this->checkoutSession->getQuote() - ->getPayment() - ->setAdditionalInformation('buckaroo_cancel_order_id', $previousOrderId); + ->getPayment() + ->setAdditionalInformation('buckaroo_cancel_order_id', $previousOrderId); $this->quoteRepository->save($this->checkoutSession->getQuote()); } @@ -199,6 +258,5 @@ public function rollbackPartialPayment($incrementId) } catch (\Throwable $th) { $this->helper->addDebug(__METHOD__ . (string)$th); } - } } diff --git a/Service/HyvaCheckoutConfig.php b/Service/HyvaCheckoutConfig.php new file mode 100644 index 000000000..a7ae80faf --- /dev/null +++ b/Service/HyvaCheckoutConfig.php @@ -0,0 +1,73 @@ +scopeConfig = $scopeConfig; + $this->layout = $layout; + } + + /** + * Check if Hyvä checkout is enabled based on configuration and layout handles. + * + * @return bool + */ + public function isHyvaCheckoutEnabled(): bool + { + return $this->isCheckoutConfiguredAsHyva() && $this->isHyvaLayoutActive(); + } + + /** + * Check if the checkout type is set to Hyvä in the configuration. + * + * @return bool + */ + private function isCheckoutConfiguredAsHyva(): bool + { + $checkoutType = $this->scopeConfig->getValue( + self::HYVA_CHECKOUT_TYPE_PATH, + ScopeInterface::SCOPE_STORE + ); + + // Adjust this condition based on how Hyvä checkout is configured in your setup + return $checkoutType === 'default'; + } + + /** + * Check if Hyvä-specific layout handles are active in the current layout. + * + * @return bool + */ + private function isHyvaLayoutActive(): bool + { + // Check if known Hyvä layout handles are present in the current layout update + return in_array('hyva_checkout_index_index', $this->layout->getUpdate()->getHandles()); + } +} diff --git a/Service/Sales/Quote/Recreate.php b/Service/Sales/Quote/Recreate.php index 1aebfbb93..31685868f 100644 --- a/Service/Sales/Quote/Recreate.php +++ b/Service/Sales/Quote/Recreate.php @@ -40,16 +40,16 @@ public function __construct( } /** - * @param Order $order - * - * @throws \Magento\Framework\Exception\NoSuchEntityException + * @param $quote + * @param array $response + * @return false|mixed */ - public function recreate($quote) + public function recreate($quote, $response = []) { // @codingStandardsIgnoreStart try { $quote->setIsActive(true); - $quote->setTriggerRecollect('1'); +// $quote->setTriggerRecollect('1'); $quote->setReservedOrderId(null); $quote->setBuckarooFee(null); $quote->setBaseBuckarooFee(null); @@ -57,9 +57,28 @@ public function recreate($quote) $quote->setBuckarooFeeBaseTaxAmount(null); $quote->setBuckarooFeeInclTax(null); $quote->setBaseBuckarooFeeInclTax(null); + + if (isset($response['add_service_action_from_magento']) && $response['add_service_action_from_magento'] === 'payfastcheckout') { + $this->logger->addDebug(__METHOD__ . '|Handling payfastcheckout specific logic.'); + + $quote->setCustomerEmail(null); + + // Remove existing addresses if they exist + if ($billingAddress = $quote->getBillingAddress()) { + $quote->removeAddress($billingAddress->getId()); + $billingAddress->addData([]); // Optionally clear address data + } + + if ($shippingAddress = $quote->getShippingAddress()) { + $quote->removeAddress($shippingAddress->getId()); + $shippingAddress->addData([]); // Optionally clear address data + } + } + $quote->save(); $this->cart->setQuote($quote); $this->cart->save(); + return $quote; } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { //No such entity diff --git a/Service/Software/Data.php b/Service/Software/Data.php index 999b8eb3b..58ae59b03 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.49.4'; + const BUCKAROO_VERSION = '1.50.0'; /** @var ProductMetadataInterface */ private $productMetadata; diff --git a/Test/BaseTest.php b/Test/BaseTest.php index 43fbfb7d9..70cae279d 100644 --- a/Test/BaseTest.php +++ b/Test/BaseTest.php @@ -244,4 +244,9 @@ public function getPartialObject($object, $arguments = [], $mockMethods = []) return $mock; } + + protected function assertInternalType(string $type, $value) + { + $this->assertEquals($type, gettype($value)); + } } diff --git a/Test/Unit/Service/Sales/Quote/RecreateTest.php b/Test/Unit/Service/Sales/Quote/RecreateTest.php index 47f72da21..2ee6fdce5 100644 --- a/Test/Unit/Service/Sales/Quote/RecreateTest.php +++ b/Test/Unit/Service/Sales/Quote/RecreateTest.php @@ -20,12 +20,12 @@ namespace Buckaroo\Magento2\Test\Unit\Service\Sales\Quote; use Magento\Checkout\Model\Cart; -use Magento\Quote\Api\CartRepositoryInterface; use Magento\Quote\Model\Quote; use Magento\Quote\Model\QuoteFactory; -use Magento\Sales\Model\Order; use Buckaroo\Magento2\Service\Sales\Quote\Recreate; use Buckaroo\Magento2\Test\BaseTest; +use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\Quote\Model\Quote\Address; class RecreateTest extends BaseTest { @@ -33,25 +33,39 @@ class RecreateTest extends BaseTest public function testRecreate() { - $quoteId = 135; - $orderMock = $this->getFakeMock(Order::class)->setMethods(['getQuoteId'])->getMock(); - $orderMock->expects($this->once())->method('getQuoteId')->willReturn($quoteId); - - $quoteMock = $this->getFakeMock(Quote::class)->setMethods(['load'])->getMock(); - $quoteMock->expects($this->once())->method('load')->willReturnSelf(); + // Mock the Quote object directly without loading by ID + $quoteMock = $this->getFakeMock(Quote::class) + ->setMethods(['save', 'getBillingAddress', 'getShippingAddress', 'removeAddress']) + ->getMock(); + $quoteMock->expects($this->any())->method('getBillingAddress')->willReturn($this->createMock(Address::class)); + $quoteMock->expects($this->any())->method('getShippingAddress')->willReturn($this->createMock(Address::class)); + $quoteMock->expects($this->any())->method('removeAddress')->willReturnSelf(); - $quoteFactoryMock = $this->getFakeMock(QuoteFactory::class) - ->setMethods(['create']) + // Mock the Resource Model to avoid "The resource isn't set" error + $quoteResourceMock = $this->getFakeMock(QuoteResource::class) + ->setMethods(['save']) ->getMock(); - $quoteFactoryMock->expects($this->once())->method('create')->willReturn($quoteMock); + $quoteMock->setResource($quoteResourceMock); - $cartMock = $this->getFakeMock(Cart::class)->setMethods(['setQuote', 'save'])->getMock(); + // Mock the Cart object + $cartMock = $this->getFakeMock(Cart::class) + ->setMethods(['setQuote', 'save']) + ->getMock(); $cartMock->expects($this->once())->method('setQuote')->with($quoteMock)->willReturnSelf(); $cartMock->expects($this->once())->method('save'); - $instance = $this->getInstance(['quoteFactory' => $quoteFactoryMock, 'cart' => $cartMock]); - $instance->recreate($orderMock); + // Define a sample response array to pass as the second argument + $response = [ + 'add_service_action_from_magento' => 'payfastcheckout', // Example response value + ]; + + // Instantiate the Recreate class with necessary mocks + $instance = $this->getInstance(['cart' => $cartMock]); + + // Call the recreate method with the quote and response + $instance->recreate($quoteMock, $response); + // Assertions to verify the quote state $this->assertTrue($quoteMock->getIsActive()); $this->assertEquals('1', $quoteMock->getTriggerRecollect()); $this->assertNull($quoteMock->getReservedOrderId()); diff --git a/composer.json b/composer.json index af5651a6c..999ed33e7 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "docs": "https://docs.buckaroo.io/" }, "homepage": "https://www.buckaroo.nl", - "version" : "v1.49.4", + "version" : "v1.50.0", "minimum-stability": "stable", "autoload": { "files": [ diff --git a/etc/adminhtml/system/payment_methods.xml b/etc/adminhtml/system/payment_methods.xml index 16022b639..2aa07251a 100644 --- a/etc/adminhtml/system/payment_methods.xml +++ b/etc/adminhtml/system/payment_methods.xml @@ -118,5 +118,8 @@ + + + diff --git a/etc/adminhtml/system/payment_methods/blik.xml b/etc/adminhtml/system/payment_methods/blik.xml new file mode 100644 index 000000000..382f2eda7 --- /dev/null +++ b/etc/adminhtml/system/payment_methods/blik.xml @@ -0,0 +1,177 @@ + + + + + + + Buckaroo\Magento2\Block\Config\Form\Field\Fieldset + + + + + Buckaroo\Magento2\Model\Config\Source\Enablemode + payment/buckaroo_magento2_blik/active + + + + + + payment/buckaroo_magento2_blik/title + + + + + + payment/buckaroo_magento2_blik/subtext + + + + + + Buckaroo\Magento2\Model\Config\Source\SubtextStyle + payment/buckaroo_magento2_blik/subtext_style + + + + + + payment/buckaroo_magento2_blik/subtext_color + Buckaroo\Magento2\Block\Config\Form\Field\ColorPicker + + + + + + + payment/buckaroo_magento2_blik/sort_order + + + + + + + + + Magento\Config\Model\Config\Source\Yesno + payment/buckaroo_magento2_blik/order_email + + + + + Configuration > Sales > Tax.]]> + payment/buckaroo_magento2_blik/payment_fee + Buckaroo\Magento2\Model\Config\Backend\PaymentFee + + + + + + payment/buckaroo_magento2_blik/payment_fee_label + + + + + + The payment method shows only for orders with an order amount greater than the minimum amount. + payment/buckaroo_magento2_blik/min_amount + Buckaroo\Magento2\Model\Config\Backend\Price + + + + + + The payment method shows only for orders with an order amount smaller than the maximum amount. + payment/buckaroo_magento2_blik/max_amount + Buckaroo\Magento2\Model\Config\Backend\Price + + + + + + Magento\Config\Model\Config\Source\Yesno + payment/buckaroo_magento2_blik/active_status + + + + + + To make a new status available it needs to be assigned to the correct state. See Magento documentation about state and status. + Buckaroo\Magento2\Model\Config\Source\StatusesSuccess + payment/buckaroo_magento2_blik/order_status_success + + 1 + + + + + + + To make a new status available it needs to be assigned to the correct state. See Magento documentation about state and status. + Buckaroo\Magento2\Model\Config\Source\StatusesFailed + payment/buckaroo_magento2_blik/order_status_failed + + 1 + + + + + + + Your contract with Buckaroo must allow for the selected currencies to be used with this payment method. + payment/buckaroo_magento2_blik/allowed_currencies + Buckaroo\Magento2\Model\Config\Source\AllowedCurrencies::blik + Buckaroo\Magento2\Model\Config\Backend\AllowedCurrencies + + + + + Buckaroo\Magento2\Model\Config\Source\AllOrSpecificCountries + payment/buckaroo_magento2_blik/allowspecific + + + + + + Magento\Config\Model\Config\Source\Locale\Country + payment/buckaroo_magento2_blik/specificcountry + + 1 + + + + + + + Magento developer client restrictions. + Magento\Config\Model\Config\Source\Yesno + payment/buckaroo_magento2_blik/limit_by_ip + + + + + Buckaroo\Magento2\Model\Config\Source\SpecificCustomerGroups + 1 + payment/buckaroo_magento2_blik/specificcustomergroup + + + + diff --git a/etc/adminhtml/system/payment_methods/voucher.xml b/etc/adminhtml/system/payment_methods/voucher.xml index 2b2d31243..f69baa7d3 100644 --- a/etc/adminhtml/system/payment_methods/voucher.xml +++ b/etc/adminhtml/system/payment_methods/voucher.xml @@ -22,11 +22,11 @@ - + Buckaroo\Magento2\Block\Config\Form\Field\Fieldset - + Buckaroo\Magento2\Model\Config\Source\Enablemode payment/buckaroo_magento2_voucher/active @@ -43,7 +43,7 @@ payment/buckaroo_magento2_voucher/subtext - + diff --git a/etc/config.xml b/etc/config.xml index 189cccd36..320d22a16 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -41,7 +41,7 @@ 0 Buckaroo\Magento2\Model\Method\Ideal pending - Buckaroo iDEAL + iDEAL 0 10 1 @@ -57,7 +57,7 @@ 0 Buckaroo\Magento2\Model\Method\PayByBank pending - Buckaroo PayByBank + PayByBank 0 350 1 @@ -71,7 +71,7 @@ 0 Buckaroo\Magento2\Model\Method\IdealProcessing pending - Buckaroo iDEAL Processing + iDEAL Processing 0 10 1 @@ -86,7 +86,7 @@ 0 Buckaroo\Magento2\Model\Method\SepaDirectDebit pending - Buckaroo SEPA Direct Debit + SEPA Direct Debit 0 110 4 @@ -95,14 +95,14 @@ buckaroo_magento2 order 0 - amex,bancontactmrcash,cartebancaire,cartebleuevisa,nexi,postepay,dankort,eps,giftcard,giropay,ideal,mastercard,paypal,sofortueberweisung,transfer,visa,maestro,visaelectron,vpay,alipay,wechatpay,p24,trustly,belfius + amex,bancontactmrcash,cartebancaire,cartebleuevisa,nexi,postepay,dankort,eps,giftcard,giropay,ideal,mastercard,paypal,sofortueberweisung,transfer,visa,maestro,visaelectron,vpay,alipay,wechatpay,p24,trustly,belfius,blik 0 Buckaroo\Magento2\Model\Method\Paypal pending - Buckaroo PayPal + PayPal 0 90 1 @@ -121,7 +121,7 @@ 0 Buckaroo\Magento2\Model\Method\Payconiq pending - Buckaroo Payconiq + Payconiq 0 90 1 @@ -135,7 +135,7 @@ 0 Buckaroo\Magento2\Model\Method\Creditcard pending - Buckaroo Creditcard and Debit Cards + Creditcard and Debit Cards 0 30 1 @@ -156,7 +156,7 @@ 0 Buckaroo\Magento2\Model\Method\Creditcards pending - Buckaroo Creditcard and Debit Cards + Creditcard and Debit Cards 35 1 Fee @@ -170,7 +170,7 @@ 0 Buckaroo\Magento2\Model\Method\Transfer pending - Buckaroo Transfer + Transfer 0 100 1 @@ -182,14 +182,14 @@ buckaroo_magento2 order 1 - amex,bancontactmrcash,cartebancaire,cartebleuevisa,nexi,postepay,dankort,eps,giftcard,giropay,ideal,mastercard,paypal,sofortueberweisung,transfer,visa,maestro,visaelectron,vpay,alipay,wechatpay,p24,trustly,belfius + amex,bancontactmrcash,cartebancaire,cartebleuevisa,nexi,postepay,dankort,eps,giftcard,giropay,ideal,mastercard,paypal,sofortueberweisung,transfer,visa,maestro,visaelectron,vpay,alipay,wechatpay,p24,trustly,belfius,blik 0 Buckaroo\Magento2\Model\Method\Giropay pending - Buckaroo Giropay + Giropay 0 160 1 @@ -203,7 +203,7 @@ 0 Buckaroo\Magento2\Model\Method\Mrcash pending - Buckaroo Bancontact/Mister Cash + Bancontact/Mister Cash 0 140 1 @@ -220,7 +220,7 @@ 0 Buckaroo\Magento2\Model\Method\Sofortbanking pending - Buckaroo Sofort + Sofort 0 150 1 @@ -234,7 +234,7 @@ 0 Buckaroo\Magento2\Model\Method\Belfius pending - Buckaroo Belfius + Belfius 0 150 1 @@ -248,7 +248,7 @@ 0 Buckaroo\Magento2\Model\Method\Afterpay pending - Buckaroo Riverty + Riverty 0 150 1 @@ -264,7 +264,7 @@ 0 Buckaroo\Magento2\Model\Method\Afterpay2 pending - Buckaroo Riverty 2 + Riverty 2 0 160 1 @@ -280,7 +280,7 @@ 0 Buckaroo\Magento2\Model\Method\PayPerEmail pending - Buckaroo PayPerEmail + PayPerEmail 0 170 1 @@ -290,8 +290,8 @@ 1 1 1 - amex,bancontactmrcash,cartebancaire,cartebleuevisa,nexi,postepay,dankort,eps,sepadirectdebit,giftcard,giropay,ideal,mastercard,paypal,sofortueberweisung,transfer,visa,maestro,visaelectron,vpay,alipay,wechatpay,p24,trustly,belfius - amex,bancontactmrcash,cartebancaire,cartebleuevisa,nexi,postepay,dankort,eps,giftcard,giropay,ideal,mastercard,paypal,sofortueberweisung,transfer,visa,maestro,visaelectron,vpay,alipay,wechatpay,p24,trustly,belfius + amex,bancontactmrcash,cartebancaire,cartebleuevisa,nexi,postepay,dankort,eps,sepadirectdebit,giftcard,giropay,ideal,mastercard,paypal,sofortueberweisung,transfer,visa,maestro,visaelectron,vpay,alipay,wechatpay,p24,trustly,belfius,blik + amex,bancontactmrcash,cartebancaire,cartebleuevisa,nexi,postepay,dankort,eps,giftcard,giropay,ideal,mastercard,paypal,sofortueberweisung,transfer,visa,maestro,visaelectron,vpay,alipay,wechatpay,p24,trustly,belfius,blik 7 1 @@ -300,7 +300,7 @@ 0 Buckaroo\Magento2\Model\Method\Eps pending - Buckaroo EPS + EPS 0 180 1 @@ -314,7 +314,7 @@ 0 Buckaroo\Magento2\Model\Method\Giftcards pending - Buckaroo Giftcards + Giftcards 190 1 Fee @@ -327,7 +327,7 @@ 0 Buckaroo\Magento2\Model\Method\Kbc pending - Buckaroo KBC + KBC 0 210 1 @@ -341,7 +341,7 @@ 0 Buckaroo\Magento2\Model\Method\Knaken pending - Buckaroo Knaken Settle + Knaken Settle 0 300 1 @@ -355,7 +355,7 @@ 0 Buckaroo\Magento2\Model\Method\Multibanco pending - Buckaroo Multibanco + Multibanco 0 211 1 @@ -369,7 +369,7 @@ 0 Buckaroo\Magento2\Model\Method\MBWay pending - Buckaroo MBWay + MBWay 0 212 1 @@ -383,7 +383,7 @@ 0 Buckaroo\Magento2\Model\Method\PayLink pending - Buckaroo PayLink + PayLink 0 215 1 @@ -397,7 +397,7 @@ 0 Buckaroo\Magento2\Model\Method\Klarna\PayLater pending - Buckaroo Klarna: Pay later + Klarna: Pay later 220 1 Fee @@ -411,7 +411,7 @@ 0 Buckaroo\Magento2\Model\Method\Klarnakp pending - Buckaroo Klarna: Pay later + Klarna: Pay later 220 1 Fee @@ -425,7 +425,7 @@ 0 Buckaroo\Magento2\Model\Method\Klarna\Klarnain pending - Buckaroo Klarna: Slice it + Klarna: Slice it 220 1 Fee @@ -439,7 +439,7 @@ 0 Buckaroo\Magento2\Model\Method\Emandate pending - Buckaroo Digitale Incassomachtiging + Digitale Incassomachtiging 1 nl 0 @@ -455,7 +455,7 @@ 0 Buckaroo\Magento2\Model\Method\Afterpay20 pending - Buckaroo Riverty + Riverty 0 240 1 @@ -488,7 +488,7 @@ 0 Buckaroo\Magento2\Model\Method\Applepay pending - Buckaroo Apple Pay + Apple Pay 0 240 1 @@ -515,7 +515,7 @@ 0 Buckaroo\Magento2\Model\Method\Alipay pending - Buckaroo Alipay + Alipay 0 270 1 @@ -529,7 +529,7 @@ 0 Buckaroo\Magento2\Model\Method\Wechatpay pending - Buckaroo WeChatPay + WeChatPay 0 280 1 @@ -543,7 +543,7 @@ 0 Buckaroo\Magento2\Model\Method\P24 pending - Buckaroo Przelewy24 + Przelewy24 0 290 1 @@ -557,7 +557,7 @@ 0 Buckaroo\Magento2\Model\Method\Trustly pending - Buckaroo Trustly + Trustly 0 300 1 @@ -571,7 +571,7 @@ 0 Buckaroo\Magento2\Model\Method\Pospayment pending - Buckaroo Point of Sale + Point of Sale 0 320 1 @@ -585,7 +585,7 @@ 0 Buckaroo\Magento2\Model\Method\Voucher pending - Buckaroo Voucher + Voucher 0 340 1 @@ -595,6 +595,20 @@ 0 + + 0 + Buckaroo\Magento2\Model\Method\Blik + pending + Blik + 0 + 350 + 1 + Fee + buckaroo_magento2 + order + 0 + + diff --git a/etc/di.xml b/etc/di.xml index ab7e0ea45..89cf99a36 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -385,6 +385,10 @@ knaken Buckaroo\Magento2\Model\ConfigProvider\Method\Knaken + + blik + Buckaroo\Magento2\Model\ConfigProvider\Method\Blik + diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index 005d75f47..6bd197d3b 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -64,6 +64,8 @@ Buckaroo\Magento2\Model\ConfigProvider\Method\MBWay Buckaroo\Magento2\Model\ConfigProvider\Method\Multibanco Buckaroo\Magento2\Model\ConfigProvider\Method\Knaken + Buckaroo\Magento2\Model\ConfigProvider\Method\Blik + diff --git a/etc/module.xml b/etc/module.xml index 2162d3fe5..086087a33 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -20,7 +20,7 @@ */ --> - + diff --git a/etc/payment.xml b/etc/payment.xml index 7aaa8bea3..80e06896c 100644 --- a/etc/payment.xml +++ b/etc/payment.xml @@ -141,5 +141,8 @@ 0 + + 0 + diff --git a/etc/sales.xml b/etc/sales.xml index efc9fdc18..a884141fb 100644 --- a/etc/sales.xml +++ b/etc/sales.xml @@ -25,6 +25,9 @@ + + + diff --git a/i18n/nl_NL.csv b/i18n/nl_NL.csv index a86c5002d..a8ea884d8 100644 --- a/i18n/nl_NL.csv +++ b/i18n/nl_NL.csv @@ -101,6 +101,8 @@ "Enable Trustly","Trustly inschakelen" "Giropay","Giropay" "Enable Giropay","Giropay inschakelen" +"Blik","Blik" +"Enable Blik","Blik inschakelen" "Refunding","Terugbetaling" "Enable or disable refunding.","Schakel de creditering/terugstorten in of uit." "Set to 'No' refunds must be done manualy in Payment Plaza.","Bij de selectie 'Nee' worden credit memo's in Magento niet aangeboden bij Payment Plaza." diff --git a/view/base/web/images/svg/afterpay.svg b/view/base/web/images/svg/afterpay.svg index 2b28dc73d..9a5f0d199 100644 --- a/view/base/web/images/svg/afterpay.svg +++ b/view/base/web/images/svg/afterpay.svg @@ -1,166 +1,195 @@ + viewBox="0 0 94.45 70.92" style="enable-background:new 0 0 94.45 70.92;" xml:space="preserve"> + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + diff --git a/view/base/web/images/svg/riverty.svg b/view/base/web/images/svg/riverty.svg new file mode 100644 index 000000000..9a5f0d199 --- /dev/null +++ b/view/base/web/images/svg/riverty.svg @@ -0,0 +1,195 @@ + + + + + + + + + + + + + + + + + + + diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml index e5ff51df4..7f1b64222 100644 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -51,15 +51,6 @@ - - Buckaroo_Magento2/js/view/checkout/summary/grand-total - - Order Total Excl. Tax - Order Total Incl. Tax - You will be charged for - Order Total - - @@ -209,6 +200,9 @@ true + + true + diff --git a/view/frontend/web/css/styles.css b/view/frontend/web/css/styles.css index 60e7df017..7afb0da75 100644 --- a/view/frontend/web/css/styles.css +++ b/view/frontend/web/css/styles.css @@ -5,7 +5,7 @@ align-items: center; } .bk-img-wrap { - width: 40px; + width: 50px; margin-right:10px; align-items: center; display: flex; 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 078ed2898..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.formatPrice(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/payment/buckaroo-payments.js b/view/frontend/web/js/view/payment/buckaroo-payments.js index a6c5484f1..efa1abc6a 100644 --- a/view/frontend/web/js/view/payment/buckaroo-payments.js +++ b/view/frontend/web/js/view/payment/buckaroo-payments.js @@ -188,6 +188,10 @@ define( { type: 'buckaroo_magento2_knaken', component: 'Buckaroo_Magento2/js/view/payment/method-renderer/knaken' + }, + { + type: 'buckaroo_magento2_blik', + component: 'Buckaroo_Magento2/js/view/payment/method-renderer/blik' } ); /** diff --git a/view/frontend/web/js/view/payment/method-renderer/blik.js b/view/frontend/web/js/view/payment/method-renderer/blik.js new file mode 100644 index 000000000..844576cd8 --- /dev/null +++ b/view/frontend/web/js/view/payment/method-renderer/blik.js @@ -0,0 +1,130 @@ +/** + * 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 + */ +/*browser:true*/ +/*global define*/ +define( + [ + 'jquery', + 'Magento_Checkout/js/view/payment/default', + 'Magento_Checkout/js/model/payment/additional-validators', + 'Buckaroo_Magento2/js/action/place-order', + 'ko', + 'Magento_Checkout/js/checkout-data', + 'Magento_Checkout/js/action/select-payment-method', + 'buckaroo/checkout/common' + ], + function ( + $, + Component, + additionalValidators, + placeOrderAction, + ko, + checkoutData, + selectPaymentMethodAction, + checkoutCommon + ) { + 'use strict'; + + return Component.extend( + { + defaults: { + template: 'Buckaroo_Magento2/payment/buckaroo_magento2_blik' + }, + redirectAfterPlaceOrder: false, + paymentFeeLabel : window.checkoutConfig.payment.buckaroo.blik.paymentFeeLabel, + subtext : window.checkoutConfig.payment.buckaroo.blik.subtext, + subTextStyle : checkoutCommon.getSubtextStyle('blik'), + currencyCode : window.checkoutConfig.quoteData.quote_currency_code, + baseCurrencyCode : window.checkoutConfig.quoteData.base_currency_code, + + /** + * @override + */ + initialize : function (options) { + if (checkoutData.getSelectedPaymentMethod() == options.index) { + window.checkoutConfig.buckarooFee.title(this.paymentFeeLabel); + } + + return this._super(options); + }, + + /** + * Place order. + * + * placeOrderAction has been changed from Magento_Checkout/js/action/place-order to our own version + * (Buckaroo_Magento2/js/action/place-order) to prevent redirect and handle the response. + */ + placeOrder: function (data, event) { + var self = this, + placeOrder; + + if (event) { + event.preventDefault(); + } + + if (this.validate() && additionalValidators.validate()) { + this.isPlaceOrderActionAllowed(false); + placeOrder = placeOrderAction(this.getData(), this.redirectAfterPlaceOrder, this.messageContainer); + + $.when(placeOrder).fail( + function () { + self.isPlaceOrderActionAllowed(true); + } + ).done(this.afterPlaceOrder.bind(this)); + return true; + } + return false; + }, + + afterPlaceOrder: function () { + var response = window.checkoutConfig.payment.buckaroo.response; + checkoutCommon.redirectHandle(response); + }, + + selectPaymentMethod: function () { + window.checkoutConfig.buckarooFee.title(this.paymentFeeLabel); + + selectPaymentMethodAction(this.getData()); + checkoutData.setSelectedPaymentMethod(this.item.method); + return true; + }, + + payWithBaseCurrency: function () { + var allowedCurrencies = window.checkoutConfig.payment.buckaroo.blik.allowedCurrencies; + + return allowedCurrencies.indexOf(this.currencyCode) < 0; + }, + + getPayWithBaseCurrencyText: function () { + var text = $.mage.__('The transaction will be processed using %s.'); + + return text.replace('%s', this.baseCurrencyCode); + } + } + ); + } +); + + + + + + + + diff --git a/view/frontend/web/js/view/summary/totals.js b/view/frontend/web/js/view/summary/totals.js index ff06a4a2e..189240767 100644 --- a/view/frontend/web/js/view/summary/totals.js +++ b/view/frontend/web/js/view/summary/totals.js @@ -165,54 +165,6 @@ define( this.getFormattedPrice(buckarooFeeSegment.value) : false; }, - - removeGiftcard: function (transaction_id, servicecode, amount) { - self = this; - if (confirm('Are you sure you want to remove?')) { - - $.ajax({ - url: url.build("buckaroo/checkout/giftcard"), - type: 'POST', - dataType: 'json', - showLoader: true, //use for display loader - data: { - refund: transaction_id, - card: servicecode, - amount: amount, - } - }).done(function (data) { - if(data.error){ - alert({ - title: $t('Error'), - content: $t(data.error), - actions: {always: function(){} } - }); - }else{ - alert({ - title: $t('Success'), - content: $t(data.message), - actions: {always: function(){} }, - buttons: [{ - text: $t(data.message), - class: 'action primary accept', - click: function () { - this.closeModal(true); - } - }] - }); - } - - var deferred = $.Deferred(); - getTotalsAction([], deferred); - // $('.buckaroo_magento2_'+self.currentGiftcard+' input[name="payment[method]"]').click(); - - }); - - } else { - console.log('no'); - } - } - } ); } diff --git a/view/frontend/web/template/payment/buckaroo_magento2_afterpay.html b/view/frontend/web/template/payment/buckaroo_magento2_afterpay.html index 6fc7ac74b..a7e9547de 100644 --- a/view/frontend/web/template/payment/buckaroo_magento2_afterpay.html +++ b/view/frontend/web/template/payment/buckaroo_magento2_afterpay.html @@ -14,7 +14,7 @@
- +
diff --git a/view/frontend/web/template/payment/buckaroo_magento2_afterpay2.html b/view/frontend/web/template/payment/buckaroo_magento2_afterpay2.html index 79b1a28d4..ade5d7b37 100644 --- a/view/frontend/web/template/payment/buckaroo_magento2_afterpay2.html +++ b/view/frontend/web/template/payment/buckaroo_magento2_afterpay2.html @@ -14,7 +14,7 @@
- +
diff --git a/view/frontend/web/template/payment/buckaroo_magento2_afterpay20.html b/view/frontend/web/template/payment/buckaroo_magento2_afterpay20.html index 1968dc26e..31264d319 100644 --- a/view/frontend/web/template/payment/buckaroo_magento2_afterpay20.html +++ b/view/frontend/web/template/payment/buckaroo_magento2_afterpay20.html @@ -14,7 +14,7 @@
- +
diff --git a/view/frontend/web/template/payment/buckaroo_magento2_blik.html b/view/frontend/web/template/payment/buckaroo_magento2_blik.html new file mode 100644 index 000000000..bc2caa4ab --- /dev/null +++ b/view/frontend/web/template/payment/buckaroo_magento2_blik.html @@ -0,0 +1,63 @@ +
+
+
+
+ + +
+
+ +
+
+
+ +
+
+ + + +
+ +
+
+ +
+
+ + +
+ +
+ + + + + + +
+ + + +
+ +
+
diff --git a/view/frontend/web/template/payment/buckaroo_magento2_paybybank.html b/view/frontend/web/template/payment/buckaroo_magento2_paybybank.html index 82e84795a..28fb1e276 100644 --- a/view/frontend/web/template/payment/buckaroo_magento2_paybybank.html +++ b/view/frontend/web/template/payment/buckaroo_magento2_paybybank.html @@ -14,7 +14,7 @@
- +