Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #259 from amzn/1.4.1
Browse files Browse the repository at this point in the history
1.4.1 Release
  • Loading branch information
ngrices committed Apr 26, 2016
2 parents fafb3c4 + a2f4210 commit 969b006
Show file tree
Hide file tree
Showing 65 changed files with 1,764 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ private function getMagento() {

private function getPayments() {


$_config = Mage::getSingleton('amazon_payments/config');

$this->log("\n===== PAYMENT SETTINGS =====");
$payments_secret_key = Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/amazon_payments/access_secret'));
$payments_secret_key = Mage::getStoreConfig('payment/amazon_payments/access_secret');
if (strlen($payments_secret_key) > 6) {
$payments_secret_key = substr($payments_secret_key, 0, 3) . "..." . substr($payments_secret_key, strlen($payments_secret_key - 3), 3);
}
Expand Down Expand Up @@ -102,6 +105,8 @@ private function getPayments() {
$payments_payment_option = (Mage::getStoreConfig('payment/amazon_payments/use_in_checkout') == 1 ? 'yes' : 'no');
$payments_async = (Mage::getStoreConfig('payment/amazon_payments/is_async') == 1 ? 'yes' : 'no');
$payments_sandbox = (Mage::getStoreConfig('payment/amazon_payments/sandbox') == 1 ? 'yes' : 'no');
$region = $_config->getRegion();
$locale = Mage::getStoreConfig('general/country/default');

$this->log("enabled: ". $enabled);
$this->log("sandbox: ". $payments_sandbox);
Expand All @@ -114,6 +119,8 @@ private function getPayments() {
$this->log("secure_cart: ". $payments_secure_cart);
$this->log("payment_option: ". $payments_payment_option);
$this->log("async: ". $payments_async);
$this->log("api region: ". $region);
$this->log("locale: ". $locale);
}

private function getLogin() {
Expand Down
11 changes: 11 additions & 0 deletions app/code/community/Amazon/Diagnostics/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,15 @@
</adminhtml>
</routers>
</admin>
<adminhtml>
<translate>
<modules>
<Amazon_Diagnostics>
<files>
<default>Amazon_Diagnostics.csv</default>
</files>
</Amazon_Diagnostics>
</modules>
</translate>
</adminhtml>
</config>
8 changes: 8 additions & 0 deletions app/code/community/Amazon/Payments/Block/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public function getButtonColor()
return Mage::getSingleton('amazon_payments/config')->getButtonColor();
}

/**
* Get language
*/
public function getLanguage()
{
return Mage::helper('amazon_payments')->getLanguage();
}

/**
* Is Disabled?
*
Expand Down
8 changes: 8 additions & 0 deletions app/code/community/Amazon/Payments/Block/Login/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,12 @@ public function getCheckoutUrl()
return $this->helper('amazon_payments')->getCheckoutUrl() . 'account/redirect';
}

/**
* Get language
*/
public function getLanguage()
{
return Mage::helper('amazon_payments')->getLanguage();
}

}
22 changes: 22 additions & 0 deletions app/code/community/Amazon/Payments/Block/Login/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ public function getLoginAuthUrl()
return $this->helper('amazon_payments')->getLoginAuthUrl();
}

/**
* Get region
*/
public function getRegion()
{
switch ($this->helper('amazon_payments')->getRegion()) {
case 'uk':
case 'de':
return 'EU';
default:
return 'NA'; // North America
}
}

/**
* Get language
*/
public function getLanguage()
{
return Mage::getStoreConfig('payment/amazon_payments/language');
}

/**
* Is Amazon Payments enabled?
*
Expand Down
55 changes: 20 additions & 35 deletions app/code/community/Amazon/Payments/Controller/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public function preDispatch()
{
parent::preDispatch();

// User clicked "Cancel" on Amazon Login consent form
if ($this->getRequest()->getParam('error') == 'access_denied') {
$this->_redirect('checkout/cart');
return;
}

$this->_amazonOrderReferenceId = htmlentities($this->getRequest()->getParam('amazon_order_reference_id'));

if (!$this->_amazonOrderReferenceId) {
Expand Down Expand Up @@ -207,56 +213,36 @@ protected function _saveShipping()
$address = $orderReferenceDetails->getDestination()->getPhysicalDestination();

// Split name into first/last
$name = $address->getName();
$firstName = substr($name, 0, strrpos($name, ' '));
$lastName = substr($name, strlen($firstName) + 1);

// Find Mage state/region ID
$regionModel = Mage::getModel('directory/region')->loadByCode($address->getStateOrRegion(), $address->getCountryCode());
$regionId = $regionModel->getId();

$data = array(
'firstname' => $firstName,
'lastname' => $lastName,
'street' => array($address->getAddressLine1(), $address->getAddressLine2()),
'city' => $address->getCity(),
'region' => $address->getStateOrRegion(),
'region_id' => $regionId,
'postcode' => $address->getPostalCode(),
'country_id' => $address->getCountryCode(),
'telephone' => ($address->getPhone()) ? $address->getPhone() : '-', // Mage requires phone number
'use_for_shipping' => true,
);
// Load region ID by name
if (!$regionId) {
$regionModel = Mage::getModel('directory/region')->loadByName($address->getStateOrRegion(), $address->getCountryCode());
$regionId = $regionModel->getId();
}

$data = Mage::helper('amazon_payments')->transformAmazonAddressToMagentoAddress($address);
$data['use_for_shipping'] = true;
$data['region'] = $address->getStateOrRegion();
$data['region_id'] = $regionId;

if ($email = Mage::getSingleton('checkout/session')->getCustomerEmail()) {
$data['email'] = $email;
}


// Set billing address (if allowed by scope)
if ($orderReferenceDetails->getBillingAddress()) {
$billing = $orderReferenceDetails->getBillingAddress()->getPhysicalAddress();
//$data['use_for_shipping'] = false;

$name = $billing->getName();
$firstName = substr($name, 0, strrpos($name, ' '));
$lastName = substr($name, strlen($firstName) + 1);

$regionModel = Mage::getModel('directory/region')->loadByCode($billing->getStateOrRegion(), $billing->getCountryCode());
$regionId = $regionModel->getId();

$dataBilling = array(
'firstname' => $firstName,
'lastname' => $lastName,
'street' => array($billing->getAddressLine1(), $billing->getAddressLine2()),
'city' => $billing->getCity(),
'region' => $billing->getStateOrRegion(),
'region_id' => $regionId,
'postcode' => $billing->getPostalCode(),
'country_id' => $billing->getCountryCode(),
'telephone' => ($billing->getPhone()) ? $billing->getPhone() : '-',
'use_for_shipping' => false,
);
$dataBilling = Mage::helper('amazon_payments')->transformAmazonAddressToMagentoAddress($billing);
$dataBilling['use_for_shipping'] = false;
$dataBilling['region'] = $billing->getStateOrRegion();
$dataBilling['region_id'] = $regionId;

$this->_getCheckout()->saveBilling($dataBilling, null);

Expand All @@ -268,6 +254,5 @@ protected function _saveShipping()
return $this->_getCheckout()->saveShipping($data);
}
}

}

112 changes: 111 additions & 1 deletion app/code/community/Amazon/Payments/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,69 @@ public function isPopup()
return (Mage::getStoreConfig('amazon_login/settings/popup'));
}

/**
* Return API region
*/
public function getRegion()
{
$region = $this->getConfig()->getRegion();
return ($region) ? $region : 'us';
}

/**
* Return language for Amazon frontend
*/
public function getLanguage()
{

if ($language = $this->getConfig()->getLanguage()) {
return $language;
}

$code = Mage::getStoreConfig('general/locale/code');

if ($code == 'en_GB') {
return 'en-GB';
}

switch (substr($code, 0, 2)) {
case 'de': return 'de-DE'; break;
case 'fr': return 'fr-FR'; break;
case 'it': return 'it-IT'; break;
case 'es': return 'es-ES'; break;
default: return false;
}
}

/**
* Get admin region for localizing URLs to Amazon
*/
public function getAdminRegion()
{
$config = $this->getConfig();

if (in_array($this->getAdminConfig($config::CONFIG_XML_PATH_REGION), array('uk', 'de'))) {
return 'eu';
}

$countryCode = $this->getAdminConfig('general/country/default');

// Is EU country?
$euCountries = explode(',', Mage::getStoreConfig('general/country/eu_countries'));
if (in_array($countryCode, $euCountries)) {
return 'eu';
}
}

/**
* Is admin set to DE?
*/
public function isAdminGermany()
{
$config = $this->getConfig();
return $this->getAdminConfig($config::CONFIG_XML_PATH_REGION) == 'de' || substr($this->getAdminConfig('general/country/default'), 0, 2) == 'DE';
}

/**
* Get config by website or store admin scope
*/
Expand All @@ -255,6 +318,53 @@ public function getAdminConfig($path)
}
}

