Skip to content

Commit 99009b1

Browse files
Afterpay v3.4.5
- Upgraded from regional APIs to a single Global API - Added support for the ES, FR and IT countries and EUR currency - Improved retention of consumer-facing checkout notifications in the event of a payment decline - Minor improvements to cron jobs - Various other improvements
1 parent 52bfb4d commit 99009b1

File tree

15 files changed

+123
-220
lines changed

15 files changed

+123
-220
lines changed

Block/Catalog/Installments.php

100644100755
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ public function canShow(): bool
8484

8585
if ($this->_getPaymentIsActive() &&
8686
$this->afterpayConfig->getCurrencyCode() &&
87-
$this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode() &&
88-
$product->isSalable())
87+
$this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode())
8988
) {
9089
$excluded_categories = $this->afterpayConfig->getExcludedCategories();
9190
if ($excluded_categories != "") {
@@ -166,4 +165,12 @@ public function isProductVirtual()
166165

167166
return $isVirtual;
168167
}
168+
/**
169+
* @retrun boolean
170+
*/
171+
public function isProductOutOfStock(){
172+
173+
$product = $this->registry->registry('product');
174+
return $product && !$product->isSalable();
175+
}
169176
}

Controller/Payment/Response.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ private function _captureVirtual($order = null,$payment = null)
401401

402402
foreach($order->getAllItems() as $items) {
403403
if($items->getIsVirtual()) {
404-
$itemPrice = ($items->getQtyOrdered() * $items->getPrice())+$items->getBaseTaxAmount();
405-
$totalCaptureAmount = $totalCaptureAmount + ($itemPrice - $items->getDiscountAmount());
404+
$itemPrice = ($items->getQtyOrdered() * $items->getBasePrice())+$items->getBaseTaxAmount();
405+
$totalCaptureAmount = $totalCaptureAmount + ($itemPrice - $items->getBaseDiscountAmount());
406406
}
407407
}
408408

