Skip to content

Commit

Permalink
Release version 3.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
afterpayplugins committed Jun 26, 2020
1 parent 1efa79d commit 63d9c05
Show file tree
Hide file tree
Showing 16 changed files with 255 additions and 97 deletions.
2 changes: 1 addition & 1 deletion Block/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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_
Expand Down
123 changes: 81 additions & 42 deletions Controller/Payment/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand Down
10 changes: 0 additions & 10 deletions Controller/Payment/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
59 changes: 59 additions & 0 deletions Helper/Category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Magento 2 extensions for Afterpay Payment
*
* @author Afterpay
* @copyright 2016-2020 Afterpay https://www.afterpay.com
*/
namespace Afterpay\Afterpay\Helper;

/**
* Catalog category helper
*
* @SuppressWarnings(PHPMD.LongVariable)
*/
class Category extends \Magento\Catalog\Helper\Category
{

/**
* Retrieve current store categories
*
* @param bool|string $sorted
* @param bool $asCollection
* @param bool $toLoad
* @return \Magento\Framework\Data\Tree\Node\Collection or
* \Magento\Catalog\Model\ResourceModel\Category\Collection or array
*/
public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true,$storeId = 1)
{
$parent = $this->_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;
}
}
4 changes: 2 additions & 2 deletions Model/Config/Payovertime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/';
Expand Down
31 changes: 25 additions & 6 deletions Model/Config/Source/Categorylist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*
Expand All @@ -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);

}

/*
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Model/Payovertime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 13 additions & 1 deletion assets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@
cart_page1 = "Check out with Afterpay and pay by instalment.</span>
<span>Simply pay 4 fortnightly instalments of "
cart_page2 = "<br> Use your payment card, instant approval.</span>
<span><a href="[modal-href]" class="afterpay-modal-popup-trigger">Learn more</a></span>"
<span><a href="[modal-href]" class="afterpay-modal-popup-trigger">Learn more</a></span>"

[CAD]
name = "CA"
product_page1 = "or 4 installments of "
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>'
product_page_from = "or 4 installments from "
cart_page1 = "Check out with Afterpay and pay by installments.</span></h3>
<span>Pay 4 installments of "
cart_page2 = "<br> Use your payment card, approval decision online.</span>
<span><a href="[modal-href]" class="afterpay-modal-popup-trigger-ca">More info</a></span>"


41 changes: 19 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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\\": ""
}
}
}
"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\\" : ""
}
}
}
Loading

0 comments on commit 63d9c05

Please sign in to comment.