Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit 61fc03f

Browse files
Release version 3.1.1
1 parent 85402d4 commit 61fc03f

File tree

7 files changed

+70
-50
lines changed

7 files changed

+70
-50
lines changed

CHANGELOG.md

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

3+
## Version 3.1.1
4+
5+
_Wed 16 Dec 2020 (AEST)_
6+
7+
### Supported Editions & Versions
8+
9+
- Magento Community Edition (CE) version 1.7 and later.
10+
- Magento Enterprise Edition (EE) version 1.13 and later.
11+
12+
### Highlights
13+
14+
- Improved compatibility with PHP 7.1+.
15+
- Fixed a defect where the instalment amount may have been rounded incorrectly on product page.
16+
- Fixed a defect where Afterpay may have appeared to be available for orders of $0 on cart page.
17+
- Refined API calls for orders that consist of virtual products only.
18+
- Improved user experience by hiding Afterpay when currency is misconfigured.
19+
20+
---
21+
322
## Version 3.1.0
423

524
_Wed 2 Sep 2020 (AEST)_

src/app/code/community/Afterpay/Afterpay/Block/Onetouch.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ class Afterpay_Afterpay_Block_Onetouch extends Mage_Core_Block_Template
99
*/
1010
protected function _toHtml()
1111
{
12+
$total = $this->getTotalAmount();
1213
if ( Mage::getStoreConfigFlag('afterpay/payovertime_cart/show_onetouch')
1314
&& Mage::getStoreConfig('payment/afterpaypayovertime/' . Afterpay_Afterpay_Model_Method_Base::API_ENABLED_FIELD)
1415
&& Mage::helper('afterpay/checkout')->noConflict()
1516
&& Mage::getModel('afterpay/method_payovertime')->canUseForCheckoutSession()
16-
&& $this->getTotalAmount() >= Mage::getStoreConfig('payment/afterpaypayovertime/' . Afterpay_Afterpay_Model_Method_Base::API_MIN_ORDER_TOTAL_FIELD)
17-
&& $this->getTotalAmount() <= Mage::getStoreConfig('payment/afterpaypayovertime/' . Afterpay_Afterpay_Model_Method_Base::API_MAX_ORDER_TOTAL_FIELD)
17+
&& $total > 0
18+
&& $total >= Mage::getStoreConfig('payment/afterpaypayovertime/' . Afterpay_Afterpay_Model_Method_Base::API_MIN_ORDER_TOTAL_FIELD)
19+
&& $total <= Mage::getStoreConfig('payment/afterpaypayovertime/' . Afterpay_Afterpay_Model_Method_Base::API_MAX_ORDER_TOTAL_FIELD)
1820
) {
1921
return parent::_toHtml();
2022
} else {

src/app/code/community/Afterpay/Afterpay/Helper/Checkout.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public function defaultUrlExtended()
132132
public function noConflict()
133133
{
134134
$currency = Mage::app()->getStore()->getCurrentCurrencyCode();
135-
return in_array($currency, Afterpay_Afterpay_Model_Method_Base::SUPPORTED_CURRENCIES);
135+
$base = Mage::app()->getStore()->getBaseCurrencyCode();
136+
return $currency == $base && in_array($currency, Afterpay_Afterpay_Model_Method_Base::SUPPORTED_CURRENCIES);
136137
}
137138
}

src/app/code/community/Afterpay/Afterpay/Model/Api/Adapters/Adapterv1.php

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public function buildOrderTokenRequest($object, $override = array(), $afterPayPa
3232
$data = $object->getData();
3333

3434
$billingAddress = $object->getBillingAddress();
35-
$shippingAddress = $object->getShippingAddress();
36-
$shippingMethods = $shippingAddress->getShippingRatesCollection();
3735

3836
$taxTotal = 0;
3937

@@ -46,22 +44,14 @@ public function buildOrderTokenRequest($object, $override = array(), $afterPayPa
4644

4745
$params['items'] = array();
4846

49-
//not sure what should go to priority, I guess it will say something in the description if it is Express
50-
foreach ($shippingMethods as $method) {
51-
$params['courier'] = array(
52-
'name' => substr($method->getMethodTitle() . " " . $method->getCarrierTitle(), 0, 128),
53-
'priority' => "STANDARD",
54-
);
55-
}
56-
5747
foreach ($object->getAllVisibleItems() as $item) {
5848
/** @var Mage_Sales_Model_Order_Item $orderItem */
5949
$params['items'][] = array(
6050
'name' => (string)$item->getName(),
6151
'sku' => $this->_truncateString( (string)$item->getSku() ),
6252
'quantity' => (int)$item->getQty(),
6353
'price' => array(
64-
'amount' => round((float)$item->getPriceInclTax(), $precision),
54+
'amount' => number_format((float)$item->getPriceInclTax(), $precision, '.', ''),
6555
'currency' => (string)Mage::app()->getStore()->getCurrentCurrencyCode()
6656
)
6757
);
@@ -80,7 +70,7 @@ public function buildOrderTokenRequest($object, $override = array(), $afterPayPa
8070
$params['discounts'][] = array(
8171
'displayName' => substr( $discount_name . ' - ' . (string)$item->getName(), 0, 128 ),
8272
'amount' => array(
83-
'amount' => round((float)$item->getDiscountAmount(), $precision),
73+
'amount' => number_format((float)$item->getDiscountAmount(), $precision, '.', ''),
8474
'currency' => (string)Mage::app()->getStore()->getCurrentCurrencyCode()
8575
),
8676
);
@@ -90,41 +80,13 @@ public function buildOrderTokenRequest($object, $override = array(), $afterPayPa
9080
$taxTotal += $item->getTaxAmount();
9181
}
9282

93-
if ($shippingAddress->getShippingInclTax()) {
94-
$params['shippingAmount'] = array(
95-
'amount' => round((float)$shippingAddress->getShippingInclTax(), $precision), // with tax
96-
'currency' => (string)Mage::app()->getStore()->getCurrentCurrencyCode()
97-
);
98-
}
99-
100-
// $taxAmount = $shippingAddress->getData('tax_amount');
10183
if( isset($taxTotal) && round((float)$taxTotal, $precision) > 0 ) {
10284
$params['taxAmount'] = array(
103-
'amount' => isset($taxTotal) ? round((float)$taxTotal, $precision) : 0,
85+
'amount' => number_format((float)$taxTotal, $precision, '.', ''),
10486
'currency' => (string)Mage::app()->getStore()->getCurrentCurrencyCode()
10587
);
10688
}
10789

108-
// $params['orderDetail']['subTotal'] = array(
109-
// 'amount' => round((float)$data['subtotal'], $precision),
110-
// 'currency' => (string)Mage::app()->getStore()->getCurrentCurrencyCode(),
111-
// );
112-
if( !empty( $shippingAddress ) ) {
113-
if( !empty( $shippingAddress->getStreet1() ) ) {
114-
$params['shipping'] = array(
115-
'name' => (string)$shippingAddress->getFirstname() . ' ' . $shippingAddress->getLastname(),
116-
'line1' => (string)$shippingAddress->getStreet1(),
117-
'line2' => (string)$shippingAddress->getStreet2(),
118-
'suburb' => (string)$shippingAddress->getCity(),
119-
'postcode' => (string)$shippingAddress->getPostcode(),
120-
'state' => (string)$shippingAddress->getRegion(),
121-
'phoneNumber' => (string)$shippingAddress->getTelephone(),
122-
// 'countryCode' => 'AU',
123-
'countryCode' => (string)$shippingAddress->getCountry(),
124-
);
125-
}
126-
}
127-
12890
$params['billing'] = array(
12991
'name' => (string)$billingAddress->getFirstname() . ' ' . $billingAddress->getLastname(),
13092
'line1' => (string)$billingAddress->getStreet1(),
@@ -133,12 +95,46 @@ public function buildOrderTokenRequest($object, $override = array(), $afterPayPa
13395
'postcode' => (string)$billingAddress->getPostcode(),
13496
'state' => (string)$billingAddress->getRegion(),
13597
'phoneNumber' => (string)$billingAddress->getTelephone(),
136-
// 'countryCode' => 'AU',
13798
'countryCode' => (string)$billingAddress->getCountry(),
13899
);
139100

101+
if (!$object->isVirtual())
102+
{
103+
$shippingAddress = $object->getShippingAddress();
104+
$shippingMethods = $shippingAddress->getShippingRatesCollection();
105+
106+
foreach ($shippingMethods as $method) {
107+
$params['courier'] = array(
108+
'name' => substr($method->getMethodTitle() . " " . $method->getCarrierTitle(), 0, 128),
109+
'priority' => "STANDARD",
110+
);
111+
}
112+
113+
if ($shippingAddress->getShippingInclTax()) {
114+
$params['shippingAmount'] = array(
115+
'amount' => number_format((float)$shippingAddress->getShippingInclTax(), $precision, '.', ''), // with tax
116+
'currency' => (string)Mage::app()->getStore()->getCurrentCurrencyCode()
117+
);
118+
}
119+
120+
if( !empty( $shippingAddress ) ) {
121+
if( !empty( $shippingAddress->getStreet1() ) ) {
122+
$params['shipping'] = array(
123+
'name' => (string)$shippingAddress->getFirstname() . ' ' . $shippingAddress->getLastname(),
124+
'line1' => (string)$shippingAddress->getStreet1(),
125+
'line2' => (string)$shippingAddress->getStreet2(),
126+
'suburb' => (string)$shippingAddress->getCity(),
127+
'postcode' => (string)$shippingAddress->getPostcode(),
128+
'state' => (string)$shippingAddress->getRegion(),
129+
'phoneNumber' => (string)$shippingAddress->getTelephone(),
130+
'countryCode' => (string)$shippingAddress->getCountry(),
131+
);
132+
}
133+
}
134+
}
135+
140136
$params['totalAmount'] = array(
141-
'amount' => round((float)$object->getGrandTotal(), $precision),
137+
'amount' => number_format((float)$object->getGrandTotal(), $precision, '.', ''),
142138
'currency' => (string)Mage::app()->getStore()->getCurrentCurrencyCode(),
143139
);
144140

@@ -175,7 +171,7 @@ public function buildDirectCaptureRequest($orderToken, $merchantOrderId)
175171
public function buildRefundRequest($amount, $payment)
176172
{
177173
$params['amount'] = array(
178-
'amount' => abs( round($amount, 2) ), // Afterpay API Ver 1 requires a positive amount
174+
'amount' => number_format($amount, 2, '.', ''),
179175
'currency' => $payment->getOrder()->getOrderCurrencyCode(),
180176
);
181177

@@ -228,7 +224,7 @@ private function _validateData( $object ) {
228224

229225
if (!$object->isVirtual()) {
230226
$shippingAddress = $object->getShippingAddress();
231-
227+
232228
$shipping_postcode = $shippingAddress->getPostcode();
233229
$shipping_telephone = $shippingAddress->getTelephone();
234230
$shipping_city = $shippingAddress->getCity();

src/app/code/community/Afterpay/Afterpay/Model/Method/Base.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ public function canUseCheckout()
143143
*/
144144
public function canUseForCurrency($currencyCode)
145145
{
146-
return in_array(strtoupper($currencyCode), self::SUPPORTED_CURRENCIES);
146+
$display = Mage::app()->getStore()->getCurrentCurrencyCode();
147+
return $currencyCode == $display && in_array(strtoupper($currencyCode), self::SUPPORTED_CURRENCIES);
147148
}
148149

149150
/**

src/app/code/community/Afterpay/Afterpay/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<config>
33
<modules>
44
<Afterpay_Afterpay>
5-
<version>3.1.0</version>
5+
<version>3.1.1</version>
66
</Afterpay_Afterpay>
77
</modules>
88
<afterpay>

src/js/Afterpay/Installments.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
}
8989

9090
var individualInstalment = price / this.config.installmentsAmount;
91+
individualInstalment = Math.round(individualInstalment * 100) / 100;
9192

9293
Element.insert(priceBoxes[i], {
9394
after: this.config.template.replace(this.config.priceSubstitution,

0 commit comments

Comments
 (0)