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

Commit

Permalink
Release version 3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
afterpayplugins committed Dec 15, 2020
1 parent 85402d4 commit 61fc03f
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 50 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Afterpay Magento 1 Extension Changelog

## Version 3.1.1

_Wed 16 Dec 2020 (AEST)_

### Supported Editions & Versions

- Magento Community Edition (CE) version 1.7 and later.
- Magento Enterprise Edition (EE) version 1.13 and later.

### Highlights

- Improved compatibility with PHP 7.1+.
- Fixed a defect where the instalment amount may have been rounded incorrectly on product page.
- Fixed a defect where Afterpay may have appeared to be available for orders of $0 on cart page.
- Refined API calls for orders that consist of virtual products only.
- Improved user experience by hiding Afterpay when currency is misconfigured.

---

## Version 3.1.0

_Wed 2 Sep 2020 (AEST)_
Expand Down
6 changes: 4 additions & 2 deletions src/app/code/community/Afterpay/Afterpay/Block/Onetouch.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ class Afterpay_Afterpay_Block_Onetouch extends Mage_Core_Block_Template
*/
protected function _toHtml()
{
$total = $this->getTotalAmount();
if ( Mage::getStoreConfigFlag('afterpay/payovertime_cart/show_onetouch')
&& Mage::getStoreConfig('payment/afterpaypayovertime/' . Afterpay_Afterpay_Model_Method_Base::API_ENABLED_FIELD)
&& Mage::helper('afterpay/checkout')->noConflict()
&& Mage::getModel('afterpay/method_payovertime')->canUseForCheckoutSession()
&& $this->getTotalAmount() >= Mage::getStoreConfig('payment/afterpaypayovertime/' . Afterpay_Afterpay_Model_Method_Base::API_MIN_ORDER_TOTAL_FIELD)
&& $this->getTotalAmount() <= Mage::getStoreConfig('payment/afterpaypayovertime/' . Afterpay_Afterpay_Model_Method_Base::API_MAX_ORDER_TOTAL_FIELD)
&& $total > 0
&& $total >= Mage::getStoreConfig('payment/afterpaypayovertime/' . Afterpay_Afterpay_Model_Method_Base::API_MIN_ORDER_TOTAL_FIELD)
&& $total <= Mage::getStoreConfig('payment/afterpaypayovertime/' . Afterpay_Afterpay_Model_Method_Base::API_MAX_ORDER_TOTAL_FIELD)
) {
return parent::_toHtml();
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/app/code/community/Afterpay/Afterpay/Helper/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public function defaultUrlExtended()
public function noConflict()
{
$currency = Mage::app()->getStore()->getCurrentCurrencyCode();
return in_array($currency, Afterpay_Afterpay_Model_Method_Base::SUPPORTED_CURRENCIES);
$base = Mage::app()->getStore()->getBaseCurrencyCode();
return $currency == $base && in_array($currency, Afterpay_Afterpay_Model_Method_Base::SUPPORTED_CURRENCIES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public function buildOrderTokenRequest($object, $override = array(), $afterPayPa
$data = $object->getData();

$billingAddress = $object->getBillingAddress();
$shippingAddress = $object->getShippingAddress();
$shippingMethods = $shippingAddress->getShippingRatesCollection();

$taxTotal = 0;

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

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

//not sure what should go to priority, I guess it will say something in the description if it is Express
foreach ($shippingMethods as $method) {
$params['courier'] = array(
'name' => substr($method->getMethodTitle() . " " . $method->getCarrierTitle(), 0, 128),
'priority' => "STANDARD",
);
}

foreach ($object->getAllVisibleItems() as $item) {
/** @var Mage_Sales_Model_Order_Item $orderItem */
$params['items'][] = array(
'name' => (string)$item->getName(),
'sku' => $this->_truncateString( (string)$item->getSku() ),
'quantity' => (int)$item->getQty(),
'price' => array(
'amount' => round((float)$item->getPriceInclTax(), $precision),
'amount' => number_format((float)$item->getPriceInclTax(), $precision, '.', ''),
'currency' => (string)Mage::app()->getStore()->getCurrentCurrencyCode()
)
);
Expand All @@ -80,7 +70,7 @@ public function buildOrderTokenRequest($object, $override = array(), $afterPayPa
$params['discounts'][] = array(
'displayName' => substr( $discount_name . ' - ' . (string)$item->getName(), 0, 128 ),
'amount' => array(
'amount' => round((float)$item->getDiscountAmount(), $precision),
'amount' => number_format((float)$item->getDiscountAmount(), $precision, '.', ''),
'currency' => (string)Mage::app()->getStore()->getCurrentCurrencyCode()
),
);
Expand All @@ -90,41 +80,13 @@ public function buildOrderTokenRequest($object, $override = array(), $afterPayPa
$taxTotal += $item->getTaxAmount();
}

if ($shippingAddress->getShippingInclTax()) {
$params['shippingAmount'] = array(
'amount' => round((float)$shippingAddress->getShippingInclTax(), $precision), // with tax
'currency' => (string)Mage::app()->getStore()->getCurrentCurrencyCode()
);
}

// $taxAmount = $shippingAddress->getData('tax_amount');
if( isset($taxTotal) && round((float)$taxTotal, $precision) > 0 ) {
$params['taxAmount'] = array(
'amount' => isset($taxTotal) ? round((float)$taxTotal, $precision) : 0,
'amount' => number_format((float)$taxTotal, $precision, '.', ''),
'currency' => (string)Mage::app()->getStore()->getCurrentCurrencyCode()
);
}

// $params['orderDetail']['subTotal'] = array(
// 'amount' => round((float)$data['subtotal'], $precision),
// 'currency' => (string)Mage::app()->getStore()->getCurrentCurrencyCode(),
// );
if( !empty( $shippingAddress ) ) {
if( !empty( $shippingAddress->getStreet1() ) ) {
$params['shipping'] = array(
'name' => (string)$shippingAddress->getFirstname() . ' ' . $shippingAddress->getLastname(),
'line1' => (string)$shippingAddress->getStreet1(),
'line2' => (string)$shippingAddress->getStreet2(),
'suburb' => (string)$shippingAddress->getCity(),
'postcode' => (string)$shippingAddress->getPostcode(),
'state' => (string)$shippingAddress->getRegion(),
'phoneNumber' => (string)$shippingAddress->getTelephone(),
// 'countryCode' => 'AU',
'countryCode' => (string)$shippingAddress->getCountry(),
);
}
}

$params['billing'] = array(
'name' => (string)$billingAddress->getFirstname() . ' ' . $billingAddress->getLastname(),
'line1' => (string)$billingAddress->getStreet1(),
Expand All @@ -133,12 +95,46 @@ public function buildOrderTokenRequest($object, $override = array(), $afterPayPa
'postcode' => (string)$billingAddress->getPostcode(),
'state' => (string)$billingAddress->getRegion(),
'phoneNumber' => (string)$billingAddress->getTelephone(),
// 'countryCode' => 'AU',
'countryCode' => (string)$billingAddress->getCountry(),
);

if (!$object->isVirtual())
{
$shippingAddress = $object->getShippingAddress();
$shippingMethods = $shippingAddress->getShippingRatesCollection();

foreach ($shippingMethods as $method) {
$params['courier'] = array(
'name' => substr($method->getMethodTitle() . " " . $method->getCarrierTitle(), 0, 128),
'priority' => "STANDARD",
);
}

if ($shippingAddress->getShippingInclTax()) {
$params['shippingAmount'] = array(
'amount' => number_format((float)$shippingAddress->getShippingInclTax(), $precision, '.', ''), // with tax
'currency' => (string)Mage::app()->getStore()->getCurrentCurrencyCode()
);
}

if( !empty( $shippingAddress ) ) {
if( !empty( $shippingAddress->getStreet1() ) ) {
$params['shipping'] = array(
'name' => (string)$shippingAddress->getFirstname() . ' ' . $shippingAddress->getLastname(),
'line1' => (string)$shippingAddress->getStreet1(),
'line2' => (string)$shippingAddress->getStreet2(),
'suburb' => (string)$shippingAddress->getCity(),
'postcode' => (string)$shippingAddress->getPostcode(),
'state' => (string)$shippingAddress->getRegion(),
'phoneNumber' => (string)$shippingAddress->getTelephone(),
'countryCode' => (string)$shippingAddress->getCountry(),
);
}
}
}

$params['totalAmount'] = array(
'amount' => round((float)$object->getGrandTotal(), $precision),
'amount' => number_format((float)$object->getGrandTotal(), $precision, '.', ''),
'currency' => (string)Mage::app()->getStore()->getCurrentCurrencyCode(),
);

Expand Down Expand Up @@ -175,7 +171,7 @@ public function buildDirectCaptureRequest($orderToken, $merchantOrderId)
public function buildRefundRequest($amount, $payment)
{
$params['amount'] = array(
'amount' => abs( round($amount, 2) ), // Afterpay API Ver 1 requires a positive amount
'amount' => number_format($amount, 2, '.', ''),
'currency' => $payment->getOrder()->getOrderCurrencyCode(),
);

Expand Down Expand Up @@ -228,7 +224,7 @@ private function _validateData( $object ) {

if (!$object->isVirtual()) {
$shippingAddress = $object->getShippingAddress();

$shipping_postcode = $shippingAddress->getPostcode();
$shipping_telephone = $shippingAddress->getTelephone();
$shipping_city = $shippingAddress->getCity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ public function canUseCheckout()
*/
public function canUseForCurrency($currencyCode)
{
return in_array(strtoupper($currencyCode), self::SUPPORTED_CURRENCIES);
$display = Mage::app()->getStore()->getCurrentCurrencyCode();
return $currencyCode == $display && in_array(strtoupper($currencyCode), self::SUPPORTED_CURRENCIES);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/app/code/community/Afterpay/Afterpay/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<Afterpay_Afterpay>
<version>3.1.0</version>
<version>3.1.1</version>
</Afterpay_Afterpay>
</modules>
<afterpay>
Expand Down
1 change: 1 addition & 0 deletions src/js/Afterpay/Installments.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
}

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

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

0 comments on commit 61fc03f

Please sign in to comment.