@@ -424,7 +424,7 @@ private function _captureVirtual($order = null,$payment = null)
424424
if($totalCaptureAmount >= 1){
425425
$afterpay_order_id = $payment->getAdditionalInformation(\Afterpay\Afterpay\Model\Payovertime::ADDITIONAL_INFORMATION_KEY_ORDERID);
426426
$merchant_order_id = $order->getIncrementId();
427-
$currencyCode = $order->getOrderCurrencyCode();
427+
$currencyCode = $order->getBaseCurrencyCode();
428428

429429
$totalAmount= [
430430
'amount' => number_format($totalCaptureAmount, 2, '.', ''),

Model/Adapter/AfterpayExpressPayment.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ public function captureVirtual($order = null, $payment = null)
281281

282282
foreach ($order->getAllItems() as $items) {
283283
if ($items->getIsVirtual()) {
284-
$itemPrice = ($items->getQtyOrdered() * $items->getPrice()) + $items->getBaseTaxAmount();
285-
$totalCaptureAmount = $totalCaptureAmount + ($itemPrice - $items->getDiscountAmount());
284+
$itemPrice = ($items->getQtyOrdered() * $items->getBasePrice()) + $items->getBaseTaxAmount();
285+
$totalCaptureAmount = $totalCaptureAmount + ($itemPrice - $items->getBaseDiscountAmount());
286286
}
287287
}
288288

@@ -302,7 +302,7 @@ public function captureVirtual($order = null, $payment = null)
302302
if ($totalCaptureAmount >= 1) {
303303
$afterpay_order_id = $payment->getAdditionalInformation(\Afterpay\Afterpay\Model\Payovertime::ADDITIONAL_INFORMATION_KEY_ORDERID);
304304
$merchant_order_id = $order->getIncrementId();
305-
$currencyCode = $order->getOrderCurrencyCode();
305+
$currencyCode = $order->getBaseCurrencyCode();
306306

307307
$totalAmount = [
308308
'amount' => number_format($totalCaptureAmount, 2, '.', ''),

Model/Config/Payovertime.php

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -194,38 +194,20 @@ public function getSiteConfig($apiMode, $type, $websiteId)
194194
}
195195

196196
$url ="";
197-
if ($type=='api_url') {
198-
if ($apiMode == 'Sandbox') {
199-
if ($currency == 'USD' || $currency == 'CAD') {
200-
$url = 'https://api.us-sandbox.afterpay.com/';
201-
} else {
202-
$url = 'https://api-sandbox.afterpay.com/';
203-
}
204-
} elseif ($apiMode == 'Production') {
205-
if ($currency == 'USD' || $currency == 'CAD') {
206-
$url = 'https://api.us.afterpay.com/';
207-
} else {
208-
$url = 'https://api.afterpay.com/';
209-
}
210-
}
211-
}
197+
switch($type){
198+
case "api_url":
199+
$url=($apiMode == 'Production')?"https://global-api.afterpay.com/" : "https://global-api-sandbox.afterpay.com/" ;
200+
break;
201+
case "web_url":
202+
$url=($apiMode == 'Production')?"https://portal.afterpay.com/" : "https://portal.sandbox.afterpay.com/" ;
203+
break;
204+
case "js_lib_url":
205+
// get JS Library URL
206+
$url=($apiMode == 'Production')?"https://js.afterpay.com/" : "https://js.sandbox.afterpay.com/" ;
207+
break;
212208

213-
if ($type=='web_url') {
214-
if ($apiMode == 'Sandbox') {
215-
$url = 'https://portal.sandbox.afterpay.com/';
216-
} elseif ($apiMode == 'Production') {
217-
$url = 'https://portal.afterpay.com/';
218-
}
219209
}
220210

221-
// get JS Library URL
222-
if ($type=='js_lib_url') {
223-
if ($apiMode == 'Sandbox') {
224-
$url = 'https://js.sandbox.afterpay.com/';
225-
} elseif ($apiMode == 'Production') {
226-
$url = 'https://js.afterpay.com/';
227-
}
228-
}
229211
return $url;
230212
}
231213

Model/ConfigProvider.php

100644100755
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ class ConfigProvider implements ConfigProviderInterface
2929
* ConfigProvider constructor.
3030
* @param Config\Payovertime $config
3131
*/
32-
public function __construct(\Afterpay\Afterpay\Model\Config\Payovertime $config,\Afterpay\Afterpay\Model\Payovertime $afterpayPayovertime)
32+
private $localeResolver;
33+
public function __construct(\Afterpay\Afterpay\Model\Config\Payovertime $config,\Afterpay\Afterpay\Model\Payovertime $afterpayPayovertime,\Magento\Framework\Locale\Resolver $localeResolver)
3334
{
3435
$this->afterpayConfig = $config;
3536
$this->afterpayPayovertime = $afterpayPayovertime;
37+
$this->localeResolver = $localeResolver;
3638
}
3739

3840
/**
@@ -57,6 +59,7 @@ public function getConfig()
5759
'termsConditionUrl' => self::TERMS_CONDITION_LINK,
5860
'currencyCode' => $this->afterpayConfig->getCurrencyCode(),
5961
'baseCurrencyCode' => $this->afterpayPayovertime->getStoreCurrencyCode(),
62+
'storeLocale' =>$this->localeResolver->getLocale()
6063
],
6164
],
6265
]);

Model/Cron/Limit.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Magento\Framework\Json\Helper\Data as JsonHelper;
1414
use Magento\Framework\App\Config\Storage\WriterInterface as WriterInterface;
1515
use Magento\Config\Model\ResourceModel\Config as RequestConfig;
16-
use Magento\Framework\Message\ManagerInterface as MessageManager;
16+
use Psr\Log\LoggerInterface as logger;
1717

1818
class Limit
1919
{
@@ -26,7 +26,7 @@ class Limit
2626
protected $_jsonHelper;
2727
protected $_resourceConfig;
2828
protected $_writerInterface;
29-
protected $_messageManager;
29+
private $_logger;
3030

3131
/**
3232
* Limit constructor.
@@ -41,15 +41,15 @@ public function __construct(
4141
JsonHelper $jsonHelper,
4242
WriterInterface $writerInterface,
4343
RequestConfig $resourceConfig,
44-
MessageManager $messageManager
44+
logger $logger
4545
) {
4646
$this->_afterpayTotalLimit = $afterpayTotalLimit;
4747
$this->_storeManager = $storeManager;
4848
$this->_jsonHelper = $jsonHelper;
4949
$this->_resourceConfig = $resourceConfig;
5050
$this->_helper = $helper;
5151
$this->_writerInterface = $writerInterface;
52-
$this->_messageManager = $messageManager;
52+
$this->_logger=$logger;
5353
}
5454

5555
/**
@@ -93,8 +93,8 @@ private function _updateDefault()
9393

9494

9595
if (array_key_exists('errorCode', $response)) {
96-
//Unfortunately Message Manager is not working with CRON jobs yet
97-
$this->_messageManager->addWarningMessage('Afterpay Update Limits Failed. Please check Merchant ID and Key. Default Config');
96+
//Log the error
97+
$this->_logger->warning('Afterpay Update Limits Failed. Please check Merchant ID and Key. Default Config');
9898
return false;
9999
} else {
100100
// default min and max if not provided
@@ -141,8 +141,8 @@ private function _updateWebsite($website)
141141
$response = $this->_jsonHelper->jsonDecode($response->getBody());
142142

143143
if (array_key_exists('errorCode', $response)) {
144-
//Unfortunately Message Manager is not working with CRON jobs yet
145-
$this->_messageManager->addWarningMessage('Afterpay Update Limits Failed. Please check Merchant ID and Key.' . $website["name"]);
144+
//Log the error
145+
$this->_logger->warning('Afterpay Update Limits Failed. Please check Merchant ID and Key.' . $website["name"]);
146146
return false;
147147
} else {
148148
// default min and max if not provided

Model/Response.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public function calculateRefund($payment, $amount)
327327
$order = $payment->getOrder();
328328
$creditmemo = $payment->getCreditmemo();
329329
$amountToCapture = 0.00;
330-
$storeCredit = $creditmemo->getCustomerBalanceAmount();
330+
$storeCredit = $creditmemo->getBaseCustomerBalanceAmount();
331331
$override = ["website_id" => $order->getStore()->getWebsiteId()];
332332

333333
$afterpayPaymentStatus = $payment->getAdditionalInformation(\Afterpay\Afterpay\Model\Payovertime::PAYMENT_STATUS);
@@ -337,10 +337,10 @@ public function calculateRefund($payment, $amount)
337337
}
338338
elseif($afterpayPaymentStatus == self::PAYMENT_STATUS_PARTIALLY_CAPTURED || $afterpayPaymentStatus == self::PAYMENT_STATUS_AUTH_APPROVED){
339339

340-
$orderTotal = $order->getGrandTotal();
341-
$shippingApplied = $creditmemo->getShippingInclTax();
342-
$adjustmentPositive = $creditmemo->getAdjustmentPositive();
343-
$adjustmentNegative = $creditmemo->getAdjustmentNegative();
340+
$orderTotal = $order->getBaseGrandTotal();
341+
$shippingApplied = $creditmemo->getBaseShippingInclTax();
342+
$adjustmentPositive = $creditmemo->getBaseAdjustmentPositive();
343+
$adjustmentNegative = $creditmemo->getBaseAdjustmentNegative();
344344
$amountCaptured = 0.00;
345345
$amountNotCaptured = 0.00;
346346
$amountToRefund = 0.00;
@@ -350,16 +350,16 @@ public function calculateRefund($payment, $amount)
350350
$refundAmountAvailable = $orderTotal - $openToCaptureAmount;
351351
$appliedDiscount = 0.00;
352352
$refundedDiscount = 0.00;
353-
$orderDiscount = $order->getCustomerBalanceAmount() + $order->getGiftCardsAmount();
353+
$orderDiscount = $order->getBaseCustomerBalanceAmount() + $order->getBaseGiftCardsAmount();
354354
$rolloverDiscount = $payment->getAdditionalInformation(\Afterpay\Afterpay\Model\Payovertime::ROLLOVER_DISCOUNT);
355355
$capturedDiscount = $orderDiscount - $rolloverDiscount;
356356
$orderShippingAmount = $order->getShippingInclTax();
357357
$actualOpenToCaptureAmount = $openToCaptureAmount - ($rolloverRefund + $rolloverAmount);
358-
$shippingRefunded = ($order->getShippingRefunded() + $order->getShippingTaxRefunded()) - $shippingApplied;
358+
$shippingRefunded = ($order->getBaseShippingRefunded() + $order->getBaseShippingTaxRefunded()) - $shippingApplied;
359359

360360
if($orderDiscount > 0){
361-
$refundedDiscount = $order->getCustomerBalanceRefunded() + $order->getGiftCardsRefunded();
362-
$appliedDiscount = $creditmemo->getCustomerBalanceAmount() + $creditmemo->getGiftCardsAmount();
361+
$refundedDiscount = $order->getBaseCustomerBalanceRefunded() + $order->getBaseGiftCardsRefunded();
362+
$appliedDiscount = $creditmemo->getBaseCustomerBalanceAmount() + $creditmemo->getBaseGiftCardsAmount();
363363
}
364364

365365
foreach ($creditmemo->getAllItems() as $item) {
@@ -512,7 +512,6 @@ public function calculateRefund($payment, $amount)
512512
if($storeCredit > 0){
513513
$storeCredit = $storeCredit + $order->getBaseCustomerBalanceRefunded();
514514
$order->setBaseCustomerBalanceRefunded($storeCredit);
515-
$order->setCustomerBalanceRefunded($storeCredit);
516515
}
517516

518517
}
@@ -546,7 +545,7 @@ public function lastShipmentProcessRefund($payment, $amount)
546545
}
547546
elseif($afterpayPaymentStatus == self::PAYMENT_STATUS_PARTIALLY_CAPTURED || $afterpayPaymentStatus == self::PAYMENT_STATUS_AUTH_APPROVED){
548547

549-
$orderTotal = $order->getGrandTotal();
548+
$orderTotal = $order->getBaseGrandTotal();
550549
$openToCaptureAmount = $payment->getAdditionalInformation(\Afterpay\Afterpay\Model\Payovertime::OPEN_TOCAPTURE_AMOUNT);
551550
$rolloverRefund = $payment->getAdditionalInformation(\Afterpay\Afterpay\Model\Payovertime::ROLLOVER_REFUND);
552551
$refundAmountAvailable = $orderTotal - $openToCaptureAmount;
@@ -596,7 +595,7 @@ public function afterpayProcessRefund($payment,$order,$amountToCapture,$afterpay
596595
$merchant_order_id = $order->getIncrementId();
597596
$totalAmount= [
598597
'amount' => number_format($amountToCapture, 2, '.', ''),
599-
'currency' => $order->getOrderCurrencyCode()
598+
'currency' => $order->getBaseCurrencyCode()
600599
];
601600

602601
$captureResponse = $this->paymentCapture->send($totalAmount,$merchant_order_id,$orderId,$override);
@@ -617,7 +616,7 @@ public function afterpayProcessRefund($payment,$order,$amountToCapture,$afterpay
617616
//Refund reqest
618617
if($afterpayRefund && $amount > 0){
619618

620-
$refundResponse = $this->afterpayApiPayment->refund(number_format($amount, 2, '.', ''),$orderId,$order->getOrderCurrencyCode(),$override);
619+
$refundResponse = $this->afterpayApiPayment->refund(number_format($amount, 2, '.', ''),$orderId,$order->getBaseCurrencyCode(),$override);
621620

622621
$refundResponse = $this->jsonHelper->jsonDecode($refundResponse->getBody());
623622

@@ -666,12 +665,12 @@ public function afterpayProcessRefund($payment,$order,$amountToCapture,$afterpay
666665
public function calculateItemPrice($item,$qty){
667666
$totalQtyOrdered = $item->getQtyOrdered();
668667
$totalTaxAmount = $item->getBaseTaxAmount();
669-
$totalDiscount = $item->getDiscountAmount();
668+
$totalDiscount = $item->getBaseDiscountAmount();
670669

671670
$taxPerItem = $totalTaxAmount/$totalQtyOrdered;
672671
$discountPerItem = $totalDiscount / $totalQtyOrdered;
673672

674-
$pricePerItem = $item->getPrice() + $taxPerItem;
673+
$pricePerItem = $item->getBasePrice() + $taxPerItem;
675674
$itemPrice = $qty * ($pricePerItem - $discountPerItem);
676675
return $itemPrice;
677676
}

Observer/BeforeShipment.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ public function execute(\Magento\Framework\Event\Observer $observer)
5555
$rolloverAmount = $payment->getAdditionalInformation(\Afterpay\Afterpay\Model\Payovertime::ROLLOVER_AMOUNT);
5656
$rolloverRefund = $payment->getAdditionalInformation(\Afterpay\Afterpay\Model\Payovertime::ROLLOVER_REFUND);
5757

58-
if($order->getShippingInclTax() > 0 && $order->getShipmentsCollection()->count()==0){
59-
$shippingAmount = $order->getShippingInclTax();
58+
if($order->getBaseShippingInclTax() > 0 && $order->getShipmentsCollection()->count()==0){
59+
$shippingAmount = $order->getBaseShippingInclTax();
6060

61-
if($order->getShippingRefunded() > 0)
61+
if($order->getBaseShippingRefunded() > 0)
6262
{
63-
$shippingAmount = $shippingAmount - ($order->getShippingRefunded() + $order->getShippingTaxRefunded());
63+
$shippingAmount = $shippingAmount - ($order->getBaseShippingRefunded() + $order->getBaseShippingTaxRefunded());
6464
}
6565
$totalCaptureAmount = $totalCaptureAmount + $shippingAmount;
6666
}
@@ -86,7 +86,6 @@ public function execute(\Magento\Framework\Event\Observer $observer)
8686

8787
if($totalDiscountAmount!=0){
8888
if($totalCaptureAmount >= $totalDiscountAmount){
89-
$this->_helper->debug("totalDiscountAmount : ".$totalDiscountAmount);
9089
$totalCaptureAmount = $totalCaptureAmount - $totalDiscountAmount;
9190
$totalDiscountAmount = 0.00;
9291
}
@@ -101,7 +100,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
101100
if($totalCaptureAmount > 1){
102101
$afterpay_order_id = $payment->getAdditionalInformation(\Afterpay\Afterpay\Model\Payovertime::ADDITIONAL_INFORMATION_KEY_ORDERID);
103102
$merchant_order_id = $order->getIncrementId();
104-
$currencyCode = $order->getOrderCurrencyCode();
103+
$currencyCode = $order->getBaseCurrencyCode();
105104
$override = ["website_id" => $payment->getOrder()->getStore()->getWebsiteId()];
106105

107106
$totalAmount= [
@@ -142,4 +141,4 @@ public function execute(\Magento\Framework\Event\Observer $observer)
142141
}
143142
}
144143
}
145-
?>
144+
?>

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ Complete the below steps to configure the merchant’s Afterpay Merchant Credent
6565
<li> In CLI, run the below command to update Afterpay module:
6666
<br/>The right installation command is dependent on your Magento 2 version:
6767

68+
6869
| Magento version | Command to run |
6970
|-----------------|-------------------------------------------------------------|
7071
| 2.4.* | composer require afterpay-global/module-afterpay:^5 |
7172
| 2.3.* | composer require afterpay-global/module-afterpay:^4 |
7273
| < 2.3.0 | composer require afterpay-global/module-afterpay:^3 |
73-
</li>
74+
75+
</li>
7476
<li> Make sure that Composer finished the update without errors </li>
7577
<li> Run Magento install/upgrade scripts: <code><em>php bin/magento setup:upgrade</em></code> </li>
7678
<li> Compile dependency injection: <code><em>php bin/magento setup:di:compile</em></code> </li>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"license" : "OSL-3.0",
44
"type" : "magento2-module",
55
"description" : "Magento 2 Afterpay Payment Module",
6-
"version" : "3.4.4",
6+
"version" : "3.4.5",
77
"authors" : [{
88
"name" : "Afterpay",
99
"homepage" : "https://www.afterpay.com"

0 commit comments

Comments
 (0)