diff --git a/Block/Config.php b/Block/Config.php
index 8c4aa0c..3b21ac0 100644
--- a/Block/Config.php
+++ b/Block/Config.php
@@ -59,7 +59,7 @@ public function getAfterpayJsUrl()
*/
public function checkCurrency()
{
- $supportedCurrency=['AUD','NZD','USD'];
+ $supportedCurrency=['AUD','NZD','USD','CAD'];
if(in_array($this->_payOverTime->getCurrencyCode(),$supportedCurrency)){
return true;
}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1cb6339..d4cd22f 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,27 @@
# Afterpay Magento 2 Extension Changelog
+## Version 3.1.4
+
+_Fri 26 Jun 2020_
+
+### Supported Editions & Versions
+
+Tested and verified in clean installations of Magento 2:
+
+- Magento Community Edition (CE) version 2.3.5-p1
+- Magento Enterprise Edition (EE) version 2.3.5-p1
+
+### Highlights
+
+- Improved reliability of logo display on cart page for high resolution mobile screens.
+- Improved billing and shipping address validation at checkout.
+- Improved Restricted Categories feature to better support multiple store views.
+- Further improved compatibility with offline refunds.
+- Added preliminary Sandbox support for transactions in CAD.
+- Added a fix to prevent duplicate order emails.
+
+---
+
## Version 3.1.3
_Wed 20 May 2020_
diff --git a/Controller/Payment/Process.php b/Controller/Payment/Process.php
index 8b803e4..679ae00 100644
--- a/Controller/Payment/Process.php
+++ b/Controller/Payment/Process.php
@@ -107,48 +107,7 @@ public function _processAuthorizeCapture()
// customer login
$quote->setCustomer($customer);
-
- $billingAddress = $quote->getBillingAddress();
- $shippingAddress = $quote->getShippingAddress();
-
- //check if shipping address is missing - e.g. Gift Cards
- if ((empty($shippingAddress) || empty($shippingAddress->getStreetLine(1))) && (empty($billingAddress) || empty($billingAddress->getStreetLine(1)))) {
-
- //Handle the virtual products
- if($quote->isVirtual()){
- try{
- $billingID = $customerSession->getCustomer()->getDefaultBilling();
- $this->_helper->debug("No billing address for the virtual product. Adding the Customer's default billing address.");
- $address = $objectManager->create('Magento\Customer\Model\Address')->load($billingID);
- $billingAddress->addData($address->getData());
-
- }catch(\Exception $e){
- $this->_helper->debug($e->getMessage());
- $result = $this->_jsonResultFactory->create()->setData(
- ['success' => false, 'message' => 'Please select an Address']
- );
-
- return $result;
- }
- }else{
- $result = $this->_jsonResultFactory->create()->setData(
- ['success' => false, 'message' => 'Please select an Address']
- );
-
- return $result;
- }
-
- }
- elseif (empty($billingAddress) || empty($billingAddress->getStreetLine(1)) || empty($billingAddress->getFirstname())) {
-
- $billingAddress = $quote->getShippingAddress();
- $quote->setBillingAddress($quote->getShippingAddress());
- $this->_helper->debug("No billing address found. Adding the shipping address as billing address");
-
- // Above code copies the shipping address to billing address with the 'address_type' ='shipping', which results in problem with order creating.
-
- $billingAddress->addData(array('address_type'=>'billing'));
- }
+
} else {
$post = $this->getRequest()->getPostValue();
@@ -169,7 +128,87 @@ public function _processAuthorizeCapture()
}
}
}
+
+ $billingAddress = $quote->getBillingAddress();
+ $shippingAddress = $quote->getShippingAddress();
+
+ if (empty($billingAddress) || empty($billingAddress->getStreetLine(1)) || empty($billingAddress->getFirstname())) {
+ if(!empty($shippingAddress) && !empty($shippingAddress->getStreetLine(1)))
+ {
+ $shippingAddressData = $shippingAddress->getData();
+ $billingAddress->setPrefix($shippingAddressData['prefix']);
+ $billingAddress->setFirstName($shippingAddressData['firstname']);
+ $billingAddress->setMiddleName($shippingAddressData['middlename']);
+ $billingAddress->setLastName($shippingAddressData['lastname']);
+ $billingAddress->setSuffix($shippingAddressData['suffix']);
+ $billingAddress->setCompany($shippingAddressData['company']);
+ $billingAddress->setStreet($shippingAddressData['street']);
+ $billingAddress->setCity($shippingAddressData['city']);
+ $billingAddress->setRegion($shippingAddressData['region']);
+ $billingAddress->setRegionId($shippingAddressData['region_id']);
+ $billingAddress->setPostcode($shippingAddressData['postcode']);
+ $billingAddress->setCountryId($shippingAddressData['country_id']);
+ $billingAddress->setTelephone($shippingAddressData['telephone']);
+ $billingAddress->setFax($shippingAddressData['fax']);
+ $this->_helper->debug("No billing address found. Adding the shipping address as billing address");
+ }
+ else{
+ if($customerSession->isLoggedIn()){
+ try{
+ $billingID = $customerSession->getCustomer()->getDefaultBilling();
+ $this->_helper->debug("No billing address found. Adding the Customer's default billing address.");
+ $address = $objectManager->create('Magento\Customer\Model\Address')->load($billingID);
+ $billingAddress->addData($address->getData());
+
+ }catch(\Exception $e){
+ $this->_helper->debug($e->getMessage());
+ $result = $this->_jsonResultFactory->create()->setData(
+ ['success' => false, 'message' => 'Please select an Address']
+ );
+ return $result;
+ }
+ }
+ else{
+ $result = $this->_jsonResultFactory->create()->setData(
+ ['success' => false, 'message' => 'Please select an Address']
+ );
+
+ return $result;
+ }
+ }
+ }
+
+ if((empty($shippingAddress) || empty($shippingAddress->getStreetLine(1))) && !$quote->isVirtual()){
+ $billingAddress = $quote->getBillingAddress();
+ if(!empty($billingAddress) && !empty($billingAddress->getStreetLine(1)))
+ {
+ $billingAddressData = $billingAddress->getData();
+ $shippingAddress->setPrefix($billingAddressData['prefix']);
+ $shippingAddress->setFirstName($billingAddressData['firstname']);
+ $shippingAddress->setMiddleName($billingAddressData['middlename']);
+ $shippingAddress->setLastName($billingAddressData['lastname']);
+ $shippingAddress->setSuffix($billingAddressData['suffix']);
+ $shippingAddress->setCompany($billingAddressData['company']);
+ $shippingAddress->setStreet($billingAddressData['street']);
+ $shippingAddress->setCity($billingAddressData['city']);
+ $shippingAddress->setRegion($billingAddressData['region']);
+ $shippingAddress->setRegionId($billingAddressData['region_id']);
+ $shippingAddress->setPostcode($billingAddressData['postcode']);
+ $shippingAddress->setCountryId($billingAddressData['country_id']);
+ $shippingAddress->setTelephone($billingAddressData['telephone']);
+ $shippingAddress->setFax($billingAddressData['fax']);
+ $this->_helper->debug("No shipping address found. Adding the billing address as shipping address");
+ }
+ else{
+ $result = $this->_jsonResultFactory->create()->setData(
+ ['success' => false, 'message' => 'Please select an Address']
+ );
+
+ return $result;
+ }
+ }
+
$payment = $quote->getPayment();
$payment->setMethod(\Afterpay\Afterpay\Model\Payovertime::METHOD_CODE);
diff --git a/Controller/Payment/Response.php b/Controller/Payment/Response.php
index d13f147..649a3f0 100644
--- a/Controller/Payment/Response.php
+++ b/Controller/Payment/Response.php
@@ -306,16 +306,6 @@ private function _processAuthCapture($query)
$this->_createTransaction($order, $response,$payment);
- //email sending mechanism
- $redirectUrl = $quote->getPayment()->getOrderPlaceRedirectUrl();
- if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
- try {
- $this->_orderSender->send($order);
- } catch (\Exception $e) {
- $this->_helper->debug("Transaction Email Sending Error: " . json_encode($e));
- }
- }
-
$this->messageManager->addSuccess("Afterpay Transaction Completed");
$redirect = 'checkout/onepage/success';
diff --git a/Helper/Category.php b/Helper/Category.php
new file mode 100644
index 0000000..2f7b196
--- /dev/null
+++ b/Helper/Category.php
@@ -0,0 +1,59 @@
+_storeManager->getStore($storeId)->getRootCategoryId();
+ $cacheKey = sprintf('%d-%d-%d-%d', $parent, $sorted, $asCollection, $toLoad);
+ if (isset($this->_storeCategories[$cacheKey])) {
+ return $this->_storeCategories[$cacheKey];
+ }
+
+ /**
+ * Check if parent node of the store still exists
+ */
+ $category = $this->_categoryFactory->create();
+ /* @var $category ModelCategory */
+ if (!$category->checkId($parent)) {
+ if ($asCollection) {
+ return $this->_dataCollectionFactory->create();
+ }
+ return [];
+ }
+
+ $recursionLevel = max(
+ 0,
+ (int)$this->scopeConfig->getValue(
+ 'catalog/navigation/max_depth',
+ \Magento\Store\Model\ScopeInterface::SCOPE_STORE
+ )
+ );
+ $storeCategories = $category->getCategories($parent, $recursionLevel, $sorted, $asCollection, $toLoad);
+
+ $this->_storeCategories[$cacheKey] = $storeCategories;
+ return $storeCategories;
+ }
+}
diff --git a/Model/Config/Payovertime.php b/Model/Config/Payovertime.php
index 1ffe598..609cf86 100644
--- a/Model/Config/Payovertime.php
+++ b/Model/Config/Payovertime.php
@@ -174,13 +174,13 @@ public function getSiteConfig($apiMode, $type, $websiteId)
if ($type=='api_url') {
if ($apiMode == 'Sandbox') {
- if ($currency == 'USD') {
+ if ($currency == 'USD' || $currency == 'CAD') {
$url = 'https://api.us-sandbox.afterpay.com/';
} else {
$url = 'https://api-sandbox.afterpay.com/';
}
} elseif ($apiMode == 'Production') {
- if ($currency == 'USD') {
+ if ($currency == 'USD' || $currency == 'CAD') {
$url = 'https://api.us.afterpay.com/';
} else {
$url = 'https://api.afterpay.com/';
diff --git a/Model/Config/Source/Categorylist.php b/Model/Config/Source/Categorylist.php
index 10bdfda..2ced260 100644
--- a/Model/Config/Source/Categorylist.php
+++ b/Model/Config/Source/Categorylist.php
@@ -8,14 +8,20 @@ class Categorylist implements ArrayInterface
protected $_categoryHelper;
protected $categoryRepository;
protected $categoryList;
+ protected $_request;
+ protected $_storeManager;
public function __construct(
- \Magento\Catalog\Helper\Category $catalogCategory,
- \Magento\Catalog\Model\CategoryRepository $categoryRepository
+ \Afterpay\Afterpay\Helper\Category $catalogCategory,
+ \Magento\Catalog\Model\CategoryRepository $categoryRepository,
+ \Magento\Framework\App\Request\Http $request,
+ \Magento\Store\Model\StoreManagerInterface $storeManager
)
{
$this->_categoryHelper = $catalogCategory;
$this->categoryRepository = $categoryRepository;
+ $this->_request = $request;
+ $this->_storeManager = $storeManager;
}
/*
@@ -24,7 +30,18 @@ public function __construct(
public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true)
{
- return $this->_categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad);
+ $storeId = (int) $this->_request->getParam('store', 0);
+ if (!isset($storeId) || empty($storeId)){
+ $storeId=$this->_storeManager->getStore()->getId();
+ $websiteId = (int) $this->_request->getParam('website', 0);
+
+ if(isset($websiteId) && !empty($websiteId)){
+ $storeId = $this->_storeManager->getWebsite($websiteId)->getDefaultStore()->getId();
+ }
+ }
+
+ return $this->_categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad,$storeId);
+
}
/*
@@ -63,9 +80,11 @@ public function toArray()
public function renderCategories($_categories)
{
foreach ($_categories as $category){
- $i = 0;
- $this->categoryList[$category->getEntityId()] = __($category->getName()); // Main categories
- $list = $this->renderSubCat($category,$i);
+ if($category->getEntityId()!= '1'){
+ $i = 0;
+ $this->categoryList[$category->getEntityId()] = __($category->getName()); // Main categories
+ $list = $this->renderSubCat($category,$i);
+ }
}
return $this->categoryList;
diff --git a/Model/Payovertime.php b/Model/Payovertime.php
index 606a2c2..52b2919 100644
--- a/Model/Payovertime.php
+++ b/Model/Payovertime.php
@@ -54,7 +54,7 @@ class Payovertime extends \Magento\Payment\Model\Method\AbstractMethod
/**
* For dependency injection
*/
- protected $supportedCurrencyCodes = ['AUD','NZD','USD'];
+ protected $supportedCurrencyCodes = ['AUD','NZD','USD','CAD'];
protected $afterPayPaymentTypeCode = self::AFTERPAY_PAYMENT_TYPE_CODE;
protected $logger;
diff --git a/assets.ini b/assets.ini
index 6940f2a..1f1646c 100644
--- a/assets.ini
+++ b/assets.ini
@@ -30,4 +30,16 @@
cart_page1 = "Check out with Afterpay and pay by instalment.
Simply pay 4 fortnightly instalments of "
cart_page2 = "
Use your payment card, instant approval.
- "
\ No newline at end of file
+ "
+
+[CAD]
+ name = "CA"
+ product_page1 = "or 4 installments of "
+ product_page2 = 'by
'
+ product_page_from = "or 4 installments from "
+ cart_page1 = "Check out with Afterpay and pay by installments.
+ Pay 4 installments of "
+ cart_page2 = "
Use your payment card, approval decision online.
+ "
+
+
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 3d8599a..3cdaedf 100644
--- a/composer.json
+++ b/composer.json
@@ -1,23 +1,20 @@
{
- "name": "afterpay-global/module-afterpay",
- "license": "OSL-3.0",
- "type": "magento2-module",
- "description": "Magento 2 Afterpay Payment Module",
- "version": "3.1.3",
- "require": {
- },
- "authors":[
- {
- "name":"Afterpay",
- "homepage":"https://www.afterpay.com"
- }
- ],
- "autoload": {
- "files": [
- "registration.php"
- ],
- "psr-4": {
- "Afterpay\\Afterpay\\": ""
- }
- }
-}
\ No newline at end of file
+ "name" : "afterpay-global/module-afterpay",
+ "license" : "OSL-3.0",
+ "type" : "magento2-module",
+ "description" : "Magento 2 Afterpay Payment Module",
+ "version" : "3.1.4",
+ "authors" : [{
+ "name" : "Afterpay",
+ "homepage" : "https://www.afterpay.com"
+ }
+ ],
+ "autoload" : {
+ "files" : [
+ "registration.php"
+ ],
+ "psr-4" : {
+ "Afterpay\\Afterpay\\" : ""
+ }
+ }
+}
diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml
index 9e2f5cc..39f803c 100644
--- a/etc/adminhtml/di.xml
+++ b/etc/adminhtml/di.xml
@@ -11,4 +11,5 @@
-
\ No newline at end of file
+
+
diff --git a/etc/di.xml b/etc/di.xml
index 56e815f..315850c 100644
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -20,7 +20,7 @@
- Production
- https://api.afterpay.com/
- https://portal.afterpay.com/
-
+
diff --git a/etc/module.xml b/etc/module.xml
index 1d406cf..8e86f0d 100644
--- a/etc/module.xml
+++ b/etc/module.xml
@@ -8,7 +8,7 @@
*/
-->
-
+
diff --git a/view/frontend/templates/afterpay/cart.phtml b/view/frontend/templates/afterpay/cart.phtml
index c22bf5e..ca4cd96 100644
--- a/view/frontend/templates/afterpay/cart.phtml
+++ b/view/frontend/templates/afterpay/cart.phtml
@@ -19,6 +19,6 @@
diff --git a/view/frontend/templates/afterpay/modal.phtml b/view/frontend/templates/afterpay/modal.phtml
index 0172372..1fb58d6 100644
--- a/view/frontend/templates/afterpay/modal.phtml
+++ b/view/frontend/templates/afterpay/modal.phtml
@@ -30,7 +30,7 @@ if(!$enable_cbt){
var enable_cbt=;
var width=$(window).width();
- if(storeCurrency=="USD" && !$("#afterpay-modal-container").length){
+ if((storeCurrency=="USD" || storeCurrency=="CAD") && !$("#afterpay-modal-container").length){
$('head').append('');
$.ajax({
url: 'https://static.afterpay.com/modal/us.html',
@@ -76,12 +76,22 @@ if(!$enable_cbt){
// register the click to be popup
$( ".afterpay-modal-popup-trigger-us" ).on( "click", function() {
+
if($("#afterpay-modal-container").length!=0){
var popup_us = modal(options, $('#afterpay-modal-content'));
$('#afterpay-modal-content').show();
$('#afterpay-modal-content').modal('openModal');
}
});
+
+ // Register the click to be popup the modal for Canada
+ $( ".afterpay-modal-popup-trigger-ca" ).on( "click", function() {
+ if($("#afterpay-modal-container").length!=0){
+ var popup_ca = modal(options, $('#afterpay-modal-content'));
+ $('#afterpay-modal-content').show();
+ $('#afterpay-modal-content').modal('openModal');
+ }
+ });
}
);
diff --git a/view/frontend/web/js/view/payment/method-renderer/afterpaypayovertime.js b/view/frontend/web/js/view/payment/method-renderer/afterpaypayovertime.js
index aa828b0..5ce5110 100644
--- a/view/frontend/web/js/view/payment/method-renderer/afterpaypayovertime.js
+++ b/view/frontend/web/js/view/payment/method-renderer/afterpaypayovertime.js
@@ -18,9 +18,10 @@ define(
'Magento_Ui/js/model/messageList',
'Magento_Customer/js/customer-data',
'Magento_Customer/js/section-config',
+ 'Magento_Checkout/js/action/set-billing-address',
'Afterpay_Afterpay/js/view/payment/method-renderer/afterpayredirect'
],
- function ($, Component, quote, resourceUrlManager, storage, mageUrl, additionalValidators, globalMessageList, customerData, sectionConfig, afterpayRedirect) {
+ function ($, Component, quote, resourceUrlManager, storage, mageUrl, additionalValidators, globalMessageList, customerData, sectionConfig,setBillingAddressAction,afterpayRedirect) {
'use strict';
return Component.extend({
@@ -61,7 +62,7 @@ define(
$(".afterpay_instalments_amount_last").text(format.replace(/%s/g, installmentFeeLast.toFixed(window.checkoutConfig.priceFormat.precision)));
- if (afterpay.currencyCode == 'USD') {
+ if (afterpay.currencyCode == 'USD' || afterpay.currencyCode == 'CAD' ) {
$(".afterpay_total_amount").text(format.replace(/%s/g, installmentFee.toFixed(window.checkoutConfig.priceFormat.precision)));
return format.replace(/%s/g, installmentFee);
} else {
@@ -92,7 +93,7 @@ define(
afterpayCheckoutText = 'Four interest-free payments totalling';
} else if (afterpay.currencyCode == 'NZD') {
afterpayCheckoutText = 'Four interest-free payments totalling';
- } else if (afterpay.currencyCode == 'USD') {
+ } else if (afterpay.currencyCode == 'USD' || afterpay.currencyCode == 'CAD') {
afterpayCheckoutText = '4 interest-free installments of';
}
@@ -102,7 +103,7 @@ define(
var afterpay = window.checkoutConfig.payment.afterpay;
var afterpayFirstInstalmentText = '';
- if (afterpay.currencyCode == 'USD') {
+ if (afterpay.currencyCode == 'USD' || afterpay.currencyCode == 'CAD') {
afterpayFirstInstalmentText = 'Due today';
}
else {
@@ -115,7 +116,7 @@ define(
var afterpay = window.checkoutConfig.payment.afterpay;
var afterpayTermsText = '';
- if (afterpay.currencyCode == 'USD') {
+ if (afterpay.currencyCode == 'USD' || afterpay.currencyCode == 'CAD') {
afterpayTermsText = 'You will be redirected to the Afterpay website to fill out your payment information. You will be redirected back to our site to complete your order.';
}
else {
@@ -129,7 +130,7 @@ define(
var afterpay = window.checkoutConfig.payment.afterpay;
var afterpayCheckoutTermsText = '';
- if (afterpay.currencyCode == 'USD') {
+ if (afterpay.currencyCode == 'USD' || afterpay.currencyCode == 'CAD') {
return -1;
}
@@ -139,7 +140,7 @@ define(
var afterpay = window.checkoutConfig.payment.afterpay;
var afterpayCheckoutTermsLink = '';
- if (afterpay.currencyCode == 'USD') {
+ if (afterpay.currencyCode == 'USD' || afterpay.currencyCode == 'CAD') {
afterpayCheckoutTermsLink="https://www.afterpay.com/purchase-payment-agreement";
}
else{
@@ -185,7 +186,12 @@ define(
countryCode = {countryCode: "NZ"};
} else if (afterpay.currencyCode == 'USD') {
countryCode = {countryCode: "US"};
+ }else if (afterpay.currencyCode == 'CAD') {
+ countryCode = {countryCode: "CA"};
}
+
+ //Update billing address of the quote
+ setBillingAddressAction(globalMessageList);
//handle guest and registering customer emails
if (!window.checkoutConfig.quoteData.customer_id) {
@@ -258,6 +264,9 @@ define(
// Making sure it using current flow
var url = mageUrl.build("afterpay/payment/process");
+
+ //Update billing address of the quote
+ setBillingAddressAction(globalMessageList);
$.ajax({
url: url,