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.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
afterpayplugins committed Dec 19, 2019
1 parent 9422a8f commit 98b4260
Show file tree
Hide file tree
Showing 12 changed files with 412 additions and 177 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Afterpay Magento 1 Extension Changelog

## Version 3.0.4

_Thu 19 Dec 2019 (AEDT)_

### Supported Editions & Versions

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

### Highlights

- Allow admin users to restrict Afterpay from a given set of product categories.
- Improved fallback mechanism for unsupported checkouts.
- Improved support for virtual products.
- Improved support for HTTP/2.
- Improved compatibility with the "OneStepCheckout" checkout extension.
- Hide Afterpay elements from PDP for Grouped Products.

---

## Version 3.0.3

_Wed 09 Oct 2019 (AEDT)_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,26 @@ class Afterpay_Afterpay_Block_Catalog_Installments extends Mage_Core_Block_Templ
{
const XML_CONFIG_PREFIX = 'afterpay/payovertime_installments/';

public function isEnabled()
/**
* Retrieve product
*
* @return Mage_Catalog_Model_Product
*/
public function getProduct()
{
return Mage::getStoreConfigFlag(self::XML_CONFIG_PREFIX . 'enable_' . $this->getPageType());
$product = $this->_getData('product');
if (!$product) {
$product = Mage::registry('product');
}
return $product;
}

public function isEnabled()
{
$product = $this->getProduct();
return Mage::getStoreConfigFlag(self::XML_CONFIG_PREFIX . 'enable_' . $this->getPageType())
&& Mage::getModel('afterpay/method_payovertime')->canUseForProduct($product)
&& !$product->isGrouped();
}

public function getCssSelectors()
Expand Down
3 changes: 2 additions & 1 deletion src/app/code/community/Afterpay/Afterpay/Block/Onetouch.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ protected function _toHtml()
{
if ( Mage::getStoreConfigFlag('afterpay/payovertime_cart/show_onetouch')
&& Mage::getStoreConfig('payment/afterpaypayovertime/' . Afterpay_Afterpay_Model_Method_Base::API_ENABLED_FIELD)
&& 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)
) {
Expand Down Expand Up @@ -39,4 +40,4 @@ public function getTotalAmount()
{
return Mage::helper('afterpay')->calculateTotal();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ private function _validateData( $object ) {
$errors = array();

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

$billing_postcode = $billingAddress->getPostcode();
$billing_telephone = $billingAddress->getTelephone();
Expand All @@ -227,7 +226,9 @@ private function _validateData( $object ) {
$errors[] = "Billing Address is required";
}

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

$shipping_postcode = $shippingAddress->getPostcode();
$shipping_telephone = $shippingAddress->getTelephone();
$shipping_city = $shippingAddress->getCity();
Expand Down
104 changes: 104 additions & 0 deletions src/app/code/community/Afterpay/Afterpay/Model/Api/Http/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
class Afterpay_Afterpay_Model_Api_Http_Client
{
protected $_url = '';
protected $_configs = array();
protected $_helper;

public function __construct($url = '')
{
$this->_helper = Mage::helper('afterpay');

if (!extension_loaded('curl')) {
throw Mage::exception(
'Afterpay_Afterpay',
$this->_helper->__('cURL extension has to be loaded to use this Afterpay Http Client.')
);
}

$this->_url = $url;
}

public function setConfigs($configs = array())
{
if (isset($configs['auth_user']) && isset($configs['auth_pwd'])) {
$this->_configs[CURLOPT_USERPWD] = $configs['auth_user'].':'.$configs['auth_pwd'];
}

if (isset($configs['useragent'])) {
$this->_configs[CURLOPT_USERAGENT] = $configs['useragent'];
}

if (isset($configs['timeout'])) {
$this->_configs[CURLOPT_TIMEOUT] = $configs['timeout'];
}
}

public function request($method = 'GET', $data = array())
{
$opts = $this->_configs + array(
CURLOPT_URL => $this->_url,
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
),
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 80,
);

if (!empty($data)) {
$opts[CURLOPT_POSTFIELDS] = json_encode($data);
$opts[CURLOPT_HTTPHEADER][] = 'Content-Type: application/json';
$opts[CURLOPT_HTTPHEADER][] = 'Content-Length: '.strlen($opts[CURLOPT_POSTFIELDS]);

switch (strtoupper($method)) {
case 'POST':
$opts[CURLOPT_POST] = TRUE;
break;
case 'PUT':
$opts[CURLOPT_CUSTOMREQUEST] = 'PUT';
break;
}
}

$ch = curl_init();

if (!curl_setopt_array($ch, $opts)) {
// If an option could not be successfully set
curl_close($ch);
$this->_helper->log('Unable to set cURL with options:');
$this->_helper->log($opts);

throw Mage::exception('Afterpay_Afterpay', $this->_helper->__('Unable to set options for cURL.'));
}

$output = curl_exec($ch);
$errno = curl_errno($ch);
$error = curl_error($ch);

if ($errno) {
// i.e. It cannot get a response
$this->_helper->log('cURL error number: ' . $errno . ', error message: ' . $error);
$output = json_encode(array(
'errorCode' => $errno,
'errorId' => null,
'message' => $error,
'httpStatusCode' => null
));
}
elseif (is_null(json_decode($output))) {
// i.e. It does return a response but it is not in JSON format
$output = json_encode(array(
'errorCode' => 'non_json',
'errorId' => null,
'message' => curl_getinfo($ch, CURLINFO_CONTENT_TYPE) . ' response could not be decoded: ' . json_last_error_msg(),
'httpStatusCode' => curl_getinfo($ch, CURLINFO_RESPONSE_CODE)
));
}

curl_close($ch);

return $output;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ public function getOrdersApiUrl( $search_target = NULL, $type = NULL )

//make sure we are using the same version of API for consistency purpose
$gatewayUrl = $settings[Afterpay_Afterpay_Model_System_Config_Source_ApiMode::KEY_API_URL] . 'v1/payments/';

if( !empty($type) && $type == $search_target ) {
$url = (substr($gatewayUrl, -1) == '/' ? $gatewayUrl : $gatewayUrl . '/') . 'token:' . urlencode($search_target);
$url = (substr($gatewayUrl, -1) == '/' ? $gatewayUrl : $gatewayUrl . '/') . 'token:' . urlencode($search_target);
}
else if( !empty($type) && $type == 'id') {
$url = (substr($gatewayUrl, -1) == '/' ? $gatewayUrl : $gatewayUrl . '/') . $search_target;
}
}
else if( !empty($type) && $type == 'courier') {
$url = (substr($gatewayUrl, -1) == '/' ? $gatewayUrl : $gatewayUrl . '/') . $search_target . "/courier/";
}
}
else if( !empty($type) && $type == 'token' ) {
$url = $settings[Afterpay_Afterpay_Model_System_Config_Source_ApiMode::KEY_API_URL] . 'v1/orders/' . $search_target;
}
$url = $settings[Afterpay_Afterpay_Model_System_Config_Source_ApiMode::KEY_API_URL] . 'v1/orders/' . $search_target;
}
else {
$url = $settings[Afterpay_Afterpay_Model_System_Config_Source_ApiMode::KEY_API_URL] . 'v1/orders/';
}
$url = $settings[Afterpay_Afterpay_Model_System_Config_Source_ApiMode::KEY_API_URL] . 'v1/orders/';
}

return $url;
}