/**
* Transform an Amazon address into a standard Magento address
*
* @param OffAmazonPaymentsService_Model_Address amazonAddress
*/
public function transformAmazonAddressToMagentoAddress($amazonAddress) {
$name = $amazonAddress->getName();
$firstName = substr($name, 0, strrpos($name, ' '));
$lastName = substr($name, strlen($firstName) + 1);

$data['firstname'] = $firstName;
$data['lastname'] = $lastName;
$data['country_id'] = $amazonAddress->getCountryCode();
$data['city'] = $amazonAddress->getCity();
$data['postcode'] = $amazonAddress->getPostalCode();
$data['telephone'] = $amazonAddress->getPhone() ? $amazonAddress->getPhone() : $this->__('-');

$data['street'] = array();

$countryCode = $amazonAddress->getCountryCode();
$addressLine1 = $amazonAddress->getAddressLine1();
$addressLine2 = $amazonAddress->getAddressLine2();
$addressLine3 = $amazonAddress->getAddressLine3();
if($countryCode && in_array($countryCode, array('AT', 'DE'))){
if ($addressLine3) {
$data['company'] = trim($addressLine1.' '.$addressLine2);
$data['street'][] = $addressLine3;
} else if ($addressLine2) {
$data['company'] = $addressLine1;
$data['street'][] = $addressLine2;
} else {
$data['street'][] = $addressLine1;
}
} else {
if ($addressLine1) {
$data['street'][] = $addressLine1;
}
if ($addressLine2) {
$data['street'][] = $addressLine2;
}
if ($addressLine3) {
$data['street'][] = $addressLine3;
}
}
return $data;
}

