Skip to content

Commit 63d9c05

Browse files
Release version 3.1.4
1 parent 1efa79d commit 63d9c05

File tree

16 files changed

+255
-97
lines changed

16 files changed

+255
-97
lines changed

Block/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function getAfterpayJsUrl()
5959
*/
6060
public function checkCurrency()
6161
{
62-
$supportedCurrency=['AUD','NZD','USD'];
62+
$supportedCurrency=['AUD','NZD','USD','CAD'];
6363
if(in_array($this->_payOverTime->getCurrencyCode(),$supportedCurrency)){
6464
return true;
6565
}

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# Afterpay Magento 2 Extension Changelog
22

3+
## Version 3.1.4
4+
5+
_Fri 26 Jun 2020_
6+
7+
### Supported Editions & Versions
8+
9+
Tested and verified in clean installations of Magento 2:
10+
11+
- Magento Community Edition (CE) version 2.3.5-p1
12+
- Magento Enterprise Edition (EE) version 2.3.5-p1
13+
14+
### Highlights
15+
16+
- Improved reliability of logo display on cart page for high resolution mobile screens.
17+
- Improved billing and shipping address validation at checkout.
18+
- Improved Restricted Categories feature to better support multiple store views.
19+
- Further improved compatibility with offline refunds.
20+
- Added preliminary Sandbox support for transactions in CAD.
21+
- Added a fix to prevent duplicate order emails.
22+
23+
---
24+
325
## Version 3.1.3
426

527
_Wed 20 May 2020_

Controller/Payment/Process.php

Lines changed: 81 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -107,48 +107,7 @@ public function _processAuthorizeCapture()
107107

108108
// customer login
109109
$quote->setCustomer($customer);
110-
111-
$billingAddress = $quote->getBillingAddress();
112-
$shippingAddress = $quote->getShippingAddress();
113-
114-
//check if shipping address is missing - e.g. Gift Cards
115-
if ((empty($shippingAddress) || empty($shippingAddress->getStreetLine(1))) && (empty($billingAddress) || empty($billingAddress->getStreetLine(1)))) {
116-
117-
//Handle the virtual products
118-
if($quote->isVirtual()){
119-
try{
120-
$billingID = $customerSession->getCustomer()->getDefaultBilling();
121-
$this->_helper->debug("No billing address for the virtual product. Adding the Customer's default billing address.");
122-
$address = $objectManager->create('Magento\Customer\Model\Address')->load($billingID);
123-
$billingAddress->addData($address->getData());
124-
125-
}catch(\Exception $e){
126-
$this->_helper->debug($e->getMessage());
127-
$result = $this->_jsonResultFactory->create()->setData(
128-
['success' => false, 'message' => 'Please select an Address']
129-
);
130-
131-
return $result;
132-
}
133-
}else{
134-
$result = $this->_jsonResultFactory->create()->setData(
135-
['success' => false, 'message' => 'Please select an Address']
136-
);
137-
138-
return $result;
139-
}
140-
141-
}
142-
elseif (empty($billingAddress) || empty($billingAddress->getStreetLine(1)) || empty($billingAddress->getFirstname())) {
143-
144-
$billingAddress = $quote->getShippingAddress();
145-
$quote->setBillingAddress($quote->getShippingAddress());
146-
$this->_helper->debug("No billing address found. Adding the shipping address as billing address");
147-
148-
// Above code copies the shipping address to billing address with the 'address_type' ='shipping', which results in problem with order creating.
149-
150-
$billingAddress->addData(array('address_type'=>'billing'));
151-
}
110+
152111
} else {
153112
$post = $this->getRequest()->getPostValue();
154113

@@ -169,7 +128,87 @@ public function _processAuthorizeCapture()
169128
}
170129
}
171130
}
131+
132+
$billingAddress = $quote->getBillingAddress();
133+
$shippingAddress = $quote->getShippingAddress();
134+
135+
if (empty($billingAddress) || empty($billingAddress->getStreetLine(1)) || empty($billingAddress->getFirstname())) {
136+
if(!empty($shippingAddress) && !empty($shippingAddress->getStreetLine(1)))
137+
{
138+
$shippingAddressData = $shippingAddress->getData();
139+
$billingAddress->setPrefix($shippingAddressData['prefix']);
140+
$billingAddress->setFirstName($shippingAddressData['firstname']);
141+
$billingAddress->setMiddleName($shippingAddressData['middlename']);
142+
$billingAddress->setLastName($shippingAddressData['lastname']);
143+
$billingAddress->setSuffix($shippingAddressData['suffix']);
144+
$billingAddress->setCompany($shippingAddressData['company']);
145+
$billingAddress->setStreet($shippingAddressData['street']);
146+
$billingAddress->setCity($shippingAddressData['city']);
147+
$billingAddress->setRegion($shippingAddressData['region']);
148+
$billingAddress->setRegionId($shippingAddressData['region_id']);
149+
$billingAddress->setPostcode($shippingAddressData['postcode']);
150+
$billingAddress->setCountryId($shippingAddressData['country_id']);
151+
$billingAddress->setTelephone($shippingAddressData['telephone']);
152+
$billingAddress->setFax($shippingAddressData['fax']);
153+
$this->_helper->debug("No billing address found. Adding the shipping address as billing address");
154+
}
155+
else{
156+
if($customerSession->isLoggedIn()){
157+
try{
158+
$billingID = $customerSession->getCustomer()->getDefaultBilling();
159+
$this->_helper->debug("No billing address found. Adding the Customer's default billing address.");
160+
$address = $objectManager->create('Magento\Customer\Model\Address')->load($billingID);
161+
$billingAddress->addData($address->getData());
162+
163+
}catch(\Exception $e){
164+
$this->_helper->debug($e->getMessage());
165+
$result = $this->_jsonResultFactory->create()->setData(
166+
['success' => false, 'message' => 'Please select an Address']
167+
);
172168

169+
return $result;
170+
}
171+
}
172+
else{
173+
$result = $this->_jsonResultFactory->create()->setData(
174+
['success' => false, 'message' => 'Please select an Address']
175+
);
176+
177+
return $result;
178+
}
179+
}
180+
}
181+
182+
if((empty($shippingAddress) || empty($shippingAddress->getStreetLine(1))) && !$quote->isVirtual()){
183+
$billingAddress = $quote->getBillingAddress();
184+
if(!empty($billingAddress) && !empty($billingAddress->getStreetLine(1)))
185+
{
186+
$billingAddressData = $billingAddress->getData();
187+
$shippingAddress->setPrefix($billingAddressData['prefix']);
188+
$shippingAddress->setFirstName($billingAddressData['firstname']);
189+
$shippingAddress->setMiddleName($billingAddressData['middlename']);
190+
$shippingAddress->setLastName($billingAddressData['lastname']);
191+
$shippingAddress->setSuffix($billingAddressData['suffix']);
192+
$shippingAddress->setCompany($billingAddressData['company']);
193+
$shippingAddress->setStreet($billingAddressData['street']);
194+
$shippingAddress->setCity($billingAddressData['city']);
195+
$shippingAddress->setRegion($billingAddressData['region']);
196+
$shippingAddress->setRegionId($billingAddressData['region_id']);
197+
$shippingAddress->setPostcode($billingAddressData['postcode']);
198+
$shippingAddress->setCountryId($billingAddressData['country_id']);
199+
$shippingAddress->setTelephone($billingAddressData['telephone']);
200+
$shippingAddress->setFax($billingAddressData['fax']);
201+
$this->_helper->debug("No shipping address found. Adding the billing address as shipping address");
202+
}
203+
else{
204+
$result = $this->_jsonResultFactory->create()->setData(
205+
['success' => false, 'message' => 'Please select an Address']
206+
);
207+
208+
return $result;
209+
}
210+
}
211+
173212
$payment = $quote->getPayment();
174213