Expand Down Expand Up @@ -127,7 +127,7 @@ public function getDirectCaptureApiUrl()
$apiMode = Mage::getStoreConfig('payment/afterpaypayovertime/' . Afterpay_Afterpay_Model_Method_Base::API_MODE_CONFIG_FIELD);
$settings = Afterpay_Afterpay_Model_System_Config_Source_ApiMode::getEnvironmentSettings($apiMode);

return $settings[Afterpay_Afterpay_Model_System_Config_Source_ApiMode::KEY_API_URL] . 'v1/payments/capture/';
return $settings[Afterpay_Afterpay_Model_System_Config_Source_ApiMode::KEY_API_URL] . 'v1/payments/capture/';
}


Expand All @@ -141,13 +141,23 @@ public function getGatewayApiUrl( $token = NULL )
$apiMode = Mage::getStoreConfig('payment/afterpaypayovertime/' . Afterpay_Afterpay_Model_Method_Base::API_MODE_CONFIG_FIELD);
$settings = Afterpay_Afterpay_Model_System_Config_Source_ApiMode::getEnvironmentSettings($apiMode);

$countryCode = 'au';
switch (Mage::app()->getStore()->getCurrentCurrencyCode()) {
case 'USD':
$countryCode = 'us';
break;
case 'NZD':
$countryCode = 'nz';
break;
}

//make sure we are using the same version of API for consistency purpose
$gatewayUrl = $settings[Afterpay_Afterpay_Model_System_Config_Source_ApiMode::KEY_WEB_URL] . 'checkout';
$gatewayUrl = $settings[Afterpay_Afterpay_Model_System_Config_Source_ApiMode::KEY_WEB_URL] . $countryCode . '/checkout';

if( !empty($token) ) {
$url = (substr($gatewayUrl, -1) == '/' ? $gatewayUrl : $gatewayUrl . '/') . '?token=' . urlencode($token) . '&redirected=1&relativeCallbackUrl=';
}
$url = (substr($gatewayUrl, -1) == '/' ? $gatewayUrl : $gatewayUrl . '/') . '?token=' . urlencode($token) . '&redirected=1&relativeCallbackUrl=';
}

return $url;
}
}
}
Loading

0 comments on commit 98b4260

Please sign in to comment.