/**
* Get admin/default store id
*/
Expand All @@ -273,4 +383,4 @@ public function getAdminStoreId()
}
}

}
}
6 changes: 3 additions & 3 deletions app/code/community/Amazon/Payments/Model/Async.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ public function syncOrderStatus(Mage_Sales_Model_Order $order, $isManualSync = f
return;
}

$message = Mage::helper('payment')->__('Sync with Amazon: Authorization state is %s.', $amazonAuthorizationState);
$message = Mage::helper('payment')->__('Sync with Amazon: Authorization state is "%s".', $amazonAuthorizationState);

switch ($amazonAuthorizationState) {
// Pending (All Authorization objects are in the Pending state for 30 seconds after Authorize request)
case Amazon_Payments_Model_Api::AUTH_STATUS_PENDING:
$message .= ' (Payment is currently authorizing. Please try again momentarily.)';
$message .= Mage::helper('payment')->__(' (Payment is currently authorizing. Please try again momentarily.)');
break;

// Declined
Expand Down Expand Up @@ -171,7 +171,7 @@ public function syncOrderStatus(Mage_Sales_Model_Order $order, $isManualSync = f
else {
$order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true);

$message .= ' Unable to create invoice due to Authorization Reason Code: ' . $reasonCode;
$message .= Mage::helper('payment')->__(' Unable to create invoice due to Authorization Reason Code: %s', $reasonCode);
}

break;
Expand Down
Loading

0 comments on commit 969b006

Please sign in to comment.