175214
$payment->setMethod(\Afterpay\Afterpay\Model\Payovertime::METHOD_CODE);

Controller/Payment/Response.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,6 @@ private function _processAuthCapture($query)
306306

307307
$this->_createTransaction($order, $response,$payment);
308308

309-
//email sending mechanism
310-
$redirectUrl = $quote->getPayment()->getOrderPlaceRedirectUrl();
311-
if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
312-
try {
313-
$this->_orderSender->send($order);
314-
} catch (\Exception $e) {
315-
$this->_helper->debug("Transaction Email Sending Error: " . json_encode($e));
316-
}
317-
}
318-
319309
$this->messageManager->addSuccess("Afterpay Transaction Completed");
320310

321311
$redirect = 'checkout/onepage/success';

Helper/Category.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Magento 2 extensions for Afterpay Payment
4+
*
5+
* @author Afterpay
6+
* @copyright 2016-2020 Afterpay https://www.afterpay.com
7+
*/
8+
namespace Afterpay\Afterpay\Helper;
9+
10+
/**
11+
* Catalog category helper
12+
*
13+
* @SuppressWarnings(PHPMD.LongVariable)
14+
*/
15+
class Category extends \Magento\Catalog\Helper\Category
16+
{
17+
18+
/**
19+
* Retrieve current store categories
20+
*
21+
* @param bool|string $sorted
22+
* @param bool $asCollection
23+
* @param bool $toLoad
24+
* @return \Magento\Framework\Data\Tree\Node\Collection or
25+
* \Magento\Catalog\Model\ResourceModel\Category\Collection or array
26+
*/
27+
public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true,$storeId = 1)
28+
{
29+
$parent = $this->_storeManager->getStore($storeId)->getRootCategoryId();
30+
$cacheKey = sprintf('%d-%d-%d-%d', $parent, $sorted, $asCollection, $toLoad);
31+
if (isset($this->_storeCategories[$cacheKey])) {
32+
return $this->_storeCategories[$cacheKey];
33+
}
34+
35+
/**
36+
* Check if parent node of the store still exists
37+
*/
38+
$category = $this->_categoryFactory->create();
39+
/* @var $category ModelCategory */
40+
if (!$category->checkId($parent)) {
41+
if ($asCollection) {
42+
return $this->_dataCollectionFactory->create();
43+
}
44+
return [];
45+
}
46+
47+
$recursionLevel = max(
48+
0,
49+
(int)$this->scopeConfig->getValue(
50+
'catalog/navigation/max_depth',
51+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
52+
)
53+
);
54+
$storeCategories = $category->getCategories($parent, $recursionLevel, $sorted, $asCollection, $toLoad);
55+
56+
$this->_storeCategories[$cacheKey] = $storeCategories;
57+
return $storeCategories;
58+
}
59+
}

