Skip to content

Commit

Permalink
Release version 5.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
afterpayplugins committed Nov 8, 2024
1 parent d3f3c33 commit 45b4b7d
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Gateway/Request/Checkout/CheckoutDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
],
Expand Down
4 changes: 2 additions & 2 deletions Gateway/Response/DiscountHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
27 changes: 19 additions & 8 deletions Gateway/Response/PaymentDetailsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions Model/GraphQl/Resolver/AfterpayConfigPdp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -76,6 +80,10 @@ public function resolve(
}
}

// Add stock status
$stockItem = $this->stockRegistry->getStockItemBySku($productSku);
$result['is_in_stock'] = (bool)$stockItem->getIsInStock();

return $result;
}
}
2 changes: 1 addition & 1 deletion Plugin/Order/Payment/State/CaptureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 13 additions & 1 deletion ViewModel/Container/ExpressCheckout/ExpressCheckout.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php declare(strict_types=1);

namespace Afterpay\Afterpay\ViewModel\Container\ExpressCheckout;

class ExpressCheckout extends \Afterpay\Afterpay\ViewModel\Container\Container
{
public const COUNTRY_CURRENCY_MAP = [
Expand All @@ -11,7 +10,18 @@ class ExpressCheckout extends \Afterpay\Afterpay\ViewModel\Container\Container
'CAD' => '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,
Expand All @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion ViewModel/Container/ExpressCheckout/ExpressCheckoutPdp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down
10 changes: 9 additions & 1 deletion ViewModel/Container/ExpressCheckout/Headless.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
}
Expand All @@ -43,4 +45,10 @@ public function getCartId(): string
{
return (string)$this->checkoutSession->getQuoteId();
}

public function getStoreLocale(): string
{
return $this->localeResolver->getLocale();
}

}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<argument name="requestBuilder" xsi:type="object">Afterpay\Afterpay\Gateway\Request\PaymentAction\RefundAndVoidDataBuilder</argument>
<argument name="transferFactory" xsi:type="object">Afterpay\Afterpay\Gateway\Http\RefundTransferFactory</argument>
<argument name="client" xsi:type="object">Afterpay\Afterpay\Gateway\Http\Client\Client</argument>
<argument name="handler" xsi:type="object">Afterpay\Afterpay\Gateway\Response\PaymentDetailsHandler</argument>
<argument name="validator" xsi:type="object">Afterpay\Afterpay\Gateway\Validator\RefundResponseValidator</argument>
</arguments>
</virtualType>
Expand All @@ -85,6 +86,7 @@
<argument name="requestBuilder" xsi:type="object">Afterpay\Afterpay\Gateway\Request\PaymentAction\ReversalDataBuilder</argument>
<argument name="transferFactory" xsi:type="object">Afterpay\Afterpay\Gateway\Http\ReversalTransferFactory</argument>
<argument name="client" xsi:type="object">Afterpay\Afterpay\Gateway\Http\Client\Client</argument>
<argument name="handler" xsi:type="object">Afterpay\Afterpay\Gateway\Response\PaymentDetailsHandler</argument>
<argument name="validator" xsi:type="object">Afterpay\Afterpay\Gateway\Validator\ReversalResponseValidator</argument>
</arguments>
</virtualType>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Afterpay_Afterpay" setup_version="5.4.1">
<module name="Afterpay_Afterpay" setup_version="5.4.2">
<sequence>
<module name="Magento_Payment"/>
<module name="Magento_Checkout"/>
Expand Down
11 changes: 4 additions & 7 deletions etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -77,6 +73,7 @@ type afterpayConfigPdpOutput {
placement_after_selector_bundle: String
price_selector: String
price_selector_bundle: String
is_in_stock: Boolean
}

