Skip to content

Commit

Permalink
Release version 3.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
afterpayplugins committed May 20, 2020
1 parent 40b41ea commit 1efa79d
Show file tree
Hide file tree
Showing 20 changed files with 305 additions and 84 deletions.
22 changes: 0 additions & 22 deletions Block/Adminhtml/Order/Creditmemo/Create/Items.php

This file was deleted.

19 changes: 12 additions & 7 deletions Block/Cart/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function canShow()
$grandTotal =$quote->getGrandTotal();
$excluded_categories=$this->afterpayConfig->getExcludedCategories();

if($this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode()) && $this->afterpayConfig->getMaxOrderLimit() > $grandTotal && $this->afterpayConfig->getMinOrderLimit() < $grandTotal){
if($this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode()) && $this->afterpayConfig->getMaxOrderLimit() >= $grandTotal && $this->afterpayConfig->getMinOrderLimit() <= $grandTotal){

if($excluded_categories !=""){
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
Expand Down Expand Up @@ -162,17 +162,22 @@ public function getCartPageText()
{
$currencyCode = $this->afterpayConfig->getCurrencyCode();
$assetsPath = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Afterpay_Afterpay');
$assets_cart_page = '';
$assets_cart_page = [];

if(file_exists($assetsPath.'/assets.ini'))
{
$assets = parse_ini_file($assetsPath.'/assets.ini',true);
if(isset($assets[$currencyCode]['cart_page']))
if(isset($assets[$currencyCode]['cart_page1']))
{
$assets_cart_page = $assets[$currencyCode]['cart_page'];
$assets_cart_page = str_replace(array('[modal-href]'),
array('javascript:void(0)'), $assets_cart_page);
}
$assets_cart_page['snippet1'] = $assets[$currencyCode]['cart_page1'];
$assets_cart_page['snippet2'] = $assets[$currencyCode]['cart_page2'];
$assets_cart_page['snippet2'] = str_replace(array('[modal-href]'),
array('javascript:void(0)'), $assets_cart_page['snippet2']);
}
else{
$assets_cart_page['snippet1'] = '';
$assets_cart_page['snippet2'] = '';
}
}
return $assets_cart_page;
}
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Afterpay Magento 2 Extension Changelog

## Version 3.1.3

_Wed 20 May 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

- Added instalment calculations within cart page assets.
- Added an automatic void/refund of an Afterpay Order where Magento throws an unrecoverable exception during submitQuote.
- Refined language presented to US consumers.
- Improved cart page logic relating to Afterpay availability, where the total exactly matches the merchant minimum.
- Improved handling of unexpected/corrupted network data.
- Improved compatibility with offline refunds.
- Adjusted the implementation of the Afterpay checkout JavaScript.

---

## Version 3.1.2

_Fri 24 Jan 2020 (AEDT)_
Expand Down
64 changes: 55 additions & 9 deletions Controller/Payment/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Response extends \Magento\Framework\App\Action\Action
protected $_paymentCapture;
protected $_quoteValidator;
protected $_timezone;
protected $_afterpayApiPayment;

/**
* Response constructor.
Expand Down Expand Up @@ -80,7 +81,8 @@ public function __construct(
\Magento\Framework\Notification\NotifierInterface $notifierPool,
\Afterpay\Afterpay\Model\Adapter\V2\AfterpayOrderPaymentCapture $paymentCapture,
\Magento\Quote\Model\QuoteValidator $quoteValidator,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone,
\Afterpay\Afterpay\Model\Adapter\AfterpayPayment $afterpayApiPayment
) {
$this->_resultForwardFactory = $resultForwardFactory;
$this->response = $response;
Expand All @@ -101,6 +103,7 @@ public function __construct(
$this->_paymentCapture = $paymentCapture;
$this->_quoteValidator = $quoteValidator;
$this->_timezone = $timezone;
$this->_afterpayApiPayment = $afterpayApiPayment;

parent::__construct($context);
}
Expand Down Expand Up @@ -230,14 +233,57 @@ private function _processAuthCapture($query)
$retry = true;
sleep(1);
}
else{
$this->_notifierPool->addMajor(
'Afterpay Order Failed',
'There was a problem with an Afterpay order. Order number : '.$response['id'].' and the merchant order number : '.$merchant_order_id,
''
);
$this->_helper->debug("Order Exception : There was a problem with order creation. ".$e->getMessage());
}
else{
//Reverse or void the order
$orderId = $payment->getAdditionalInformation(\Afterpay\Afterpay\Model\Payovertime::ADDITIONAL_INFORMATION_KEY_ORDERID);
$paymentStatus = $payment->getAdditionalInformation(\Afterpay\Afterpay\Model\Payovertime::PAYMENT_STATUS);

if($paymentStatus == \Afterpay\Afterpay\Model\Response::PAYMENT_STATUS_AUTH_APPROVED){
$voidResponse = $this->_afterpayApiPayment->voidOrder($orderId);
$voidResponse = $this->_jsonHelper->jsonDecode($voidResponse->getBody());

if(!array_key_exists("errorCode",$voidResponse)) {
$payment->setAdditionalInformation(\Afterpay\Afterpay\Model\Payovertime::PAYMENT_STATUS, $voidResponse['paymentState']);

if(array_key_exists('openToCaptureAmount',$voidResponse) && !empty($voidResponse['openToCaptureAmount'])){
$payment->setAdditionalInformation(\Afterpay\Afterpay\Model\Payovertime::OPEN_TOCAPTURE_AMOUNT,$voidResponse['openToCaptureAmount']['amount']);
}

throw new \Magento\Framework\Exception\LocalizedException(__('There was a problem placing your order. Your Afterpay order ' .$orderId. ' is refunded.'));
$this->_helper->debug('Order Exception : There was a problem with order creation. Afterpay Order ' .$orderId. ' Voided.'.$e->getMessage());
}
else{
$this->_helper->debug("Transaction Exception : " . json_encode($voidResponse));
$this->_notifierPool->addMajor(
'Afterpay Order Failed',
'There was a problem with an Afterpay order. Order number : '.$response['id'].' and the merchant order number : '.$merchant_order_id,
''
);
throw new \Magento\Framework\Exception\LocalizedException(__('There was a problem placing your order.'));
}
}
else{
$orderTotal = $quote->getGrandTotal();

$refundResponse = $this->_afterpayApiPayment->refund(number_format($orderTotal, 2, '.', ''),$orderId,$quote->getQuoteCurrencyCode());

$refundResponse = $this->_jsonHelper->jsonDecode($refundResponse->getBody());

if (!empty($refundResponse['refundId'])) {
throw new \Magento\Framework\Exception\LocalizedException(__('There was a problem placing your order. Your Afterpay order ' .$orderId. ' is refunded.'));
$this->_helper->debug('Order Exception : There was a problem with order creation. Afterpay Order ' .$orderId. ' refunded.'.$e->getMessage());

} else {
$this->_helper->debug("Transaction Exception : " . json_encode($refundResponse));
$this->_notifierPool->addMajor(
'Afterpay Order Failed',
'There was a problem with an Afterpay order. Order number : '.$response['id'].' and the merchant order number : '.$merchant_order_id,
''
);
throw new \Magento\Framework\Exception\LocalizedException(__('There was a problem placing your order.'));
}
}
}
}
$tries++;
}while($tries<3 && $retry);
Expand Down
21 changes: 16 additions & 5 deletions Model/Adapter/Afterpay/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public function send($url, $body = false, $method = \Magento\Framework\HTTP\Zend
$client->setUri($url);

// set body and the url
if ($body) {
$client->setRawData($this->jsonHelper->jsonEncode($body), 'application/json');
if ($body || ($method == \Magento\Framework\HTTP\ZendClient::POST || $method == \Magento\Framework\HTTP\ZendClient::PUT)) {
$client->setRawData($this->jsonHelper->jsonEncode($body), 'application/json');
}

// add auth for API requirements
Expand Down Expand Up @@ -116,7 +116,7 @@ public function send($url, $body = false, $method = \Magento\Framework\HTTP\Zend
[
'timeout' => 80,
'maxredirects' => 0,
'useragent' => 'AfterpayMagento2Plugin ' . $this->helper->getModuleVersion() . ' (' . $description . ' ' . $version . ') MerchantID: ' . trim($this->afterpayConfig->getMerchantId($override) . ' URL: ' . $url)
'useragent' => 'AfterpayMagento2Plugin ' . $this->helper->getModuleVersion() . ' (' . $description . ' ' . $version . ')' . ' PHPVersion: PHP/' . phpversion() . ' MerchantID: ' . trim($this->afterpayConfig->getMerchantId($override) . ' URL: ' . $url)
]
);

Expand All @@ -132,14 +132,25 @@ public function send($url, $body = false, $method = \Magento\Framework\HTTP\Zend
// do the request with catch
try {
$response = $client->request($method);
$responseBody = $response->getBody();

try{
$responseBody = $this->jsonHelper->jsonDecode($responseBody);
}
catch(\Exception $e){
$this->helper->debug("A non JSON response was received. Cf-ray ID : ".$response->getHeaders()['Cf-ray']);
throw new \Magento\Framework\Exception\LocalizedException(
__($e->getMessage())
);
}

// debug mode
$responseLog = [
'type' => 'Response',
'method' => $method,
'url' => $url,
'httpStatusCode' => $response->getStatus(),
'body' => $this->obfuscateCustomerData($this->jsonHelper->jsonDecode($response->getBody()))
'body' => $this->obfuscateCustomerData($responseBody)
];
$this->helper->debug($this->jsonHelper->jsonEncode($responseLog));

Expand Down Expand Up @@ -184,7 +195,7 @@ private function obfuscateCustomerData($body = array())
{
$fieldsToObfuscate= ["shipping","billing","consumer",'orderDetails'];
$body_replace=[];
if(!empty($body)){
if(!empty($body) && is_array($body)){
foreach($body as $body_key=>$body_value)
{
if(in_array($body_key,$fieldsToObfuscate)){
Expand Down
8 changes: 1 addition & 7 deletions Model/Adapter/AfterpayPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,11 @@ public function voidOrder($orderId, $override = [])
// create url to request refunds
$url = $this->afterpayConfig->getApiUrl('v2/payments/' . $orderId . '/void', [], $override);

// generate body to be sent to refunds
$body = [
'orderId' => $orderId
];


// refunding now
try {
$response = $this->afterpayApiCall->send(
$url,
$body,
[],
\Magento\Framework\HTTP\ZendClient::POST,
$override
);
Expand Down
60 changes: 60 additions & 0 deletions Observer/BeforeCreditmemoLoad.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Magento 2 extensions for Afterpay Payment
*
* @author Afterpay
* @copyright 2016-2020 Afterpay https://www.afterpay.com
*/
namespace Afterpay\Afterpay\Observer;

use \Magento\Framework\Event\ObserverInterface;
use \Afterpay\Afterpay\Helper\Data as Helper;

/**
* Class BeforeCreditmemoLoad
* @package Afterpay\Afterpay\Observer
*/
class BeforeCreditmemoLoad implements ObserverInterface
{
protected $_helper;
protected $_layout;
protected $_registry;

public function __construct(
Helper $helper,
\Magento\Framework\View\LayoutInterface $layout,
\Magento\Framework\Registry $registry
)
{
$this->_helper = $helper;
$this->_layout = $layout;
$this->_registry = $registry;
}

public function execute(\Magento\Framework\Event\Observer $observer)
{
$block = $observer->getEvent()->getBlock();
$layout = $block->getLayout();

if($layout->hasElement('sales_creditmemo_create')){
$creditmemo = $this->_registry->registry('current_creditmemo');
if($creditmemo){
$order = $creditmemo->getOrder();
$payment = $order->getPayment();

if($payment->getMethod() == \Afterpay\Afterpay\Model\Payovertime::METHOD_CODE ){
$afterpayPaymentStatus = $payment->getAdditionalInformation(\Afterpay\Afterpay\Model\Payovertime::PAYMENT_STATUS);
if($afterpayPaymentStatus == \Afterpay\Afterpay\Model\Response::PAYMENT_STATUS_AUTH_APPROVED || $afterpayPaymentStatus == \Afterpay\Afterpay\Model\Response::PAYMENT_STATUS_PARTIALLY_CAPTURED){
$block->unsetChild(
'submit_offline'
);
if($layout->hasElement('customerbalance.creditmemo')){
$layout->unsetElement('customerbalance.creditmemo');
}
}
}
}
}
}
}
?>
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,24 @@
<li> Click the <em>Update Limits</em> button to retrieve the Minimum and Maximum Afterpay Order values.</li>
</ol>

<h2> 1.4 Upgrade Of Afterpay Installation </h2>
<h2> 1.4 Upgrade Of Afterpay Installation using Composer</h2>
<p> This section outlines the steps to upgrade the currently installed Afterpay plugin version using composer. </p>
<p> Notes: </p>
<p>Prerequisite for this section is that the module should be installed using composer. Please see section 1.1 for guidelines to install Afterpay module using composer.</p>
<p>[MAGENTO] refers to the root folder where Magento is installed. </p>

<ol>
<li> Open Command Line Interface and navigate to the Magento directory on your server</li>
<li> In CLI, run the below command to update Afterpay module: <br/> <em>composer update afterpay-global/module-afterpay</em> </li>
<li> Make sure that Composer finished the update without errors </li>
<li> In CLI, run the Magento setup upgrade: <br/> <em>php bin/magento setup:upgrade</em> </li>
<li> In CLI, run the Magento Dependencies Injection Compile: <br/> <em>php bin/magento setup:di:compile</em> </li>
<li> In CLI, run the Magento Static Content deployment: <br/> <em>php bin/magento setup:static-content:deploy</em> </li>
<li> Login to Magento Admin and navigate to System/Cache Management </li>
<li> Flush the cache storage by selecting Flush Cache Storage </li>
</ol>

<h2> 1.5 Upgrade Of Afterpay Installation </h2>
<p> This section outlines the steps to upgrade the currently installed Afterpay plugin version. </p>
<p> The process of upgrading the Afterpay plugin version involves the complete removal of Afterpay plugin files. </p>
<p> Note: [MAGENTO] refers to the root folder where Magento is installed. </p>
Expand Down
14 changes: 9 additions & 5 deletions assets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
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-us">More info</a>'
product_page_from = "or 4 installments from "
cart_page = "Check out with Afterpay and pay by installments.</span></h3><span>Pay 4 installments.<br> Use your payment card, instant approval.</span>
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-us">More info</a></span>"

[AUD]
Expand All @@ -14,8 +16,9 @@
product_page2 = '<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">Learn more</a>'
product_page_from = "or 4 interest-free payments from "
cart_page = "Check out with Afterpay and pay by instalment.</span></h3>
<span>Simply pay 4 fortnightly instalments.<br> Use your payment card, instant approval.</span>
cart_page1 = "Check out with Afterpay and pay by instalment.</span></h3>
<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>"

[NZD]
Expand All @@ -24,6 +27,7 @@
product_page2 = '<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">Learn more</a>'
product_page_from = "or 4 interest-free payments from "
cart_page = "Check out with Afterpay and pay by instalment.</span></h3>
<span>Simply pay 4 fortnightly instalments.<br> Use your payment card, instant approval.</span>
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>"
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": "OSL-3.0",
"type": "magento2-module",
"description": "Magento 2 Afterpay Payment Module",
"version": "3.1.2",
"version": "3.1.3",
"require": {
},
"authors":[
Expand Down
1 change: 0 additions & 1 deletion etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
<type name="Magento\Config\Model\Config">
<plugin name="updateOrderTotalLimitAfterpay" type="Afterpay\Afterpay\Model\Config\Save\Plugin" />
</type>
<preference for="Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Items" type="Afterpay\Afterpay\Block\Adminhtml\Order\Creditmemo\Create\Items" />
</config>
Loading

0 comments on commit 1efa79d

Please sign in to comment.