Model/Config/Payovertime.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ public function getSiteConfig($apiMode, $type, $websiteId)
174174

175175
if ($type=='api_url') {
176176
if ($apiMode == 'Sandbox') {
177-
if ($currency == 'USD') {
177+
if ($currency == 'USD' || $currency == 'CAD') {
178178
$url = 'https://api.us-sandbox.afterpay.com/';
179179
} else {
180180
$url = 'https://api-sandbox.afterpay.com/';
181181
}
182182
} elseif ($apiMode == 'Production') {
183-
if ($currency == 'USD') {
183+
if ($currency == 'USD' || $currency == 'CAD') {
184184
$url = 'https://api.us.afterpay.com/';
185185
} else {
186186
$url = 'https://api.afterpay.com/';

Model/Config/Source/Categorylist.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@ class Categorylist implements ArrayInterface
88
protected $_categoryHelper;
99
protected $categoryRepository;
1010
protected $categoryList;
11+
protected $_request;
12+
protected $_storeManager;
1113

1214
public function __construct(
13-
\Magento\Catalog\Helper\Category $catalogCategory,
14-
\Magento\Catalog\Model\CategoryRepository $categoryRepository
15+
\Afterpay\Afterpay\Helper\Category $catalogCategory,
16+
\Magento\Catalog\Model\CategoryRepository $categoryRepository,
17+
\Magento\Framework\App\Request\Http $request,
18+
\Magento\Store\Model\StoreManagerInterface $storeManager
1519
)
1620
{
1721
$this->_categoryHelper = $catalogCategory;
1822
$this->categoryRepository = $categoryRepository;
23+
$this->_request = $request;
24+
$this->_storeManager = $storeManager;
1925
}
2026

2127
/*
@@ -24,7 +30,18 @@ public function __construct(
2430

2531
public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true)
2632
{
27-
return $this->_categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad);
33+
$storeId = (int) $this->_request->getParam('store', 0);
34+
if (!isset($storeId) || empty($storeId)){
35+
$storeId=$this->_storeManager->getStore()->getId();
36+
$websiteId = (int) $this->_request->getParam('website', 0);
37+
38+
if(isset($websiteId) && !empty($websiteId)){
39+
$storeId = $this->_storeManager->getWebsite($websiteId)->getDefaultStore()->getId();
40+
}
41+
}
42+
43+
return $this->_categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad,$storeId);
44+
2845
}
2946

3047
/*
@@ -63,9 +80,11 @@ public function toArray()
6380
public function renderCategories($_categories)
6481
{
6582
foreach ($_categories as $category){
66-
$i = 0;
67-
$this->categoryList[$category->getEntityId()] = __($category->getName()); // Main categories
68-
$list = $this->renderSubCat($category,$i);
83+
if($category->getEntityId()!= '1'){
84+
$i = 0;
85+
$this->categoryList[$category->getEntityId()] = __($category->getName()); // Main categories
86+
$list = $this->renderSubCat($category,$i);
87+
}
6988
}
7089

7190
return $this->categoryList;

Model/Payovertime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Payovertime extends \Magento\Payment\Model\Method\AbstractMethod
5454
/**
5555
* For dependency injection
5656
*/
57-
protected $supportedCurrencyCodes = ['AUD','NZD','USD'];
57+
protected $supportedCurrencyCodes = ['AUD','NZD','USD','CAD'];
5858
protected $afterPayPaymentTypeCode = self::AFTERPAY_PAYMENT_TYPE_CODE;
5959

6060
protected $logger;

assets.ini

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,16 @@
3030
cart_page1 = "Check out with Afterpay and pay by instalment.</span>
3131
<span>Simply pay 4 fortnightly instalments of "
3232
cart_page2 = "<br> Use your payment card, instant approval.</span>
33-
<span><a href="[modal-href]" class="afterpay-modal-popup-trigger">Learn more</a></span>"
33+
<span><a href="[modal-href]" class="afterpay-modal-popup-trigger">Learn more</a></span>"
34+
35+
[CAD]
36+
name = "CA"
37+
product_page1 = "or 4 installments of "
38+
product_page2 = 'by <img class="afterpay_instalments_logo" src="https://static.afterpay.com/integration/logo-afterpay-colour-72x15.png" srcset="https://static.afterpay.com/integration/logo-afterpay-colour-72x15.png 1x,https://static.afterpay.com/integration/[email protected] 2x,https://static.afterpay.com/integration/[email protected] 3x" height="15"/><a href="[modal-href]" class="afterpay-modal-popup-trigger-ca">More info</a>'
39+
product_page_from = "or 4 installments from "
40+
cart_page1 = "Check out with Afterpay and pay by installments.</span></h3>
41+
<span>Pay 4 installments of "
42+
cart_page2 = "<br> Use your payment card, approval decision online.</span>
43+
<span><a href="[modal-href]" class="afterpay-modal-popup-trigger-ca">More info</a></span>"
44+
45+

composer.json

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
{
2-
"name": "afterpay-global/module-afterpay",
3-
"license": "OSL-3.0",
4-
"type": "magento2-module",
5-
"description": "Magento 2 Afterpay Payment Module",
6-
"version": "3.1.3",
7-
"require": {
8-
},
9-
"authors":[
10-
{
11-
"name":"Afterpay",
12-
"homepage":"https://www.afterpay.com"
13-
}
14-
],
15-
"autoload": {
16-
"files": [
17-
"registration.php"
18-
],
19-
"psr-4": {
20-
"Afterpay\\Afterpay\\": ""
21-
}
22-
}
23-
}
2+
"name" : "afterpay-global/module-afterpay",
3+
"license" : "OSL-3.0",
4+
"type" : "magento2-module",
5+
"description" : "Magento 2 Afterpay Payment Module",
6+
"version" : "3.1.4",
7+
"authors" : [{
8+
"name" : "Afterpay",
9+
"homepage" : "https://www.afterpay.com"
10+
}
11+
],
12+
"autoload" : {
13+
"files" : [
14+
"registration.php"
15+
],
16+
"psr-4" : {
17+
"Afterpay\\Afterpay\\" : ""
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)