diff --git a/Gateway/Request/Checkout/CheckoutDataBuilder.php b/Gateway/Request/Checkout/CheckoutDataBuilder.php index 43decb3..d1960a7 100644 --- a/Gateway/Request/Checkout/CheckoutDataBuilder.php +++ b/Gateway/Request/Checkout/CheckoutDataBuilder.php @@ -72,7 +72,7 @@ public function build(array $buildSubject): array 'merchantReference' => $quote->getReservedOrderId(), 'taxAmount' => [ 'amount' => $this->formatPrice( - $billingTaxAmount ?: $shippingTaxAmount + (float)$billingTaxAmount ?: $shippingTaxAmount ), 'currency' => $isCBTCurrencyAvailable ? $quote->getQuoteCurrencyCode() : $quote->getBaseCurrencyCode() ], diff --git a/Gateway/Response/DiscountHandler.php b/Gateway/Response/DiscountHandler.php index cd51e45..a806820 100644 --- a/Gateway/Response/DiscountHandler.php +++ b/Gateway/Response/DiscountHandler.php @@ -44,9 +44,9 @@ protected function getOrderDiscountAmount(\Magento\Sales\Model\Order $order): fl ); if ($isCBTCurrency) { - return (float)($order->getGiftCardsAmount() + $order->getCustomerBalanceAmount()); + return (float)($order->getGiftCardsAmount() + $order->getCustomerBalanceAmount() + $order->getRewardCurrencyAmount()); } else { - return (float)($order->getBaseGiftCardsAmount() + $order->getBaseCustomerBalanceAmount()); + return (float)($order->getBaseGiftCardsAmount() + $order->getBaseCustomerBalanceAmount() + $order->getBaseRewardCurrencyAmount()); } } } diff --git a/Gateway/Response/PaymentDetailsHandler.php b/Gateway/Response/PaymentDetailsHandler.php index 3b518a6..2f282b5 100644 --- a/Gateway/Response/PaymentDetailsHandler.php +++ b/Gateway/Response/PaymentDetailsHandler.php @@ -6,22 +6,33 @@ class PaymentDetailsHandler implements \Magento\Payment\Gateway\Response\Handler { private \Afterpay\Afterpay\Model\Order\Payment\Auth\ExpiryDate $authExpiryDate; + private \Afterpay\Afterpay\Model\Order\CreditMemo\PaymentUpdater\Proxy $paymentUpdater; + public function __construct( - \Afterpay\Afterpay\Model\Order\Payment\Auth\ExpiryDate $authExpiryDate + \Afterpay\Afterpay\Model\Order\Payment\Auth\ExpiryDate $authExpiryDate, + \Afterpay\Afterpay\Model\Order\CreditMemo\PaymentUpdater\Proxy $paymentUpdater ) { $this->authExpiryDate = $authExpiryDate; + $this->paymentUpdater = $paymentUpdater; } public function handle(array $handlingSubject, array $response): void { if (!isset($response['id'])) { - throw new \Magento\Payment\Gateway\Command\CommandException( - __( - 'Afterpay response error: Code: %1, Id: %2', - $response['errorCode'] ?? '', - $response['errorId'] ?? '' - ) - ); + if (isset($response['errorCode'], $response['errorId'])) { + throw new \Magento\Payment\Gateway\Command\CommandException( + __( + 'Afterpay response error: Code: %1, Id: %2', + $response['errorCode'], + $response['errorId'] + ) + ); + } + + $paymentDO = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($handlingSubject); + $this->paymentUpdater->updatePayment($paymentDO->getPayment()); + + return; } $paymentDO = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($handlingSubject); diff --git a/Model/GraphQl/Resolver/AfterpayConfigPdp.php b/Model/GraphQl/Resolver/AfterpayConfigPdp.php index 38554f2..10816a2 100644 --- a/Model/GraphQl/Resolver/AfterpayConfigPdp.php +++ b/Model/GraphQl/Resolver/AfterpayConfigPdp.php @@ -4,6 +4,7 @@ use Afterpay\Afterpay\Model\Config; use Magento\Catalog\Api\ProductRepositoryInterface; +use Magento\CatalogInventory\Api\StockRegistryInterface; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; use Magento\Framework\GraphQl\Query\Resolver\Value; @@ -14,14 +15,17 @@ class AfterpayConfigPdp extends AfterpayConfig implements ResolverInterface { private ProductRepositoryInterface $productRepository; + private StockRegistryInterface $stockRegistry; public function __construct( Config $config, StoreManagerInterface $storeManager, ProductRepositoryInterface $productRepository, + StockRegistryInterface $stockRegistry ) { parent::__construct($config, $storeManager); $this->productRepository = $productRepository; + $this->stockRegistry = $stockRegistry; } /** @@ -76,6 +80,10 @@ public function resolve( } } + // Add stock status + $stockItem = $this->stockRegistry->getStockItemBySku($productSku); + $result['is_in_stock'] = (bool)$stockItem->getIsInStock(); + return $result; } } diff --git a/Plugin/Order/Payment/State/CaptureCommand.php b/Plugin/Order/Payment/State/CaptureCommand.php index 308f3f1..2cbb4eb 100644 --- a/Plugin/Order/Payment/State/CaptureCommand.php +++ b/Plugin/Order/Payment/State/CaptureCommand.php @@ -52,7 +52,7 @@ public function aroundExecute( $order->setState($state); $order->setStatus($status); - return __($message, $order->getBaseCurrency()->formatTxt($amount)); + return __($message, $order->getOrderCurrency()->formatTxt($amount)); } return $proceed($payment, $amount, $order); diff --git a/ViewModel/Container/ExpressCheckout/ExpressCheckout.php b/ViewModel/Container/ExpressCheckout/ExpressCheckout.php index 97229d0..7499f6d 100644 --- a/ViewModel/Container/ExpressCheckout/ExpressCheckout.php +++ b/ViewModel/Container/ExpressCheckout/ExpressCheckout.php @@ -1,7 +1,6 @@ 'CA', 'GBP' => 'GB' ]; + protected $localeResolver; + public function __construct( + \Magento\Framework\Serialize\SerializerInterface $serializer, + \Afterpay\Afterpay\Model\Config $config, + \Afterpay\Afterpay\Model\ResourceModel\NotAllowedProductsProvider $notAllowedProductsProvider, + \Magento\Store\Model\StoreManagerInterface $storeManager, + \Magento\Framework\Locale\Resolver $localeResolver + ) { + parent::__construct($serializer, $config, $notAllowedProductsProvider, $storeManager); + $this->localeResolver = $localeResolver; + } public function updateJsLayout( string $jsLayoutJson, bool $remove = false, @@ -22,6 +32,8 @@ public function updateJsLayout( $config['minOrderTotal'] = $this->config->getMinOrderTotal(); $config['maxOrderTotal'] = $this->config->getMaxOrderTotal(); $config['countryCode'] = $this->getCountryCode(); + $config['buttonImageUrl'] = 'https://static.afterpay.com/'.str_replace("_","-",$this->localeResolver->getLocale()).'/integration/button/checkout-with-afterpay/white-on-black.svg'; + } return parent::updateJsLayout($jsLayoutJson, $remove, $containerNodeName, $config); } diff --git a/ViewModel/Container/ExpressCheckout/ExpressCheckoutPdp.php b/ViewModel/Container/ExpressCheckout/ExpressCheckoutPdp.php index 3391f63..08f49e2 100644 --- a/ViewModel/Container/ExpressCheckout/ExpressCheckoutPdp.php +++ b/ViewModel/Container/ExpressCheckout/ExpressCheckoutPdp.php @@ -12,10 +12,11 @@ public function __construct( \Afterpay\Afterpay\Model\Config $config, \Afterpay\Afterpay\Model\ResourceModel\NotAllowedProductsProvider $notAllowedProductsProvider, \Magento\Store\Model\StoreManagerInterface $storeManager, + \Magento\Framework\Locale\Resolver $localeResolver, \Magento\Catalog\Helper\Data $catalogHelper, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory ) { - parent::__construct($serializer, $config, $notAllowedProductsProvider, $storeManager); + parent::__construct($serializer, $config, $notAllowedProductsProvider, $storeManager, $localeResolver); $this->catalogHelper = $catalogHelper; $this->productCollectionFactory = $productCollectionFactory; } @@ -31,6 +32,8 @@ public function updateJsLayout( if ($product) { $config['isVirtual'] = $this->isProductVirtual($product); } + $config['buttonImageUrl'] = 'https://static.afterpay.com/'.str_replace("_","-",$this->localeResolver->getLocale()).'/integration/button/checkout-with-afterpay/white-on-black.svg'; + } return parent::updateJsLayout($jsLayoutJson, $remove, $containerNodeName, $config); } diff --git a/ViewModel/Container/ExpressCheckout/Headless.php b/ViewModel/Container/ExpressCheckout/Headless.php index 0ce3aee..b5207e8 100644 --- a/ViewModel/Container/ExpressCheckout/Headless.php +++ b/ViewModel/Container/ExpressCheckout/Headless.php @@ -9,6 +9,7 @@ use Magento\Framework\Registry; use Magento\Framework\Serialize\SerializerInterface; use Magento\Store\Model\StoreManagerInterface; +use Magento\Framework\Locale\Resolver; class Headless extends ExpressCheckout { @@ -21,10 +22,11 @@ public function __construct( Config $config, NotAllowedProductsProvider $notAllowedProductsProvider, StoreManagerInterface $storeManager, + Resolver $localeResolver, Session $checkoutSession, Registry $registry ) { - parent::__construct($serializer, $config, $notAllowedProductsProvider, $storeManager); + parent::__construct($serializer, $config, $notAllowedProductsProvider, $storeManager,$localeResolver); $this->checkoutSession = $checkoutSession; $this->registry = $registry; } @@ -43,4 +45,10 @@ public function getCartId(): string { return (string)$this->checkoutSession->getQuoteId(); } + + public function getStoreLocale(): string + { + return $this->localeResolver->getLocale(); + } + } diff --git a/composer.json b/composer.json index 2088320..15c94a6 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "license": "Apache-2.0", "type": "magento2-module", "description": "Magento 2 Afterpay Payment Module", - "version": "5.4.1", + "version": "5.4.2", "require": { "php": ">=7.4.0", "magento/framework": "^103.0", diff --git a/etc/di.xml b/etc/di.xml index 706e20a..04856aa 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -77,6 +77,7 @@ Afterpay\Afterpay\Gateway\Request\PaymentAction\RefundAndVoidDataBuilder Afterpay\Afterpay\Gateway\Http\RefundTransferFactory Afterpay\Afterpay\Gateway\Http\Client\Client + Afterpay\Afterpay\Gateway\Response\PaymentDetailsHandler Afterpay\Afterpay\Gateway\Validator\RefundResponseValidator @@ -85,6 +86,7 @@ Afterpay\Afterpay\Gateway\Request\PaymentAction\ReversalDataBuilder Afterpay\Afterpay\Gateway\Http\ReversalTransferFactory Afterpay\Afterpay\Gateway\Http\Client\Client + Afterpay\Afterpay\Gateway\Response\PaymentDetailsHandler Afterpay\Afterpay\Gateway\Validator\ReversalResponseValidator diff --git a/etc/module.xml b/etc/module.xml index 89e052a..d36ee70 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,7 +1,7 @@ - + diff --git a/etc/schema.graphqls b/etc/schema.graphqls index 76c4bb7..c6cfef7 100644 --- a/etc/schema.graphqls +++ b/etc/schema.graphqls @@ -1,5 +1,8 @@ type Mutation { createAfterpayCheckout(input: createAfterpayCheckoutInput): createAfterpayCheckoutOutput @resolver(class: "\\Afterpay\\Afterpay\\Model\\GraphQl\\Resolver\\CreateAfterpayCheckout") @doc(description:"Creates an Afterpay Checkout.") + getAfterpayConfigPdp(input: getAfterpayConfigPdpInput): afterpayConfigPdpOutput @resolver(class: "Afterpay\\Afterpay\\Model\\GraphQl\\Resolver\\AfterpayConfigPdp") @doc(description:"return Afterpay PDP config") + getAfterpayConfigCart(input: getAfterpayConfigCartInput): afterpayConfigCartOutput @resolver(class: "Afterpay\\Afterpay\\Model\\GraphQl\\Resolver\\AfterpayConfigCart") @doc(description:"return Afterpay Cart config") + getAfterpayConfigMiniCart(input: getAfterpayConfigCartInput): afterpayConfigMiniCartOutput @resolver(class: "Afterpay\\Afterpay\\Model\\GraphQl\\Resolver\\AfterpayConfigMiniCart") @doc(description:"return Afterpay Mini Cart config") } input createAfterpayCheckoutInput { @@ -30,13 +33,6 @@ type Query { afterpayConfig: afterpayConfigOutput @resolver(class: "Afterpay\\Afterpay\\Model\\GraphQl\\Resolver\\AfterpayConfig") @doc(description:"return Afterpay config") } -type Mutation { - getAfterpayConfigPdp(input: getAfterpayConfigPdpInput): afterpayConfigPdpOutput @resolver(class: "Afterpay\\Afterpay\\Model\\GraphQl\\Resolver\\AfterpayConfigPdp") @doc(description:"return Afterpay PDP config") - getAfterpayConfigCart(input: getAfterpayConfigCartInput): afterpayConfigCartOutput @resolver(class: "Afterpay\\Afterpay\\Model\\GraphQl\\Resolver\\AfterpayConfigCart") @doc(description:"return Afterpay Cart config") - getAfterpayConfigMiniCart(input: getAfterpayConfigCartInput): afterpayConfigMiniCartOutput @resolver(class: "Afterpay\\Afterpay\\Model\\GraphQl\\Resolver\\AfterpayConfigMiniCart") @doc(description:"return Afterpay Mini Cart config") -} - - input getAfterpayConfigPdpInput { store_id: String! product_sku: String! @@ -77,6 +73,7 @@ type afterpayConfigPdpOutput { placement_after_selector_bundle: String price_selector: String price_selector_bundle: String + is_in_stock: Boolean } type afterpayConfigCartOutput { diff --git a/view/frontend/templates/cta/cart/headless.phtml b/view/frontend/templates/cta/cart/headless.phtml index f33cc80..3b0adee 100644 --- a/view/frontend/templates/cta/cart/headless.phtml +++ b/view/frontend/templates/cta/cart/headless.phtml @@ -12,7 +12,7 @@ $jsUrl = $block->getViewFileUrl('Afterpay_Afterpay::js/view/container/cta/cart/h var afterpayStoreId = "getStoreId() ?>"; } if (typeof afterpayCurrency === 'undefined') { - var afterpayCurrency = "getCurrency() ?>"; + window.afterpayCurrency = "getCurrency() ?>"; } if (typeof afterpayLocale === 'undefined') { var afterpayLocale = "getLocale() ?>"; diff --git a/view/frontend/templates/cta/minicart/headless.phtml b/view/frontend/templates/cta/minicart/headless.phtml index ef2c19a..33e32c3 100644 --- a/view/frontend/templates/cta/minicart/headless.phtml +++ b/view/frontend/templates/cta/minicart/headless.phtml @@ -6,7 +6,7 @@ $jsUrl = $block->getViewFileUrl('Afterpay_Afterpay::js/view/container/cta/minica ?>