type afterpayConfigCartOutput {
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/templates/cta/cart/headless.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $jsUrl = $block->getViewFileUrl('Afterpay_Afterpay::js/view/container/cta/cart/h
var afterpayStoreId = "<?= /* @noEscape */ $viewModel->getStoreId() ?>";
}
if (typeof afterpayCurrency === 'undefined') {
var afterpayCurrency = "<?= /* @noEscape */ $viewModel->getCurrency() ?>";
window.afterpayCurrency = "<?= /* @noEscape */ $viewModel->getCurrency() ?>";
}
if (typeof afterpayLocale === 'undefined') {
var afterpayLocale = "<?= /* @noEscape */ $viewModel->getLocale() ?>";
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/templates/cta/minicart/headless.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ $jsUrl = $block->getViewFileUrl('Afterpay_Afterpay::js/view/container/cta/minica
?>
<script>
if (typeof afterpayCurrency === 'undefined') {
var afterpayCurrency = "<?= /* @noEscape */ $viewModel->getCurrency() ?>";
window.afterpayCurrency = "<?= /* @noEscape */ $viewModel->getCurrency() ?>";
}
if (typeof afterpayLocale === 'undefined') {
var afterpayLocale = "<?= /* @noEscape */ $viewModel->getLocale() ?>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $externalJsUrl = $block->getViewFileUrl('Afterpay_Afterpay::js/view/container/ex
<section id="headless-afterpay-cart-ec" class="headless-afterpay-ec hidden headless-afterpay-cart-ec">
<div class="afterpay-express-checkout-product-wrapper">
<button class="afterpay-express-button-cart">
<img src="https://static.afterpay.com/button/checkout-with-afterpay/white-on-black.svg"
<img src="https://static.afterpay.com/<?= /* @noEscape */ str_replace('_','-',$viewModel->getStoreLocale()) ?>/integration/button/checkout-with-afterpay/white-on-black.svg"
alt="<?= /* @noEscape */ __('Checkout with Afterpay') ?>" style="width: 267px;"/>
</button>
<div class="hiidden" id="afterpay-button-cart" data-afterpay-entry-point="cart"></div>
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/templates/express-checkout/headless.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $externalJsUrl = $block->getViewFileUrl('Afterpay_Afterpay::js/view/container/ex
<section id="headless-afterpay-pdp-ec" class="headless-afterpay-ec hidden headless-afterpay-pdp-ec">
<div class="afterpay-express-checkout-product-wrapper">
<button class="afterpay-express-button afterpay-express-pdp-button">
<img src="https://static.afterpay.com/button/checkout-with-afterpay/white-on-black.svg"
<img src="https://static.afterpay.com/<?= /* @noEscape */ str_replace('_','-',$viewModel->getStoreLocale()) ?>/integration/button/checkout-with-afterpay/white-on-black.svg"
alt="<?= /* @noEscape */ __('Checkout with Afterpay') ?>" style="width: 267px;"/>
</button>
<div class="hiidden" id="afterpay-button-pdp" data-afterpay-entry-point="product-page"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ window.addEventListener("load", () => {
ecButtonPlace: document.querySelector(".cart-container .cart-totals"),
wrapElement: document.querySelector("#headless-afterpay-cart-ec"),
isVirtual: false,
configData: '',

init() {
let self = this;
document.addEventListener('showHeadlessCart', (event) => {
setTimeout(() => {
self.extractSectionData(event.detail.afterpayConfig);
self.configData = event.detail.afterpayConfig;
}, 1000);
});

Expand All @@ -28,6 +30,19 @@ window.addEventListener("load", () => {
document.dispatchEvent(window.reloadCartPage);
}, 1000);
}

let element = e.target;

while (element) {
if (element.id === 'discount-coupon-form') {
setTimeout(function() {
self.extractSectionData(self.configData);
}, 2000);
break;
}

element = element.parentElement;
}
});
},

Expand All @@ -44,9 +59,6 @@ window.addEventListener("load", () => {
}

if (this.ecButtonPlace) {
if (document.querySelector('#afterpay-cta-cart')) {
this.ecButtonPlace = document.querySelector('#afterpay-cta-cart');
}
let afterpaySection = document.querySelector('.headless-afterpay-cart-ec');
if(!afterpaySection) {
afterpaySection = self.wrapElement;
Expand Down Expand Up @@ -99,10 +111,10 @@ window.addEventListener("load", () => {
},

getCurrentSubtotal () {
let currentCartData = JSON.parse(localStorage.getItem("mage-cache-storage"))?.cart;
let currentCartData = window?.checkoutConfig?.totalsData?.base_grand_total;

if(currentCartData && currentCartData?.subtotalAmount) {
return +currentCartData?.subtotalAmount;
if(currentCartData) {
return +currentCartData;
}

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
min_amount
price_selector
price_selector_bundle
is_in_stock
}
}`;

Expand All @@ -42,7 +43,7 @@
}
const afterpayConfig = data.data.getAfterpayConfigPdp;

if(afterpayConfig) {
if (afterpayConfig && afterpayConfig?.is_in_stock && afterpayConfig?.is_product_allowed && afterpayConfig?.product_type != "grouped") {
const event = new CustomEvent('showHeadlessEC', { detail: { afterpayConfig} });
document.dispatchEvent(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
afterRender: initAfterpay
"
class="afterpay primary express-button afterpay-express-button">
<img src="https://static.afterpay.com/button/checkout-with-afterpay/white-on-black.svg"
<img data-bind="attr: { src: buttonImageUrl }"
alt="Checkout with Afterpay"/>
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/web/template/express-checkout/button.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
afterRender: initAfterpay
"
class="afterpay primary express-button afterpay-express-button">
<img src="https://static.afterpay.com/button/checkout-with-afterpay/white-on-black.svg"
<img data-bind="attr: { src: buttonImageUrl }"
alt="Checkout with Afterpay"/>
</button>
<!-- /ko -->

0 comments on commit 45b4b7d

Please sign in to comment.