Huehuehue - Version 1.0.1

Version Notes

1.1.3

Download this release

Release Info

Developer Magento Core Team
Extension Huehuehue
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

Files changed (57) hide show
  1. app/code/core/Mage/AmazonPayments/Block/Adminhtml/Shipping/Methods.php +103 -0
  2. app/code/core/Mage/AmazonPayments/Block/Asp/Form.php +55 -0
  3. app/code/core/Mage/AmazonPayments/Block/Asp/Redirect.php +77 -0
  4. app/code/core/Mage/AmazonPayments/Block/Asp/Shortcut.php +55 -0
  5. app/code/core/Mage/AmazonPayments/Block/Cba/Form.php +46 -0
  6. app/code/core/Mage/AmazonPayments/Block/Cba/Redirect.php +69 -0
  7. app/code/core/Mage/AmazonPayments/Block/Cba/Success.php +50 -0
  8. app/code/core/Mage/AmazonPayments/Block/Form.php +46 -0
  9. app/code/core/Mage/AmazonPayments/Block/Link/Shortcut.php +90 -0
  10. app/code/core/Mage/AmazonPayments/Helper/Data.php +46 -0
  11. app/code/core/Mage/AmazonPayments/Model/Api/Abstract.php +157 -0
  12. app/code/core/Mage/AmazonPayments/Model/Api/Asp.php +217 -0
  13. app/code/core/Mage/AmazonPayments/Model/Api/Asp/Abstract.php +109 -0
  14. app/code/core/Mage/AmazonPayments/Model/Api/Asp/Amount.php +139 -0
  15. app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps.php +217 -0
  16. app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Request/Abstract.php +86 -0
  17. app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Request/Cancel.php +68 -0
  18. app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Request/Refund.php +92 -0
  19. app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Request/Settle.php +69 -0
  20. app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Response/Abstract.php +107 -0
  21. app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Response/Cancel.php +67 -0
  22. app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Response/Error.php +80 -0
  23. app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Response/Refund.php +67 -0
  24. app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Response/Settle.php +68 -0
  25. app/code/core/Mage/AmazonPayments/Model/Api/Asp/Ipn/Request.php +215 -0
  26. app/code/core/Mage/AmazonPayments/Model/Api/Cba.php +1007 -0
  27. app/code/core/Mage/AmazonPayments/Model/Api/Cba/Document.php +476 -0
  28. app/code/core/Mage/AmazonPayments/Model/Api/Debug.php +44 -0
  29. app/code/core/Mage/AmazonPayments/Model/Mysql4/Api/Debug.php +45 -0
  30. app/code/core/Mage/AmazonPayments/Model/Mysql4/Api/Debug/Collection.php +45 -0
  31. app/code/core/Mage/AmazonPayments/Model/Mysql4/Setup.php +31 -0
  32. app/code/core/Mage/AmazonPayments/Model/Observer.php +58 -0
  33. app/code/core/Mage/AmazonPayments/Model/Payment.php +54 -0
  34. app/code/core/Mage/AmazonPayments/Model/Payment/Asp.php +435 -0
  35. app/code/core/Mage/AmazonPayments/Model/Payment/Asp/Abstract.php +30 -0
  36. app/code/core/Mage/AmazonPayments/Model/Payment/Asp/Fps.php +35 -0
  37. app/code/core/Mage/AmazonPayments/Model/Payment/Asp/Notification.php +544 -0
  38. app/code/core/Mage/AmazonPayments/Model/Payment/Asp/Source/PaymentAction.php +49 -0
  39. app/code/core/Mage/AmazonPayments/Model/Payment/Cba.php +598 -0
  40. app/code/core/Mage/AmazonPayments/Model/Session.php +39 -0
  41. app/code/core/Mage/AmazonPayments/controllers/AspController.php +155 -0
  42. app/code/core/Mage/AmazonPayments/controllers/CbaController.php +167 -0
  43. app/code/core/Mage/AmazonPayments/etc/config.xml +227 -0
  44. app/code/core/Mage/AmazonPayments/etc/system.xml +443 -0
  45. app/code/core/Mage/AmazonPayments/sql/amazonpayments_setup/mysql4-install-0.1.2.php +45 -0
  46. app/code/core/Mage/AmazonPayments/sql/amazonpayments_setup/mysql4-upgrade-0.1.0-0.1.1.php +45 -0
  47. app/code/core/Mage/AmazonPayments/sql/amazonpayments_setup/mysql4-upgrade-0.1.1-0.1.2.php +45 -0
  48. app/design/frontend/base/default/layout/amazonpayments.xml +61 -0
  49. app/design/frontend/base/default/template/amazonpayments/asp/form.phtml +32 -0
  50. app/design/frontend/base/default/template/amazonpayments/asp/redirect.phtml +39 -0
  51. app/design/frontend/base/default/template/amazonpayments/asp/shortcut.phtml +31 -0
  52. app/design/frontend/base/default/template/amazonpayments/cba/form.phtml +32 -0
  53. app/design/frontend/base/default/template/amazonpayments/cba/success.phtml +35 -0
  54. app/design/frontend/base/default/template/amazonpayments/link.phtml +51 -0
  55. app/etc/modules/Mage_AmazonPayments.xml +39 -0
  56. app/locale/en_US/Mage_AmazonCheckout.csv +99 -0
  57. package.xml +18 -0
app/code/core/Mage/AmazonPayments/Block/Adminhtml/Shipping/Methods.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ class Mage_AmazonPayments_Block_Adminhtml_Shipping_Methods
28
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
29
+ {
30
+
31
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
32
+ {
33
+ $this->setElement($element);
34
+
35
+ $html = '<select name="'.$this->getElement()->getName().'[method]" '.$this->_getDisabled().'>';
36
+ $html .= '<option value="None">'.$this->__(' Select shipping method').'</option>';
37
+ foreach ($this->getShippingMethods() as $carrierCode=>$carrier) {
38
+ $html .= '<optgroup label="'.$carrier['title'].'" style="border-top:solid 1px black; margin-top:3px;">';
39
+ foreach ($carrier['methods'] as $methodCode=>$method) {
40
+ $code = $carrierCode.'/'.$methodCode;
41
+ $html .= '<option value="'.$code.'" '.$this->_getSelected($code).' style="background:white;">'.$method['title'].'</option>';
42
+ }
43
+ $html .= '</optgroup>';
44
+ }
45
+ $html .= '</select>';
46
+
47
+ return $html;
48
+ }
49
+
50
+ protected function getShippingMethods()
51
+ {
52
+ if (!$this->hasData('shipping_methods')) {
53
+ $website = $this->getRequest()->getParam('website');
54
+ $store = $this->getRequest()->getParam('store');
55
+
56
+ $storeId = null;
57
+ if (!is_null($website)) {
58
+ $storeId = Mage::getModel('core/website')->load($website, 'code')->getDefaultGroup()->getDefaultStoreId();
59
+ } elseif (!is_null($store)) {
60
+ $storeId = Mage::getModel('core/store')->load($store, 'code')->getId();
61
+ }
62
+
63
+ $methods = array();
64
+ $carriers = Mage::getSingleton('shipping/config')->getActiveCarriers($storeId);
65
+ foreach ($carriers as $carrierCode=>$carrierModel) {
66
+ if (!$carrierModel->isActive()) {
67
+ continue;
68
+ }
69
+ $carrierMethods = $carrierModel->getAllowedMethods();
70
+ if (!$carrierMethods) {
71
+ continue;
72
+ }
73
+ $carrierTitle = Mage::getStoreConfig('carriers/'.$carrierCode.'/title', $storeId);
74
+ $methods[$carrierCode] = array(
75
+ 'title' => $carrierTitle,
76
+ 'methods' => array(),
77
+ );
78
+ foreach ($carrierMethods as $methodCode=>$methodTitle) {
79
+ $methods[$carrierCode]['methods'][$methodCode] = array(
80
+ 'title' => '['.$carrierCode.'] '.$methodTitle,
81
+ );
82
+ }
83
+ }
84
+ $this->setData('shipping_methods', $methods);
85
+ }
86
+ return $this->getData('shipping_methods');
87
+ }
88
+
89
+ protected function _getDisabled()
90
+ {
91
+ return $this->getElement()->getDisabled() ? ' disabled' : '';
92
+ }
93
+
94
+ protected function _getValue($key)
95
+ {
96
+ return $this->getElement()->getData('value/'.$key);
97
+ }
98
+
99
+ protected function _getSelected($value)
100
+ {
101
+ return $this->getElement()->getData('value/method') == $value ? 'selected="selected"' : '';
102
+ }
103
+ }
app/code/core/Mage/AmazonPayments/Block/Asp/Form.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments Form Block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Block_Asp_Form extends Mage_Payment_Block_Form
35
+ {
36
+ /**
37
+ * Varien constructor
38
+ */
39
+ protected function _construct()
40
+ {
41
+ $this->setTemplate('amazonpayments/asp/form.phtml');
42
+ parent::_construct();
43
+ }
44
+
45
+ /**
46
+ * Return method description message
47
+ *
48
+ * @return string
49
+ */
50
+ public function getDescriptionMessage()
51
+ {
52
+ return $this->getMethod()->getChoiceMethodDescription();
53
+ }
54
+
55
+ }
app/code/core/Mage/AmazonPayments/Block/Asp/Redirect.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments Form Block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Block_Asp_Redirect extends Mage_Core_Block_Template
35
+ {
36
+
37
+ /**
38
+ * Return Amazon Simple Pay payment model
39
+ *
40
+ * @return Mage_AmazonPayments_Model_Payment_Asp
41
+ */
42
+ public function getPayment()
43
+ {
44
+ return Mage::registry('amazonpayments_payment_asp');
45
+ }
46
+
47
+ /**
48
+ * Return Amazon Simple Pay payment url
49
+ *
50
+ * @return string
51
+ */
52
+ public function getRedirectUrl()
53
+ {
54
+ return $this->getPayment()->getPayRedirectUrl();
55
+ }
56
+
57
+ /**
58
+ * Return pay params for current order
59
+ *
60
+ * @return array
61
+ */
62
+ public function getRedirectParams()
63
+ {
64
+ return $this->getPayment()->getPayRedirectParams();
65
+ }
66
+
67
+ /**
68
+ * Return redirect message
69
+ *
70
+ * @return string
71
+ */
72
+ public function getRedirectMessage()
73
+ {
74
+ return $this->getPayment()->getRedirectMessage();
75
+ }
76
+
77
+ }
app/code/core/Mage/AmazonPayments/Block/Asp/Shortcut.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Paypal shortcut link
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Paypal
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Block_Asp_Shortcut extends Mage_Core_Block_Template
35
+ {
36
+ public function getCheckoutUrl()
37
+ {
38
+ return $this->getUrl('amazonpayments/asp/checkout');
39
+ }
40
+
41
+ public function getButtonImageUrl()
42
+ {
43
+ return Mage::getStoreConfig('payment/amazonpayments_asp/pay_now_button_image_url');
44
+ }
45
+
46
+ public function _toHtml()
47
+ {
48
+ if (Mage::getStoreConfigFlag('payment/amazonpayments_asp/active')
49
+ && Mage::getSingleton('checkout/session')->getQuote()->validateMinimumAmount()) {
50
+ return parent::_toHtml();
51
+ }
52
+
53
+ return '';
54
+ }
55
+ }
app/code/core/Mage/AmazonPayments/Block/Cba/Form.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Amazon Payments Form Block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Block_Cba_Form extends Mage_Payment_Block_Form
35
+ {
36
+
37
+ /**
38
+ * Varien constructor
39
+ */
40
+ protected function _construct()
41
+ {
42
+ $this->setTemplate('amazonpayments/cba/form.phtml');
43
+ parent::_construct();
44
+ }
45
+
46
+ }
app/code/core/Mage/AmazonPayments/Block/Cba/Redirect.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Amazon Payments Checkout by Amazon Redirect Block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Block_Cba_Redirect extends Mage_Core_Block_Abstract
35
+ {
36
+ /**
37
+ * Shopping cart form to CBA in case XML-based cart
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ $cba = Mage::getModel('amazonpayments/payment_cba');
44
+ /* @var $cba Mage_AmazonPayments_Model_Payment_Cba */
45
+
46
+ $form = new Varien_Data_Form();
47
+ $form->setAction($cba->getAmazonRedirectUrl())
48
+ ->setId('amazonpayments_cba')
49
+ ->setName('amazonpayments_cba')
50
+ ->setMethod('POST')
51
+ ->setUseContainer(true);
52
+
53
+ $formFields = $cba->getCheckoutXmlFormFields();
54
+ $values = '';
55
+ $i = 1;
56
+ foreach ($formFields as $field=>$value) {
57
+ $form->addField($field, 'hidden', array('name'=>$field, 'value'=>$value));
58
+ $values .= ($i++ > 1) ? '&' : '';
59
+ $values .= "{$field}={$value}";
60
+ }
61
+ $html = '<html><body>';
62
+ $html.= $this->__('You will be redirected to Checkout by Amazon in a few seconds.');
63
+ $html.= $form->toHtml();
64
+ $html.= '<script type="text/javascript">document.getElementById("amazonpayments_cba").submit();</script>';
65
+ $html.= '</body></html>';
66
+
67
+ return $html;
68
+ }
69
+ }
app/code/core/Mage/AmazonPayments/Block/Cba/Success.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Amazon Payments Checkout by Amazon Success Block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Block_Cba_Success extends Mage_Core_Block_Abstract
35
+ {
36
+ /**
37
+ * Success page
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ echo "<p><strong>{$this->__('Thank you for your purchase!') }</strong></p>\n";
44
+ echo $this->__('You will receive an order confirmation email with details of your order and a link to track its progress.<br/>');
45
+
46
+
47
+ return '';
48
+ }
49
+
50
+ }
app/code/core/Mage/AmazonPayments/Block/Form.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Amazon Payments Form Block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Block_Form extends Mage_Payment_Block_Form
35
+ {
36
+
37
+ /**
38
+ * Varien constructor
39
+ */
40
+ protected function _construct()
41
+ {
42
+ $this->setTemplate('amazonpayments/form.phtml');
43
+ parent::_construct();
44
+ }
45
+
46
+ }
app/code/core/Mage/AmazonPayments/Block/Link/Shortcut.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Paypal shortcut link
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Paypal
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Block_Link_Shortcut extends Mage_Core_Block_Template
35
+ {
36
+ public function getCheckoutUrl()
37
+ {
38
+ #return $this->getUrl('amazonpayments/cba', array('_secure'=>true));
39
+ return $this->getUrl('amazonpayments/cba/shortcut');
40
+ }
41
+
42
+ public function getImageUrl()
43
+ {
44
+ return Mage::getStoreConfig('payment/amazonpayments_cba/button_url');
45
+ #return 'http://g-ecx.images-amazon.com/images/G/01/cba/images/buttons/btn_Chkout-orange-large.gif';
46
+ }
47
+
48
+ public function _toHtml()
49
+ {
50
+ if (Mage::getStoreConfigFlag('payment/amazonpayments_cba/active')
51
+ && Mage::getSingleton('checkout/session')->getQuote()->validateMinimumAmount()) {
52
+ return parent::_toHtml();
53
+ }
54
+
55
+ return '';
56
+ }
57
+
58
+ public function getCbaOneClickJsUrl()
59
+ {
60
+ if (Mage::getStoreConfigFlag('payment/amazonpayments_cba/sandbox_flag')) {
61
+ $url = 'https://images-na.ssl-images-amazon.com/images/G/01/cba/js/widget/sandbox/widget.js';
62
+ } else {
63
+ $url = 'https://images-na.ssl-images-amazon.com/images/G/01/cba/js/widget/widget.js';
64
+ }
65
+ return $url;
66
+ }
67
+
68
+ public function getCbaStylesheetUrl()
69
+ {
70
+ $url = 'https://images-na.ssl-images-amazon.com/images/G/01/cba/styles/one-click.css';
71
+ return $url;
72
+ }
73
+
74
+ public function getCbaJquerySetupUrl()
75
+ {
76
+ $url = 'https://images-na.ssl-images-amazon.com/images/G/01/cba/js/jquery.js';
77
+ return $url;
78
+ }
79
+
80
+ /**
81
+ * Return true if 1-Click is enabled
82
+ *
83
+ * @return boolean
84
+ */
85
+ public function getIsOneClickEnabled()
86
+ {
87
+ return Mage::getStoreConfigFlag('payment/amazonpayments_cba/use_oneclick');
88
+ }
89
+
90
+ }
app/code/core/Mage/AmazonPayments/Helper/Data.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Amazon Checlout Data Helper
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Helper_Data extends Mage_Core_Helper_Abstract
35
+ {
36
+ /**
37
+ * Format amount value (2 digits after the decimal point)
38
+ *
39
+ * @param float $amount
40
+ * @return float
41
+ */
42
+ public function formatAmount($amount)
43
+ {
44
+ return round($amount, 2);
45
+ }
46
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Abstract.php ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments Base API Model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ abstract class Mage_AmazonPayments_Model_Api_Abstract extends Varien_Object
35
+ {
36
+ /*
37
+ * payment actions
38
+ */
39
+ const PAYMENT_TYPE_AUTH = 'Authorization';
40
+ const USER_ACTION_COMMIT = 'commit';
41
+
42
+ /*
43
+ * signature generation algorithm name
44
+ */
45
+ protected static $HMAC_SHA1_ALGORITHM = 'sha1';
46
+
47
+ /*
48
+ * payment module code
49
+ */
50
+ protected $paymentCode;
51
+
52
+ /**
53
+ * Set payment module code
54
+ *
55
+ * @return string
56
+ */
57
+ public function setPaymentCode($paymentCode)
58
+ {
59
+ if(is_null($this->paymentCode)) {
60
+ $this->paymentCode = $paymentCode;
61
+ $this->setData(Mage::getStoreConfig('payment/' . $paymentCode));
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Return payment url
67
+ *
68
+ * @return string
69
+ */
70
+ public function getPayServiceUrl()
71
+ {
72
+ if ($this->getSandboxFlag()) {
73
+ return $this->getData('sandbox_pay_service_url');
74
+ }
75
+ return $this->getData('pay_service_url');
76
+ }
77
+
78
+ /**
79
+ * Get value from the payment module config
80
+ *
81
+ * @param string $kay
82
+ * @param string $default
83
+ * @return string
84
+ */
85
+ public function getConfigData($key, $default = false)
86
+ {
87
+ if (!$this->hasData($key)) {
88
+ $value = Mage::getStoreConfig('payment/' . $paymentCode . '/' . $key);
89
+ if (is_null($value) || false===$value) {
90
+ $value = $default;
91
+ }
92
+ $this->setData($key, $value);
93
+ }
94
+ return $this->getData($key);
95
+ }
96
+
97
+ /**
98
+ * Check signed params
99
+ *
100
+ * @param array $params
101
+ * @return bool
102
+ */
103
+ public function checkSignParams($params)
104
+ {
105
+ if (is_array($params) && isset($params[$this->getRequestSignatureParamName()])) {
106
+ $paramSignature = $params[$this->getRequestSignatureParamName()];
107
+ unset($params[$this->getRequestSignatureParamName()]);
108
+ $generateSignature = $this->_getSignatureForArray($params, $this->getSecretKey());
109
+ return $paramSignature == $generateSignature;
110
+ }
111
+
112
+ return false;
113
+ }
114
+
115
+ /**
116
+ * Add signature param to params array
117
+ *
118
+ * @param array $params
119
+ * @return array
120
+ */
121
+ public function signParams($params)
122
+ {
123
+ $signature = $this->_getSignatureForArray($params, $this->getSecretKey());
124
+ $params[$this->getRequestSignatureParamName()] = $signature;
125
+ return $params;
126
+ }
127
+
128
+ /**
129
+ * Return signature for array
130
+ *
131
+ * @param array $array
132
+ * @param string $secretKey
133
+ * @return array
134
+ */
135
+ protected function _getSignatureForArray($array, $secretKey)
136
+ {
137
+ uksort($array, 'strcasecmp');
138
+ $tmpString = '';
139
+ foreach ($array as $paramName => $paramValue) {
140
+ $tmpString = $tmpString . $paramName . $paramValue;
141
+ }
142
+ return $this->_getSignatureForString($tmpString, $secretKey);
143
+ }
144
+
145
+ /**
146
+ * Return signature for string
147
+ *
148
+ * @param string $string
149
+ * @param string $secretKey
150
+ * @return string
151
+ */
152
+ protected function _getSignatureForString($string, $secretKey)
153
+ {
154
+ $rawHmac = hash_hmac(self::$HMAC_SHA1_ALGORITHM, $string, $secretKey, true);
155
+ return base64_encode($rawHmac);
156
+ }
157
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Asp.php ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments ASP API Model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Api_Asp extends Mage_AmazonPayments_Model_Api_Asp_Abstract
35
+ {
36
+ /**
37
+ * collect shipping address to IPN notification request
38
+ */
39
+ protected $_collectShippingAddress = 0;
40
+
41
+ /**
42
+ * IPN notification request model path
43
+ */
44
+ protected $_ipnRequest = 'amazonpayments/api_asp_ipn_request';
45
+
46
+ /**
47
+ * FPS model path
48
+ */
49
+ protected $_fpsModel = 'amazonpayments/api_asp_fps';
50
+
51
+ /**
52
+ * Get singleton with AmazonPayments ASP API FPS Model
53
+ *
54
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps
55
+ */
56
+ protected function _getFps()
57
+ {
58
+ return Mage::getSingleton($this->_fpsModel)->setStoreId($this->getStoreId());
59
+ }
60
+
61
+ /**
62
+ * Get singleton with AmazonPayments ASP IPN notification request Model
63
+ *
64
+ * @return Mage_AmazonPayments_Model_Api_Asp_Ipn_Request
65
+ */
66
+ protected function _getIpnRequest()
67
+ {
68
+ return Mage::getSingleton($this->_ipnRequest);
69
+ }
70
+
71
+
72
+ /**
73
+ * Return Amazon Simple Pay payment url
74
+ *
75
+ * @return string
76
+ */
77
+ public function getPayUrl ()
78
+ {
79
+ if ($this->_isSandbox()) {
80
+ return $this->_getConfig('pay_service_url_sandbox');
81
+ }
82
+ return $this->_getConfig('pay_service_url');
83
+ }
84
+
85
+ /**
86
+ * Return Amazon Simple Pay payment params
87
+ *
88
+ * @param string $referenceId
89
+ * @param string $amountValue
90
+ * @param string $currencyCode
91
+ * @param string $abandonUrl
92
+ * @param string $returnUrl
93
+ * @param string $ipnUrl
94
+ * @return array
95
+ */
96
+ public function getPayParams($referenceId, $amountValue, $currencyCode, $abandonUrl, $returnUrl, $ipnUrl)
97
+ {
98
+ $amount = Mage::getSingleton('amazonpayments/api_asp_amount')
99
+ ->setValue($amountValue)
100
+ ->setCurrencyCode($currencyCode);
101
+
102
+ $requestParams = array();
103
+ $requestParams['referenceId'] = $referenceId;
104
+ $requestParams['amount'] = $amount->toString();
105
+ $requestParams['description'] = $this->_getConfig('pay_description');
106
+
107
+ $requestParams['accessKey'] = $this->_getConfig('access_key');
108
+ $requestParams['processImmediate'] = $this->_getConfig('pay_process_immediate');
109
+ $requestParams['immediateReturn'] = $this->_getConfig('pay_immediate_return');
110
+ $requestParams['collectShippingAddress'] = $this->_collectShippingAddress;
111
+ $requestParams['abandonUrl'] = $abandonUrl;
112
+ $requestParams['returnUrl'] = $returnUrl;
113
+ $requestParams['ipnUrl'] = $ipnUrl;
114
+
115
+ $signature = $this->_getSignatureForArray($requestParams, $this->_getConfig('secret_key'));
116
+ $requestParams['signature'] = $signature;
117
+
118
+ return $requestParams;
119
+ }
120
+
121
+ /**
122
+ * process notification request
123
+ *
124
+ * @param array $requestParams
125
+ * @return Mage_AmazonPayments_Model_Api_Asp_Ipn_Request
126
+ */
127
+ public function processNotification($requestParams)
128
+ {
129
+ $requestSignature = false;
130
+
131
+ if (isset($requestParams['signature'])) {
132
+ $requestSignature = $requestParams['signature'];
133
+ unset($requestParams['signature']);
134
+ }
135
+
136
+ $originalSignature = $this->_getSignatureForArray($requestParams, $this->_getConfig('secret_key'));
137
+ if ($requestSignature != $originalSignature) {
138
+ Mage::throwException(Mage::helper('amazonpayments')->__('Request signed an incorrect or missing signature'));
139
+ }
140
+
141
+ $ipnRequest = $this->_getIpnRequest();
142
+
143
+ if(!$ipnRequest->init($requestParams)) {
144
+ Mage::throwException(Mage::helper('amazonpayments')->__('Request is not a valid IPN request'));
145
+ }
146
+
147
+ return $ipnRequest;
148
+ }
149
+
150
+ /**
151
+ * cancel payment through FPS api
152
+ *
153
+ * @param string $transactionId
154
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract
155
+ */
156
+ public function cancel($transactionId)
157
+ {
158
+ $fps = $this->_getFps();
159
+
160
+ $request = $fps->getRequest(Mage_AmazonPayments_Model_Api_Asp_Fps::ACTION_CODE_CANCEL)
161
+ ->setTransactionId($transactionId)
162
+ ->setDescription($this->_getConfig('cancel_description'));
163
+
164
+ $response = $fps->process($request);
165
+ return $response;
166
+ }
167
+
168
+ /**
169
+ * capture payment through FPS api
170
+ *
171
+ * @param string $transactionId
172
+ * @param string $amount
173
+ * @param string $currencyCode
174
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract
175
+ */
176
+ public function capture($transactionId, $amount, $currencyCode)
177
+ {
178
+ $fps = $this->_getFps();
179
+ $amount = $this->_getAmount()
180
+ ->setValue($amount)
181
+ ->setCurrencyCode($currencyCode);
182
+
183
+ $request = $fps->getRequest(Mage_AmazonPayments_Model_Api_Asp_Fps::ACTION_CODE_SETTLE)
184
+ ->setTransactionId($transactionId)
185
+ ->setAmount($amount);
186
+
187
+ $response = $fps->process($request);
188
+ return $response;
189
+ }
190
+
191
+ /**
192
+ * capture payment through FPS api
193
+ *
194
+ * @param string $transactionId
195
+ * @param string $amount
196
+ * @param string $currencyCode
197
+ * @param string $referenceId
198
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract
199
+ */
200
+ public function refund($transactionId, $amount, $currencyCode, $referenceId)
201
+ {
202
+ $fps = $this->_getFps();
203
+
204
+ $amount = $this->_getAmount()
205
+ ->setValue($amount)
206
+ ->setCurrencyCode($currencyCode);
207
+
208
+ $request = $fps->getRequest(Mage_AmazonPayments_Model_Api_Asp_Fps::ACTION_CODE_REFUND)
209
+ ->setTransactionId($transactionId)
210
+ ->setReferenceId($referenceId)
211
+ ->setAmount($amount)
212
+ ->setDescription($this->_getConfig('refund_description'));
213
+
214
+ $response = $fps->process($request);
215
+ return $response;
216
+ }
217
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Asp/Abstract.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments ASP Base API Model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Api_Asp_Abstract extends Mage_AmazonPayments_Model_Api_Abstract
35
+ {
36
+ /**
37
+ * payment actions
38
+ */
39
+ const PAY_ACTION_SETTLE = 0;
40
+ const PAY_ACTION_SETTLE_CAPTURE = 1;
41
+
42
+ /**
43
+ * rewrited for Mage_AmazonPayments_Model_Api_Abstract
44
+ */
45
+ protected $paymentCode = 'amazonpayments_asp';
46
+
47
+ /**
48
+ * Amount model path
49
+ */
50
+ protected $_amountModel = 'amazonpayments/api_asp_amount';
51
+
52
+ /**
53
+ * Store id for current operation
54
+ */
55
+ protected $_storeId = null;
56
+
57
+ /**
58
+ * Set store id for current operation
59
+ *
60
+ * @param $id string
61
+ * @return Mage_AmazonPayments_Model_Api_Asp_Abstract
62
+ */
63
+ public function setStoreId($id)
64
+ {
65
+ $this->_storeId = $id;
66
+ return $this;
67
+ }
68
+
69
+ /**
70
+ * Get store id for current operation
71
+ *
72
+ * @return string
73
+ */
74
+ public function getStoreId()
75
+ {
76
+ return $this->_storeId;
77
+ }
78
+
79
+ /**
80
+ * Get singleton with AmazonPayments ASP Amount Model
81
+ *
82
+ * @return Mage_AmazonPayments_Model_Api_Asp_Amount
83
+ */
84
+ protected function _getAmount()
85
+ {
86
+ return Mage::getSingleton($this->_amountModel);
87
+ }
88
+
89
+ /**
90
+ * Return sandbox mode flag
91
+ *
92
+ * @return bool
93
+ */
94
+ protected function _isSandbox()
95
+ {
96
+ return $this->_getConfig('is_sandbox');
97
+ }
98
+
99
+ /**
100
+ * Get value from the module config
101
+ *
102
+ * @param string $path
103
+ * @return string
104
+ */
105
+ protected function _getConfig($path)
106
+ {
107
+ return Mage::getStoreConfig('payment/' . $this->paymentCode . '/' . $path, $this->getStoreId());
108
+ }
109
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Asp/Amount.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments ASP Amount Model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Api_Asp_Amount
35
+ {
36
+ /*
37
+ * Amount value
38
+ */
39
+ private $_value;
40
+
41
+ /*
42
+ * Amount currency code
43
+ */
44
+ private $_currencyCode;
45
+
46
+ /*
47
+ * Template union amount
48
+ */
49
+ protected $_amountStringTemplate = "/^([A-Z]{3})\s([0-9]{1,}|[0-9]{1,}[.][0-9]{1,})$/";
50
+
51
+ /*
52
+ * Template amount value
53
+ */
54
+ protected $_valueStringTemplate = "/^([0-9]{1,}|[0-9]{1,}[.][0-9]{1,})$/";
55
+
56
+ /*
57
+ * Template amount currency code
58
+ */
59
+ protected $_currencyCodeStringTemplate = "/^([A-Z]{3})$/";
60
+
61
+ /**
62
+ * Init object
63
+ *
64
+ * @param string $amount - union amount
65
+ * @return Mage_AmazonPayments_Model_Api_Asp_Amount
66
+ */
67
+ public function init($amount)
68
+ {
69
+ $tmpArr = array();
70
+ if (!preg_match($this->_amountStringTemplate, $amount, $tmpArr)) {
71
+ return false;
72
+ }
73
+ $this->_value = $tmpArr[2];
74
+ $this->_currencyCode = $tmpArr[1];
75
+ return $this;
76
+ }
77
+
78
+ /**
79
+ * Set amount value
80
+ *
81
+ * @param string $value
82
+ * @return Mage_AmazonPayments_Model_Api_Asp_Amount
83
+ */
84
+ public function setValue($value)
85
+ {
86
+ $tmpArr = array();
87
+ if (!preg_match($this->_valueStringTemplate, $value, $tmpArr)) {
88
+ return false;
89
+ }
90
+ $this->_value = $tmpArr[1];
91
+ return $this;
92
+ }
93
+
94
+ /**
95
+ * Set amount currency code
96
+ *
97
+ * @param string $currencyCode
98
+ * @return Mage_AmazonPayments_Model_Api_Asp_Amount
99
+ */
100
+ public function setCurrencyCode($currencyCode)
101
+ {
102
+ $tmpArr = array();
103
+ if (!preg_match($this->_currencyCodeStringTemplate, $currencyCode, $tmpArr)) {
104
+ return false;
105
+ }
106
+ $this->_currencyCode = $tmpArr[1];
107
+ return $this;
108
+ }
109
+
110
+ /**
111
+ * Get amount value
112
+ *
113
+ * @return string
114
+ */
115
+ public function getValue()
116
+ {
117
+ return $this->_value;
118
+ }
119
+
120
+ /**
121
+ * Get amount currency code
122
+ *
123
+ * @return string
124
+ */
125
+ public function getCurrencyCode()
126
+ {
127
+ return $this->_currencyCode;
128
+ }
129
+
130
+ /**
131
+ * Return union amount string
132
+ *
133
+ * @return string
134
+ */
135
+ public function toString()
136
+ {
137
+ return $this->getCurrencyCode() . ' ' . $this->getValue();
138
+ }
139
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps.php ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments FPS Model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Api_Asp_Fps extends Mage_AmazonPayments_Model_Api_Asp_Abstract
35
+ {
36
+ /*
37
+ * Amazon FPS version protocol
38
+ */
39
+ const SERVICE_VERSION = '2008-09-17';
40
+
41
+ /*
42
+ * FPS action codes
43
+ */
44
+ const ACTION_CODE_CANCEL = 'Cancel';
45
+ const ACTION_CODE_SETTLE = 'Settle';
46
+ const ACTION_CODE_REFUND = 'Refund';
47
+
48
+ /*
49
+ * Exeption identifiers
50
+ */
51
+ const EXCEPTION_INVALID_ACTION_CODE = 10031;
52
+ const EXCEPTION_INVALID_REQUEST = 10031;
53
+ const EXCEPTION_INVALID_RESPONSE = 10032;
54
+
55
+ /**
56
+ * Return FPS request model
57
+ *
58
+ * @param string $actionCode
59
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract
60
+ */
61
+ public function getRequest($actionCode)
62
+ {
63
+ switch ($actionCode) {
64
+ case self::ACTION_CODE_CANCEL:
65
+ $requestModelPath = 'amazonpayments/api_asp_fps_request_cancel';
66
+ break;
67
+ case self::ACTION_CODE_SETTLE:
68
+ $requestModelPath = 'amazonpayments/api_asp_fps_request_settle';
69
+ break;
70
+ case self::ACTION_CODE_REFUND:
71
+ $requestModelPath = 'amazonpayments/api_asp_fps_request_refund';
72
+ break;
73
+ default: $this->_throwExeptionInvalidActionCode();
74
+ }
75
+
76
+ return Mage::getSingleton($requestModelPath)->init($actionCode);
77
+ }
78
+
79
+ /**
80
+ * Return FPS response model for response body
81
+ *
82
+ * @param string $requestActionCode
83
+ * @param string $responseBody
84
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract
85
+ */
86
+ protected function _getResponse($requestActionCode, $responseBody)
87
+ {
88
+ switch ($requestActionCode) {
89
+ case self::ACTION_CODE_CANCEL:
90
+ $responseModelPath = 'amazonpayments/api_asp_fps_response_cancel';
91
+ break;
92
+ case self::ACTION_CODE_SETTLE:
93
+ $responseModelPath = 'amazonpayments/api_asp_fps_response_settle';
94
+ break;
95
+ case self::ACTION_CODE_REFUND:
96
+ $responseModelPath = 'amazonpayments/api_asp_fps_response_refund';
97
+ break;
98
+ default: $this->_throwExeptionInvalidActionCode();
99
+ }
100
+
101
+ $actionResponse = Mage::getSingleton($responseModelPath);
102
+ if ($actionResponse->init($responseBody)) {
103
+ return $actionResponse;
104
+ }
105
+
106
+ $errorResponse = Mage::getSingleton('amazonpayments/api_asp_fps_response_error');
107
+ if ($errorResponse->init($responseBody)) {
108
+ return $errorResponse;
109
+ }
110
+
111
+ throw new Exception(
112
+ Mage::helper('amazonpayments')->__('Response body is not valid FPS respons'),
113
+ self::EXCEPTION_INVALID_RESPONSE
114
+ );
115
+ }
116
+
117
+ /**
118
+ * Process FPS request
119
+ *
120
+ * @param object Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract $request
121
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract
122
+ */
123
+ public function process($request)
124
+ {
125
+ if (!$request->isValid()) {
126
+ throw new Exception(
127
+ Mage::helper('amazonpayments')->__('Invalid request'),
128
+ self::EXCEPTION_INVALID_REQUEST
129
+ );
130
+ }
131
+
132
+ $request = $this->_addRequiredParameters($request);
133
+ $request = $this->_signRequest($request);
134
+
135
+ $responseBody = $this->_call($this->_getServiceUrl(), $request->getData());
136
+ return $this->_getResponse($request->getActionCode(), $responseBody);
137
+ }
138
+
139
+ /**
140
+ * Return Amazon FPS service url
141
+ *
142
+ * @return string
143
+ */
144
+ protected function _getServiceUrl()
145
+ {
146
+ if ($this->_isSandbox()) {
147
+ return $this->_getConfig('fps_service_url_sandbox');
148
+ }
149
+ return $this->_getConfig('fps_service_url');
150
+ }
151
+
152
+ /**
153
+ * Add required params to FPS request
154
+ *
155
+ * @param object Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract
156
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract
157
+ */
158
+ protected function _addRequiredParameters($request)
159
+ {
160
+ return $request->setData('AWSAccessKeyId', $this->_getConfig('access_key'))
161
+ ->setData('Timestamp', gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()))
162
+ ->setData('Version', self::SERVICE_VERSION)
163
+ ->setData('SignatureVersion', '1');
164
+ }
165
+
166
+ /**
167
+ * Add signature param to FPS request
168
+ *
169
+ * @param object Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract
170
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract
171
+ */
172
+ protected function _signRequest($request)
173
+ {
174
+ $signature = $this->_getSignatureForArray($request->getData(), $this->_getConfig('secret_key'));
175
+ return $request->setData('Signature', $signature);
176
+ }
177
+
178
+ /**
179
+ * Send request to Amazon FPS service and return response body
180
+ *
181
+ * @param string $serviceUrl
182
+ * @param array $params
183
+ * @return Varien_Simplexml_Element
184
+ */
185
+ protected function _call($serviceUrl, $params)
186
+ {
187
+ $tmpArray = array();
188
+ foreach ($params as $kay => $value) {
189
+ $tmpArray[] = $kay . '=' . urlencode($value);
190
+ }
191
+ $requestBody = implode('&', $tmpArray);
192
+
193
+ $http = new Varien_Http_Adapter_Curl();
194
+ $http->setConfig(array('timeout' => 30));
195
+ $http->write(Zend_Http_Client::POST, $serviceUrl, '1.1', array(), $requestBody);
196
+
197
+ $responseBody = $http->read();
198
+ $responseBody = preg_split('/^\r?$/m', $responseBody, 2);
199
+ $responseBody = trim($responseBody[1]);
200
+
201
+ $responseBody = new Varien_Simplexml_Element($responseBody);
202
+
203
+ $http->close();
204
+ return $responseBody;
205
+ }
206
+
207
+ /**
208
+ * Throw exeption: Invalid action code
209
+ */
210
+ protected function _throwExeptionInvalidActionCode()
211
+ {
212
+ throw new Exception(
213
+ Mage::helper('amazonpayments')->__('Invalid action code'),
214
+ self::EXCEPTION_INVALID_ACTION_CODE
215
+ );
216
+ }
217
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Request/Abstract.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments FPS base request Model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract extends Varien_Object
35
+ {
36
+ /*
37
+ * Request action code
38
+ */
39
+ private $_actionCode;
40
+
41
+ /**
42
+ * Init object
43
+ *
44
+ * @param string $actionCode
45
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract
46
+ */
47
+ public function init($actionCode)
48
+ {
49
+ if (is_null($this->_actionCode)) {
50
+ $this->_actionCode = $actionCode;
51
+ $this->initDefaultParams();
52
+ }
53
+ return $this;
54
+ }
55
+
56
+ /**
57
+ * Init default request params
58
+ */
59
+ protected function initDefaultParams()
60
+ {
61
+ $this->setData('Action', $this->getActionCode());
62
+ }
63
+
64
+ /**
65
+ * Return request action code
66
+ *
67
+ * @return string
68
+ */
69
+ public function getActionCode()
70
+ {
71
+ return $this->_actionCode;
72
+ }
73
+
74
+ /**
75
+ * Validation request params
76
+ *
77
+ * @return bool
78
+ */
79
+ public function isValid()
80
+ {
81
+ if (!$this->getData('Action')) {
82
+ return false;
83
+ }
84
+ return true;
85
+ }
86
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Request/Cancel.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments FPS request Model, cancel
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Cancel extends Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract
35
+ {
36
+ /**
37
+ * rewrited for Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract
38
+ */
39
+ public function isValid()
40
+ {
41
+ if (!$this->getData('TransactionId')) {
42
+ return false;
43
+ }
44
+ return parent::isValid();
45
+ }
46
+
47
+ /**
48
+ * Set request TransactionId
49
+ *
50
+ * @param string $transactionId
51
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Cancel
52
+ */
53
+ public function setTransactionId($transactionId)
54
+ {
55
+ return $this->setData('TransactionId', $transactionId);
56
+ }
57
+
58
+ /**
59
+ * Set request Description
60
+ *
61
+ * @param string $description
62
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Cancel
63
+ */
64
+ public function setDescription($description)
65
+ {
66
+ return $this->setData('Description', $description);
67
+ }
68
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Request/Refund.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments FPS request Model, refund
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Refund extends Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract
35
+ {
36
+ /**
37
+ * rewrited for Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract
38
+ */
39
+ public function isValid()
40
+ {
41
+ if (!$this->getData('TransactionId') ||
42
+ !$this->getData('CallerReference')) {
43
+ return false;
44
+ }
45
+ return parent::isValid();
46
+ }
47
+
48
+ /**
49
+ * Set request transactionId
50
+ *
51
+ * @param string $transactionId
52
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Refund
53
+ */
54
+ public function setTransactionId($transactionId)
55
+ {
56
+ return $this->setData('TransactionId', $transactionId);
57
+ }
58
+
59
+ /**
60
+ * Set request referenceId
61
+ *
62
+ * @param string $referenceId
63
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Refund
64
+ */
65
+ public function setReferenceId($referenceId)
66
+ {
67
+ return $this->setData('CallerReference', $referenceId);
68
+ }
69
+
70
+ /**
71
+ * Set request description
72
+ *
73
+ * @param string $description
74
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Refund
75
+ */
76
+ public function setDescription($description)
77
+ {
78
+ return $this->setData('CallerDescription', $description);
79
+ }
80
+
81
+ /**
82
+ * Set request amount
83
+ *
84
+ * @param Mage_AmazonPayments_Model_Api_Asp_Amount $amount
85
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Refund
86
+ */
87
+ public function setAmount($amount)
88
+ {
89
+ return $this->setData('RefundAmount.Value', $amount->getValue())
90
+ ->setData('RefundAmount.CurrencyCode', $amount->getCurrencyCode());
91
+ }
92
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Request/Settle.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments FPS request Model, settle
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Settle extends Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract
35
+ {
36
+ /**
37
+ * rewrited for Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract
38
+ */
39
+ public function isValid()
40
+ {
41
+ if (!$this->getData('ReserveTransactionId')) {
42
+ return false;
43
+ }
44
+ return parent::isValid();
45
+ }
46
+
47
+ /**
48
+ * Set request transactionId
49
+ *
50
+ * @param string $transactionId
51
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Settle
52
+ */
53
+ public function setTransactionId($transactionId)
54
+ {
55
+ return $this->setData('ReserveTransactionId', $transactionId);
56
+ }
57
+
58
+ /**
59
+ * Set request amount
60
+ *
61
+ * @param Mage_AmazonPayments_Model_Api_Asp_Amount $amount
62
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Settle
63
+ */
64
+ public function setAmount($amount)
65
+ {
66
+ return $this->setData('TransactionAmount.Value', $amount->getValue())
67
+ ->setData('TransactionAmount.CurrencyCode', $amount->getCurrencyCode());
68
+ }
69
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Response/Abstract.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments FPS base response Model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract extends Varien_Object
35
+ {
36
+ /*
37
+ * Response statuses
38
+ */
39
+ const STATUS_CANCELLED = 'Cancelled';
40
+ const STATUS_FAILURE = 'Failure';
41
+ const STATUS_PENDING = 'Pending';
42
+ const STATUS_RESERVED = 'Reserved';
43
+ const STATUS_SUCCESS = 'Success';
44
+ const STATUS_ERROR = 'Error';
45
+
46
+ /**
47
+ * Init object
48
+ *
49
+ * @param Varien_Simplexml_Element $responseBody
50
+ * @return Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract
51
+ */
52
+ public function init($responseBody)
53
+ {
54
+ if (!$this->parse($responseBody)) {
55
+ return false;
56
+ }
57
+ return $this;
58
+ }
59
+
60
+ /**
61
+ * Parse response body
62
+ *
63
+ * @param Varien_Simplexml_Element $responseBody
64
+ * @return bool
65
+ */
66
+ protected function parse($responseBody)
67
+ {
68
+ $responseId = (string)$responseBody->ResponseMetadata->RequestId;
69
+ if($responseId == '') {
70
+ return false;
71
+ }
72
+ $this->setData('Id', $responseId);
73
+
74
+ if (!$status = $this->getData('Status')) {
75
+ return false;
76
+ }
77
+ if ($status != self::STATUS_CANCELLED &&
78
+ $status != self::STATUS_FAILURE &&
79
+ $status != self::STATUS_PENDING &&
80
+ $status != self::STATUS_RESERVED &&
81
+ $status != self::STATUS_SUCCESS) {
82
+ return false;
83
+ }
84
+ return true;
85
+ }
86
+
87
+ /**
88
+ * Return status of respons
89
+ *
90
+ * @return string
91
+ */
92
+ public function getStatus()
93
+ {
94
+ return $this->getData('Status');
95
+ }
96
+
97
+ /**
98
+ * Return response ID
99
+ *
100
+ * @return string
101
+ */
102
+ public function getId()
103
+ {
104
+ return $this->getData('Id');
105
+ }
106
+
107
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Response/Cancel.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments FPS response Model, cancel
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Cancel extends Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract
35
+ {
36
+ /**
37
+ * rewrited for Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract
38
+ */
39
+ protected function parse($responseBody)
40
+ {
41
+ if ($responseBody->getName() != 'CancelResponse') {
42
+ return false;
43
+ }
44
+
45
+ $transactionId = (string)$responseBody->CancelResult->TransactionId;
46
+ $transactionStatus = (string)$responseBody->CancelResult->TransactionStatus;
47
+
48
+ if($transactionId == '' || $transactionStatus == '') {
49
+ return false;
50
+ }
51
+
52
+ $this->setData('TransactionId', $transactionId);
53
+ $this->setData('Status', $transactionStatus);
54
+
55
+ return parent::parse($responseBody);
56
+ }
57
+
58
+ /**
59
+ * Return response TransactionId
60
+ *
61
+ * @return string
62
+ */
63
+ public function getTransactionId()
64
+ {
65
+ return $this->getData('TransactionId');
66
+ }
67
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Response/Error.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments FPS response Model, error
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Error extends Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract
35
+ {
36
+ /**
37
+ * rewrited for Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract
38
+ */
39
+ protected function parse($responseBody)
40
+ {
41
+ if ($responseBody->getName() != 'Response') {
42
+ return false;
43
+ }
44
+
45
+ $code = (string)$responseBody->Errors->Error->Code;
46
+ $message = (string)$responseBody->Errors->Error->Message;
47
+ $responseId = (string)$responseBody->RequestID;
48
+
49
+ if($code == '' || $message == '' || $responseId == '') {
50
+ return false;
51
+ }
52
+
53
+ $this->setData('Id', $responseId);
54
+ $this->setData('Status', parent::STATUS_ERROR);
55
+ $this->setData('Code', $code);
56
+ $this->setData('Message', $message);
57
+ return true;
58
+ }
59
+
60
+ /**
61
+ * Return response Code
62
+ *
63
+ * @return string
64
+ */
65
+ public function getCode()
66
+ {
67
+ return $this->getData('Code');
68
+ }
69
+
70
+ /**
71
+ * Return response Message
72
+ *
73
+ * @return string
74
+ */
75
+ public function getMessage()
76
+ {
77
+ return $this->getData('Message');
78
+ }
79
+
80
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Response/Refund.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments FPS response Model, refund
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Refund extends Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract
35
+ {
36
+ /**
37
+ * rewrited for Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract
38
+ */
39
+ protected function parse($responseBody)
40
+ {
41
+ if ($responseBody->getName() != 'RefundResponse') {
42
+ return false;
43
+ }
44
+
45
+ $transactionId = (string)$responseBody->RefundResult->TransactionId;
46
+ $transactionStatus = (string)$responseBody->RefundResult->TransactionStatus;
47
+
48
+ if($transactionId == '' || $transactionStatus == '') {
49
+ return false;
50
+ }
51
+
52
+ $this->setData('TransactionId', $transactionId);
53
+ $this->setData('Status', $transactionStatus);
54
+
55
+ return parent::parse($responseBody);
56
+ }
57
+
58
+ /**
59
+ * Return response TransactionId
60
+ *
61
+ * @return string
62
+ */
63
+ public function getTransactionId()
64
+ {
65
+ return $this->getData('TransactionId');
66
+ }
67
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Asp/Fps/Response/Settle.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments FPS response Model, settle
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Settle extends Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract
35
+ {
36
+ /**
37
+ * rewrited for Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract
38
+ */
39
+ protected function parse($responseBody)
40
+ {
41
+ if ($responseBody->getName() != 'SettleResponse') {
42
+ return false;
43
+ }
44
+
45
+ $transactionId = (string)$responseBody->SettleResult->TransactionId;
46
+ $transactionStatus = (string)$responseBody->SettleResult->TransactionStatus;
47
+
48
+ if($transactionId == '' || $transactionStatus == '') {
49
+ return false;
50
+ }
51
+
52
+ $this->setData('TransactionId', $transactionId);
53
+ $this->setData('Status', $transactionStatus);
54
+
55
+ return parent::parse($responseBody);
56
+ }
57
+
58
+ /**
59
+ * Return response TransactionId
60
+ *
61
+ * @return string
62
+ */
63
+ public function getTransactionId()
64
+ {
65
+ return $this->getData('TransactionId');
66
+ }
67
+
68
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Asp/Ipn/Request.php ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments ASP IPN notification request Model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Api_Asp_Ipn_Request extends Varien_Object
35
+ {
36
+ /*
37
+ * Status request
38
+ */
39
+ const STATUS_CANCEL_CUSTOMER = 'A';
40
+ const STATUS_CANCEL_TRANSACTION = 'CANCELLED';
41
+ const STATUS_RESERVE_SUCCESSFUL = 'PR';
42
+ const STATUS_PAYMENT_INITIATED = 'PI';
43
+ const STATUS_PAYMENT_SUCCESSFUL = 'PS';
44
+ const STATUS_PAYMENT_FAILED = 'PF';
45
+ const STATUS_REFUND_SUCCESSFUL = 'RS';
46
+ const STATUS_REFUND_FAILED = 'RF';
47
+ const STATUS_SYSTEM_ERROR = 'SE';
48
+
49
+ /*
50
+ * Request params
51
+ */
52
+ private $requestParams;
53
+
54
+ /**
55
+ * Init object
56
+ *
57
+ * @param array $requestParams
58
+ * @return Mage_AmazonPayments_Model_Api_Asp_Ipn_Request
59
+ */
60
+ public function init($requestParams)
61
+ {
62
+ if (!$this->_validateRequestParams($requestParams)) {
63
+ return false;
64
+ }
65
+ $this->requestParams = $requestParams;
66
+ $this->_setRequestParamsToData($this->_convertRequestParams($requestParams));
67
+ return $this;
68
+ }
69
+
70
+ /**
71
+ * Validate request params
72
+ *
73
+ * @param array $requestParams
74
+ * @return bool
75
+ */
76
+ private function _validateRequestParams($requestParams)
77
+ {
78
+ if (!isset($requestParams['transactionAmount']) ||
79
+ !isset($requestParams['transactionDate']) ||
80
+ !isset($requestParams['status'])) {
81
+ return false;
82
+ }
83
+
84
+ $statusCode = $requestParams['status'];
85
+ if ($statusCode != self::STATUS_CANCEL_CUSTOMER &&
86
+ $statusCode != self::STATUS_CANCEL_TRANSACTION &&
87
+ $statusCode != self::STATUS_RESERVE_SUCCESSFUL &&
88
+ $statusCode != self::STATUS_PAYMENT_INITIATED &&
89
+ $statusCode != self::STATUS_PAYMENT_SUCCESSFUL &&
90
+ $statusCode != self::STATUS_PAYMENT_FAILED &&
91
+ $statusCode != self::STATUS_REFUND_SUCCESSFUL &&
92
+ $statusCode != self::STATUS_REFUND_FAILED &&
93
+ $statusCode != self::STATUS_SYSTEM_ERROR) {
94
+ return false;
95
+ }
96
+
97
+ if ($statusCode != self::STATUS_CANCEL_TRANSACTION &&
98
+ !isset($requestParams['referenceId'])){
99
+ return false;
100
+ }
101
+
102
+ if (($statusCode == self::STATUS_RESERVE_SUCCESSFUL ||
103
+ $statusCode == self::STATUS_PAYMENT_SUCCESSFUL ||
104
+ $statusCode == self::STATUS_REFUND_SUCCESSFUL) &&
105
+ !isset($requestParams['transactionId'])) {
106
+ return false;
107
+ }
108
+
109
+ if (!$this->_convertAmount($requestParams['transactionAmount'])) {
110
+ return false;
111
+ }
112
+
113
+ if ($requestParams['status'] == self::STATUS_REFUND_SUCCESSFUL ||
114
+ $requestParams['status'] == self::STATUS_REFUND_FAILED) {
115
+ if (!$this->_convertReferenceId($requestParams['referenceId'])) {
116
+ return false;
117
+ }
118
+ }
119
+
120
+ return true;
121
+ }
122
+
123
+ /**
124
+ * convert request params
125
+ *
126
+ * @param array $requestParams
127
+ * @return array
128
+ */
129
+ private function _convertRequestParams($requestParams)
130
+ {
131
+ $_tmpResultArray = $this->_convertAmount($requestParams['transactionAmount']);
132
+ unset($requestParams['transactionAmount']);
133
+ $requestParams = array_merge($requestParams, $_tmpResultArray);
134
+
135
+ if ($requestParams['status'] == self::STATUS_REFUND_SUCCESSFUL ||
136
+ $requestParams['status'] == self::STATUS_REFUND_FAILED) {
137
+ $requestParams['referenceId'] = $this->_convertReferenceId($requestParams['referenceId']);
138
+ }
139
+
140
+ $requestParams['transactionDate'] = $this->_convertTransactionDate($requestParams['transactionDate']);
141
+
142
+ return $requestParams;
143
+ }
144
+
145
+
146
+ /**
147
+ * convert union amount string to amount value and amount currency code
148
+ *
149
+ * @param string $requestAmount
150
+ * @return Mage_AmazonPayments_Model_Api_Asp_Amount
151
+ */
152
+ private function _convertAmount($requestAmount)
153
+ {
154
+ $amount = Mage::getSingleton('amazonpayments/api_asp_amount');
155
+ if (!$amount->init($requestAmount)) {
156
+ return false;
157
+ }
158
+
159
+ $resultArray = array();
160
+ $resultArray['amount'] = $amount->getValue();
161
+ $resultArray['currencyCode'] = $amount->getCurrencyCode();
162
+ return $resultArray;
163
+ }
164
+
165
+ /**
166
+ * convert peferenceId request param
167
+ *
168
+ * @param string $referenceId
169
+ * @return string
170
+ */
171
+ private function _convertReferenceId($referenceId)
172
+ {
173
+ $tmpArr = array();
174
+ if (!preg_match("/^Refund\sfor\s([0-9]{9})$/", $referenceId, $tmpArr)) {
175
+ return false;
176
+ }
177
+ return $tmpArr[1];
178
+ }
179
+
180
+ /**
181
+ * convert TransactionDate request param
182
+ *
183
+ * @param string $transactionDate
184
+ * @return string
185
+ */
186
+ private function _convertTransactionDate($transactionDate)
187
+ {
188
+ return Mage::app()->getLocale()->date($transactionDate);
189
+ }
190
+
191
+ /**
192
+ * set request params to object date
193
+ *
194
+ * @param array $requestParams
195
+ */
196
+ private function _setRequestParamsToData($requestParams)
197
+ {
198
+ foreach ($requestParams as $kay => $value) {
199
+ $setMethodName = 'set' . ucfirst($kay);
200
+ $this->$setMethodName($value);
201
+ }
202
+ }
203
+
204
+ /**
205
+ * rewrited for Varien_Object
206
+ */
207
+ public function toString($format='')
208
+ {
209
+ $resultString = '';
210
+ foreach($this->getData() as $kay => $value){
211
+ $resultString .= "[$kay] = $value<br/>";
212
+ }
213
+ return $resultString;
214
+ }
215
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Cba.php ADDED
@@ -0,0 +1,1007 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments CBA API wrappers model
29
+ *
30
+ * @author Magento Core Team <core@magentocommerce.com>
31
+ */
32
+ class Mage_AmazonPayments_Model_Api_Cba extends Mage_AmazonPayments_Model_Api_Abstract
33
+ {
34
+ protected static $HMAC_SHA1_ALGORITHM = "sha1";
35
+ protected $_paymentCode = 'amazonpayments_cba';
36
+
37
+ protected $_carriers;
38
+ protected $_address;
39
+
40
+ const STANDARD_SHIPMENT_RATE = 'Standard';
41
+ const EXPEDITED_SHIPMENT_RATE = 'Expedited';
42
+ const ONEDAY_SHIPMENT_RATE = 'OneDay';
43
+ const TWODAY_SHIPMENT_RATE = 'TwoDay';
44
+
45
+ protected $_shippingRates = array(
46
+ self::STANDARD_SHIPMENT_RATE,
47
+ self::EXPEDITED_SHIPMENT_RATE,
48
+ self::ONEDAY_SHIPMENT_RATE,
49
+ self::TWODAY_SHIPMENT_RATE,
50
+ );
51
+
52
+ protected $_configShippingRates = null;
53
+
54
+ /**
55
+ * Return Merchant Id from config
56
+ *
57
+ * @return string
58
+ */
59
+ public function getMerchantId()
60
+ {
61
+ return Mage::getStoreConfig('payment/amazonpayments_cba/merchant_id');
62
+ }
63
+
64
+ /**
65
+ * Return action url for CBA Cart form to Amazon
66
+ *
67
+ * @return unknown
68
+ */
69
+ public function getAmazonRedirectUrl()
70
+ {
71
+ #$_url = $this->getCbaPaymentUrl();
72
+ $_url = $this->getPayServiceUrl();
73
+ $_merchantId = Mage::getStoreConfig('payment/amazonpayments_cba/merchant_id');
74
+ return $_url.$_merchantId;
75
+ }
76
+
77
+ public function getConfigShippingRates()
78
+ {
79
+ if (is_null($this->_configShippingRates)) {
80
+ $this->_configShippingRates = array();
81
+ foreach ($this->_shippingRates as $_rate) {
82
+ $_carrier = unserialize(Mage::getStoreConfig('payment/amazonpayments_cba/' . strtolower($_rate) . '_rate'));
83
+ if ($_carrier['method'] && $_carrier['method'] != 'None') {
84
+ $_carrierInfo = explode('/', $_carrier['method']);
85
+ $this->_configShippingRates[$_rate] = array(
86
+ 'carrier' => $_carrierInfo[0],
87
+ 'method' => $_carrierInfo[1]
88
+ );
89
+ }
90
+ }
91
+ }
92
+ return $this->_configShippingRates;
93
+ }
94
+
95
+ /**
96
+ * Computes RFC 2104-compliant HMAC signature.
97
+ *
98
+ * @param data Array
99
+ * The data to be signed.
100
+ * @param key String
101
+ * The signing key, a.k.a. the AWS secret key.
102
+ * @return The base64-encoded RFC 2104-compliant HMAC signature.
103
+ */
104
+ public function calculateSignature($data, $secretKey)
105
+ {
106
+ $stringData = '';
107
+ if (is_array($data)) {
108
+ ksort($data);
109
+ foreach ($data as $key => $value) {
110
+ $stringData .= $key.'='.rawurlencode($value).'&';
111
+ }
112
+ } elseif (is_string($data)) {
113
+ $stringData = $data;
114
+ } else {
115
+ $stringData = $data;
116
+ }
117
+
118
+ // compute the hmac on input data bytes, make sure to set returning raw hmac to be true
119
+ $rawHmac = hash_hmac(self::$HMAC_SHA1_ALGORITHM, $stringData, $secretKey, true);
120
+
121
+ // base64-encode the raw hmac
122
+ return base64_encode($rawHmac);
123
+ }
124
+
125
+ /**
126
+ * Format amount value (2 digits after the decimal point)
127
+ *
128
+ * @param float $amount
129
+ * @return float
130
+ */
131
+ public function formatAmount($amount)
132
+ {
133
+ return Mage::helper('amazonpayments')->formatAmount($amount);
134
+ }
135
+
136
+ /**
137
+ * Build XML-based Cart for Checkout by Amazon
138
+ *
139
+ * @param Mage_Sales_Model_Quote
140
+ * @return string
141
+ */
142
+ public function getXmlCart(Mage_Sales_Model_Quote $quote)
143
+ {
144
+ $_xml = '<?xml version="1.0" encoding="UTF-8"?>'."\n"
145
+ .'<Order xmlns="http://payments.amazon.com/checkout/2008-11-30/">'."\n";
146
+ if (!$quote->hasItems()) {
147
+ return false;
148
+ }
149
+ $_xml .= " <ClientRequestId>{$quote->getId()}</ClientRequestId>\n"; // Returning parametr
150
+ # ."<ExpirationDate></ExpirationDate>";
151
+
152
+ $_xml .= " <Cart>\n"
153
+ ." <Items>\n";
154
+
155
+ foreach ($quote->getAllVisibleItems() as $_item) {
156
+ $_xml .= " <Item>\n"
157
+ ." <SKU>{$_item->getSku()}/{$_item->getId()}</SKU>\n"
158
+ ." <MerchantId>{$this->getMerchantId()}</MerchantId>\n"
159
+ ." <Title>{$_item->getName()}</Title>\n"
160
+ ." <Price>\n"
161
+ ." <Amount>{$this->formatAmount($_item->getPrice())}</Amount>\n"
162
+ ." <CurrencyCode>{$quote->getBaseCurrencyCode()}</CurrencyCode>\n"
163
+ ." </Price>\n"
164
+ ." <Quantity>{$_item->getQty()}</Quantity>\n"
165
+ ." <Weight>\n"
166
+ ." <Amount>{$this->formatAmount($_item->getWeight())}</Amount>\n"
167
+ ." <Unit>lb</Unit>\n"
168
+ ." </Weight>\n";
169
+ $_xml .= " </Item>\n";
170
+
171
+ }
172
+ $_xml .= " </Items>\n"
173
+ ." <CartPromotionId>cart-total-discount</CartPromotionId>\n"
174
+ ." </Cart>\n";
175
+
176
+ $_xml .= " <IntegratorId>A2ZZYWSJ0WMID8MAGENTO</IntegratorId>\n"
177
+ ." <IntegratorName>Varien</IntegratorName>\n";
178
+ $_xml .= " <OrderCalculationCallbacks>\n"
179
+ ." <CalculateTaxRates>true</CalculateTaxRates>\n"
180
+ ." <CalculatePromotions>true</CalculatePromotions>\n"
181
+ ." <CalculateShippingRates>true</CalculateShippingRates>\n"
182
+ ." <OrderCallbackEndpoint>".Mage::getUrl('amazonpayments/cba/callback', array('_secure' => true))."</OrderCallbackEndpoint>\n"
183
+ ." <ProcessOrderOnCallbackFailure>true</ProcessOrderOnCallbackFailure>\n"
184
+ ." </OrderCalculationCallbacks>\n";
185
+
186
+ $_xml .= "</Order>\n";
187
+ return $_xml;
188
+
189
+ }
190
+
191
+ /**
192
+ * Retreive checkout tax tables xml
193
+ *
194
+ * @param Mage_Sales_Model_Quote $quote
195
+ * @return string
196
+ */
197
+ protected function _getCheckoutTaxXml(Mage_Sales_Model_Quote $quote)
198
+ {
199
+ $xml = '';
200
+
201
+ // shipping tax table (used as default, because we have no ability to specify shipping tax table)
202
+ //$xml .= $this->_getTaxTablesXml($quote, $this->_getShippingTaxRules($quote), true);
203
+ // removed because of no ability to use default tax table as shipping tax table
204
+
205
+ $xml .= "<TaxTables>\n";
206
+
207
+ // item tax tables
208
+ $xml .= $this->_getTaxTablesXml($quote, $this->_getTaxRules($quote));
209
+
210
+ // empty tax table for products without tax class
211
+ $xml .= " <TaxTable>\n"
212
+ ." <TaxTableId>none</TaxTableId>\n"
213
+ ." <TaxRules>\n"
214
+ ." <TaxRule>\n"
215
+ ." <Rate>0</Rate>\n"
216
+ ." <PredefinedRegion>WorldAll</PredefinedRegion>\n"
217
+ ." </TaxRule>\n"
218
+ ." </TaxRules>\n"
219
+ ." </TaxTable>\n";
220
+
221
+ $xml .= "</TaxTables>\n";
222
+
223
+
224
+ return $xml;
225
+ }
226
+
227
+ /**
228
+ * Retreive specified tax rates xml
229
+ *
230
+ * @param Mage_Sales_Model_Quote $quote
231
+ * @param array $rates
232
+ * @param string $type
233
+ * @param mixed $addTo
234
+ * @return string
235
+ */
236
+ protected function _getTaxTablesXml($quote, $rules, $isShipping = false, $addTo = null)
237
+ {
238
+ $xml = '';
239
+ if ($isShipping) {
240
+ $isShippingTaxed = 'true';
241
+ $taxTableTag = 'DefaultTaxTable';
242
+ } else {
243
+ $isShippingTaxed = 'false';
244
+ $taxTableTag = 'TaxTable';
245
+ }
246
+
247
+ if (is_array($rules)) {
248
+ if ($addTo) {
249
+ $_tables = $addTo->addChild('TaxTables');
250
+ }
251
+
252
+ foreach ($rules as $group=>$taxRates) {
253
+ $isShippingTaxed = ($isShipping ? 'true' : 'false');
254
+ if ($isShipping) {
255
+ $tableName = 'default-tax-table';
256
+ } else {
257
+ $tableName = "tax_{$group}";
258
+ if ($group == $this->_getShippingTaxClassId($quote)) {
259
+ $isShippingTaxed = 'true';
260
+ }
261
+ }
262
+ if ($addTo) {
263
+ // $_tables = $addTo->addChild('TaxTables');
264
+ $_table = $_tables->addChild($taxTableTag);
265
+ $_table->addChild('TaxTableId', $tableName);
266
+ $_rules = $_table->addChild('TaxRules');
267
+ } else {
268
+ $xml .= " <{$taxTableTag}>\n";
269
+ $xml .= " <TaxTableId>{$tableName}</TaxTableId>\n";
270
+ $xml .= " <TaxRules>\n";
271
+ }
272
+
273
+ if (is_array($taxRates)) {
274
+ foreach ($taxRates as $rate) {
275
+ if ($addTo) {
276
+ $_rule = $_rules->addChild('TaxRule');
277
+ $_rule->addChild('Rate', $rate['value']);
278
+ $_rule->addChild('IsShippingTaxed', $isShippingTaxed);
279
+ } else {
280
+ $xml .= " <TaxRule>\n";
281
+ $xml .= " <Rate>{$rate['value']}</Rate>\n";
282
+ $xml .= " <IsShippingTaxed>{$isShippingTaxed}</IsShippingTaxed>\n";
283
+ }
284
+
285
+ if ($rate['country']==='US') {
286
+ if (!empty($rate['postcode']) && $rate['postcode']!=='*') {
287
+ if ($addTo) {
288
+ $_rule->addChild('USZipRegion', $rate['postcode']);
289
+ } else {
290
+ $xml .= " <USZipRegion>{$rate['postcode']}</USZipRegion>\n";
291
+ }
292
+ } else if (!empty($rate['state']) && $rate['state']!=='*') {
293
+ if ($addTo) {
294
+ $_rule->addChild('USStateRegion', $rate['state']);
295
+ } else {
296
+ $xml .= " <USStateRegion>{$rate['state']}</USStateRegion>\n";
297
+ }
298
+ } else {
299
+ if ($addTo) {
300
+ $_rule->addChild('PredefinedRegion', 'USAll');
301
+ } else {
302
+ $xml .= " <PredefinedRegion>USAll</PredefinedRegion>\n";
303
+ }
304
+ }
305
+ } else {
306
+ if ($addTo) {
307
+ $_region = $_rule->addChild('WorldRegion');
308
+ $_region->addChild('CountryCode', $rate['country']);
309
+ if (!empty($rate['postcode']) && $rate['postcode']!=='*') {
310
+ $_region->addChild('PostalRegion', $rate['postcode']);
311
+ }
312
+ } else {
313
+ $xml .= " <WorldRegion>\n";
314
+ $xml .= " <CountryCode>{$rate['country']}</CountryCode>\n";
315
+ if (!empty($rate['postcode']) && $rate['postcode']!=='*') {
316
+ $xml .= " <PostalRegion>{$rate['postcode']}</PostalRegion>\n";
317
+ }
318
+ $xml .= " </WorldRegion>\n";
319
+ }
320
+ }
321
+
322
+ $xml .= " </TaxRule>\n";
323
+ }
324
+ } else {
325
+ $taxRate = $taxRates/100;
326
+ if ($addTo) {
327
+ $_rule = $_rules->addChild('TaxRule');
328
+ $_rule->addChild('Rate', $taxRate);
329
+ $_rule->addChild('IsShippingTaxed', $isShippingTaxed);
330
+ $_rule->addChild('PredefinedRegion', 'WorldAll');
331
+ } else {
332
+ $xml .= " <TaxRule>\n";
333
+ $xml .= " <Rate>{$taxRate}</Rate>\n";
334
+ $xml .= " <IsShippingTaxed>{$isShippingTaxed}</IsShippingTaxed>\n";
335
+ $xml .= " <PredefinedRegion>WorldAll</PredefinedRegion>\n";
336
+ $xml .= " </TaxRule>\n";
337
+ }
338
+ }
339
+
340
+ $xml .= " </TaxRules>\n";
341
+ $xml .= " </{$taxTableTag}>\n";
342
+ }
343
+
344
+ } else {
345
+ if (is_numeric($rules)) {
346
+ $taxRate = $rules/100;
347
+
348
+ if ($addTo) {
349
+ $_table = $addTo->addChild($taxTableTag);
350
+ $_rules = $_table->addChild('TaxRules');
351
+ $_rule = $_rules->addChild('TaxRule');
352
+ $_rule->addChild('Rate', $taxRate);
353
+ $_rule->addChild('IsShippingTaxed', $isShippingTaxed);
354
+ $_rule->addChild('PredefinedRegion', 'WorldAll');
355
+ } else {
356
+ $xml .= " <{$taxTableTag}>\n";
357
+ $xml .= " <TaxRules>\n";
358
+ $xml .= " <TaxRule>\n";
359
+ $xml .= " <Rate>{$taxRate}</Rate>\n";
360
+ $xml .= " <IsShippingTaxed>{$isShippingTaxed}</IsShippingTaxed>\n";
361
+ $xml .= " <PredefinedRegion>WorldAll</PredefinedRegion>\n";
362
+ $xml .= " </TaxRule>\n";
363
+ $xml .= " </TaxRules>\n";
364
+ $xml .= " </{$taxTableTag}>\n";
365
+ }
366
+ }
367
+ }
368
+
369
+ if ($addTo) {
370
+ return $addTo;
371
+ }
372
+
373
+ return $xml;
374
+ }
375
+
376
+
377
+ /**
378
+ * Retreive tax rules applicable to quote items
379
+ *
380
+ * @param Mage_Sales_Model_Quote $quote
381
+ * @return array
382
+ */
383
+ protected function _getTaxRules(Mage_Sales_Model_Quote $quote)
384
+ {
385
+ $customerTaxClass = $this->_getCustomerTaxClass($quote);
386
+ if (Mage::helper('tax')->getTaxBasedOn() == 'origin') {
387
+ $request = Mage::getSingleton('tax/calculation')->getRateRequest();
388
+ return Mage::getSingleton('tax/calculation')->getRatesForAllProductTaxClasses($request->setCustomerClassId($customerTaxClass));
389
+ } else {
390
+ $customerRules = Mage::getSingleton('tax/calculation')->getRatesByCustomerTaxClass($customerTaxClass);
391
+ $rules = array();
392
+ foreach ($customerRules as $rule) {
393
+ $rules[$rule['product_class']][] = $rule;
394
+ }
395
+ return $rules;
396
+ }
397
+ }
398
+
399
+ /**
400
+ * Retreive tax rules applicable to shipping
401
+ *
402
+ * @param Mage_Sales_Model_Quote $quote
403
+ * @return array
404
+ */
405
+ protected function _getShippingTaxRules(Mage_Sales_Model_Quote $quote)
406
+ {
407
+ $customerTaxClass = $this->_getCustomerTaxClass($quote);
408
+ if ($shippingTaxClass = $this->_getShippingTaxClassId($quote)) {
409
+ if (Mage::helper('tax')->getTaxBasedOn() == 'origin') {
410
+ $request = Mage::getSingleton('tax/calculation')->getRateRequest();
411
+ $request
412
+ ->setCustomerClassId($customerTaxClass)
413
+ ->setProductClassId($shippingTaxClass);
414
+
415
+ return Mage::getSingleton('tax/calculation')->getRate($request);
416
+ }
417
+ $customerRules = Mage::getSingleton('tax/calculation')->getRatesByCustomerAndProductTaxClasses($customerTaxClass, $shippingTaxClass);
418
+ $rules = array();
419
+ foreach ($customerRules as $rule) {
420
+ $rules[$rule['product_class']][] = $rule;
421
+ }
422
+ return $rules;
423
+ } else {
424
+ return array();
425
+ }
426
+ }
427
+
428
+ /**
429
+ * Retreive shipping tax class
430
+ *
431
+ * @param Mage_Sales_Model_Quote $quote
432
+ * @return int
433
+ */
434
+ protected function _getShippingTaxClassId(Mage_Sales_Model_Quote $quote)
435
+ {
436
+ return Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, $quote->getStoreId());
437
+ }
438
+
439
+ /**
440
+ * Retreive customer tax class from quote
441
+ *
442
+ * @param Mage_Sales_Model_Quote $quote
443
+ * @return int
444
+ */
445
+ protected function _getCustomerTaxClass(Mage_Sales_Model_Quote $quote)
446
+ {
447
+ $customerGroup = $quote->getCustomerGroupId();
448
+ if (!$customerGroup) {
449
+ $customerGroup = Mage::getStoreConfig('customer/create_account/default_group', $quote->getStoreId());
450
+ }
451
+ return Mage::getModel('customer/group')->load($customerGroup)->getTaxClassId();
452
+ }
453
+
454
+ /**
455
+ * Handle Callback from CBA and calculate Shipping, Taxes in case XML-based shopping cart
456
+ *
457
+ */
458
+ public function handleXmlCallback($xmlRequest, $session)
459
+ {
460
+ $_address = $this->_parseRequestAddress($xmlRequest);
461
+
462
+ #$quoteId = $session->getAmazonQuoteId();
463
+ $quoteId = $_address['ClientRequestId'];
464
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
465
+
466
+ $baseCurrency = $session->getQuote()->getBaseCurrencyCode();
467
+ $currency = Mage::app()->getStore($session->getQuote()->getStoreId())->getBaseCurrency();
468
+
469
+ $billingAddress = $quote->getBillingAddress();
470
+ $address = $quote->getShippingAddress();
471
+
472
+ $this->_address = $_address;
473
+
474
+ $regionModel = Mage::getModel('directory/region')->loadByCode($_address['regionCode'], $_address['countryCode']);
475
+ $_regionId = $regionModel->getId();
476
+
477
+ $address->setCountryId($_address['countryCode'])
478
+ ->setRegion($_address['regionCode'])
479
+ ->setRegionId($_regionId)
480
+ ->setCity($_address['city'])
481
+ ->setStreet($_address['street'])
482
+ ->setPostcode($_address['postCode']);
483
+ $billingAddress->setCountryId($_address['countryCode'])
484
+ ->setRegion($_address['regionCode'])
485
+ ->setRegionId($_regionId)
486
+ ->setCity($_address['city'])
487
+ ->setStreet($_address['street'])
488
+ ->setPostcode($_address['postCode']);
489
+
490
+ $quote->setBillingAddress($billingAddress);
491
+ $quote->setShippingAddress($address);
492
+ $quote->save();
493
+
494
+ $address->setCollectShippingRates(true)->collectShippingRates();
495
+
496
+ $errors = array();
497
+ $_carriers = array();
498
+ foreach ($this->getConfigShippingRates() as $_cfgRate) {
499
+ if ($carrier = Mage::getStoreConfig('carriers/' . $_cfgRate['carrier'], $this->getStoreId())) {
500
+ if (isset($carrier['title']) && $carrier['active'] && !in_array($_cfgRate['carrier'], $_carriers)) {
501
+ $_carriers[] = $_cfgRate['carrier'];
502
+ }
503
+ }
504
+ }
505
+
506
+ $result = Mage::getModel('shipping/shipping')
507
+ ->collectRatesByAddress($address, $_carriers)
508
+ ->getResult();
509
+ $rateCodes = array();
510
+ foreach ($this->getConfigShippingRates() as $_cfgRateLevel => $_cfgRate) {
511
+ if ($rates = $result->getRatesByCarrier($_cfgRate['carrier'])) {
512
+ foreach ($rates as $rate) {
513
+ if (!$rate instanceof Mage_Shipping_Model_Rate_Result_Error && $rate->getMethod() == $_cfgRate['method']) {
514
+ if ($address->getFreeShipping()) {
515
+ $price = 0;
516
+ } else {
517
+ $price = $rate->getPrice();
518
+ }
519
+ if ($price) {
520
+ $price = Mage::helper('tax')->getShippingPrice($price, true, $address);
521
+ }
522
+ $this->_carriers[] = array(
523
+ 'service_level' => $_cfgRateLevel,
524
+ 'code' => $rate->getCarrier() . '_' . $rate->getMethod(),
525
+ 'price' => $price,
526
+ 'currency' => $currency['currency_code'],
527
+ 'description' => $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle() . ' (Amazon ' . $_cfgRateLevel . ' Service Level)'
528
+ );
529
+ }
530
+ }
531
+ }
532
+ }
533
+
534
+ if ($_extShippingInfo = unserialize($quote->getExtShippingInfo())) {
535
+ $_extShippingInfo = array_merge($_extShippingInfo, array('amazon_service_level' => $this->_carriers));
536
+ } else {
537
+ $_extShippingInfo = array('amazon_service_level' => $this->_carriers);
538
+ }
539
+ $quote->setExtShippingInfo(serialize($_extShippingInfo));
540
+
541
+ $_items = $this->_parseRequestItems($xmlRequest);
542
+ $xml = $this->_generateXmlResponse($quote, $_items);
543
+
544
+ $session->getQuote()
545
+ ->setForcedCurrency($currency)
546
+ ->collectTotals()
547
+ ->save();
548
+ $quote->save();
549
+ return $xml;
550
+ }
551
+
552
+ /**
553
+ * Parse request from Amazon and return order details
554
+ *
555
+ * @param string xml
556
+ */
557
+ public function parseOrder($xmlData)
558
+ {
559
+ $parsedOrder = array();
560
+ if (strlen(trim($xmlData)) > 0) {
561
+ $xml = simplexml_load_string($xmlData, 'Varien_Simplexml_Element');
562
+ $parsedOrder = array(
563
+ 'NotificationReferenceId' => (string) $xml->descend("NotificationReferenceId"),
564
+ 'amazonOrderID' => (string) $xml->descend("ProcessedOrder/AmazonOrderID"),
565
+ 'orderDate' => (string) $xml->descend("ProcessedOrder/OrderDate"),
566
+ 'orderChannel' => (string) $xml->descend("ProcessedOrder/OrderChannel"),
567
+ 'buyerName' => (string) $xml->descend("ProcessedOrder/BuyerInfo/BuyerName"),
568
+ 'buyerEmailAddress' => (string) $xml->descend("ProcessedOrder/BuyerInfo/BuyerEmailAddress"),
569
+ 'ShippingLevel' => (string) $xml->descend("ProcessedOrder/ShippingServiceLevel"),
570
+ 'shippingAddress' => array(
571
+ 'name' => (string) $xml->descend("ProcessedOrder/ShippingAddress/Name"),
572
+ 'street' => (string) $xml->descend("ProcessedOrder/ShippingAddress/AddressFieldOne"),
573
+ 'city' => (string) $xml->descend("ProcessedOrder/ShippingAddress/City"),
574
+ 'regionCode' => (string) $xml->descend("ProcessedOrder/ShippingAddress/State"),
575
+ 'postCode' => (string) $xml->descend("ProcessedOrder/ShippingAddress/PostalCode"),
576
+ 'countryCode' => (string) $xml->descend("ProcessedOrder/ShippingAddress/CountryCode"),
577
+ ),
578
+ 'items' => array(),
579
+ );
580
+
581
+ $_total = $_shipping = $_tax = $_shippingTax = $_subtotalPromo = $_shippingPromo = $_subtotal = 0;
582
+ $_itemsCount = $_itemsQty = 0;
583
+ foreach ($xml->descend("ProcessedOrder/ProcessedOrderItems/ProcessedOrderItem") as $_item) {
584
+ $parsedOrder['ClientRequestId'] = (string) $_item->ClientRequestId;
585
+ $_compositeSku = explode('/', (string) $_item->SKU);
586
+ $_sku = '';
587
+ if (isset($_compositeSku[0])) {
588
+ $_sku = $_compositeSku[0];
589
+ }
590
+ $_itemId = '';
591
+ if ($_compositeSku[1]) {
592
+ $_itemId = $_compositeSku[1];
593
+ }
594
+ $_itemQty = (string) $_item->Quantity;
595
+ $_itemsQty += $_itemQty;
596
+ $_itemsCount++;
597
+ $parsedOrder['items'][$_itemId] = array(
598
+ 'AmazonOrderItemCode' => (string) $_item->AmazonOrderItemCode,
599
+ 'sku' => $_sku,
600
+ 'title' => (string) $_item->Title,
601
+ 'price' => array(
602
+ 'amount' => (string) $_item->Price->Amount,
603
+ 'currencyCode' => (string) $_item->Price->CurrencyCode,
604
+ ),
605
+ 'qty' => $_itemQty,
606
+ 'weight' => array(
607
+ 'amount' => (string) $_item->Weight->Amount,
608
+ 'unit' => (string) $_item->Weight->Unit,
609
+ ),
610
+ );
611
+ $_itemSubtotal = 0;
612
+ foreach ($_item->ItemCharges->Component as $_component) {
613
+ switch ((string) $_component->Type) {
614
+ case 'Principal':
615
+ $_itemSubtotal += (string) $_component->Charge->Amount;
616
+ $parsedOrder['items'][$_itemId]['subtotal'] = $_itemSubtotal;
617
+ break;
618
+ case 'Shipping':
619
+ $_shipping += (string) $_component->Charge->Amount;
620
+ $parsedOrder['items'][$_itemId]['shipping'] = (string) $_component->Charge->Amount;
621
+ break;
622
+ case 'Tax':
623
+ $_tax += (string) $_component->Charge->Amount;
624
+ $parsedOrder['items'][$_itemId]['tax'] = (string) $_component->Charge->Amount;
625
+ break;
626
+ case 'ShippingTax':
627
+ $_shippingTax += (string) $_component->Charge->Amount;
628
+ $parsedOrder['items'][$_itemId]['shipping_tax'] = (string) $_component->Charge->Amount;
629
+ break;
630
+ case 'PrincipalPromo':
631
+ $_subtotalPromo += (string) $_component->Charge->Amount;
632
+ $parsedOrder['items'][$_itemId]['principal_promo'] = (string) $_component->Charge->Amount;
633
+ break;
634
+ case 'ShippingPromo':
635
+ $_shippingPromo += (string) $_component->Charge->Amount;
636
+ $parsedOrder['items'][$_itemId]['shipping_promo'] = (string) $_component->Charge->Amount;
637
+ break;
638
+ }
639
+ }
640
+ $_subtotal += $_itemSubtotal;
641
+ }
642
+
643
+ $parsedOrder['itemsCount'] = $_itemsCount;
644
+ $parsedOrder['itemsQty'] = $_itemsQty;
645
+
646
+ $parsedOrder['subtotal'] = $_subtotal;
647
+ $parsedOrder['shippingAmount'] = $_shipping;
648
+ $parsedOrder['tax'] = $_tax + $_shippingTax;
649
+ $parsedOrder['shippingTax'] = $_shippingTax;
650
+ $parsedOrder['discount'] = $_subtotalPromo + $_shippingPromo;
651
+ $parsedOrder['discountShipping'] = $_shippingPromo;
652
+
653
+ $parsedOrder['total'] = $_subtotal + $_shipping + $_tax + $_shippingTax - abs($_subtotalPromo) - abs($_shippingPromo);
654
+ }
655
+ return $parsedOrder;
656
+ }
657
+
658
+ /**
659
+ * Parsing xml notification for amazon order id
660
+ *
661
+ * @param string $xmlData
662
+ * @return array
663
+ */
664
+ public function parseOrderReadyToShipNotification($xmlData)
665
+ {
666
+ $readyToShipData = array();
667
+ if (strlen(trim($xmlData))) {
668
+ $xml = simplexml_load_string($xmlData, 'Varien_Simplexml_Element');
669
+ $aOrderId = (string) $xml->descend('ProcessedOrder/AmazonOrderID');
670
+ $readyToShipData['amazon_order_id'] = $aOrderId;
671
+ $readyToShipData['items'] = array();
672
+ foreach ($xml->descend('ProcessedOrder/ProcessedOrderItems/ProcessedOrderItem') as $item) {
673
+ $readyToShipData['items'][(string)$item->AmazonOrderItemCode] = (string)$item->Quantity;
674
+ }
675
+ }
676
+ return $readyToShipData;
677
+ }
678
+
679
+ public function parseCancelNotification($xmlData)
680
+ {
681
+ $cancelData = array();
682
+ if (strlen(trim($xmlData))) {
683
+ $xml = simplexml_load_string($xmlData, 'Varien_Simplexml_Element');
684
+ $aOrderId = (string) $xml->descend('ProcessedOrder/AmazonOrderID');
685
+ $cancelData['amazon_order_id'] = $aOrderId;
686
+ }
687
+ return $cancelData;
688
+ }
689
+
690
+ /**
691
+ * Return address from Amazon request
692
+ *
693
+ * @param array $responseArr
694
+ */
695
+ protected function _parseRequestAddress($xmlResponse)
696
+ {
697
+ $address = array();
698
+ if (strlen(trim($xmlResponse)) > 0) {
699
+ $xml = simplexml_load_string($xmlResponse, 'Varien_Simplexml_Element');
700
+
701
+ $address = array(
702
+ 'addressId' => (string) $xml->descend("CallbackOrders/CallbackOrder/Address/AddressId"),
703
+ 'regionCode' => (string) $xml->descend("CallbackOrders/CallbackOrder/Address/State"),
704
+ 'countryCode' => (string) $xml->descend("CallbackOrders/CallbackOrder/Address/CountryCode"),
705
+ 'city' => (string) $xml->descend("CallbackOrders/CallbackOrder/Address/City"),
706
+ 'street' => (string) $xml->descend("CallbackOrders/CallbackOrder/Address/AddressFieldOne"),
707
+ 'postCode' => (string) $xml->descend("CallbackOrders/CallbackOrder/Address/PostalCode"),
708
+ 'ClientRequestId' => (string) $xml->descend("ClientRequestId"),
709
+ );
710
+ } else {
711
+ $address = array(
712
+ 'addressId' => '',
713
+ 'regionCode' => '',
714
+ 'countryCode' => '',
715
+ 'city' => '',
716
+ 'street' => '',
717
+ 'postCode' => '',
718
+ );
719
+ }
720
+ return $address;
721
+ }
722
+
723
+ /**
724
+ * Return items SKUs from Amazon request
725
+ *
726
+ * @param array $responseArr
727
+ */
728
+ protected function _parseRequestItems($xmlResponse)
729
+ {
730
+ $items = array();
731
+ if (strlen(trim($xmlResponse)) > 0) {
732
+ $xml = simplexml_load_string($xmlResponse, 'Varien_Simplexml_Element');
733
+ $itemsXml = $xml->descend("Cart/Items");
734
+ foreach ($itemsXml->Item as $_item) {
735
+ $sku = '';
736
+ $compositeSku = explode('/', (string)$_item->SKU);
737
+ if (isset($compositeSku[0])) {
738
+ $sku = $compositeSku[0];
739
+ }
740
+ $items[(string)$_item->SKU] = $sku;
741
+ }
742
+ } else {
743
+ return false;
744
+ }
745
+ return $items;
746
+ }
747
+
748
+ /**
749
+ * Generate XML Responce for Amazon with Shipping, Taxes, Promotions
750
+ *
751
+ * @return string xml
752
+ */
753
+ protected function _generateXmlResponse($quote, $items = array())
754
+ {
755
+
756
+ $_xmlString = <<<XML
757
+ <?xml version="1.0" encoding="UTF-8"?>
758
+ <OrderCalculationsResponse xmlns="http://payments.amazon.com/checkout/2008-11-30/">
759
+ </OrderCalculationsResponse>
760
+ XML;
761
+
762
+ $xml = new SimpleXMLElement($_xmlString);
763
+
764
+ if (count($this->_carriers) > 0) {
765
+ $_xmlResponse = $xml->addChild('Response');
766
+ $_xmlCallbackOrders = $_xmlResponse->addChild('CallbackOrders');
767
+ $_xmlCallbackOrder = $_xmlCallbackOrders->addChild('CallbackOrder');
768
+
769
+ $_xmlAddress = $_xmlCallbackOrder->addChild('Address');
770
+ $_xmlAddressId = $_xmlAddress->addChild('AddressId', $this->_address['addressId']);
771
+
772
+ $_xmlCallbackOrderItems = $_xmlCallbackOrder->addChild('CallbackOrderItems');
773
+ foreach ($items as $_itemSku) {
774
+ $_quoteItem = null;
775
+ foreach ($quote->getAllItems() as $_item) {
776
+ if ($_item->getSku() == $_itemSku) {
777
+ $_quoteItem = $_item;
778
+ break;
779
+ }
780
+ }
781
+ if (is_null($_quoteItem)) {
782
+ Mage::throwException($this->__('Item specified in callback request XML was not found in quote.'));
783
+ }
784
+
785
+ $_xmlCallbackOrderItem = $_xmlCallbackOrderItems->addChild('CallbackOrderItem');
786
+ $_xmlCallbackOrderItem->addChild('SKU', $_itemSku . '/' . $_quoteItem->getId());
787
+ $_xmlCallbackOrderItem->addChild('TaxTableId', 'tax_'.$_quoteItem->getTaxClassId());
788
+
789
+
790
+
791
+ $_xmlShippingMethodIds = $_xmlCallbackOrderItem->addChild('ShippingMethodIds');
792
+ foreach ($this->_carriers as $_carrier) {
793
+ $_xmlShippingMethodIds->addChild('ShippingMethodId', $_carrier['code']);
794
+ }
795
+ }
796
+
797
+ $this->_appendTaxTables($xml, $quote, $this->_getTaxRules($quote));
798
+ $this->_appendDiscounts($xml, $quote);
799
+
800
+ $_xmlShippingMethods = $xml->addChild('ShippingMethods');
801
+ foreach ($this->_carriers as $_carrier) {
802
+ $_xmlShippingMethod = $_xmlShippingMethods->addChild('ShippingMethod');
803
+
804
+ $_xmlShippingMethod->addChild('ShippingMethodId', $_carrier['code']);
805
+ $_xmlShippingMethod->addChild('ServiceLevel', $_carrier['service_level']);
806
+
807
+ $_xmlShippingMethodRate = $_xmlShippingMethod->addChild('Rate');
808
+ // Posible values: ShipmentBased | WeightBased | ItemQuantityBased
809
+ $_xmlShippingMethodRateItem = $_xmlShippingMethodRate->addChild('ShipmentBased');
810
+ $_xmlShippingMethodRateItem->addChild('Amount', $_carrier['price']);
811
+ $_xmlShippingMethodRateItem->addChild('CurrencyCode', $_carrier['currency']);
812
+
813
+ $_xmlShippingMethodIncludedRegions = $_xmlShippingMethod->addChild('IncludedRegions');
814
+ $_xmlShippingMethodIncludedRegions->addChild('PredefinedRegion', 'WorldAll');
815
+ }
816
+ $xml->addChild('CartPromotionId', 'cart-total-discount');
817
+ }
818
+
819
+ return $xml;
820
+ }
821
+
822
+ protected function _appendTaxTables($xml, $quote, $rules, $isShipping = false)
823
+ {
824
+ return $this->_getTaxTablesXml($quote, $rules, $isShipping, $xml);
825
+ }
826
+
827
+ protected function _appendDiscounts($xml, $quote)
828
+ {
829
+ $totalDiscount = $quote->getShippingAddress()->getBaseDiscountAmount() + $quote->getBillingAddress()->getBaseDiscountAmount();
830
+ $discountAmount = ($totalDiscount ? $totalDiscount : 0);
831
+
832
+ $_promotions = $xml->addChild('Promotions');
833
+ $_promotion = $_promotions->addChild('Promotion');
834
+ $_promotion->addChild('PromotionId', 'cart-total-discount');
835
+ $_promotion->addChild('Description', 'Discount');
836
+ $_benefit = $_promotion->addChild('Benefit');
837
+ $_fad = $_benefit->addChild('FixedAmountDiscount');
838
+ $_fad->addChild('Amount', $discountAmount);
839
+ $_fad->addChild('CurrencyCode', $quote->getBaseCurrencyCode());
840
+
841
+ return $xml;
842
+ }
843
+
844
+ /**
845
+ * Generate XML with error message in case Calculation Callbacks error
846
+ *
847
+ * @param Exception $e
848
+ */
849
+ public function callbackXmlError(Exception $e)
850
+ {
851
+ // Posible error codes: INVALID_SHIPPING_ADDRESS | INTERNAL_SERVER_ERROR | SERVICE_UNAVAILABLE
852
+ $xmlErrorString = '<?xml version="1.0" encoding="UTF-8"?>'."\n"
853
+ .'<OrderCalculationsResponse xmlns="http://payments.amazon.com/checkout/2008-11-30/">'."\n"
854
+ .' <Response>'."\n"
855
+ .' <Error>'."\n"
856
+ .' <Code>INTERNAL_SERVER_ERROR</Code>'."\n"
857
+ .' <Message>[MESSAGE]</Message>'."\n"
858
+ .' </Error>'."\n"
859
+ .' </Response>'."\n"
860
+ .'</OrderCalculationsResponse>';
861
+ $_errorMsg = $e->getMessage();
862
+ $_errorMessage = "{$_errorMsg}\n\n"
863
+ ."code: {$e->getCode()}\n\n"
864
+ ."file: {$e->getFile()}\n\n"
865
+ ."line: {$e->getLine()}\n\n"
866
+ ."trac: {$e->getTraceAsString()}\n\n";
867
+ if ($this->getDebug()) {
868
+ $debug = Mage::getModel('amazonpayments/api_debug')
869
+ ->setResponseBody($_errorMessage)
870
+ ->setRequestBody(time() .' - error callback response')
871
+ ->save();
872
+ }
873
+
874
+ if ($_errorMsg = $e->getMessage() && 0) {
875
+ $xmlErrorString = str_replace('[MESSAGE]', $_errorMsg, $xmlErrorString);
876
+ } else {
877
+ $xmlErrorString = str_replace('[MESSAGE]', 'Error', $xmlErrorString);
878
+ }
879
+ $xml = new SimpleXMLElement($xmlErrorString);
880
+ return $xml;
881
+ }
882
+
883
+ /**
884
+ * Get order amazon api
885
+ *
886
+ * @return Mage_AmazonPayments_Model_Api_Cba_Document
887
+ */
888
+ public function getDocumentApi()
889
+ {
890
+ if (is_null($this->getData('document_api'))) {
891
+ $_documentApi = Mage::getModel('amazonpayments/api_cba_document')
892
+ ->setWsdlUri('https://merchant-api.amazon.com/gateway/merchant-interface-mime/')
893
+ ->setMerchantInfo(array(
894
+ 'merchantIdentifier' => Mage::getStoreConfig('payment/amazonpayments_cba/merchant_tocken'),
895
+ 'merchantName' => Mage::getStoreConfig('payment/amazonpayments_cba/merchant_name'),
896
+ ))
897
+ ->init(
898
+ Mage::getStoreConfig('payment/amazonpayments_cba/merchant_login'),
899
+ Mage::getStoreConfig('payment/amazonpayments_cba/merchant_pass')
900
+ );
901
+ $this->setData('document_api', $_documentApi);
902
+ }
903
+ return $this->getData('document_api');
904
+ }
905
+
906
+ /**
907
+ * Associate Magento real order id with Amazon order id
908
+ *
909
+ * @param Mage_Sales_Model_Order $order
910
+ * @return Mage_AmazonPayments_Model_Api_Cba
911
+ */
912
+ public function syncOrder($order)
913
+ {
914
+ if ($order->getId()) {
915
+ $this->getDocumentApi()->sendAcknowledgement($order);
916
+ }
917
+ return $this;
918
+ }
919
+
920
+ /**
921
+ * Cancel order
922
+ *
923
+ * @param Mage_Sales_Model_Order $order
924
+ * @return Mage_AmazonPayments_Model_Api_Cba
925
+ */
926
+ public function cancel($order)
927
+ {
928
+ $this->getDocumentApi()->cancel($order);
929
+ return $this;
930
+ }
931
+
932
+ /**
933
+ * Refund order
934
+ *
935
+ * @param Mage_Sales_Model_Order_Payment $payment
936
+ * @param float $amount
937
+ * @return Mage_AmazonPayments_Model_Api_Cba
938
+ */
939
+ public function refund($payment, $amount)
940
+ {
941
+ $this->getDocumentApi()->refund($payment, $amount);
942
+ return $this;
943
+ }
944
+
945
+ /**
946
+ * Confirm crating of shipment
947
+ *
948
+ * @param Mage_Sales_Model_Order_Shipment $shipment
949
+ * @return Mage_AmazonPayments_Model_Api_Cba
950
+ */
951
+ public function confirmShipment($shipment)
952
+ {
953
+ $items = array();
954
+ foreach ($shipment->getAllItems() as $item) {
955
+ /* @var $item Mage_Sales_Model_Order_Shipment_Item */
956
+ if ($item->getOrderItem()->getParentItemId()) {
957
+ continue;
958
+ }
959
+ $items[] = array(
960
+ 'id' => $item->getOrderItem()->getExtOrderItemId(),
961
+ 'qty' => $item->getQty()
962
+ );
963
+ }
964
+
965
+ $carrierName = '';
966
+ $shippingMethod = '';
967
+ $trackNumber = '';
968
+ /**
969
+ * Magento track numbers is not connected with items.
970
+ * Get only first track number
971
+ */
972
+ foreach ($shipment->getAllTracks() as $track) {
973
+ $carrierName = $track->getTitle();
974
+ $trackNumber = $track->getNumber();
975
+ break;
976
+ }
977
+ if (preg_match("/\((.+)\)/", $shipment->getOrder()->getShippingDescription(), $_result)) {
978
+ $shippingMethod = $_result[1];
979
+ }
980
+
981
+ $this->getDocumentApi()->confirmShipment(
982
+ $shipment->getOrder()->getExtOrderId(),
983
+ $carrierName,
984
+ $shippingMethod,
985
+ $items,
986
+ $trackNumber
987
+ );
988
+ $shipment->addComment(
989
+ Mage::helper('amazonpayments')->__('Shipment was created with Checkout by Amazon.')
990
+ );
991
+ return $this;
992
+ }
993
+
994
+ /**
995
+ * Send shipping track number
996
+ *
997
+ * @param Mage_Sales_Model_Order $order
998
+ * @param Mage_Sales_Model_Order_Shipment_Track $track
999
+ * @param Mage_AmazonPayments_Model_Api_Cba
1000
+ */
1001
+ public function sendTrackingNumber($order, $track)
1002
+ {
1003
+ // $this->getDocumentApi()->sendTrackNumber($order, $carrierCode, $carrierMethod, $trackNumber);
1004
+ return $this;
1005
+ }
1006
+
1007
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Cba/Document.php ADDED
@@ -0,0 +1,476 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ /**
29
+ * Amazon Order Document Api
30
+ *
31
+ * @category Mage
32
+ * @package Mage_AmazonPayments
33
+ * @author Magento Core Team <core@magentocommerce.com>
34
+ */
35
+ class Mage_AmazonPayments_Model_Api_Cba_Document extends Varien_Object
36
+ {
37
+ const MESSAGE_TYPE_ADJUSTMENT = '_POST_PAYMENT_ADJUSTMENT_DATA_';
38
+ const MESSAGE_TYPE_FULFILLMENT = '_POST_ORDER_FULFILLMENT_DATA_';
39
+ const MESSAGE_TYPE_ACKNOWLEDGEMENT = '_POST_ORDER_ACKNOWLEDGEMENT_DATA_';
40
+
41
+ protected $_wsdlUri = null;
42
+ protected $_merchantInfo = array();
43
+ protected $_client = null;
44
+ protected $_result = null;
45
+ protected $_proccessFailed = false;
46
+ protected $_options = array(
47
+ 'trace' => true,
48
+ 'timeout' => '20',
49
+ );
50
+
51
+ protected function _construct()
52
+ {
53
+ parent::_construct();
54
+ }
55
+
56
+ /**
57
+ * Set Wsdl uri
58
+ *
59
+ * @param string $wsdlUri
60
+ * @return Mage_AmazonPayments_Model_Api_Cba_Document
61
+ */
62
+ public function setWsdlUri($wsdlUri)
63
+ {
64
+ $this->_wsdlUri = $wsdlUri;
65
+ return $this;
66
+ }
67
+
68
+ /**
69
+ * Return Wsdl Uri
70
+ *
71
+ * @return string
72
+ */
73
+ public function getWsdlUri()
74
+ {
75
+ return $this->_wsdlUri;
76
+ }
77
+
78
+ /**
79
+ * Set merchant info
80
+ *
81
+ * @param array $merchantInfo
82
+ * @return Mage_AmazonPayments_Model_Api_Cba_Document
83
+ */
84
+ public function setMerchantInfo(array $merchantInfo = array())
85
+ {
86
+ $this->_merchantInfo = $merchantInfo;
87
+ return $this;
88
+ }
89
+
90
+ /**
91
+ * Return merchant info
92
+ *
93
+ * @return array
94
+ */
95
+ public function getMerchantInfo()
96
+ {
97
+ return $this->_merchantInfo;
98
+ }
99
+
100
+ /**
101
+ * Return merchant identifier
102
+ *
103
+ * @return string
104
+ */
105
+ public function getMerchantIdentifier()
106
+ {
107
+ if (array_key_exists('merchantIdentifier', $this->_merchantInfo)) {
108
+ return $this->_merchantInfo['merchantIdentifier'];
109
+ }
110
+ return null;
111
+ }
112
+
113
+ /**
114
+ * Return Soap object
115
+ *
116
+ * @return SOAP_Client
117
+ */
118
+ public function getClient()
119
+ {
120
+ return $this->_client;
121
+ }
122
+
123
+ /**
124
+ * Initialize Soap Client object and authorize
125
+ *
126
+ * @param string $login
127
+ * @param string $password
128
+ * @return Mage_AmazonPayments_Model_Api_Cba_Document
129
+ */
130
+ public function init($login, $password)
131
+ {
132
+ if ($this->getWsdlUri()) {
133
+ $this->_client = null;
134
+ $auth = array('user' => $login, 'pass' => $password);
135
+ try {
136
+ set_include_path(
137
+ BP . DS . 'lib' . DS . 'PEAR' . PS . get_include_path()
138
+ );
139
+ require_once 'SOAP/Client.php';
140
+ $this->_client = new SOAP_Client($this->getWsdlUri(), true, false, $auth, false);
141
+ } catch (Exception $e) {
142
+ Zend_Debug::dump($e->getMessage());
143
+ }
144
+ }
145
+ return $this;
146
+ }
147
+
148
+ /**
149
+ * Create soap attachment (MIME encoding)
150
+ *
151
+ * @param string $document
152
+ * @return string
153
+ */
154
+ protected function _createAttachment($document)
155
+ {
156
+ require_once 'SOAP/Value.php';
157
+ $attachment = new SOAP_Attachment('doc', 'application/binary', null, $document);
158
+ $attachment->options['attachment']['encoding'] = '8bit';
159
+ $this->_options['attachments'] = 'Mime';
160
+ return $attachment;
161
+ }
162
+
163
+ /**
164
+ * Proccess request and setting result
165
+ *
166
+ * @param string $method
167
+ * @param array $params
168
+ * @return Mage_AmazonPayments_Model_Api_Cba_Document
169
+ */
170
+ protected function _proccessRequest($method, $params)
171
+ {
172
+ if ($this->getClient()) {
173
+ $this->_result = null;
174
+ $this->_proccessFailed = false;
175
+ try {
176
+ $this->_result = $this->getClient()
177
+ ->call($method, $params, $this->_options);
178
+ } catch (Exception $e) {
179
+ $this->_proccessFailed = true;
180
+ }
181
+ }
182
+ return $this;
183
+ }
184
+
185
+ /**
186
+ * Format amount value (2 digits after the decimal point)
187
+ *
188
+ * @param float $amount
189
+ * @return float
190
+ */
191
+ public function formatAmount($amount)
192
+ {
193
+ return Mage::helper('amazonpayments')->formatAmount($amount);
194
+ }
195
+
196
+ /**
197
+ * Get order info
198
+ *
199
+ * @param string $aOrderId Amazon order id
200
+ * @return Varien_Simplexml_Element
201
+ */
202
+ public function getDocument($aOrderId)
203
+ {
204
+ $params = array(
205
+ 'merchant' => $this->getMerchantInfo(),
206
+ 'documentIdentifier' => $aOrderId
207
+ );
208
+ $this->_proccessRequest('getDocument', $params);
209
+
210
+ require_once 'Mail/mimeDecode.php';
211
+ $decoder = new Mail_mimeDecode($this->getClient()->xml);
212
+ $decoder->decode(array(
213
+ 'include_bodies' => true,
214
+ 'decode_bodies' => true,
215
+ 'decode_headers' => true,
216
+ ));
217
+ $xml = $decoder->_body;
218
+
219
+ // remove the ending mime boundary
220
+ $boundaryIndex = strripos($xml, '--xxx-WASP-CPP-MIME-Boundary-xxx');
221
+ if (!($boundaryIndex === false)) {
222
+ $xml = substr($xml, 0, $boundaryIndex);
223
+ }
224
+
225
+ return simplexml_load_string($xml, 'Varien_Simplexml_Element');
226
+ }
227
+
228
+ /**
229
+ * Get pending orders
230
+ *
231
+ * @return array
232
+ */
233
+ public function getPendingDocuments()
234
+ {
235
+ $params = array(
236
+ 'merchant' => $this->getMerchantInfo(),
237
+ 'messageType' => '_GET_ORDERS_DATA_'
238
+ );
239
+ $this->_proccessRequest('getAllPendingDocumentInfo', $params);
240
+ if (!is_array($this->_result)) {
241
+ $this->_result = array($this->_result);
242
+ }
243
+ return $this->_result;
244
+ }
245
+
246
+ /**
247
+ * Associate Magento real order id with Amazon order id
248
+ *
249
+ * @param Mage_Sales_Model_Order $order
250
+ * @return string
251
+ */
252
+ public function sendAcknowledgement($order)
253
+ {
254
+ $_document = '<?xml version="1.0" encoding="UTF-8"?>
255
+ <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
256
+ <Header>
257
+ <DocumentVersion>1.01</DocumentVersion>
258
+ <MerchantIdentifier>' . $this->getMerchantIdentifier() . '</MerchantIdentifier>
259
+ </Header>
260
+ <MessageType>OrderAcknowledgement</MessageType>
261
+ <Message>
262
+ <MessageID>1</MessageID>
263
+ <OperationType>Update</OperationType>
264
+ <OrderAcknowledgement>
265
+ <AmazonOrderID>' . $order->getExtOrderId() . '</AmazonOrderID>
266
+ <MerchantOrderID>' . $order->getRealOrderId() . '</MerchantOrderID>
267
+ <StatusCode>Success</StatusCode>
268
+ </OrderAcknowledgement>
269
+ </Message>
270
+ </AmazonEnvelope>';
271
+
272
+ $params = array(
273
+ 'merchant' => $this->getMerchantInfo(),
274
+ 'messageType' => self::MESSAGE_TYPE_ACKNOWLEDGEMENT,
275
+ 'doc' => $this->_createAttachment($_document)
276
+ );
277
+
278
+ $this->_proccessRequest('postDocument', $params);
279
+ return $this->_result;
280
+ }
281
+
282
+ /**
283
+ * Cancel order
284
+ *
285
+ * @param Mage_Sales_Model_Order $order
286
+ * @return string Amazon Transaction Id
287
+ */
288
+ public function cancel($order)
289
+ {
290
+ $_document = '<?xml version="1.0" encoding="UTF-8"?>
291
+ <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
292
+ <Header>
293
+ <DocumentVersion>1.01</DocumentVersion>
294
+ <MerchantIdentifier>' . $this->getMerchantIdentifier() . '</MerchantIdentifier>
295
+ </Header>
296
+ <MessageType>OrderAcknowledgement</MessageType>
297
+ <Message>
298
+ <MessageID>1</MessageID>
299
+ <OperationType>Update</OperationType>
300
+ <OrderAcknowledgement>
301
+ <AmazonOrderID>' . $order->getExtOrderId() . '</AmazonOrderID>
302
+ <StatusCode>Failure</StatusCode>
303
+ </OrderAcknowledgement>
304
+ </Message>
305
+ </AmazonEnvelope>';
306
+
307
+ $params = array(
308
+ 'merchant' => $this->getMerchantInfo(),
309
+ 'messageType' => self::MESSAGE_TYPE_ACKNOWLEDGEMENT,
310
+ 'doc' => $this->_createAttachment($_document)
311
+ );
312
+
313
+ $this->_proccessRequest('postDocument', $params);
314
+ return $this->_result;
315
+ }
316
+
317
+ /**
318
+ * Refund order
319
+ *
320
+ * @param Mage_Sales_Model_Order_Payment $payment
321
+ * @param float $amount
322
+ * @return string Amazon Transaction Id
323
+ */
324
+ public function refund($payment, $amount)
325
+ {
326
+ $_document = '<?xml version="1.0" encoding="UTF-8"?>
327
+ <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
328
+ <Header>
329
+ <DocumentVersion>1.01</DocumentVersion>
330
+ <MerchantIdentifier>' . $this->getMerchantIdentifier() . '</MerchantIdentifier>
331
+ </Header>
332
+ <MessageType>OrderAdjustment</MessageType>';
333
+
334
+ $_shippingAmount = $payment->getCreditmemo()->getShippingAmount();
335
+ $_messageId = 1;
336
+ foreach ($payment->getCreditmemo()->getAllItems() as $item) {
337
+ /* @var $item Mage_Sales_Model_Order_Creditmemo_Item */
338
+ if ($item->getOrderItem()->getParentItemId()) {
339
+ continue;
340
+ }
341
+
342
+ $shipping = 0;
343
+ $amazon_amounts = unserialize($item->getOrderItem()->getProductOptionByCode('amazon_amounts'));
344
+ if ($amazon_amounts['shipping'] > $_shippingAmount) {
345
+ $shipping = $_shippingAmount;
346
+ } else {
347
+ $shipping = $amazon_amounts['shipping'];
348
+ }
349
+ $_shippingAmount -= $shipping;
350
+
351
+ $_document .= '<Message>
352
+ <MessageID>' . $_messageId . '</MessageID>
353
+ <OrderAdjustment>
354
+ <AmazonOrderID>' . $payment->getOrder()->getExtOrderId() . '</AmazonOrderID>
355
+ <AdjustedItem>
356
+ <AmazonOrderItemCode>'. $item->getOrderItem()->getExtOrderItemId() . '</AmazonOrderItemCode>
357
+ <AdjustmentReason>GeneralAdjustment</AdjustmentReason>
358
+ <ItemPriceAdjustments>
359
+ <Component>
360
+ <Type>Principal</Type>
361
+ <Amount currency="USD">' . $this->formatAmount($item->getBaseRowTotal()) . '</Amount>
362
+ </Component>
363
+ <Component>
364
+ <Type>Tax</Type>
365
+ <Amount currency="USD">' . $this->formatAmount($item->getBaseTaxAmount()) . '</Amount>
366
+ </Component>'
367
+ .'<Component>
368
+ <Type>Shipping</Type>
369
+ <Amount currency="USD">' . $this->formatAmount($shipping) . '</Amount>
370
+ </Component>'
371
+ .'</ItemPriceAdjustments>';
372
+ $_document .= '</AdjustedItem>
373
+ </OrderAdjustment>
374
+ </Message>';
375
+ $_messageId++;
376
+ }
377
+
378
+ $_document .= '</AmazonEnvelope>';
379
+ $params = array(
380
+ 'merchant' => $this->getMerchantInfo(),
381
+ 'messageType' => self::MESSAGE_TYPE_ADJUSTMENT,
382
+ 'doc' => $this->_createAttachment($_document)
383
+ );
384
+ $this->_proccessRequest('postDocument', $params);
385
+ return $this->_result;
386
+ }
387
+
388
+ /**
389
+ * Confirm creating of shipment
390
+ *
391
+ * @param string $aOrderId
392
+ * @param string $carrierName
393
+ * @param string $shippingMethod
394
+ * @param array $items
395
+ * @param string $trackNumber
396
+ * @return string Amazon Transaction Id
397
+ */
398
+ public function confirmShipment($aOrderId, $carrierName, $shippingMethod, $items, $trackNumber = '')
399
+ {
400
+ $fulfillmentDate = gmdate('Y-m-d\TH:i:s');
401
+ $_document = '<?xml version="1.0" encoding="UTF-8"?>
402
+ <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
403
+ <Header>
404
+ <DocumentVersion>1.01</DocumentVersion>
405
+ <MerchantIdentifier>' . $this->getMerchantIdentifier() . '</MerchantIdentifier>
406
+ </Header>
407
+ <MessageType>OrderFulfillment</MessageType>
408
+ <Message>
409
+ <MessageID>1</MessageID>
410
+ <OrderFulfillment>
411
+ <AmazonOrderID>' . $aOrderId . '</AmazonOrderID>
412
+ <FulfillmentDate>' . $fulfillmentDate . '</FulfillmentDate>
413
+ <FulfillmentData>
414
+ <CarrierName>' . strtoupper($carrierName) . '</CarrierName>
415
+ <ShippingMethod>' . $shippingMethod . '</ShippingMethod>
416
+ <ShipperTrackingNumber>' . $trackNumber .'</ShipperTrackingNumber>
417
+ </FulfillmentData>';
418
+ foreach ($items as $item) {
419
+ $_document .= '<Item>
420
+ <AmazonOrderItemCode>' . $item['id'] . '</AmazonOrderItemCode>
421
+ <Quantity>' . $item['qty'] . '</Quantity>
422
+ </Item>';
423
+ }
424
+ $_document .= '</OrderFulfillment>
425
+ </Message>
426
+ </AmazonEnvelope>';
427
+ $params = array(
428
+ 'merchant' => $this->getMerchantInfo(),
429
+ 'messageType' => self::MESSAGE_TYPE_FULFILLMENT,
430
+ 'doc' => $this->_createAttachment($_document)
431
+ );
432
+ $this->_proccessRequest('postDocument', $params);
433
+ return $this->_result;
434
+ }
435
+
436
+ /**
437
+ * Send Tracking Number
438
+ *
439
+ * @param Mage_Sales_Model_Order $order
440
+ * @param string $carrierCode
441
+ * @param string $carrierMethod
442
+ * @param string $trackNumber
443
+ * @return string Amazon Transaction Id
444
+ */
445
+ public function sendTrackNumber($order, $carrierCode, $carrierMethod, $trackNumber)
446
+ {
447
+ $fulfillmentDate = gmdate('Y-m-d\TH:i:s');
448
+ $_document = '<?xml version="1.0" encoding="UTF-8"?>
449
+ <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
450
+ <Header>
451
+ <DocumentVersion>1.01</DocumentVersion>
452
+ <MerchantIdentifier>' . $this->getMerchantIdentifier() . '</MerchantIdentifier>
453
+ </Header>
454
+ <MessageType>OrderFulfillment</MessageType>';
455
+ $_document .= '<Message>
456
+ <MessageID>1</MessageID>
457
+ <OrderFulfillment>
458
+ <AmazonOrderID>' . $order->getExtOrderId() . '</AmazonOrderID>
459
+ <FulfillmentDate>' . $fulfillmentDate . '</FulfillmentDate>
460
+ <FulfillmentData>
461
+ <CarrierCode>' . $carrierCode . '</CarrierCode>
462
+ <ShippingMethod>' . $carrierMethod . '</ShippingMethod>
463
+ <ShipperTrackingNumber>' . $trackNumber .'</ShipperTrackingNumber>
464
+ </FulfillmentData>
465
+ </OrderFulfillment>
466
+ </Message>';
467
+ $_document .= '</AmazonEnvelope>';
468
+ $params = array(
469
+ 'merchant' => $this->getMerchantInfo(),
470
+ 'messageType' => self::MESSAGE_TYPE_FULFILLMENT,
471
+ 'doc' => $this->_createAttachment($_document)
472
+ );
473
+ $this->_proccessRequest('postDocument', $params);
474
+ return $this->_result;
475
+ }
476
+ }
app/code/core/Mage/AmazonPayments/Model/Api/Debug.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments Api Debug Model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Api_Debug extends Mage_Core_Model_Abstract
35
+ {
36
+ /**
37
+ * Model initialization
38
+ *
39
+ */
40
+ protected function _construct()
41
+ {
42
+ $this->_init('amazonpayments/api_debug');
43
+ }
44
+ }
app/code/core/Mage/AmazonPayments/Model/Mysql4/Api/Debug.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments API Debug Resource
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @name Mage_AmazonPayments_Model_Mysql4_Api_Debug
33
+ * @author Magento Core Team <core@magentocommerce.com>
34
+ */
35
+
36
+ class Mage_AmazonPayments_Model_Mysql4_Api_Debug extends Mage_Core_Model_Mysql4_Abstract
37
+ {
38
+ /**
39
+ * Resource model initialization
40
+ */
41
+ protected function _construct()
42
+ {
43
+ $this->_init('amazonpayments/api_debug', 'transaction_id');
44
+ }
45
+ }
app/code/core/Mage/AmazonPayments/Model/Mysql4/Api/Debug/Collection.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments API Debug Resource Collection
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @name Mage_AmazonPayments_Model_Mysql4_Api_Debug_Collection
33
+ * @author Magento Core Team <core@magentocommerce.com>
34
+ */
35
+ class Mage_AmazonPayments_Model_Mysql4_Api_Debug_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
36
+ {
37
+ /**
38
+ * Collection constructor
39
+ *
40
+ */
41
+ protected function _construct()
42
+ {
43
+ $this->_init('amazonpayments/api_debug');
44
+ }
45
+ }
app/code/core/Mage/AmazonPayments/Model/Mysql4/Setup.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ class Mage_AmazonPayments_Model_Mysql4_Setup extends Mage_Sales_Model_Mysql4_Setup
29
+ {
30
+
31
+ }
app/code/core/Mage/AmazonPayments/Model/Observer.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ /**
29
+ * Amazon Payments Event Observer
30
+ *
31
+ * @category Mage
32
+ * @package Mage_AmazonPayments
33
+ */
34
+ class Mage_AmazonPayments_Model_Observer
35
+ {
36
+ public function confirmShipment(Varien_Event_Observer $observer)
37
+ {
38
+ $shipment = $observer->getEvent()->getShipment();
39
+ if ($shipment->getOrder()->getPayment()->getMethod() != 'amazonpayments_cba') {
40
+ return;
41
+ }
42
+
43
+ Mage::getModel('amazonpayments/api_cba')
44
+ ->confirmShipment($shipment);
45
+ }
46
+
47
+ public function salesOrderShipmentTrackSaveAfter(Varien_Event_Observer $observer)
48
+ {
49
+ $track = $observer->getEvent()->getTrack();
50
+ $order = $track->getShipment()->getOrder();
51
+ /* @var $order Mage_Sales_Model_Order */
52
+ if ($order->getPayment()->getMethod() != 'amazonpayments_cba') {
53
+ return;
54
+ }
55
+ Mage::getModel('amazonpayments/api_cba')
56
+ ->sendTrackingNumber($order, $track);
57
+ }
58
+ }
app/code/core/Mage/AmazonPayments/Model/Payment.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_GooglePayments
23
+ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ class Mage_AmazonPayments_Model_Payment extends Mage_Payment_Model_Method_Abstract
28
+ {
29
+ protected $_code = 'amazonpayments';
30
+ protected $_formBlockType = 'amazonpayments/form';
31
+
32
+ const ACTION_AUTHORIZE = 0;
33
+ const ACTION_AUTHORIZE_CAPTURE = 1;
34
+
35
+ public function __construct()
36
+ {
37
+ echo 'hello';
38
+ }
39
+
40
+ public function getOrderPlaceRedirectUrl()
41
+ {
42
+ return $this->getRedirectUrl();
43
+ }
44
+
45
+ public function getRedirectUrl()
46
+ {
47
+ #Mage::exception($this, 'worldpay');
48
+ #throw new Exception('qwe')
49
+ die('test2');
50
+ $_url = Mage::getUrl('amazonepayments/redirect');
51
+ echo "url: {$_url}<br />";
52
+ return $_url;
53
+ }
54
+ }
app/code/core/Mage/AmazonPayments/Model/Payment/Asp.php ADDED
@@ -0,0 +1,435 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments ASP payment Model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Payment_Asp extends Mage_Payment_Model_Method_Abstract
35
+ {
36
+ /**
37
+ * rewrited for Mage_Payment_Model_Method_Abstract
38
+ */
39
+ protected $_isGateway = false;
40
+ protected $_canAuthorize = false;
41
+ protected $_canCapture = true;
42
+ protected $_canCapturePartial = false;
43
+ protected $_canRefund = true;
44
+ protected $_canVoid = true;
45
+ protected $_canUseInternal = false;
46
+ protected $_canUseCheckout = true;
47
+ protected $_canUseForMultishipping = false;
48
+ protected $_isInitializeNeeded = true;
49
+
50
+ /**
51
+ * rewrited for Mage_Payment_Model_Method_Abstract
52
+ */
53
+ protected $_formBlockType = 'amazonpayments/asp_form';
54
+
55
+ /**
56
+ * rewrited for Mage_Payment_Model_Method_Abstract
57
+ */
58
+ protected $_code = 'amazonpayments_asp';
59
+
60
+ /**
61
+ * current order
62
+ */
63
+ protected $_order;
64
+
65
+ /**
66
+ * Get value from the module config
67
+ *
68
+ * @param string $path
69
+ * @return string
70
+ */
71
+ public function getConfig($path)
72
+ {
73
+ return Mage::getStoreConfig('payment/' . $this->_code . '/' . $path);
74
+ }
75
+
76
+
77
+ /**
78
+ * Get singleton with AmazonPayments ASP API Model
79
+ *
80
+ * @return Mage_AmazonPayments_Model_Api_Asp
81
+ */
82
+ public function getApi()
83
+ {
84
+ return Mage::getSingleton('amazonpayments/api_asp');
85
+ }
86
+
87
+ /**
88
+ * Get singleton with AmazonPayments ASP Notification Model
89
+ *
90
+ * @return Mage_AmazonPayments_Model_Payment_Asp_Notification
91
+ */
92
+ public function getNotification()
93
+ {
94
+ return Mage::getSingleton('amazonpayments/payment_asp_notification');
95
+ }
96
+
97
+ /**
98
+ * Set model of current order
99
+ *
100
+ * @param Mage_Sales_Model_Order $order
101
+ * @return Mage_AmazonPayments_Model_Payment_Asp
102
+ */
103
+ public function setOrder($order)
104
+ {
105
+ $this->_order = $order;
106
+ return $this;
107
+ }
108
+
109
+ /**
110
+ * Get model of current order
111
+ *
112
+ * @return Mage_Sales_Model_Order
113
+ */
114
+ public function getOrder()
115
+ {
116
+ if (!$this->_order) {
117
+ $paymentInfo = $this->getInfoInstance();
118
+ $this->_order = Mage::getModel('sales/order')->loadByIncrementId(
119
+ $paymentInfo->getOrder()->getRealOrderId()
120
+ );
121
+ }
122
+ return $this->_order;
123
+ }
124
+
125
+ /**
126
+ * Add item in to log storage
127
+ *
128
+ * @param string $request
129
+ * @param string $response
130
+ * @return Mage_AmazonPayments_Model_Payment_Asp
131
+ */
132
+ protected function _log($request, $response = '')
133
+ {
134
+ $debug = Mage::getModel('amazonpayments/api_debug')
135
+ ->setRequestBody($request)
136
+ ->setResponseBody($response)
137
+ ->save();
138
+ return $this;
139
+ }
140
+
141
+ /**
142
+ * Send mail
143
+ *
144
+ * @param string $template
145
+ * @param array $variables
146
+ * @return Mage_AmazonPayments_Model_Payment_Asp
147
+ */
148
+ protected function _mail($template, array $variables = array())
149
+ {
150
+ $mailTemplate = Mage::getModel('core/email_template');
151
+ $mailTemplate->setDesignConfig(array('area' => 'frontend'))
152
+ ->sendTransactional(
153
+ $this->getConfig($template),
154
+ $this->getConfig('email_sender_identity'),
155
+ $this->getConfig('report_email'),
156
+ null,
157
+ $variables
158
+ );
159
+ return $this;
160
+ }
161
+
162
+ /**
163
+ * rewrited for Mage_Payment_Model_Method_Abstract
164
+ */
165
+ public function getOrderPlaceRedirectUrl()
166
+ {
167
+ return Mage::getUrl('amazonpayments/asp/pay');
168
+ }
169
+
170
+ /**
171
+ * Return Amazon Simple Pay payment url
172
+ *
173
+ * @return string
174
+ */
175
+ public function getPayRedirectUrl()
176
+ {
177
+ return $this->getApi()->getPayUrl();
178
+ }
179
+
180
+ /**
181
+ * Return choice method description
182
+ *
183
+ * @return string
184
+ */
185
+ public function getChoiceMethodDescription()
186
+ {
187
+ return $this->getConfig('choice_method_description');
188
+ }
189
+
190
+ /**
191
+ * Return redirect message
192
+ *
193
+ * @return string
194
+ */
195
+ public function getRedirectMessage()
196
+ {
197
+ return $this->getConfig('redirect_message');
198
+ }
199
+
200
+ /**
201
+ * Return pay params for current order
202
+ *
203
+ * @return array
204
+ */
205
+ public function getPayRedirectParams()
206
+ {
207
+ $orderId = $this->getOrder()->getRealOrderId();
208
+ $amount = Mage::app()->getStore()->roundPrice($this->getOrder()->getBaseGrandTotal());
209
+ $currencyCode = $this->getOrder()->getBaseCurrencyCode();
210
+
211
+ $urlModel = Mage::getModel('core/url')
212
+ ->setUseSession(false);
213
+
214
+ return $this->getApi()->getPayParams(
215
+ $orderId,
216
+ $amount,
217
+ $currencyCode,
218
+ $urlModel->getUrl('amazonpayments/asp/returnCancel'),
219
+ $urlModel->getUrl('amazonpayments/asp/returnSuccess'),
220
+ $urlModel->getUrl('amazonpayments/asp/notification')
221
+ );
222
+ }
223
+
224
+ /**
225
+ * When a customer redirect to Amazon Simple Pay site
226
+ *
227
+ * @return Mage_AmazonPayments_Model_Payment_Asp
228
+ */
229
+ public function processEventRedirect()
230
+ {
231
+ $this->getOrder()->addStatusToHistory(
232
+ $this->getOrder()->getStatus(),
233
+ Mage::helper('amazonpayments')->__('Customer was redirected to Amazon Simple Pay site')
234
+ )->save();
235
+ return $this;
236
+ }
237
+
238
+ /**
239
+ * When a customer successfully returned from Amazon Simple Pay site
240
+ *
241
+ * @return Mage_AmazonPayments_Model_Payment_Asp
242
+ */
243
+ public function processEventReturnSuccess()
244
+ {
245
+ $this->getOrder()->sendNewOrderEmail();
246
+ $this->getOrder()->addStatusToHistory(
247
+ $this->getOrder()->getStatus(),
248
+ Mage::helper('amazonpayments')->__('Customer successfully returned from Amazon Simple Pay site')
249
+ )->save();
250
+ return $this;
251
+ }
252
+
253
+ /**
254
+ * Customer canceled payment and successfully returned from Amazon Simple Pay site
255
+ *
256
+ * @return Mage_AmazonPayments_Model_Payment_Asp
257
+ */
258
+ public function processEventReturnCancel()
259
+ {
260
+ $this->getOrder()->addStatusToHistory(
261
+ $this->getOrder()->getStatus(),
262
+ Mage::helper('amazonpayments')->__('Customer canceled payment and successfully returned from Amazon Simple Pay site')
263
+ )->save();
264
+ return $this;
265
+ }
266
+
267
+ /**
268
+ * rewrited for Mage_Payment_Model_Method_Abstract
269
+ */
270
+ public function initialize($paymentAction, $stateObject)
271
+ {
272
+ $state = Mage_Sales_Model_Order::STATE_NEW;
273
+ $stateObject->setState($state);
274
+ $stateObject->setStatus(Mage::getSingleton('sales/order_config')->getStateDefaultStatus($state));
275
+ $stateObject->setIsNotified(false);
276
+ return $this;
277
+ }
278
+
279
+ /**
280
+ * process Amazon Simple Pay notification request
281
+ *
282
+ * @param array $requestParams
283
+ * @return bool
284
+ */
285
+ public function processNotification($requestParams)
286
+ {
287
+ if ($this->getConfig('debug_log')) {
288
+ $this->_log('DEBUG ASP notification: ' . print_r($requestParams, 1));
289
+ }
290
+
291
+ try {
292
+ $this->getNotification()->setPayment($this)->process($requestParams);
293
+ } catch(Exception $e) {
294
+ if ($this->getConfig('error_log')) {
295
+ $this->_log('ERROR ASP notification: ' . print_r($requestParams, 1), $e->getMessage());
296
+ }
297
+
298
+ if ($this->getConfig('report_error_to_email')) {
299
+ $variables = array();
300
+ $variables['request'] = print_r($requestParams, 1);
301
+ $variables['error'] = $e->getMessage();
302
+ $this->_mail('email_template_notification_error', $variables);
303
+ }
304
+
305
+ return false;
306
+ }
307
+
308
+ return true;
309
+ }
310
+
311
+ /**
312
+ * rewrited for Mage_Payment_Model_Method_Abstract
313
+ */
314
+ public function capture(Varien_Object $payment, $amount)
315
+ {
316
+ if (is_null($payment->getCcTransId())) {
317
+ Mage::throwException(
318
+ Mage::helper('amazonpayments')->__('Order was not captured online. Authorization confirmation is required.')
319
+ );
320
+ }
321
+ return $this;
322
+ }
323
+
324
+ /**
325
+ * rewrited for Mage_Payment_Model_Method_Abstract
326
+ */
327
+ public function processInvoice($invoice, $payment)
328
+ {
329
+ if (!is_null($payment->getCcTransId()) &&
330
+ is_null($payment->getLastTransId()) &&
331
+ is_null($invoice->getTransactionId())) {
332
+
333
+ $amount = Mage::app()->getStore()->roundPrice($invoice->getBaseGrandTotal());
334
+ $currencyCode = $payment->getOrder()->getBaseCurrencyCode();
335
+ $transactionId = $payment->getCcTransId();
336
+ $response = $this->getApi()
337
+ ->setStoreId($payment->getOrder()->getStoreId())
338
+ ->capture($transactionId, $amount, $currencyCode);
339
+
340
+ if ($response->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract::STATUS_ERROR) {
341
+ Mage::throwException(
342
+ Mage::helper('amazonpayments')->__('Order was not captured. Amazon Simple Pay service error: [%s] %s', $response->getCode(), $response->getMessage())
343
+ );
344
+ }
345
+
346
+ if ($response->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract::STATUS_SUCCESS ||
347
+ $response->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract::STATUS_PENDING) {
348
+
349
+ $payment->setForcedState(Mage_Sales_Model_Order_Invoice::STATE_OPEN);
350
+ $payment->setLastTransId($response->getTransactionId());
351
+
352
+ $invoice->setTransactionId($response->getTransactionId());
353
+ $invoice->addComment(Mage::helper('amazonpayments')->__('Invoice was created (online capture). Waiting for capture confirmation from Amazon Simple Pay service.'));
354
+
355
+ $payment->getOrder()->addStatusToHistory(
356
+ $payment->getOrder()->getStatus(),
357
+ Mage::helper('amazonpayments')->__('Payment was captured online with Amazon Simple Pay service. Invoice was created. Waiting for capture confirmation from payment service.')
358
+ );
359
+
360
+ }
361
+ }
362
+ return $this;
363
+ }
364
+
365
+ /**
366
+ * rewrited for Mage_Payment_Model_Method_Abstract
367
+ */
368
+ public function processCreditmemo($creditmemo, $payment)
369
+ {
370
+
371
+ $transactionId = $creditmemo->getInvoice()->getTransactionId();
372
+
373
+ if (!is_null($transactionId) &&
374
+ is_null($creditmemo->getTransactionId())) {
375
+
376
+ $amount = Mage::app()->getStore()->roundPrice($creditmemo->getBaseGrandTotal());
377
+ $currencyCode = $payment->getOrder()->getBaseCurrencyCode();
378
+ $referenseID = $creditmemo->getInvoice()->getIncrementId();
379
+ $response = $this->getApi()
380
+ ->setStoreId($payment->getOrder()->getStoreId())
381
+ ->refund($transactionId, $amount, $currencyCode, $referenseID);
382
+
383
+ if ($response->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract::STATUS_ERROR) {
384
+ Mage::throwException(
385
+ Mage::helper('amazonpayments')->__('Invoice was not refunded. Amazon Simple Pay service error: [%s] %s', $response->getCode(), $response->getMessage())
386
+ );
387
+ }
388
+
389
+ if ($response->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract::STATUS_SUCCESS ||
390
+ $response->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract::STATUS_PENDING) {
391
+
392
+ $creditmemo->setTransactionId($response->getTransactionId());
393
+ $creditmemo->addComment(Mage::helper('amazonpayments')->__('Payment refunded online. Waiting for refund confirmation from Amazon Simple Pay service.'));
394
+ $creditmemo->setState(Mage_Sales_Model_Order_Creditmemo::STATE_OPEN);
395
+
396
+ $payment->getOrder()->addStatusToHistory(
397
+ $payment->getOrder()->getStatus(),
398
+ Mage::helper('amazonpayments')->__('Payment refunded online with Amazon Simple Pay service. Creditmemo was created. Waiting for refund confirmation from Amazon Simple Pay service.')
399
+ );
400
+ }
401
+ }
402
+ return $this;
403
+ }
404
+
405
+ /**
406
+ * rewrited for Mage_Payment_Model_Method_Abstract
407
+ */
408
+ public function cancel(Varien_Object $payment)
409
+ {
410
+ if (!is_null($payment->getCcTransId()) &&
411
+ is_null($payment->getLastTransId())) {
412
+
413
+ $transactionId = $payment->getCcTransId();
414
+ $response = $this->getApi()
415
+ ->setStoreId($payment->getOrder()->getStoreId())
416
+ ->cancel($transactionId);
417
+
418
+ if ($response->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract::STATUS_ERROR) {
419
+ Mage::throwException(
420
+ Mage::helper('amazonpayments')->__('Order was not cancelled. Amazon Simple Pay service error: [%s] %s', $response->getCode(), $response->getMessage())
421
+ );
422
+ }
423
+
424
+ if ($response->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract::STATUS_CANCELLED) {
425
+ $payment->getOrder()->setState(
426
+ Mage_Sales_Model_Order::STATE_CANCELED,
427
+ true,
428
+ Mage::helper('amazonpayments')->__('Payment authorization cancelled with Amazon Simple Pay service.'),
429
+ $notified = false
430
+ );
431
+ }
432
+ }
433
+ return $this;
434
+ }
435
+ }
app/code/core/Mage/AmazonPayments/Model/Payment/Asp/Abstract.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ class Mage_AmazonPayments_Model_Payment_Asp_Abstract extends Mage_Payment_Model_Method_Abstract
28
+ {
29
+
30
+ }
app/code/core/Mage/AmazonPayments/Model/Payment/Asp/Fps.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ class Mage_AmazonPayments_Model_Payment_Asp_Fps extends Mage_AmazonPayments_Model_Payment_Asp_Abstract
28
+ {
29
+
30
+ public function refund($reserveTransactionId, $callerReference)
31
+ {
32
+ $this->getApi()->getFps()->refund($reserveTransactionId, $callerReference);
33
+ }
34
+
35
+ }
app/code/core/Mage/AmazonPayments/Model/Payment/Asp/Notification.php ADDED
@@ -0,0 +1,544 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments ASP notification Model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Payment_Asp_Notification extends Varien_Object
35
+ {
36
+ /*
37
+ * payment Model
38
+ */
39
+ protected $_payment;
40
+
41
+ /**
42
+ * Set payment Model
43
+ *
44
+ * @param Mage_AmazonPayments_Model_Payment_Asp $payment
45
+ * @return Mage_AmazonPayments_Model_Payment_Asp_Notification
46
+ */
47
+ public function setPayment($payment)
48
+ {
49
+ $this->_payment = $payment;
50
+ return $this;
51
+ }
52
+
53
+ /**
54
+ * Get payment Model
55
+ *
56
+ * @return Mage_AmazonPayments_Model_Payment_Asp
57
+ */
58
+ public function getPayment()
59
+ {
60
+ return $this->_payment;
61
+ }
62
+
63
+ /**
64
+ * process notification request
65
+ *
66
+ * @param array $requestParams
67
+ */
68
+ public function process($requestParams)
69
+ {
70
+ $request = $this->getPayment()->getApi()->processNotification($requestParams);
71
+
72
+ if ($request->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Ipn_Request::STATUS_CANCEL_TRANSACTION) {
73
+ return true;
74
+ }
75
+
76
+ $order = $this->_getRequestOrder($request);
77
+ switch ($request->getStatus()) {
78
+ case Mage_AmazonPayments_Model_Api_Asp_Ipn_Request::STATUS_CANCEL_CUSTOMER:
79
+ $this->_processCancel($request, $order);
80
+ break;
81
+ case Mage_AmazonPayments_Model_Api_Asp_Ipn_Request::STATUS_RESERVE_SUCCESSFUL:
82
+ $this->_processReserveSuccess($request, $order);
83
+ break;
84
+ case Mage_AmazonPayments_Model_Api_Asp_Ipn_Request::STATUS_PAYMENT_INITIATED:
85
+ $this->_processPaymetInitiated($request, $order);
86
+ break;
87
+ case Mage_AmazonPayments_Model_Api_Asp_Ipn_Request::STATUS_PAYMENT_SUCCESSFUL:
88
+ $this->_processPaymentSuccessful($request, $order);
89
+ break;
90
+ case Mage_AmazonPayments_Model_Api_Asp_Ipn_Request::STATUS_PAYMENT_FAILED:
91
+ $this->_processPaymentFailed($request, $order);
92
+ break;
93
+ case Mage_AmazonPayments_Model_Api_Asp_Ipn_Request::STATUS_REFUND_SUCCESSFUL:
94
+ $this->_processRefundSuccessful($request, $order);
95
+ break;
96
+ case Mage_AmazonPayments_Model_Api_Asp_Ipn_Request::STATUS_REFUND_FAILED:
97
+ $this->_processRefundFailed($request, $order);
98
+ break;
99
+ case Mage_AmazonPayments_Model_Api_Asp_Ipn_Request::STATUS_SYSTEM_ERROR:
100
+ $this->_processSystemError($request, $order);
101
+ break;
102
+ }
103
+ }
104
+
105
+ /**
106
+ * When a customer cancel payment
107
+ */
108
+ protected function _processCancel($request, $order)
109
+ {
110
+ if ($order->isCanceled()) {
111
+ $order->addStatusToHistory(
112
+ $order->getStatus(),
113
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmed cancelation.')
114
+ )->save();
115
+ return true;
116
+ }
117
+
118
+ if ($order->getState() == Mage_Sales_Model_Order::STATE_NEW) {
119
+ $order->addStatusToHistory(
120
+ $order->getStatus(),
121
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmed cancelation.')
122
+ )->cancel()->save();
123
+ return true;
124
+ }
125
+
126
+ $this->_errorViolationSequenceStates($request, $order);
127
+ }
128
+
129
+ /**
130
+ * When a authorize payment
131
+ */
132
+ protected function _processReserveSuccess($request, $order)
133
+ {
134
+ if ($order->getState() != Mage_Sales_Model_Order::STATE_NEW) {
135
+ $this->_errorViolationSequenceStates($request, $order);
136
+ }
137
+
138
+ $order->getPayment()->setCcTransId($request->getTransactionId());
139
+
140
+ $order->setState(
141
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
142
+ 'pending_amazon_asp',
143
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmed amount authorization.'),
144
+ $notified = false
145
+ )->save();
146
+
147
+ return true;
148
+ }
149
+
150
+ /**
151
+ * When a initiation capture payment
152
+ */
153
+ protected function _processPaymetInitiated($request, $order)
154
+ {
155
+ if ($order->getState() != Mage_Sales_Model_Order::STATE_NEW &&
156
+ $order->getState() != Mage_Sales_Model_Order::STATE_PENDING_PAYMENT) {
157
+ $this->_errorViolationSequenceStates($request, $order);
158
+ }
159
+
160
+ $order->setState(
161
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
162
+ 'pending_amazon_asp',
163
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmed capture initiation.'),
164
+ $notified = false
165
+ )->save();
166
+
167
+ return true;
168
+ }
169
+
170
+ /**
171
+ * When a capture payment
172
+ */
173
+ protected function _processPaymentSuccessful($request, $order)
174
+ {
175
+ if ($order->getState() != Mage_Sales_Model_Order::STATE_NEW &&
176
+ $order->getState() != Mage_Sales_Model_Order::STATE_PENDING_PAYMENT &&
177
+ $order->getState() != Mage_Sales_Model_Order::STATE_PROCESSING &&
178
+ $order->getState() != Mage_Sales_Model_Order::STATE_COMPLETE) {
179
+ $this->_errorViolationSequenceStates($request, $order);
180
+ }
181
+
182
+ if (!$invoice = $this->_getOrderInvoice($order)) {
183
+
184
+ $orderAmount = Mage::app()->getStore()->roundPrice($order->getBaseGrandTotal());
185
+ $requestAmount = Mage::app()->getStore()->roundPrice($request->getAmount());
186
+ if ($orderAmount != $requestAmount) {
187
+ $this->_error(
188
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service capture confirmation error: confirmation request amount not equal to the amount of order.'),
189
+ $request,
190
+ $order
191
+ );
192
+ }
193
+
194
+ $invoice = $order->prepareInvoice();
195
+ $invoice->register()->pay();
196
+ $invoice->addComment(Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmed payment capture. Invoice created automatically.'));
197
+ $invoice->setTransactionId($request->getTransactionId());
198
+
199
+ $order->getPayment()->setLastTransId($request->getTransactionId());
200
+ $order->setState(
201
+ Mage_Sales_Model_Order::STATE_PROCESSING,
202
+ true,
203
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmed payment capture. Invoice %s was automatically created after confirmation.', $invoice->getIncrementId()),
204
+ $notified = true
205
+ );
206
+
207
+ $transactionSave = Mage::getModel('core/resource_transaction')
208
+ ->addObject($invoice)
209
+ ->addObject($invoice->getOrder())
210
+ ->save();
211
+
212
+ } else {
213
+
214
+ if ($invoice->getTransactionId() != $request->getTransactionId()) {
215
+ $this->_error(
216
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service capture confirmation error: existing transaction ID doesn\'t match transaction ID in the confirmation request.'),
217
+ $request,
218
+ $order
219
+ );
220
+ }
221
+
222
+ $invoiceAmount = Mage::app()->getStore()->roundPrice($invoice->getGrandTotal());
223
+ $requestAmount = Mage::app()->getStore()->roundPrice($request->getAmount());
224
+ if ($invoiceAmount != $requestAmount) {
225
+ $this->_error(
226
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service capture confirmation error: amount in the existing invoice doensn\'t match the amount in confirmation request.'),
227
+ $request,
228
+ $order
229
+ );
230
+ }
231
+
232
+ $msg = '';
233
+
234
+ switch ($invoice->getState())
235
+ {
236
+ case Mage_Sales_Model_Order_Invoice::STATE_OPEN:
237
+ $invoice->addComment(Mage::helper('amazonpayments')->__('Amazon Simple Pay service capture confirmation. Invoice was captured automatically.'));
238
+ $invoice->setState(Mage_Sales_Model_Order_Invoice::STATE_PAID);
239
+ $msg = $msg . Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmed capture for invoice %s. Invoice automatically captured.', $invoice->getIncrementId());
240
+ break;
241
+
242
+ case Mage_Sales_Model_Order_Invoice::STATE_PAID:
243
+ $invoice->addComment(Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmed capture'));
244
+ $msg = $msg . Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmed capture for invoice %s', $invoice->getIncrementId());
245
+ break;
246
+ }
247
+
248
+ $order->getPayment()->setLastTransId($request->getTransactionId());
249
+ $order->setState(
250
+ Mage_Sales_Model_Order::STATE_PROCESSING,
251
+ true,
252
+ $msg,
253
+ $notified = true
254
+ );
255
+
256
+ $transactionSave = Mage::getModel('core/resource_transaction')
257
+ ->addObject($invoice)
258
+ ->addObject($order)
259
+ ->save();
260
+
261
+ }
262
+
263
+ return true;
264
+ }
265
+
266
+ /**
267
+ * When a failed capture payment
268
+ */
269
+ protected function _processPaymentFailed($request, $order)
270
+ {
271
+ if ($order->getState() != Mage_Sales_Model_Order::STATE_NEW &&
272
+ $order->getState() != Mage_Sales_Model_Order::STATE_PENDING_PAYMENT) {
273
+ $this->_errorViolationSequenceStates($request, $order);
274
+ }
275
+
276
+ $order->setState(
277
+ Mage_Sales_Model_Order::STATE_CANCELED,
278
+ true,
279
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service payment confirmation failed'),
280
+ $notified = false
281
+ )->save();
282
+
283
+ return true;
284
+ }
285
+
286
+ /**
287
+ * When a refund payment
288
+ */
289
+ protected function _processRefundSuccessful($request, $order)
290
+ {
291
+ if ($order->getState() != Mage_Sales_Model_Order::STATE_PROCESSING &&
292
+ $order->getState() != Mage_Sales_Model_Order::STATE_CLOSED &&
293
+ $order->getState() != Mage_Sales_Model_Order::STATE_COMPLETE) {
294
+ $this->_errorViolationSequenceStates($request, $order);
295
+ }
296
+
297
+ if (!$creditmemo = $this->_getOrderCreditmemo($order)) {
298
+
299
+ $orderAmount = Mage::app()->getStore()->roundPrice($order->getBaseGrandTotal());
300
+ $requestAmount = Mage::app()->getStore()->roundPrice($request->getAmount());
301
+ if ($orderAmount != $requestAmount || $order->getBaseTotalRefunded() > 0) {
302
+ $this->_error(
303
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service refund confirmation error: confirmation request amount doesn\'t match the order amount.'),
304
+ $request,
305
+ $order
306
+ );
307
+ }
308
+
309
+ if ($creditmemo = $this->_initCreditmemo($order)) {
310
+ $creditmemo->setTransactionId($request->getTransactionId());
311
+ $creditmemo->addComment(Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmed payment refund. Creditmemo %s was automatically created after confirmation.', $creditmemo->getIncrementId()));
312
+ $creditmemo->register();
313
+
314
+ $transactionSave = Mage::getModel('core/resource_transaction')
315
+ ->addObject($creditmemo)
316
+ ->addObject($creditmemo->getOrder());
317
+ if ($creditmemo->getInvoice()) {
318
+ $transactionSave->addObject($creditmemo->getInvoice());
319
+ }
320
+
321
+ $order->addStatusToHistory(
322
+ $order->getStatus(),
323
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmed payment refund. Credit memo created automatically.', $creditmemo->getIncrementId())
324
+ );
325
+
326
+ $transactionSave->save();
327
+ }
328
+
329
+ } else {
330
+
331
+ if ($creditmemo->getTransactionId() != $request->getTransactionId()) {
332
+ $this->_error(
333
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service refund confirmation error: transaction ID in the existing creditmemo doesn\'t match the transaction ID in the confirmation request.'),
334
+ $request,
335
+ $order
336
+ );
337
+ }
338
+
339
+ $creditmemoAmount = Mage::app()->getStore()->roundPrice($creditmemo->getBaseGrandTotal());
340
+ $requestAmount = Mage::app()->getStore()->roundPrice($request->getAmount());
341
+ if ($creditmemoAmount != $requestAmount) {
342
+ $this->_error(
343
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service refund confirmation error: amount in the existing creditmemo doensn\'t match the amount in confirmation request.'),
344
+ $request,
345
+ $order
346
+ );
347
+ }
348
+
349
+ $msg = '';
350
+
351
+ switch ($creditmemo->getState())
352
+ {
353
+ case Mage_Sales_Model_Order_Creditmemo::STATE_OPEN:
354
+ $creditmemo->addComment(Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmed refund. Creditmemo processed automatically.'));
355
+ $creditmemo->setState(Mage_Sales_Model_Order_Creditmemo::STATE_REFUNDED);
356
+ $msg = $msg . Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmed refunded creditmemo %s. Creditmemo processed automatically.', $creditmemo->getIncrementId());
357
+ break;
358
+
359
+ case Mage_Sales_Model_Order_Creditmemo::STATE_REFUNDED:
360
+ $creditmemo->addComment(Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmed refund.'));
361
+ $msg = $msg . Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmed refund for creditmemo %s.', $creditmemo->getIncrementId());
362
+ break;
363
+ }
364
+
365
+ $order->addStatusToHistory(
366
+ $order->getStatus(),
367
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmed payment refund. Credit memo created automatically.', $creditmemo->getIncrementId())
368
+ );
369
+
370
+ $transactionSave = Mage::getModel('core/resource_transaction')
371
+ ->addObject($creditmemo)
372
+ ->addObject($order)
373
+ ->save();
374
+
375
+ }
376
+
377
+ return true;
378
+ }
379
+
380
+ /**
381
+ * When a failed refund payment
382
+ */
383
+ protected function _processRefundFailed($request, $order)
384
+ {
385
+ $order->addStatusToHistory(
386
+ $order->getStatus(),
387
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service payment confirmation failed')
388
+ )->save();
389
+ return true;
390
+ }
391
+
392
+ /**
393
+ * When a Amazon Simple Pay system error
394
+ */
395
+ protected function _processSystemError($request, $order)
396
+ {
397
+ $order->setState(
398
+ Mage_Sales_Model_Order::STATE_CANCELED,
399
+ true,
400
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service is not available. Payment was not processed.'),
401
+ $notified = false
402
+ )->save();
403
+
404
+ return true;
405
+ }
406
+
407
+ /**
408
+ * Return order model for current request
409
+ *
410
+ * @param array $request
411
+ * @return Mage_Sales_Model_Order
412
+ */
413
+ protected function _getRequestOrder($request)
414
+ {
415
+ $order = Mage::getModel('sales/order');
416
+ $order->loadByIncrementId($request->getReferenceId());
417
+
418
+ if ($order->isEmpty()) {
419
+ $this->_error(
420
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmation error: order specified in the IPN request can not be found'),
421
+ $request
422
+ );
423
+ }
424
+
425
+ if ($order->getPayment()->getMethodInstance()->getCode() != $this->getPayment()->getCode()) {
426
+ $this->_error(
427
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmation error: payment method in the order is not Amazon Simple Pay'),
428
+ $request
429
+ );
430
+ }
431
+
432
+ if ($order->getBaseCurrency()->getCurrencyCode() != $request->getCurrencyCode()) {
433
+ $this->_error(
434
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmation error: order currency does not match the currency of the IPN request'),
435
+ $request
436
+ );
437
+ }
438
+
439
+ return $order;
440
+ }
441
+
442
+ /**
443
+ * Return invoice model for current order
444
+ *
445
+ * @param Mage_Sales_Model_Order $order
446
+ * @return Mage_Sales_Model_Order_Invoice
447
+ */
448
+ protected function _getOrderInvoice($order)
449
+ {
450
+ foreach ($order->getInvoiceCollection() as $orderInvoice) {
451
+ if ($orderInvoice->getState() == Mage_Sales_Model_Order_Invoice::STATE_PAID ||
452
+ $orderInvoice->getState() == Mage_Sales_Model_Order_Invoice::STATE_OPEN) {
453
+ return $orderInvoice->load($orderInvoice->getId());
454
+ }
455
+ }
456
+
457
+ return false;
458
+ }
459
+
460
+ /**
461
+ * Create and return creditmemo for current order
462
+ *
463
+ * @param Mage_Sales_Model_Order $order
464
+ * @return Mage_Sales_Model_Order_Creditmemo
465
+ */
466
+ protected function _initCreditMemo($order)
467
+ {
468
+ $invoice = $this->_getOrderInvoice($order);
469
+
470
+ if (!$invoice) {
471
+ return false;
472
+ }
473
+
474
+ $convertor = Mage::getModel('sales/convert_order');
475
+ $creditmemo = $convertor->toCreditmemo($order)->setInvoice($invoice);
476
+
477
+ foreach ($invoice->getAllItems() as $invoiceItem) {
478
+ $orderItem = $invoiceItem->getOrderItem();
479
+ $item = $convertor->itemToCreditmemoItem($orderItem);
480
+ $item->setQty($orderItem->getQtyToRefund());
481
+ $creditmemo->addItem($item);
482
+ }
483
+
484
+ $creditmemo->setShippingAmount($invoice->getShippingAmount());
485
+ $creditmemo->collectTotals();
486
+ Mage::register('current_creditmemo', $creditmemo);
487
+
488
+ return $creditmemo;
489
+ }
490
+
491
+ /**
492
+ * Return creditmemo model for current order
493
+ *
494
+ * @param Mage_Sales_Model_Order $order
495
+ * @return Mage_Sales_Model_Order_Creditmemo
496
+ */
497
+ protected function _getOrderCreditmemo($order)
498
+ {
499
+ foreach ($order->getCreditmemosCollection() as $orderCreditmemo) {
500
+ if ($orderCreditmemo->getState() == Mage_Sales_Model_Order_Creditmemo::STATE_REFUNDED ||
501
+ $orderCreditmemo->getState() == Mage_Sales_Model_Order_Creditmemo::STATE_OPEN) {
502
+ return $orderCreditmemo->load($orderCreditmemo->getId());
503
+ }
504
+ }
505
+
506
+ return false;
507
+ }
508
+
509
+ /**
510
+ * Process error: order states sequence violation
511
+ *
512
+ * @param array $request
513
+ * @param Mage_Sales_Model_Order $order
514
+ */
515
+ protected function _errorViolationSequenceStates($request, $order)
516
+ {
517
+ $this->_error(
518
+ Mage::helper('amazonpayments')->__('Amazon Simple Pay service confirmation error: order states sequence violation'),
519
+ $request,
520
+ $order
521
+ );
522
+ }
523
+
524
+ /**
525
+ * Process error
526
+ *
527
+ * @param string $comment
528
+ * @param array $request
529
+ * @param Mage_Sales_Model_Order $order
530
+ */
531
+ protected function _error($comment, $request, $order = null)
532
+ {
533
+ $message = $comment . Mage::helper('amazonpayments')->__('<br/>Trace confirmation request:<br/>%s', $request->toString());
534
+
535
+ if (!is_null($order)) {
536
+ $order->addStatusToHistory(
537
+ $order->getStatus(),
538
+ $message
539
+ )->save();
540
+ }
541
+
542
+ Mage::throwException($comment);
543
+ }
544
+ }
app/code/core/Mage/AmazonPayments/Model/Payment/Asp/Source/PaymentAction.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments ASP Payment Action Dropdown source
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_Model_Payment_Asp_Source_PaymentAction
35
+ {
36
+ public function toOptionArray()
37
+ {
38
+ return array(
39
+ array(
40
+ 'value' => Mage_AmazonPayments_Model_Api_Asp_Abstract::PAY_ACTION_SETTLE,
41
+ 'label' => Mage::helper('amazonpayments')->__('Authorize Only')
42
+ ),
43
+ array(
44
+ 'value' => Mage_AmazonPayments_Model_Api_Asp_Abstract::PAY_ACTION_SETTLE_CAPTURE,
45
+ 'label' => Mage::helper('amazonpayments')->__('Authorize and Capture')
46
+ ),
47
+ );
48
+ }
49
+ }
app/code/core/Mage/AmazonPayments/Model/Payment/Cba.php ADDED
@@ -0,0 +1,598 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ class Mage_AmazonPayments_Model_Payment_Cba extends Mage_Payment_Model_Method_Abstract
28
+ {
29
+ /**
30
+ * Payment module of Checkout by Amazon
31
+ * CBA - Checkout By Amazon
32
+ */
33
+
34
+ protected $_code = 'amazonpayments_cba';
35
+ protected $_formBlockType = 'amazonpayments/cba_form';
36
+ protected $_api;
37
+
38
+ protected $_isGateway = false;
39
+ protected $_canAuthorize = true;
40
+ protected $_canCapture = false;
41
+ protected $_canCapturePartial = false;
42
+ protected $_canRefund = true;
43
+ protected $_canVoid = false;
44
+ protected $_canUseInternal = false;
45
+ protected $_canUseCheckout = false;
46
+ protected $_canUseForMultishipping = false;
47
+
48
+ // const ACTION_AUTHORIZE = 0;
49
+ // const ACTION_AUTHORIZE_CAPTURE = 1;
50
+
51
+ protected $_skipProccessDocument = false;
52
+
53
+ /**
54
+ * Get checkout session namespace
55
+ *
56
+ * @return Mage_Checkout_Model_Session
57
+ */
58
+ public function getCheckout()
59
+ {
60
+ return Mage::getSingleton('checkout/session');
61
+ }
62
+
63
+ /**
64
+ * Get AmazonPayments API Model
65
+ *
66
+ * @return Mage_AmazonPayments_Model_Api_Cba
67
+ */
68
+ public function getApi()
69
+ {
70
+ if (!$this->_api) {
71
+ $this->_api = Mage::getSingleton('amazonpayments/api_cba');
72
+ $this->_api->setPaymentCode($this->getCode());
73
+ }
74
+ return $this->_api;
75
+ }
76
+
77
+ /**
78
+ * Get AmazonPayments session namespace
79
+ *
80
+ * @return Mage_AmazonPayments_Model_Session
81
+ */
82
+ public function getSession()
83
+ {
84
+ return Mage::getSingleton('amazonpayments/session');
85
+ }
86
+
87
+ /**
88
+ * Retrieve redirect url
89
+ *
90
+ * @return string
91
+ */
92
+ public function getRedirectUrl()
93
+ {
94
+ return Mage::getUrl('amazonpayments/cba/redirect');
95
+ }
96
+
97
+ /**
98
+ * Retrieve redirect to Amazon CBA url
99
+ *
100
+ * @return string
101
+ */
102
+ public function getAmazonRedirectUrl()
103
+ {
104
+ return $this->getApi()->getAmazonRedirectUrl();
105
+ }
106
+
107
+ /**
108
+ * Authorize
109
+ *
110
+ * @param Varien_Object $orderPayment
111
+ * @return Mage_Payment_Model_Abstract
112
+ */
113
+ public function authorize(Varien_Object $payment, $amount)
114
+ {
115
+ parent::authorize($payment, $amount);
116
+ return $this;
117
+ }
118
+
119
+ /**
120
+ * Capture payment
121
+ *
122
+ * @param Varien_Object $orderPayment
123
+ * @return Mage_Payment_Model_Abstract
124
+ */
125
+ public function capture(Varien_Object $payment, $amount)
126
+ {
127
+ parent::capture($payment, $amount);
128
+ return $this;
129
+ }
130
+
131
+ public function processInvoice($invoice, $payment)
132
+ {
133
+ parent::processInvoice($invoice, $payment);
134
+ $invoice->addComment(
135
+ Mage::helper('amazonpayments')->__('Invoice was created with Checkout by Amazon.')
136
+ );
137
+ return $this;
138
+ }
139
+
140
+ public function cancel(Varien_Object $payment)
141
+ {
142
+ if ($this->_skipProccessDocument) {
143
+ return $this;
144
+ }
145
+ $this->getApi()->cancel($payment->getOrder());
146
+ $payment->getOrder()->addStatusToHistory(
147
+ $payment->getOrder()->getStatus(),
148
+ Mage::helper('amazonpayments')->__('Order was canceled with Checkout by Amazon.')
149
+ );
150
+ return $this;
151
+ }
152
+
153
+ /**
154
+ * Refund order
155
+ *
156
+ * @param Varien_Object $payment
157
+ * @return Mage_AmazonPayments_Model_Payment_Cba
158
+ */
159
+ public function refund(Varien_Object $payment, $amount)
160
+ {
161
+ if ($this->_skipProccessDocument) {
162
+ return $this;
163
+ }
164
+ $this->getApi()->refund($payment, $amount);
165
+ $payment->getCreditmemo()->addComment(
166
+ Mage::helper('amazonpayments')->__('Refund was created with Checkout by Amazon.')
167
+ );
168
+ return $this;
169
+ }
170
+
171
+ /**
172
+ * Handle Callback from CBA and calculate Shipping, Taxes in case XML-based shopping cart
173
+ *
174
+ */
175
+ public function handleCallback($_request)
176
+ {
177
+ $response = '';
178
+
179
+ if (!empty($_request['order-calculations-request'])) {
180
+ $xmlRequest = urldecode($_request['order-calculations-request']);
181
+
182
+ $session = $this->getCheckout();
183
+ $xml = $this->getApi()->handleXmlCallback($xmlRequest, $session);
184
+
185
+ if ($this->getDebug()) {
186
+ $debug = Mage::getModel('amazonpayments/api_debug')
187
+ ->setRequestBody(print_r($_request, 1))
188
+ ->setResponseBody(time().' - request callback')
189
+ ->save();
190
+ }
191
+
192
+ if ($xml) {
193
+ $xmlText = $xml->asXML();
194
+ $response .= 'order-calculations-response='.urlencode($xmlText);
195
+ #$response .= 'order-calculations-response='.base64_encode($xmlText);
196
+
197
+ $secretKeyID = Mage::getStoreConfig('payment/amazonpayments_cba/secretkey_id');
198
+
199
+ $_signature = $this->getApi()->calculateSignature($xmlText, $secretKeyID);
200
+
201
+ if ($_signature) {
202
+ $response .= '&Signature='.urlencode($_signature);
203
+ #$response .= '&Signature='.$_signature;
204
+ }
205
+ $response .= '&aws-access-key-id='.urlencode(Mage::getStoreConfig('payment/amazonpayments_cba/accesskey_id'));
206
+
207
+ if ($this->getDebug()) {
208
+ $debug = Mage::getModel('amazonpayments/api_debug')
209
+ ->setResponseBody($response)
210
+ ->setRequestBody(time() .' - response calllback')
211
+ ->save();
212
+ }
213
+ }
214
+ } else {
215
+ if ($this->getDebug()) {
216
+ $debug = Mage::getModel('amazonpayments/api_debug')
217
+ ->setRequestBody(print_r($_request, 1))
218
+ ->setResponseBody(time().' - error request callback')
219
+ ->save();
220
+ }
221
+ }
222
+ return $response;
223
+ }
224
+
225
+ public function handleNotification($_request)
226
+ {
227
+ if (!empty($_request) && !empty($_request['NotificationData']) && !empty($_request['NotificationType'])) {
228
+ /**
229
+ * Debug
230
+ */
231
+ if ($this->getDebug()) {
232
+ $debug = Mage::getModel('amazonpayments/api_debug')
233
+ ->setRequestBody(print_r($_request, 1))
234
+ ->setResponseBody(time().' - Notification: '. $_request['NotificationType'])
235
+ ->save();
236
+ }
237
+ switch ($_request['NotificationType']) {
238
+ case 'NewOrderNotification':
239
+ $newOrderDetails = $this->getApi()->parseOrder($_request['NotificationData']);
240
+ $this->_createNewOrder($newOrderDetails);
241
+ break;
242
+ case 'OrderReadyToShipNotification':
243
+ $orderReadyToShipDetails = $this->getApi()->parseOrder($_request['NotificationData']);
244
+ $this->_proccessOrder($orderReadyToShipDetails);
245
+ break;
246
+ case 'OrderCancelledNotification':
247
+ $cancelDetails = $this->getApi()->parseCancelNotification($_request['NotificationData']);
248
+ $this->_skipProccessDocument = true;
249
+ $this->_cancelOrder($cancelDetails);
250
+ $this->_skipProccessDocument = false;
251
+ break;
252
+ default:
253
+ // Unknown notification type
254
+ }
255
+ } else {
256
+ if ($this->getDebug()) {
257
+ $debug = Mage::getModel('amazonpayments/api_debug')
258
+ ->setRequestBody(print_r($_request, 1))
259
+ ->setResponseBody(time().' - error request callback')
260
+ ->save();
261
+ }
262
+ }
263
+ return $this;
264
+ }
265
+
266
+ /**
267
+ * Create new order by data from Amazon NewOrderNotification
268
+ *
269
+ * @param array $newOrderDetails
270
+ */
271
+ protected function _createNewOrder(array $newOrderDetails)
272
+ {
273
+ /* @var $order Mage_Sales_Model_Order */
274
+ if (array_key_exists('amazonOrderID', $newOrderDetails)) {
275
+ $_order = Mage::getModel('sales/order')
276
+ ->loadByAttribute('ext_order_id', $newOrderDetails['amazonOrderID']);
277
+ if ($_order->getId()) {
278
+ /**
279
+ * associate real order id with Amazon order
280
+ */
281
+ $this->getApi()->syncOrder($_order);
282
+ $_order = null;
283
+ return $this;
284
+ }
285
+ $_order = null;
286
+ }
287
+ $session = $this->getCheckout();
288
+
289
+ #$quoteId = $session->getAmazonQuoteId();
290
+
291
+ $quoteId = $newOrderDetails['ClientRequestId'];
292
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
293
+
294
+ $baseCurrency = $session->getQuote()->getBaseCurrencyCode();
295
+ $currency = Mage::app()->getStore($session->getQuote()->getStoreId())->getBaseCurrency();
296
+
297
+ $shipping = $quote->getShippingAddress();
298
+ $billing = $quote->getBillingAddress();
299
+
300
+ $_address = $newOrderDetails['shippingAddress'];
301
+ $this->_address = $_address;
302
+
303
+ $regionModel = Mage::getModel('directory/region')->loadByCode($_address['regionCode'], $_address['countryCode']);
304
+ $_regionId = $regionModel->getId();
305
+
306
+ $sName = explode(' ', $newOrderDetails['shippingAddress']['name']);
307
+ $sFirstname = isset($sName[0])?$sName[0]:'';
308
+ $sLastname = isset($sName[1])?$sName[1]:'';
309
+
310
+ $bName = explode(' ', $newOrderDetails['buyerName']);
311
+ $bFirstname = isset($bName[0])?$bName[0]:'';
312
+ $bLastname = isset($bName[1])?$bName[1]:'';
313
+
314
+ $shipping->setCountryId($_address['countryCode'])
315
+ ->setRegion($_address['regionCode'])
316
+ ->setRegionId($_regionId)
317
+ ->setCity($_address['city'])
318
+ ->setStreet($_address['street'])
319
+ ->setPostcode($_address['postCode'])
320
+ ->setTaxAmount($newOrderDetails['tax'])
321
+ ->setBaseTaxAmount($newOrderDetails['tax'])
322
+ ->setShippingAmount($newOrderDetails['shippingAmount'])
323
+ ->setBaseShippingAmount($newOrderDetails['shippingAmount'])
324
+ ->setShippingTaxAmount($newOrderDetails['shippingTax'])
325
+ ->setBaseShippingTaxAmount($newOrderDetails['shippingTax'])
326
+ ->setDiscountAmount($newOrderDetails['discount'])
327
+ ->setBaseDiscountAmount($newOrderDetails['discount'])
328
+ ->setSubtotal($newOrderDetails['subtotal'])
329
+ ->setBaseSubtotal($newOrderDetails['subtotal'])
330
+ ->setGrandTotal($newOrderDetails['total'])
331
+ ->setBaseGrandTotal($newOrderDetails['total'])
332
+ ->setFirstname($sFirstname)
333
+ ->setLastname($sLastname);
334
+
335
+ $_shippingDesc = '';
336
+ $_shippingServices = unserialize($quote->getExtShippingInfo());
337
+ if (is_array($_shippingServices) && array_key_exists('amazon_service_level', $_shippingServices)) {
338
+ foreach ($_shippingServices['amazon_service_level'] as $_level) {
339
+ if ($_level['service_level'] == $newOrderDetails['ShippingLevel']) {
340
+ $shipping->setShippingMethod($_level['code']);
341
+ $_shippingDesc = $_level['description'];
342
+ }
343
+ }
344
+ }
345
+
346
+ $billing->setCountryId($_address['countryCode'])
347
+ ->setRegion($_address['regionCode'])
348
+ ->setRegionId($_regionId)
349
+ ->setCity($_address['city'])
350
+ ->setStreet($_address['street'])
351
+ ->setPostcode($_address['postCode'])
352
+ ->setTaxAmount($newOrderDetails['tax'])
353
+ ->setBaseTaxAmount($newOrderDetails['tax'])
354
+ ->setShippingAmount($newOrderDetails['shippingAmount'])
355
+ ->setBaseShippingAmount($newOrderDetails['shippingAmount'])
356
+ ->setShippingTaxAmount($newOrderDetails['shippingTax'])
357
+ ->setBaseShippingTaxAmount($newOrderDetails['shippingTax'])
358
+ ->setDiscountAmount($newOrderDetails['discount'])
359
+ ->setBaseDiscountAmount($newOrderDetails['discount'])
360
+ ->setSubtotal($newOrderDetails['subtotal'])
361
+ ->setBaseSubtotal($newOrderDetails['subtotal'])
362
+ ->setGrandTotal($newOrderDetails['total'])
363
+ ->setBaseGrandTotal($newOrderDetails['total'])
364
+ ->setFirstname($bFirstname)
365
+ ->setLastname($bLastname);
366
+
367
+ $quote->setBillingAddress($billing);
368
+ $quote->setShippingAddress($shipping);
369
+
370
+ $billing = $quote->getBillingAddress();
371
+ $shipping = $quote->getShippingAddress();
372
+
373
+ $convertQuote = Mage::getModel('sales/convert_quote');
374
+ /* @var $convertQuote Mage_Sales_Model_Convert_Quote */
375
+ $order = Mage::getModel('sales/order');
376
+ /* @var $order Mage_Sales_Model_Order */
377
+
378
+ $order = $convertQuote->addressToOrder($billing);
379
+
380
+ // add payment information to order
381
+ $order->setBillingAddress($convertQuote->addressToOrderAddress($billing))
382
+ ->setShippingAddress($convertQuote->addressToOrderAddress($shipping));
383
+
384
+ $order->setShippingMethod($shipping->getShippingMethod())
385
+ ->setShippingDescription($_shippingDesc)
386
+ ->setForcedDoShipmentWithInvoice(true);
387
+
388
+ $order->setPayment($convertQuote->paymentToOrderPayment($quote->getPayment()));
389
+
390
+ /**
391
+ * Amazon Order Id
392
+ */
393
+ $order->setExtOrderId($newOrderDetails['amazonOrderID']);
394
+
395
+ // add items to order
396
+ foreach ($quote->getAllItems() as $item) {
397
+ /* @var $item Mage_Sales_Model_Quote_Item */
398
+ $order->addItem($convertQuote->itemToOrderItem($item));
399
+ /* @var $orderItem Mage_Sales_Model_Order_Item */
400
+ $orderItem = $order->getItemByQuoteItemId($item->getId());
401
+ $orderItem->setExtOrderItemId($newOrderDetails['items'][$item->getId()]['AmazonOrderItemCode']);
402
+ $orderItemOptions = $orderItem->getProductOptions();
403
+ $orderItemOptions['amazon_amounts'] = serialize(array(
404
+ 'shipping' => $newOrderDetails['items'][$item->getId()]['shipping'],
405
+ 'tax' => $newOrderDetails['items'][$item->getId()]['tax'],
406
+ 'shipping_tax' => $newOrderDetails['items'][$item->getId()]['shipping_tax'],
407
+ 'principal_promo' => $newOrderDetails['items'][$item->getId()]['principal_promo'],
408
+ 'shipping_promo' => $newOrderDetails['items'][$item->getId()]['shipping_promo']
409
+ ));
410
+ $orderItem->setProductOptions($orderItemOptions);
411
+ $orderItem->setLockedDoInvoice(true)
412
+ ->setLockedDoShip(true);
413
+ }
414
+
415
+ $order->place();
416
+
417
+ $order->addStatusToHistory(
418
+ $order->getStatus(),
419
+ Mage::helper('amazonpayments')->__('New Order Notification received from Checkout by Amazon service.')
420
+ );
421
+
422
+ $customer = $quote->getCustomer();
423
+ if ($customer && $customer->getId()) {
424
+ $order->setCustomerId($customer->getId())
425
+ ->setCustomerEmail($customer->getEmail())
426
+ ->setCustomerPrefix($customer->getPrefix())
427
+ ->setCustomerFirstname($customer->getFirstname())
428
+ ->setCustomerMiddlename($customer->getMiddlename())
429
+ ->setCustomerLastname($customer->getLastname())
430
+ ->setCustomerSuffix($customer->getSuffix())
431
+ ->setCustomerGroupId($customer->getGroupId())
432
+ ->setCustomerTaxClassId($customer->getTaxClassId());
433
+ } else {
434
+ $quote->setCustomerEmail($newOrderDetails['buyerEmailAddress'])
435
+ ->setCustomerIsGuest(true)
436
+ ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
437
+ }
438
+
439
+ $order->save();
440
+
441
+ $quote->setIsActive(false);
442
+ $quote->save();
443
+
444
+ $orderId = $order->getIncrementId();
445
+ $this->getCheckout()->setLastQuoteId($quote->getId());
446
+ $this->getCheckout()->setLastSuccessQuoteId($quote->getId());
447
+ $this->getCheckout()->setLastOrderId($order->getId());
448
+ $this->getCheckout()->setLastRealOrderId($order->getIncrementId());
449
+
450
+ $order->sendNewOrderEmail();
451
+ /**
452
+ * associate real order id with Amazon order
453
+ */
454
+ $this->getApi()->syncOrder($order);
455
+ return $this;
456
+ }
457
+
458
+ /**
459
+ * Proccess existing order
460
+ *
461
+ * @param array $amazonOrderDetails
462
+ * @return boolean
463
+ */
464
+ protected function _proccessOrder($amazonOrderDetails)
465
+ {
466
+ if (array_key_exists('amazon_order_id', $amazonOrderDetails)) {
467
+ $order = Mage::getModel('sales/order')
468
+ ->loadByAttribute('ext_order_id', $amazonOrderDetails['amazon_order_id']);
469
+ /* @var $order Mage_Sales_Model_Order */
470
+ if ($order->getId()) {
471
+ /* @var $item Mage_Sales_Model_Order_Item */
472
+ foreach ($order->getAllVisibleItems() as $item) {
473
+ if (array_key_exists($item->getExtOrderItemId(), $amazonOrderDetails['items'])) {
474
+ $item->setLockedDoInvoice(false)
475
+ ->setLockedDoShip(false)
476
+ ->save();
477
+ }
478
+ }
479
+ $order->addStatusToHistory(
480
+ $order->getStatus(),
481
+ Mage::helper('amazonpayments')->__('Order Ready To Ship Notification received form Checkout by Amazon service.')
482
+ )->save();
483
+ }
484
+ }
485
+ return true;
486
+ }
487
+
488
+ /**
489
+ * Cancel the order
490
+ *
491
+ * @param array $amazonOrderDetails
492
+ * @return boolean
493
+ */
494
+ protected function _cancelOrder($cancelDetails)
495
+ {
496
+ if (array_key_exists('amazon_order_id', $cancelDetails)) {
497
+ $order = Mage::getModel('sales/order')
498
+ ->loadByAttribute('ext_order_id', $cancelDetails['amazon_order_id']);
499
+ /* @var $order Mage_Sales_Model_Order */
500
+ if ($order->getId()) {
501
+ try {
502
+ $order->cancel()
503
+ ->addStatusToHistory(
504
+ $order->getStatus(),
505
+ Mage::helper('amazonpayments')->__('Cancel Order Notification received from Checkout by Amazon service.')
506
+ )->save();
507
+ } catch (Exception $e) {
508
+ return false;
509
+ }
510
+ }
511
+ }
512
+ return true;
513
+ }
514
+
515
+ /**
516
+ * Return xml with error
517
+ *
518
+ * @param Exception $e
519
+ * @return string
520
+ */
521
+
522
+ public function callbackXmlError(Exception $e)
523
+ {
524
+ $_xml = $this->getApi()->callbackXmlError($e);
525
+ $secretKeyID = Mage::getStoreConfig('payment/amazonpayments_cba/secretkey_id');
526
+ $_signature = $this->getApi()->calculateSignature($_xml->asXml(), $secretKeyID);
527
+
528
+ $response = 'order-calculations-response='.urlencode($_xml->asXML())
529
+ .'&Signature='.urlencode($_signature)
530
+ .'&aws-access-key-id='.urlencode(Mage::getStoreConfig('payment/amazonpayments_cba/accesskey_id'));
531
+ return $response;
532
+ }
533
+
534
+ /**
535
+ * Prepare fields for XML-based signed cart form for CBA
536
+ *
537
+ * @return array
538
+ */
539
+ public function getCheckoutXmlFormFields()
540
+ {
541
+ $secretKeyID = Mage::getStoreConfig('payment/amazonpayments_cba/secretkey_id');
542
+ $_quote = $this->getCheckout()->getQuote();
543
+
544
+ $xml = $this->getApi()->getXmlCart($_quote);
545
+
546
+ $xmlCart = array('order-input' =>
547
+ "type:merchant-signed-order/aws-accesskey/1;"
548
+ ."order:".base64_encode($xml).";"
549
+ ."signature:{$this->getApi()->calculateSignature($xml, $secretKeyID)};"
550
+ ."aws-access-key-id:".Mage::getStoreConfig('payment/amazonpayments_cba/accesskey_id')
551
+ );
552
+ if ($this->getDebug()) {
553
+ $debug = Mage::getModel('amazonpayments/api_debug')
554
+ ->setResponseBody(print_r($xmlCart, 1)."\norder:".$xml)
555
+ ->setRequestBody(time() .' - xml cart')
556
+ ->save();
557
+ }
558
+ return $xmlCart;
559
+ }
560
+
561
+ /**
562
+ * Return CBA order details in case Html-based shopping cart commited to Amazon
563
+ *
564
+ */
565
+ public function returnAmazon()
566
+ {
567
+ $_request = Mage::app()->getRequest()->getParams();
568
+ #$_amazonOrderId = Mage::app()->getRequest()->getParam('amznPmtsOrderIds');
569
+ #$_quoteId = Mage::app()->getRequest()->getParam('amznPmtsReqId');
570
+
571
+ if ($this->getDebug()) {
572
+ $debug = Mage::getModel('amazonpayments/api_debug')
573
+ ->setRequestBody(print_r($_request, 1))
574
+ ->setResponseBody(time().' - success')
575
+ ->save();
576
+ }
577
+ }
578
+
579
+ /**
580
+ * Rewrite standard logic
581
+ *
582
+ * @return bool
583
+ */
584
+ public function isInitializeNeeded()
585
+ {
586
+ return false;
587
+ }
588
+
589
+ /**
590
+ * Get debug flag
591
+ *
592
+ * @return string
593
+ */
594
+ public function getDebug()
595
+ {
596
+ return Mage::getStoreConfig('payment/' . $this->getCode() . '/debug_flag');
597
+ }
598
+ }
app/code/core/Mage/AmazonPayments/Model/Session.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ *
29
+ * Paypal transaction session namespace
30
+ *
31
+ * @author Magento Core Team <core@magentocommerce.com>
32
+ */
33
+ class Mage_AmazonPayments_Model_Session extends Mage_Core_Model_Session_Abstract
34
+ {
35
+ public function __construct()
36
+ {
37
+ $this->init('amazonpayments');
38
+ }
39
+ }
app/code/core/Mage/AmazonPayments/controllers/AspController.php ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * AmazonPayments Controller
29
+ *
30
+ * @category Mage
31
+ * @package Mage_AmazonPayments
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_AmazonPayments_AspController extends Mage_Core_Controller_Front_Action
35
+ {
36
+ /**
37
+ * Get singleton with payment model AmazonPayments ASP
38
+ *
39
+ * @return Mage_AmazonPayments_Model_Payment_Asp
40
+ */
41
+ public function getPayment()
42
+ {
43
+ return Mage::getSingleton('amazonpayments/payment_asp');
44
+ }
45
+
46
+ /**
47
+ * Get singleton with model checkout session
48
+ *
49
+ * @return Mage_Checkout_Model_Session
50
+ */
51
+ public function getSession()
52
+ {
53
+ return Mage::getSingleton('checkout/session');
54
+ }
55
+
56
+ /**
57
+ * When a customer press "Place Order" button on Checkout/Review page
58
+ * Redirect customer to Amazon Simple Pay payment interface
59
+ *
60
+ */
61
+ public function payAction()
62
+ {
63
+ $session = $this->getSession();
64
+ $quoteId = $session->getQuoteId();
65
+ $lastRealOrderId = $session->getLastRealOrderId();
66
+ if (is_null($quoteId) || is_null($lastRealOrderId)){
67
+ $this->_redirect('checkout/cart/');
68
+ } else {
69
+ $session->setAmazonAspQuoteId($quoteId);
70
+ $session->setAmazonAspLastRealOrderId($lastRealOrderId);
71
+
72
+ $order = Mage::getModel('sales/order');
73
+ $order->loadByIncrementId($lastRealOrderId);
74
+
75
+ $payment = $this->getPayment();
76
+ $payment->setOrder($order);
77
+ $payment->processEventRedirect();
78
+
79
+ Mage::register('amazonpayments_payment_asp', $payment);
80
+ $this->loadLayout();
81
+ $this->renderLayout();
82
+
83
+ $quote = $session->getQuote();
84
+ $quote->setIsActive(false);
85
+ $quote->save();
86
+
87
+ $session->setQuoteId(null);
88
+ $session->setLastRealOrderId(null);
89
+ }
90
+ }
91
+
92
+ /**
93
+ * When a customer successfully returned from Amazon Simple Pay site
94
+ * Redirect customer to Checkout/Success page
95
+ *
96
+ */
97
+ public function returnSuccessAction()
98
+ {
99
+ $session = $this->getSession();
100
+
101
+ $orderId = $session->getAmazonAspLastRealOrderId();
102
+ $quoteId = $session->getAmazonAspQuoteId(true);
103
+
104
+ $order = Mage::getModel('sales/order');
105
+ $order->loadByIncrementId($orderId);
106
+
107
+ if ($order->isEmpty()) { return false;
108
+ }
109
+
110
+ $payment = $this->getPayment();
111
+ $payment->setOrder($order);
112
+ $payment->processEventReturnSuccess();
113
+
114
+ $session->setQuoteId($quoteId);
115
+ $session->getQuote()->setIsActive(false)->save();
116
+ $session->setLastRealOrderId($orderId);
117
+
118
+ $this->_redirect('checkout/onepage/success');
119
+ }
120
+
121
+ /**
122
+ * Customer canceled payment and successfully returned from Amazon Simple Pay site
123
+ * Redirect customer to Shopping Cart page
124
+ *
125
+ */
126
+ public function returnCancelAction()
127
+ {
128
+ $session = $this->getSession();
129
+ $session->setQuoteId($session->getAmazonAspQuoteId(true));
130
+
131
+ $order = Mage::getModel('sales/order');
132
+ $order->loadByIncrementId($session->getAmazonAspLastRealOrderId());
133
+
134
+ if ($order->isEmpty()) {
135
+ return false;
136
+ }
137
+
138
+ $payment = $this->getPayment();
139
+ $payment->setOrder($order);
140
+ $payment->processEventReturnCancel();
141
+
142
+ $this->_redirect('checkout/cart/');
143
+ }
144
+
145
+ /**
146
+ * Amazon Simple Pay service send notification
147
+ *
148
+ */
149
+ public function notificationAction()
150
+ {
151
+ if (!$this->getPayment()->processNotification($this->getRequest()->getParams())) {
152
+ $this->_forward('noRoute');
153
+ }
154
+ }
155
+ }
app/code/core/Mage/AmazonPayments/controllers/CbaController.php ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ class Mage_AmazonPayments_CbaController extends Mage_Core_Controller_Front_Action
28
+ {
29
+ /**
30
+ * Get checkout session namespace
31
+ *
32
+ * @return Mage_Checkout_Model_Session
33
+ */
34
+ public function getCheckout()
35
+ {
36
+ return Mage::getSingleton('checkout/session');
37
+ }
38
+
39
+ /**
40
+ * Get singleton with Checkout by Amazon order transaction information
41
+ *
42
+ * @return Mage_AmazonPayments_Model_Payment_CBA
43
+ */
44
+ public function getCba()
45
+ {
46
+ return Mage::getSingleton('amazonpayments/payment_cba');
47
+ }
48
+
49
+ /**
50
+ * When a customer chooses Checkout by Amazon on Shopping Cart page
51
+ *
52
+ */
53
+ public function shortcutAction()
54
+ {
55
+ if (!$this->getCba()->isAvailable()) {
56
+ $this->_redirect('checkout/cart/');
57
+ }
58
+ $session = $this->getCheckout();
59
+ if ($quoteId = $this->getCheckout()->getQuoteId()) {
60
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
61
+
62
+ /** @var $quote Mage_Sales_Model_Quote */
63
+ if ($quote->hasItems()) {
64
+ $session->setAmazonQuoteId($quoteId);
65
+
66
+ $quote->getPayment()->setMethod($this->getCba()->getCode());
67
+ $quote->setIsActive(false);
68
+ $quote->save();
69
+
70
+ $this->getResponse()->setBody($this->getLayout()->createBlock('amazonpayments/cba_redirect')->toHtml());
71
+
72
+ if ($session->hasData('quote_id_'.Mage::app()->getStore()->getWebsiteId())) {
73
+ $session->unsetData('quote_id_'.Mage::app()->getStore()->getWebsiteId());
74
+ }
75
+ } else {
76
+ $this->_redirect('checkout/cart/');
77
+ }
78
+ } else {
79
+ $this->_redirect('checkout/cart/');
80
+ }
81
+ }
82
+
83
+ /**
84
+ * When a customer has checkout on Amazon and return with Successful payment
85
+ *
86
+ */
87
+ public function successAction()
88
+ {
89
+ #$amazonOrderID = Mage::app()->getRequest()->getParam('amznPmtsOrderIds');
90
+ #$referenceId = Mage::app()->getRequest()->getParam('amznPmtsOrderIds');
91
+
92
+ $this->getCba()->returnAmazon();
93
+
94
+ $this->loadLayout();
95
+ #$this->_initLayoutMessages('amazonpayments/session');
96
+ $this->renderLayout();
97
+ }
98
+
99
+ /**
100
+ * When Amazon return callback request for calculation shipping, taxes and etc.
101
+ *
102
+ */
103
+ public function callbackAction()
104
+ {
105
+ $response = '';
106
+ $session = $this->getCheckout();
107
+
108
+ $_request = Mage::app()->getRequest()->getParams();
109
+
110
+ try {
111
+ if ($_request) {
112
+ $response = $this->getCba()->handleCallback($_request);
113
+ } else {
114
+ $e = new Exception('Inavlid Shipping Address');
115
+ }
116
+ }
117
+ catch (Exception $e) {
118
+ // Return Xml with Error
119
+ $response = $this->getCba()->callbackXmlError($e);
120
+ }
121
+ echo $response;
122
+ exit(0);
123
+ }
124
+
125
+ public function notificationAction()
126
+ {
127
+ $response = '';
128
+ $session = $this->getCheckout();
129
+
130
+ $_request = Mage::app()->getRequest()->getParams();
131
+
132
+ try {
133
+ $this->getCba()
134
+ ->handleNotification($_request);
135
+ }
136
+ catch (Exception $e) {
137
+ // Return Xml with Error
138
+ $response = $this->getCba()->callbackXmlError($e);
139
+ }
140
+ $this->getResponse()
141
+ ->setHttpResponseCode(200);
142
+ }
143
+
144
+ /**
145
+ * When a customer has checkout on Amazon and return with Cancel
146
+ *
147
+ */
148
+ public function cancelAction()
149
+ {
150
+ $session = $this->getCheckout();
151
+ if ($quoteId = $session->getAmazonQuoteId()) {
152
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
153
+ $quote->setIsActive(true);
154
+ $quote->save();
155
+ $session->setQuoteId($quoteId);
156
+ }
157
+ if ($this->getCba()->getDebug()) {
158
+ $_request = Mage::app()->getRequest()->getParams();
159
+ $debug = Mage::getModel('amazonpayments/api_debug')
160
+ ->setResponseBody(print_r($_request, 1))
161
+ ->setRequestBody(time() .' - cancel')
162
+ ->save();
163
+ }
164
+ $this->_redirect('checkout/cart/');
165
+ }
166
+
167
+ }
app/code/core/Mage/AmazonPayments/etc/config.xml ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Academic Free License (AFL 3.0)
9
+ * that is bundled with this package in the file LICENSE_AFL.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/afl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Mage_AmazonPayments
24
+ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
+ */
27
+ -->
28
+ <config>
29
+ <modules>
30
+ <Mage_AmazonPayments>
31
+ <version>0.1.2</version>
32
+ </Mage_AmazonPayments>
33
+ </modules>
34
+ <global>
35
+ <models>
36
+ <amazonpayments>
37
+ <class>Mage_AmazonPayments_Model</class>
38
+ <resourceModel>amazonpayments_mysql4</resourceModel>
39
+ </amazonpayments>
40
+ <amazonpayments_mysql4>
41
+ <class>Mage_AmazonPayments_Model_Mysql4</class>
42
+ <entities>
43
+ <api_debug><table>amazonpayments_api_debug</table></api_debug>
44
+ </entities>
45
+ </amazonpayments_mysql4>
46
+ </models>
47
+ <helpers>
48
+ <amazonpayments>
49
+ <class>Mage_AmazonPayments_Helper</class>
50
+ </amazonpayments>
51
+ </helpers>
52
+ <resources>
53
+ <amazonpayments_setup>
54
+ <setup>
55
+ <module>Mage_AmazonPayments</module>
56
+ <class>Mage_AmazonPayments_Model_Mysql4_Setup</class>
57
+ </setup>
58
+ </amazonpayments_setup>
59
+ </resources>
60
+ <blocks>
61
+ <amazonpayments><class>Mage_AmazonPayments_Block</class></amazonpayments>
62
+ </blocks>
63
+ <sales>
64
+ <order>
65
+ <statuses>
66
+ <pending_amazon_asp translate="label"><label>Pending Amazon Simple Pay</label></pending_amazon_asp>
67
+ </statuses>
68
+ <states>
69
+ <pending_payment>
70
+ <statuses>
71
+ <pending_amazon_asp/>
72
+ </statuses>
73
+ </pending_payment>
74
+ </states>
75
+
76
+ </order>
77
+ </sales>
78
+ <template>
79
+ <email>
80
+ <payment_amazonpayments_asp_email_template_notification_error translate="label" module="amazonpayments">
81
+ <label>Amazon Simple Pay notification error</label>
82
+ <file>amazonpayments_asp_notification_error.html</file>
83
+ <type>html</type>
84
+ </payment_amazonpayments_asp_email_template_notification_error>
85
+ </email>
86
+ </template>
87
+ </global>
88
+ <!--
89
+ Something like this is to be added to resolve bug #4890
90
+ <global>
91
+ <rewrite>
92
+ <amazonpayments>
93
+ <core>
94
+ <from>/^.*?amazonpayments\/api/</from>
95
+ <to>amazonpayments/api</to>
96
+ </amazonpayments>
97
+ </rewrite>
98
+ </global>
99
+ -->
100
+ <frontend>
101
+ <!--<secure_url>
102
+ <amazonpayments_redirect>/amazonpayments/redirect/</amazonpayments_redirect>
103
+ <amazonpayments_beacon>/amazonpayments/api/beacon/</amazonpayments_beacon>
104
+ </secure_url>-->
105
+ <translate>
106
+ <modules>
107
+ <Mage_AmazonPayments>
108
+ <files>
109
+ <default>Mage_AmazonPayments.csv</default>
110
+ </files>
111
+ </Mage_AmazonPayments>
112
+ </modules>
113
+ </translate>
114
+ <routers>
115
+ <amazonpayments>
116
+ <use>standard</use>
117
+ <args>
118
+ <module>Mage_AmazonPayments</module>
119
+ <frontName>amazonpayments</frontName>
120
+ </args>
121
+ </amazonpayments>
122
+ </routers>
123
+ <layout>
124
+ <updates>
125
+ <amazonpayments>
126
+ <file>amazonpayments.xml</file>
127
+ </amazonpayments>
128
+ </updates>
129
+ </layout>
130
+ </frontend>
131
+
132
+ <adminhtml>
133
+ <translate>
134
+ <modules>
135
+ <Mage_AmazonPayments>
136
+ <files>
137
+ <default>Mage_AmazonPayments.csv</default>
138
+ </files>
139
+ </Mage_AmazonPayments>
140
+ </modules>
141
+ </translate>
142
+ <events>
143
+ <sales_order_shipment_save_after>
144
+ <observers>
145
+ <amazonpayments>
146
+ <type>model</type>
147
+ <class>amazonpayments/observer</class>
148
+ <method>confirmShipment</method>
149
+ </amazonpayments>
150
+ </observers>
151
+ </sales_order_shipment_save_after>
152
+ <sales_order_shipment_track_save_after>
153
+ <observers>
154
+ <amazonpayments>
155
+ <type>model</type>
156
+ <class>amazonpayments/observer</class>
157
+ <method>salesOrderShipmentTrackSaveAfter</method>
158
+ </amazonpayments>
159
+ </observers>
160
+ </sales_order_shipment_track_save_after>
161
+ </events>
162
+ </adminhtml>
163
+
164
+ <default>
165
+ <payment>
166
+
167
+ <amazonpayments_cba>
168
+ <active>0</active>
169
+ <model>amazonpayments/payment_cba</model>
170
+ <title>Checkout by Amazon</title>
171
+ <order_status>pending</order_status>
172
+ <allowspecific>0</allowspecific>
173
+ <payment_action>Authorization</payment_action>
174
+ <merchant_id></merchant_id>
175
+ <merchant_name></merchant_name>
176
+ <sandbox_flag>1</sandbox_flag>
177
+ <accesskey_id></accesskey_id>
178
+ <secretkey_id></secretkey_id>
179
+ <pay_service_url>https://payments.amazon.com/checkout/</pay_service_url>
180
+ <sandbox_pay_service_url>https://payments-sandbox.amazon.com/checkout/</sandbox_pay_service_url>
181
+ <button_url>http://g-ecx.images-amazon.com/images/G/01/cba/images/buttons/btn_Chkout-orange-medium.gif</button_url>
182
+ <wsdl>https://merchant-api.amazon.com/gateway/merchant-interface-mime/</wsdl>
183
+ <use_callback_api>1</use_callback_api>
184
+ <use_oneclick>0</use_oneclick>
185
+ </amazonpayments_cba>
186
+
187
+ <amazonpayments_asp>
188
+
189
+ <model>amazonpayments/payment_asp</model>
190
+ <title>Amazon Simple Pay</title>
191
+ <active>0</active>
192
+
193
+ <is_sandbox>1</is_sandbox>
194
+ <access_key></access_key>
195
+ <secret_key></secret_key>
196
+
197
+ <pay_service_url>https://authorize.payments.amazon.com/pba/paypipeline</pay_service_url>
198
+ <pay_service_url_sandbox>https://authorize.payments-sandbox.amazon.com/pba/paypipeline</pay_service_url_sandbox>
199
+
200
+ <choice_method_description>Your billing address will be ignored and you will be redirected to Amazon Simple Pay website.</choice_method_description>
201
+ <redirect_message>You will be redirected to Amazon Simple Pay in a few seconds.</redirect_message>
202
+ <pay_description>MAGENTO ASP PAYMENT</pay_description>
203
+ <refund_description>MAGENTO ASP REFUND</refund_description>
204
+ <cancel_description>MAGENTO ASP CANCEL</cancel_description>
205
+
206
+ <pay_immediate_return>1</pay_immediate_return>
207
+ <pay_collect_shipping_address>0</pay_collect_shipping_address>
208
+
209
+ <pay_process_immediate>1</pay_process_immediate>
210
+
211
+ <fps_service_url>https://fps.amazonaws.com</fps_service_url>
212
+ <fps_service_url_sandbox>https://fps.sandbox.amazonaws.com/</fps_service_url_sandbox>
213
+
214
+ <email_sender_identity>general</email_sender_identity>
215
+ <email_template_notification_error>payment_amazonpayments_asp_email_template_notification_error</email_template_notification_error>
216
+ <report_error_to_email>0</report_error_to_email>
217
+
218
+ <error_log>0</error_log>
219
+ <debug_log>0</debug_log>
220
+
221
+ </amazonpayments_asp>
222
+
223
+ </payment>
224
+
225
+
226
+ </default>
227
+ </config>
app/code/core/Mage/AmazonPayments/etc/system.xml ADDED
@@ -0,0 +1,443 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Academic Free License (AFL 3.0)
9
+ * that is bundled with this package in the file LICENSE_AFL.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/afl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Mage_AmazonPayments
24
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
+ */
27
+ -->
28
+ <config>
29
+ <sections>
30
+ <payment>
31
+ <groups>
32
+ <amazonpayments_cba translate="label" module="amazonpayments">
33
+ <label>Checkout by Amazon</label>
34
+ <comment><![CDATA[<br />
35
+ <div class="custom-options">
36
+ <div class="box">
37
+ <p class="grand-total"><br /><b>Signing up with Checkout by Amazon</b></p>
38
+ <p>To configure Checkout by Amazon&trade; you will need to enter your Checkout by Amazon&trade; Merchant ID, Access Key ID, and Secret Access Key.</p>
39
+ <p>If you do not already have a Checkout by Amazon&trade; account, click here to create one now. <a href="https://sellercentral.amazon.com/gp/on-board/workflow/Registration/login.html/902-0586098-4611057?passthrough%2Fsource=AmazonCheckout&passthrough%2Fld=RPVARIENA2ZZYWSJ0WMID8&passthrough%2Faccount=cba&passthrough%2FsuperSource=OAR&passthrough%2FmarketplaceID=AZ4B0ZS3LGLX" target="_blank">Sign-Up</a></p>
40
+ <p>To locate your Merchant ID, sign in to your Seller Central Checkout by Amazon&trade; account and click <b>Settings > Checkout Pipeline Settings.</b></p>
41
+ <p>To locate your Access Key ID and Secret Access Key, sign in to your Seller Central Checkout by Amazon&trade; account and click <b>Integration > AWS Key.</b> Click the link to read the Amazon Web Services Customer Agreement, and then click the check box, if you are setting up a new Access Key ID.</p>
42
+ <p>To enable XML Order Reports click <b>Settings > Checkout Pipeline Settings</b>, and then clicking Edit under the Order Report Settings section. Select <u>Order Report Type</u> as XML to get XML Order Reports using SOAP APIs. Configure your downloads for <u>hourly.</u></p>
43
+ <p>For additional information on setting up your Checkout by Amazon account, <a href="https://payments.amazon.com/sdui/sdui/business?sn=cba/faq" target="_blank">Click Here - FAQ.</a></p>
44
+ <p><br /><a href="https://sellercentral.amazon.com/gp/on-board/workflow/Registration/login.html/902-0586098-4611057?passthrough%2Fsource=AmazonCheckout&passthrough%2Fld=RPVARIENA2ZZYWSJ0WMID8&passthrough%2Faccount=cba&passthrough%2FsuperSource=OAR&passthrough%2FmarketplaceID=AZ4B0ZS3LGLX" target="_blank">Signup for Checkout by Amazon</a><br /><br /></p>
45
+ </div>
46
+ </div>
47
+ ]]></comment>
48
+ <frontend_type>text</frontend_type>
49
+ <sort_order>601</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>1</show_in_store>
53
+ <fields>
54
+ <title translate="label">
55
+ <label>Title</label>
56
+ <frontend_type>text</frontend_type>
57
+ <sort_order>2</sort_order>
58
+ <show_in_default>1</show_in_default>
59
+ <show_in_website>1</show_in_website>
60
+ <show_in_store>1</show_in_store>
61
+ </title>
62
+ <active translate="label">
63
+ <label>Enable</label>
64
+ <frontend_type>select</frontend_type>
65
+ <source_model>adminhtml/system_config_source_yesno</source_model>
66
+ <sort_order>10</sort_order>
67
+ <show_in_default>1</show_in_default>
68
+ <show_in_website>1</show_in_website>
69
+ <show_in_store>0</show_in_store>
70
+ </active>
71
+ <sandbox_flag translate="label">
72
+ <label>Sandbox</label>
73
+ <frontend_type>select</frontend_type>
74
+ <source_model>adminhtml/system_config_source_yesno</source_model>
75
+ <sort_order>12</sort_order>
76
+ <show_in_default>1</show_in_default>
77
+ <show_in_website>1</show_in_website>
78
+ <show_in_store>0</show_in_store>
79
+ </sandbox_flag>
80
+ <!--<use_secure_callback_url translate="label comment">
81
+ <label>Secure Callback URL</label>
82
+ <frontend_type>select</frontend_type>
83
+ <source_model>adminhtml/system_config_source_yesno</source_model>
84
+ <sort_order>13</sort_order>
85
+ <show_in_default>1</show_in_default>
86
+ <show_in_website>1</show_in_website>
87
+ <show_in_store>0</show_in_store>
88
+ <comment>Required for live Checkout by Amazon transactions.</comment>
89
+ </use_secure_callback_url>-->
90
+ <debug_flag translate="label">
91
+ <label>Debug</label>
92
+ <frontend_type>select</frontend_type>
93
+ <source_model>adminhtml/system_config_source_yesno</source_model>
94
+ <sort_order>14</sort_order>
95
+ <show_in_default>1</show_in_default>
96
+ <show_in_website>1</show_in_website>
97
+ <show_in_store>0</show_in_store>
98
+ </debug_flag>
99
+ <merchant_id translate="label">
100
+ <label>Merchant ID</label>
101
+ <frontend_type>text</frontend_type>
102
+ <sort_order>20</sort_order>
103
+ <show_in_default>1</show_in_default>
104
+ <show_in_website>1</show_in_website>
105
+ <show_in_store>0</show_in_store>
106
+ </merchant_id>
107
+ <merchant_name translate="label">
108
+ <label>Merchant Name</label>
109
+ <frontend_type>text</frontend_type>
110
+ <sort_order>21</sort_order>
111
+ <show_in_default>1</show_in_default>
112
+ <show_in_website>1</show_in_website>
113
+ <show_in_store>0</show_in_store>
114
+ </merchant_name>
115
+ <accesskey_id translate="label">
116
+ <label>Access Key ID</label>
117
+ <frontend_type>text</frontend_type>
118
+ <sort_order>30</sort_order>
119
+ <show_in_default>1</show_in_default>
120
+ <show_in_website>1</show_in_website>
121
+ <show_in_store>0</show_in_store>
122
+ </accesskey_id>
123
+ <secretkey_id translate="label">
124
+ <label>Secret Key ID</label>
125
+ <frontend_type>text</frontend_type>
126
+ <sort_order>40</sort_order>
127
+ <show_in_default>1</show_in_default>
128
+ <show_in_website>1</show_in_website>
129
+ <show_in_store>0</show_in_store>
130
+ </secretkey_id>
131
+ <merchant_tocken translate="label">
132
+ <label>Merchant Token</label>
133
+ <frontend_type>text</frontend_type>
134
+ <sort_order>45</sort_order>
135
+ <show_in_default>1</show_in_default>
136
+ <show_in_website>1</show_in_website>
137
+ <show_in_store>0</show_in_store>
138
+ </merchant_tocken>
139
+ <merchant_login translate="label">
140
+ <label>Merchant Login</label>
141
+ <frontend_type>text</frontend_type>
142
+ <sort_order>50</sort_order>
143
+ <show_in_default>1</show_in_default>
144
+ <show_in_website>1</show_in_website>
145
+ <show_in_store>0</show_in_store>
146
+ </merchant_login>
147
+ <merchant_pass translate="label">
148
+ <label>Merchant Password</label>
149
+ <frontend_type>text</frontend_type>
150
+ <sort_order>55</sort_order>
151
+ <show_in_default>1</show_in_default>
152
+ <show_in_website>1</show_in_website>
153
+ <show_in_store>0</show_in_store>
154
+ </merchant_pass>
155
+ <!--<button_url translate="label comment">
156
+ <label>Button URL</label>
157
+ <sort_order>60</sort_order>
158
+ <show_in_default>1</show_in_default>
159
+ <show_in_website>1</show_in_website>
160
+ <show_in_store>0</show_in_store>
161
+ </button_url>-->
162
+ <order_status translate="label">
163
+ <label>New Order Status</label>
164
+ <frontend_type>select</frontend_type>
165
+ <source_model>adminhtml/system_config_source_order_status_new</source_model>
166
+ <sort_order>70</sort_order>
167
+ <show_in_default>1</show_in_default>
168
+ <show_in_website>1</show_in_website>
169
+ <show_in_store>0</show_in_store>
170
+ </order_status>
171
+ <use_callback_api translate="label">
172
+ <label>Use Callback Api</label>
173
+ <frontend_type>select</frontend_type>
174
+ <source_model>adminhtml/system_config_source_yesno</source_model>
175
+ <sort_order>91</sort_order>
176
+ <show_in_default>0</show_in_default>
177
+ <show_in_website>0</show_in_website>
178
+ <show_in_store>0</show_in_store>
179
+ </use_callback_api>
180
+ <standard_rate>
181
+ <label>Standard Rate</label>
182
+ <frontend_type>select</frontend_type>
183
+ <frontend_model>amazonpayments/adminhtml_shipping_methods</frontend_model>
184
+ <backend_model>adminhtml/system_config_backend_serialized</backend_model>
185
+ <sort_order>100</sort_order>
186
+ <show_in_default>1</show_in_default>
187
+ <show_in_website>1</show_in_website>
188
+ <show_in_store>0</show_in_store>
189
+ </standard_rate>
190
+ <expedited_rate>
191
+ <label>Expedited Rate</label>
192
+ <frontend_type>select</frontend_type>
193
+ <frontend_model>amazonpayments/adminhtml_shipping_methods</frontend_model>
194
+ <backend_model>adminhtml/system_config_backend_serialized</backend_model>
195
+ <sort_order>110</sort_order>
196
+ <show_in_default>1</show_in_default>
197
+ <show_in_website>1</show_in_website>
198
+ <show_in_store>0</show_in_store>
199
+ </expedited_rate>
200
+ <oneday_rate>
201
+ <label>OneDay Rate</label>
202
+ <frontend_type>select</frontend_type>
203
+ <frontend_model>amazonpayments/adminhtml_shipping_methods</frontend_model>
204
+ <backend_model>adminhtml/system_config_backend_serialized</backend_model>
205
+ <sort_order>120</sort_order>
206
+ <show_in_default>1</show_in_default>
207
+ <show_in_website>1</show_in_website>
208
+ <show_in_store>0</show_in_store>
209
+ </oneday_rate>
210
+ <twoday_rate>
211
+ <label>TwoDay Rate</label>
212
+ <frontend_type>select</frontend_type>
213
+ <frontend_model>amazonpayments/adminhtml_shipping_methods</frontend_model>
214
+ <backend_model>adminhtml/system_config_backend_serialized</backend_model>
215
+ <sort_order>130</sort_order>
216
+ <show_in_default>1</show_in_default>
217
+ <show_in_website>1</show_in_website>
218
+ <show_in_store>0</show_in_store>
219
+ </twoday_rate>
220
+ </fields>
221
+ </amazonpayments_cba>
222
+ <amazonpayments_asp translate="label" module="amazonpayments">
223
+ <label>Amazon Simple Pay</label>
224
+ <comment><![CDATA[<br />
225
+ <div class="custom-options">
226
+ <div class="box">
227
+ <p class="grand-total"><br /><b>Signing up with Amazon Simple Pay</b></p>
228
+ <p>To configure your Amazon Alternate Payment Method (Amazon Simple Pay), you will need to enter your Amazon Web Services Access Key ID, and Secret Access Key.</p>
229
+ <p>If you do not already have an Amazon Payments Business account, click here to create one now. <a href="https://payments.amazon.com/sdui/sdui/business?sn=paynow/o" target="_blank">Sign-Up.</a></p>
230
+ <p>To locate your Amazon Web Services Access Key ID and Secret Key ID, sign in to your AWS account and click <b>Your Account > Access Identifiers.</b> Don't have an AWS account? Log in to <a href="http://aws.amazon.com/" target="_blank">aws.amazon.com</a> and setup an AWS account.</p>
231
+ <p>For additional information on setting up your Amazon Simple Pay, <a href="https://payments.amazon.com/sdui/sdui/business?sn=paynow/faq" target="_blank">Click Here - FAQ.</a></p>
232
+ <p><br /><a href="https://payments.amazon.com/sdui/sdui/business?sn=paynow/o" target="_blank">Signup for Amazon Simple Pay</a><br /><br /></p>
233
+ </div>
234
+ </div>
235
+ ]]></comment>
236
+ <frontend_type>text</frontend_type>
237
+ <sort_order>601</sort_order>
238
+ <show_in_default>1</show_in_default>
239
+ <show_in_website>1</show_in_website>
240
+ <show_in_store>1</show_in_store>
241
+ <fields>
242
+ <title translate="label">
243
+ <label>Title</label>
244
+ <frontend_type>text</frontend_type>
245
+ <sort_order>2</sort_order>
246
+ <show_in_default>1</show_in_default>
247
+ <show_in_website>1</show_in_website>
248
+ <show_in_store>1</show_in_store>
249
+ </title>
250
+ <active translate="label">
251
+ <label>Enable</label>
252
+ <frontend_type>select</frontend_type>
253
+ <source_model>adminhtml/system_config_source_yesno</source_model>
254
+ <sort_order>9</sort_order>
255
+ <show_in_default>1</show_in_default>
256
+ <show_in_website>1</show_in_website>
257
+ <show_in_store>0</show_in_store>
258
+ </active>
259
+ <is_sandbox translate="label">
260
+ <label>Sandbox</label>
261
+ <frontend_type>select</frontend_type>
262
+ <source_model>adminhtml/system_config_source_yesno</source_model>
263
+ <sort_order>10</sort_order>
264
+ <show_in_default>1</show_in_default>
265
+ <show_in_website>1</show_in_website>
266
+ <show_in_store>0</show_in_store>
267
+ </is_sandbox>
268
+ <pay_process_immediate translate="label">
269
+ <label>Payment Action</label>
270
+ <frontend_type>select</frontend_type>
271
+ <!-- source_model>adminhtml/system_config_source_yesno</source_model -->
272
+ <source_model>amazonpayments/payment_asp_source_paymentAction</source_model>
273
+ <sort_order>11</sort_order>
274
+ <show_in_default>1</show_in_default>
275
+ <show_in_website>1</show_in_website>
276
+ <show_in_store>0</show_in_store>
277
+ </pay_process_immediate>
278
+ <access_key translate="label">
279
+ <label>Access Key</label>
280
+ <frontend_type>text</frontend_type>
281
+ <sort_order>12</sort_order>
282
+ <show_in_default>1</show_in_default>
283
+ <show_in_website>1</show_in_website>
284
+ <show_in_store>0</show_in_store>
285
+ </access_key>
286
+ <secret_key translate="label">
287
+ <label>Secret Key</label>
288
+ <frontend_type>text</frontend_type>
289
+ <sort_order>13</sort_order>
290
+ <show_in_default>1</show_in_default>
291
+ <show_in_website>1</show_in_website>
292
+ <show_in_store>0</show_in_store>
293
+ </secret_key>
294
+ <pay_service_url translate="label">
295
+ <label>Payment Service URI</label>
296
+ <frontend_type>text</frontend_type>
297
+ <sort_order>15</sort_order>
298
+ <show_in_default>0</show_in_default>
299
+ <show_in_website>0</show_in_website>
300
+ <show_in_store>0</show_in_store>
301
+ </pay_service_url>
302
+ <pay_service_url_sandbox translate="label">
303
+ <label>Payment Sandbox Service URI</label>
304
+ <frontend_type>text</frontend_type>
305
+ <sort_order>16</sort_order>
306
+ <show_in_default>0</show_in_default>
307
+ <show_in_website>0</show_in_website>
308
+ <show_in_store>0</show_in_store>
309
+ </pay_service_url_sandbox>
310
+ <pay_immediate_return translate="label">
311
+ <label>Immediate Return</label>
312
+ <frontend_type>select</frontend_type>
313
+ <source_model>adminhtml/system_config_source_yesno</source_model>
314
+ <sort_order>19</sort_order>
315
+ <show_in_default>1</show_in_default>
316
+ <show_in_website>1</show_in_website>
317
+ <show_in_store>0</show_in_store>
318
+ <comment>Automatically redirect after payment to success page</comment>
319
+ </pay_immediate_return>
320
+ <fps_service_url translate="label">
321
+ <label>FPS Service URI</label>
322
+ <frontend_type>text</frontend_type>
323
+ <sort_order>21</sort_order>
324
+ <show_in_default>0</show_in_default>
325
+ <show_in_website>0</show_in_website>
326
+ <show_in_store>0</show_in_store>
327
+ </fps_service_url>
328
+ <fps_service_url_sandbox translate="label">
329
+ <label>FPS Sandbox Service URI</label>
330
+ <frontend_type>text</frontend_type>
331
+ <sort_order>22</sort_order>
332
+ <show_in_default>0</show_in_default>
333
+ <show_in_website>0</show_in_website>
334
+ <show_in_store>0</show_in_store>
335
+ </fps_service_url_sandbox>
336
+
337
+ <choice_method_description translate="label">
338
+ <label>Method Choice Checkout Message</label>
339
+ <frontend_type>text</frontend_type>
340
+ <sort_order>30</sort_order>
341
+ <show_in_default>1</show_in_default>
342
+ <show_in_website>1</show_in_website>
343
+ <show_in_store>1</show_in_store>
344
+ </choice_method_description>
345
+ <redirect_message translate="label">
346
+ <label>Redirect Message</label>
347
+ <frontend_type>text</frontend_type>
348
+ <sort_order>31</sort_order>
349
+ <show_in_default>1</show_in_default>
350
+ <show_in_website>1</show_in_website>
351
+ <show_in_store>1</show_in_store>
352
+ </redirect_message>
353
+ <pay_description translate="label">
354
+ <label>Payment Description</label>
355
+ <frontend_type>text</frontend_type>
356
+ <sort_order>32</sort_order>
357
+ <show_in_default>1</show_in_default>
358
+ <show_in_website>1</show_in_website>
359
+ <show_in_store>1</show_in_store>
360
+ </pay_description>
361
+ <refund_description translate="label">
362
+ <label>Refund Description</label>
363
+ <frontend_type>text</frontend_type>
364
+ <sort_order>33</sort_order>
365
+ <show_in_default>1</show_in_default>
366
+ <show_in_website>1</show_in_website>
367
+ <show_in_store>1</show_in_store>
368
+ </refund_description>
369
+ <pay_description translate="label">
370
+ <label>Payment Description</label>
371
+ <frontend_type>text</frontend_type>
372
+ <sort_order>34</sort_order>
373
+ <show_in_default>1</show_in_default>
374
+ <show_in_website>1</show_in_website>
375
+ <show_in_store>1</show_in_store>
376
+ </pay_description>
377
+ <cancel_description translate="label">
378
+ <label>Cancel Description</label>
379
+ <frontend_type>text</frontend_type>
380
+ <sort_order>35</sort_order>
381
+ <show_in_default>1</show_in_default>
382
+ <show_in_website>1</show_in_website>
383
+ <show_in_store>1</show_in_store>
384
+ </cancel_description>
385
+ <report_email translate="label">
386
+ <label>Report Email</label>
387
+ <frontend_type>text</frontend_type>
388
+ <sort_order>36</sort_order>
389
+ <show_in_default>1</show_in_default>
390
+ <show_in_website>1</show_in_website>
391
+ <show_in_store>0</show_in_store>
392
+ </report_email>
393
+ <email_sender_identity translate="label">
394
+ <label>Email Sender</label>
395
+ <frontend_type>select</frontend_type>
396
+ <source_model>adminhtml/system_config_source_email_identity</source_model>
397
+ <sort_order>37</sort_order>
398
+ <show_in_default>1</show_in_default>
399
+ <show_in_website>1</show_in_website>
400
+ <show_in_store>0</show_in_store>
401
+ </email_sender_identity>
402
+ <email_template_notification_error translate="label">
403
+ <label>Notification Error Transactional Email</label>
404
+ <frontend_type>select</frontend_type>
405
+ <source_model>adminhtml/system_config_source_email_template</source_model>
406
+ <sort_order>38</sort_order>
407
+ <show_in_default>1</show_in_default>
408
+ <show_in_website>1</show_in_website>
409
+ <show_in_store>1</show_in_store>
410
+ </email_template_notification_error>
411
+ <report_error_to_email translate="label">
412
+ <label>Report Error to Email</label>
413
+ <frontend_type>select</frontend_type>
414
+ <source_model>adminhtml/system_config_source_yesno</source_model>
415
+ <sort_order>39</sort_order>
416
+ <show_in_default>1</show_in_default>
417
+ <show_in_website>1</show_in_website>
418
+ <show_in_store>0</show_in_store>
419
+ </report_error_to_email>
420
+ <error_log translate="label">
421
+ <label>Error Log</label>
422
+ <frontend_type>select</frontend_type>
423
+ <source_model>adminhtml/system_config_source_yesno</source_model>
424
+ <sort_order>40</sort_order>
425
+ <show_in_default>1</show_in_default>
426
+ <show_in_website>1</show_in_website>
427
+ <show_in_store>0</show_in_store>
428
+ </error_log>
429
+ <debug_log translate="label">
430
+ <label>Debug Log</label>
431
+ <frontend_type>select</frontend_type>
432
+ <source_model>adminhtml/system_config_source_yesno</source_model>
433
+ <sort_order>41</sort_order>
434
+ <show_in_default>1</show_in_default>
435
+ <show_in_website>1</show_in_website>
436
+ <show_in_store>0</show_in_store>
437
+ </debug_log>
438
+ </fields>
439
+ </amazonpayments_asp>
440
+ </groups>
441
+ </payment>
442
+ </sections>
443
+ </config>
app/code/core/Mage/AmazonPayments/sql/amazonpayments_setup/mysql4-install-0.1.2.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ $installer = $this;
29
+ /* @var $installer Mage_AmazonPayments_Model_Mysql4_Setup */
30
+
31
+ $installer->startSetup();
32
+
33
+ $installer->run("
34
+ CREATE TABLE `{$this->getTable('amazonpayments_api_debug')}` (
35
+ `debug_id` int(10) unsigned NOT NULL auto_increment,
36
+ `transaction_id` varchar(255) NOT NULL default '',
37
+ `debug_at` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
38
+ `request_body` text,
39
+ `response_body` text,
40
+ PRIMARY KEY (`debug_id`),
41
+ KEY `debug_at` (`debug_at`)
42
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
43
+ ");
44
+
45
+ $installer->endSetup();
app/code/core/Mage/AmazonPayments/sql/amazonpayments_setup/mysql4-upgrade-0.1.0-0.1.1.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ $installer = $this;
29
+ /* @var $installer Mage_AmazonPayments_Model_Mysql4_Setup */
30
+
31
+ $installer->startSetup();
32
+
33
+ $installer->run("
34
+ CREATE TABLE `{$this->getTable('amazonpayments_api_debug')}` (
35
+ `debug_id` int(10) unsigned NOT NULL auto_increment,
36
+ `transaction_id` varchar(255) NOT NULL default '',
37
+ `debug_at` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
38
+ `request_body` text,
39
+ `response_body` text,
40
+ PRIMARY KEY (`debug_id`),
41
+ KEY `debug_at` (`debug_at`)
42
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
43
+ ");
44
+
45
+ $installer->endSetup();
app/code/core/Mage/AmazonPayments/sql/amazonpayments_setup/mysql4-upgrade-0.1.1-0.1.2.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_AmazonPayments
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ $installer = $this;
29
+ /* @var $installer Mage_AmazonPayments_Model_Mysql4_Setup */
30
+
31
+ $installer->startSetup();
32
+
33
+ $installer->run("
34
+ CREATE TABLE IF NOT EXISTS `{$this->getTable('amazonpayments_api_debug')}` (
35
+ `debug_id` int(10) unsigned NOT NULL auto_increment,
36
+ `transaction_id` varchar(255) NOT NULL default '',
37
+ `debug_at` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
38
+ `request_body` text,
39
+ `response_body` text,
40
+ PRIMARY KEY (`debug_id`),
41
+ KEY `debug_at` (`debug_at`)
42
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
43
+ ");
44
+
45
+ $installer->endSetup();
app/design/frontend/base/default/layout/amazonpayments.xml ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Academic Free License (AFL 3.0)
9
+ * that is bundled with this package in the file LICENSE_AFL.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/afl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category design
23
+ * @package base_default
24
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
+ */
27
+
28
+ -->
29
+ <layout version="0.1.0">
30
+
31
+ <!--
32
+ Shopping cart
33
+ -->
34
+
35
+ <checkout_cart_index>
36
+ <!-- Mage_AmazonPayments -->
37
+ <reference name="checkout.cart.methods">
38
+ <block type="amazonpayments/link_shortcut" name="checkout.cart.methods.amazon_cba" template="amazonpayments/link.phtml"/>
39
+ </reference>
40
+ </checkout_cart_index>
41
+
42
+ <amazonpayments_cba_success>
43
+ <reference name="root">
44
+ <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
45
+ </reference>
46
+ <reference name="content">
47
+ <block type="amazonpayments/cba_success" name="amazonpayments_cba_success" template="amazonpayments/cba/success.phtml"></block>
48
+ </reference>
49
+ </amazonpayments_cba_success>
50
+
51
+
52
+ <amazonpayments_asp_pay>
53
+ <reference name="root">
54
+ <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
55
+ </reference>
56
+ <reference name="content">
57
+ <!-- block type="amazonpayments/asp_redirect" name="amazonpayments_asp_redirect" template="page/redirect.phtml" / -->
58
+ <block type="amazonpayments/asp_redirect" name="amazonpayments_asp_redirect" template="amazonpayments/asp/redirect.phtml" />
59
+ </reference>
60
+ </amazonpayments_asp_pay>
61
+ </layout>
app/design/frontend/base/default/template/amazonpayments/asp/form.phtml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php $_code=$this->getMethodCode() ?>
28
+ <ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none;">
29
+ <li>
30
+ <?php echo $this->getDescriptionMessage() ?>
31
+ </li>
32
+ </ul>
app/design/frontend/base/default/template/amazonpayments/asp/redirect.phtml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <html>
28
+ <body>
29
+ <?php echo($this->getRedirectMessage()); ?>
30
+ <form id="amazonpayments_asp_checkout" method="post" action="<?php echo($this->getRedirectUrl()); ?>">
31
+ <fieldset>
32
+ <?php foreach ($this->getRedirectParams() as $name => $value) { ?>
33
+ <input type="hidden" name="<?php echo($name); ?>" value="<?php echo($value); ?>" />
34
+ <?php }?>
35
+ </fieldset>
36
+ </form>
37
+ <script type="text/javascript">document.getElementById("amazonpayments_asp_checkout").submit();</script>
38
+ </body>
39
+ </html>
app/design/frontend/base/default/template/amazonpayments/asp/shortcut.phtml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+
27
+ /**
28
+ * @see Mage_AmazonPayments_Block_Link
29
+ */
30
+ ?>
31
+ <a href="<?php echo($this->getCheckoutUrl()); ?>"><img src="<?php echo($this->getButtonImageUrl()); ?>" alt="" /></a>
app/design/frontend/base/default/template/amazonpayments/cba/form.phtml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php $_code=$this->getMethodCode() ?>
28
+ <ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none;">
29
+ <li>
30
+ <?php echo $this->__('Your billing address will be ignored and you will be redirected to Checkout by Amazon website.') ?>
31
+ </li>
32
+ </ul>
app/design/frontend/base/default/template/amazonpayments/cba/success.phtml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ SUCCESS
28
+ <div class="page-head">
29
+ <h3><?php echo $this->__('Your order has been received') ?></h3>
30
+ </div>
31
+ <p><strong><?php echo $this->__('Thank you for your purchase!') ?></strong></p>
32
+ <p><?php echo $this->__('You will receive an order confirmation email with details of your order and a link to track its progress.') ?></p>
33
+ <div class="button-set">
34
+ <button type="button" class="button" onclick="window.location='<?php #echo $this->getUrl() ?>'"><span><span><?php echo $this->__('Continue Shopping') ?></span></span></button>
35
+ </div>
app/design/frontend/base/default/template/amazonpayments/link.phtml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+
27
+ /**
28
+ * @see Mage_AmazonPayments_Block_Link
29
+ */
30
+ ?>
31
+
32
+ <li>
33
+ <?php if (!$this->getIsDisabled()): ?>
34
+ <?php if ($this->getIsOneClickEnabled()): ?>
35
+ <script type="text/javascript" src="https://images-na.ssl-images-amazon.com/images/G/01/cba/js/jquery.js"></script>
36
+ <script type="text/javascript">
37
+ //<![CDATA[
38
+ jQuery.noConflict();
39
+ //]]>
40
+ </script>
41
+ <script type="text/javascript" src="https://images-na.ssl-images-amazon.com/images/G/01/cba/js/widget/widget.js"></script>
42
+ <form action="<?php echo $this->getCheckoutUrl();?>" method="post" id="cbaOneClickForm">
43
+ <fieldset>
44
+ <input alt="<?php echo Mage::helper('amazonpayments')->__('Checkout by Amazon');?>" src="<?php echo $this->htmlEscape($this->getImageUrl())?>" type="image" />
45
+ </fieldset>
46
+ </form>
47
+ <?php else: ?>
48
+ <a href="<?php echo $this->getCheckoutUrl();?>" title="<?php echo Mage::helper('amazonpayments')->__('Checkout by Amazon');?>"><img src="<?php echo $this->htmlEscape($this->getImageUrl())?>" alt="<?php echo Mage::helper('amazonpayments')->__('Checkout by Amazon');?>" /></a>
49
+ <?php endif; ?>
50
+ <?php endif; ?>
51
+ </li>
app/etc/modules/Mage_AmazonPayments.xml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Academic Free License (AFL 3.0)
9
+ * that is bundled with this package in the file LICENSE_AFL.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/afl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Mage_AmazonPayments
24
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
+ */
27
+ -->
28
+ <config>
29
+ <modules>
30
+ <Mage_AmazonPayments>
31
+ <active>true</active>
32
+ <codePool>core</codePool>
33
+ <depends>
34
+ <Mage_Sales />
35
+ <Mage_Payment />
36
+ </depends>
37
+ </Mage_AmazonPayments>
38
+ </modules>
39
+ </config>
app/locale/en_US/Mage_AmazonCheckout.csv ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ " Select shipping method"," Select shipping method"
2
+ "<br/>Trace confirmation request:<br/>%s","<br/>Trace confirmation request:<br/>%s"
3
+ "Access Key","Access Key"
4
+ "Access Key ID","Access Key ID"
5
+ "Amazon Simple Pay","Amazon Simple Pay"
6
+ "Amazon Simple Pay notification error","Amazon Simple Pay notification error"
7
+ "Amazon Simple Pay service capture confirmation error: amount in the existing invoice doensn\'t match the amount in confirmation request.","Amazon Simple Pay service capture confirmation error: amount in the existing invoice doensn\'t match the amount in confirmation request."
8
+ "Amazon Simple Pay service capture confirmation error: confirmation request amount not equal to the amount of order.","Amazon Simple Pay service capture confirmation error: confirmation request amount not equal to the amount of order."
9
+ "Amazon Simple Pay service capture confirmation error: existing transaction ID doesn\'t match transaction ID in the confirmation request.","Amazon Simple Pay service capture confirmation error: existing transaction ID doesn\'t match transaction ID in the confirmation request."
10
+ "Amazon Simple Pay service capture confirmation. Invoice was captured automatically.","Amazon Simple Pay service capture confirmation. Invoice was captured automatically."
11
+ "Amazon Simple Pay service confirmation error: order currency does not match the currency of the IPN request","Amazon Simple Pay service confirmation error: order currency does not match the currency of the IPN request"
12
+ "Amazon Simple Pay service confirmation error: order specified in the IPN request can not be found","Amazon Simple Pay service confirmation error: order specified in the IPN request can not be found"
13
+ "Amazon Simple Pay service confirmation error: order states sequence violation","Amazon Simple Pay service confirmation error: order states sequence violation"
14
+ "Amazon Simple Pay service confirmation error: payment method in the order is not Amazon Simple Pay","Amazon Simple Pay service confirmation error: payment method in the order is not Amazon Simple Pay"
15
+ "Amazon Simple Pay service confirmed amount authorization.","Amazon Simple Pay service confirmed amount authorization."
16
+ "Amazon Simple Pay service confirmed cancelation.","Amazon Simple Pay service confirmed cancelation."
17
+ "Amazon Simple Pay service confirmed capture","Amazon Simple Pay service confirmed capture"
18
+ "Amazon Simple Pay service confirmed capture for invoice %s","Amazon Simple Pay service confirmed capture for invoice %s"
19
+ "Amazon Simple Pay service confirmed capture for invoice %s. Invoice automatically captured.","Amazon Simple Pay service confirmed capture for invoice %s. Invoice automatically captured."
20
+ "Amazon Simple Pay service confirmed capture initiation.","Amazon Simple Pay service confirmed capture initiation."
21
+ "Amazon Simple Pay service confirmed payment capture. Invoice %s was automatically created after confirmation.","Amazon Simple Pay service confirmed payment capture. Invoice %s was automatically created after confirmation."
22
+ "Amazon Simple Pay service confirmed payment capture. Invoice created automatically.","Amazon Simple Pay service confirmed payment capture. Invoice created automatically."
23
+ "Amazon Simple Pay service confirmed payment refund. Credit memo created automatically.","Amazon Simple Pay service confirmed payment refund. Credit memo created automatically."
24
+ "Amazon Simple Pay service confirmed payment refund. Creditmemo %s was automatically created after confirmation.","Amazon Simple Pay service confirmed payment refund. Creditmemo %s was automatically created after confirmation."
25
+ "Amazon Simple Pay service confirmed refund for creditmemo %s.","Amazon Simple Pay service confirmed refund for creditmemo %s."
26
+ "Amazon Simple Pay service confirmed refund.","Amazon Simple Pay service confirmed refund."
27
+ "Amazon Simple Pay service confirmed refund. Creditmemo processed automatically.","Amazon Simple Pay service confirmed refund. Creditmemo processed automatically."
28
+ "Amazon Simple Pay service confirmed refunded creditmemo %s. Creditmemo processed automatically.","Amazon Simple Pay service confirmed refunded creditmemo %s. Creditmemo processed automatically."
29
+ "Amazon Simple Pay service is not available. Payment was not processed.","Amazon Simple Pay service is not available. Payment was not processed."
30
+ "Amazon Simple Pay service payment confirmation failed","Amazon Simple Pay service payment confirmation failed"
31
+ "Amazon Simple Pay service refund confirmation error: amount in the existing creditmemo doensn\'t match the amount in confirmation request.","Amazon Simple Pay service refund confirmation error: amount in the existing creditmemo doensn\'t match the amount in confirmation request."
32
+ "Amazon Simple Pay service refund confirmation error: confirmation request amount doesn\'t match the order amount.","Amazon Simple Pay service refund confirmation error: confirmation request amount doesn\'t match the order amount."
33
+ "Amazon Simple Pay service refund confirmation error: transaction ID in the existing creditmemo doesn\'t match the transaction ID in the confirmation request.","Amazon Simple Pay service refund confirmation error: transaction ID in the existing creditmemo doesn\'t match the transaction ID in the confirmation request."
34
+ "Authorize Only","Authorize Only"
35
+ "Authorize and Capture","Authorize and Capture"
36
+ "Cancel Description","Cancel Description"
37
+ "Cancel Order Notification received from Checkout by Amazon service.","Cancel Order Notification received from Checkout by Amazon service."
38
+ "Checkout by Amazon","Checkout by Amazon"
39
+ "Continue Shopping","Continue Shopping"
40
+ "Customer canceled payment and successfully returned from Amazon Simple Pay site","Customer canceled payment and successfully returned from Amazon Simple Pay site"
41
+ "Customer successfully returned from Amazon Simple Pay site","Customer successfully returned from Amazon Simple Pay site"
42
+ "Customer was redirected to Amazon Simple Pay site","Customer was redirected to Amazon Simple Pay site"
43
+ "Debug","Debug"
44
+ "Debug Log","Debug Log"
45
+ "Email Sender","Email Sender"
46
+ "Enable","Enable"
47
+ "Error Log","Error Log"
48
+ "FPS Sandbox Service URI","FPS Sandbox Service URI"
49
+ "FPS Service URI","FPS Service URI"
50
+ "Immediate Return","Immediate Return"
51
+ "Invalid action code","Invalid action code"
52
+ "Invalid request","Invalid request"
53
+ "Invoice was created (online capture). Waiting for capture confirmation from Amazon Simple Pay service.","Invoice was created (online capture). Waiting for capture confirmation from Amazon Simple Pay service."
54
+ "Invoice was created with Checkout by Amazon.","Invoice was created with Checkout by Amazon."
55
+ "Invoice was not refunded. Amazon Simple Pay service error: [%s] %s","Invoice was not refunded. Amazon Simple Pay service error: [%s] %s"
56
+ "Item specified in callback request XML was not found in quote.","Item specified in callback request XML was not found in quote."
57
+ "Merchant ID","Merchant ID"
58
+ "Merchant Login","Merchant Login"
59
+ "Merchant Name","Merchant Name"
60
+ "Merchant Password","Merchant Password"
61
+ "Merchant Token","Merchant Token"
62
+ "Method Choice Checkout Message","Method Choice Checkout Message"
63
+ "New Order Notification received from Checkout by Amazon service.","New Order Notification received from Checkout by Amazon service."
64
+ "New Order Status","New Order Status"
65
+ "Notification Error Transactional Email","Notification Error Transactional Email"
66
+ "Order Ready To Ship Notification received form Checkout by Amazon service.","Order Ready To Ship Notification received form Checkout by Amazon service."
67
+ "Order was canceled with Checkout by Amazon.","Order was canceled with Checkout by Amazon."
68
+ "Order was not cancelled. Amazon Simple Pay service error: [%s] %s","Order was not cancelled. Amazon Simple Pay service error: [%s] %s"
69
+ "Order was not captured online. Authorization confirmation is required.","Order was not captured online. Authorization confirmation is required."
70
+ "Order was not captured. Amazon Simple Pay service error: [%s] %s","Order was not captured. Amazon Simple Pay service error: [%s] %s"
71
+ "Payment Action","Payment Action"
72
+ "Payment Description","Payment Description"
73
+ "Payment Sandbox Service URI","Payment Sandbox Service URI"
74
+ "Payment Service URI","Payment Service URI"
75
+ "Payment authorization cancelled with Amazon Simple Pay service.","Payment authorization cancelled with Amazon Simple Pay service."
76
+ "Payment refunded online with Amazon Simple Pay service. Creditmemo was created. Waiting for refund confirmation from Amazon Simple Pay service.","Payment refunded online with Amazon Simple Pay service. Creditmemo was created. Waiting for refund confirmation from Amazon Simple Pay service."
77
+ "Payment refunded online. Waiting for refund confirmation from Amazon Simple Pay service.","Payment refunded online. Waiting for refund confirmation from Amazon Simple Pay service."
78
+ "Payment was captured online with Amazon Simple Pay service. Invoice was created. Waiting for capture confirmation from payment service.","Payment was captured online with Amazon Simple Pay service. Invoice was created. Waiting for capture confirmation from payment service."
79
+ "Pending Amazon Simple Pay","Pending Amazon Simple Pay"
80
+ "Redirect Message","Redirect Message"
81
+ "Refund Description","Refund Description"
82
+ "Refund was created with Checkout by Amazon.","Refund was created with Checkout by Amazon."
83
+ "Report Email","Report Email"
84
+ "Report Error to Email","Report Error to Email"
85
+ "Request is not a valid IPN request","Request is not a valid IPN request"
86
+ "Request signed an incorrect or missing signature","Request signed an incorrect or missing signature"
87
+ "Response body is not valid FPS respons","Response body is not valid FPS respons"
88
+ "Sandbox","Sandbox"
89
+ "Secret Key","Secret Key"
90
+ "Secret Key ID","Secret Key ID"
91
+ "Shipment was created with Checkout by Amazon.","Shipment was created with Checkout by Amazon."
92
+ "Thank you for your purchase!","Thank you for your purchase!"
93
+ "Title","Title"
94
+ "Use Callback Api","Use Callback Api"
95
+ "You will be redirected to Checkout by Amazon in a few seconds.","You will be redirected to Checkout by Amazon in a few seconds."
96
+ "You will receive an order confirmation email with details of your order and a link to track its progress.","You will receive an order confirmation email with details of your order and a link to track its progress."
97
+ "You will receive an order confirmation email with details of your order and a link to track its progress.<br/>","You will receive an order confirmation email with details of your order and a link to track its progress.<br/>"
98
+ "Your billing address will be ignored and you will be redirected to Checkout by Amazon website.","Your billing address will be ignored and you will be redirected to Checkout by Amazon website."
99
+ "Your order has been received","Your order has been received"
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Huehuehue</name>
4
+ <version>1.0.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Integration with Amazon Payment system</summary>
10
+ <description>This extension provides integration with Amazon Payment System. Implementing two payment methods such as "Checkout by Amazon" and "Amazon Simple Pay"</description>
11
+ <notes>1.1.3</notes>
12
+ <authors><author><name>Magento Core</name><user>auto-converted</user><email>core@magentocommerce.com</email></author></authors>
13
+ <date>2010-02-26</date>
14
+ <time>17:22:48</time>
15
+ <contents><target name="magelocale"><dir name="en_US"><file name="Mage_AmazonCheckout.csv" hash="df73c78db71f5e713a46d238e81f7585"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="amazonpayments.xml" hash="f365444e245e59be540163247e7b0352"/></dir><dir name="template"><dir name="amazonpayments"><dir name="asp"><file name="form.phtml" hash="2aca66761ea18c703a773a19ba3f312c"/><file name="redirect.phtml" hash="8f18affe7f1b1e6018f410a491385121"/><file name="shortcut.phtml" hash="0351f98fd65e87984a013b580e93be9d"/></dir><dir name="cba"><file name="form.phtml" hash="110eab7b282b6e9cddc8646311b73720"/><file name="success.phtml" hash="30fe4d6e9de481c713a4703f9fe14299"/></dir><file name="link.phtml" hash="fcc324b2bb82dd4fd0d983ce9669ca67"/></dir></dir></dir></dir></dir></target><target name="magecore"><dir name="Mage"><dir name="AmazonPayments"><dir name="Block"><dir name="Adminhtml"><dir name="Shipping"><file name="Methods.php" hash="7b8f47fa2a45011796dd1c56c0b591f6"/></dir></dir><dir name="Asp"><file name="Form.php" hash="180748d4d7c1edf9d7cc515abfff8265"/><file name="Redirect.php" hash="90dba07975275c7a9f3abfe6fbed06a1"/><file name="Shortcut.php" hash="bbee6a64e247965d4bb8175b8489427c"/></dir><dir name="Cba"><file name="Form.php" hash="01d927b0c36ae101df58e80628495daa"/><file name="Redirect.php" hash="117da711f1f3e001cd5336af3c9c5de4"/><file name="Success.php" hash="0cf2abe7e6ec9bccdf94ebe616542e48"/></dir><dir name="Link"><file name="Shortcut.php" hash="e3a8e2020123eeddb6d75bcbaf53f3d0"/></dir><file name="Form.php" hash="3a8879202da789609e12c2d6f728f3f6"/></dir><dir name="controllers"><file name="AspController.php" hash="a69f0f3106a8f7abb256b854ce761664"/><file name="CbaController.php" hash="8ae016af22e024b3ff38a55ab71d7b41"/></dir><dir name="etc"><file name="config.xml" hash="21f4c00bb3279dcee9d1813e50bd7ff3"/><file name="system.xml" hash="9842c18c36ce72f9be6d81660f160f1c"/></dir><dir name="Helper"><file name="Data.php" hash="47e6224e9fab6dfd46d5fe2c9a298528"/></dir><dir name="Model"><dir name="Api"><dir name="Asp"><dir name="Fps"><dir name="Request"><file name="Abstract.php" hash="5c5891f367228ecda1c0bcf244308a64"/><file name="Cancel.php" hash="143c9988f294489ef3eac235486e9c8a"/><file name="Refund.php" hash="5b9c949f393a00ad5826daf9e4255d82"/><file name="Settle.php" hash="cd1dd4adac4e8b58a62953312b5fea8b"/></dir><dir name="Response"><file name="Abstract.php" hash="f6bad402786f854fa02dcdd58cea367e"/><file name="Cancel.php" hash="c2b3bab102360df717fee33e8552fcbe"/><file name="Error.php" hash="45824b198098d94055893321d332bcac"/><file name="Refund.php" hash="94c794c206fe0457150f35e61d691c41"/><file name="Settle.php" hash="2f2c6cd810e74146f52438b4cea5e6db"/></dir></dir><dir name="Ipn"><file name="Request.php" hash="68d212c9b3ad3d846fda00f05f72de8e"/></dir><file name="Abstract.php" hash="504e10685d6f674d71a7f777f2d74bf2"/><file name="Amount.php" hash="b5e8b3e9782f2c3395c4d7c44caeb90f"/><file name="Fps.php" hash="0f046fad998530e563282e8b7dff6a5e"/></dir><dir name="Cba"><file name="Document.php" hash="6e5fb2512ce9a91e2b60ca660370434e"/></dir><file name="Abstract.php" hash="548d31659fddc7dba99dc60d4dd0cc22"/><file name="Asp.php" hash="8eece809e484703673d7ccbf83695c43"/><file name="Cba.php" hash="587d73ca44f8854b096afb8bf624ea89"/><file name="Debug.php" hash="5aa26a6bc9b09690de101b59ee062e65"/></dir><dir name="Mysql4"><dir name="Api"><dir name="Debug"><file name="Collection.php" hash="6398888e5cacfbbcb38ad90b1ad0998e"/></dir><file name="Debug.php" hash="cfe7690dcf4fdcac4e1970ec26633b97"/></dir><file name="Setup.php" hash="0a9859a775ff9beda449c22dd1017281"/></dir><dir name="Payment"><dir name="Asp"><dir name="Source"><file name="PaymentAction.php" hash="f6a5caddd9978ab7ac2aa35ba5d21dbd"/></dir><file name="Abstract.php" hash="72938c600ae3fd7dc0a3428013ea8350"/><file name="Fps.php" hash="ca149148a27f934c5304ecbf93d9daf6"/><file name="Notification.php" hash="a2797901c477b65356026547d51d8c29"/></dir><file name="Asp.php" hash="571b3fa1d97d6eb16bab49d76a9a56ad"/><file name="Cba.php" hash="abddf660e07aa9f0f4eac779529d1427"/></dir><file name="Observer.php" hash="4fc8b2d4ddf66e51e5f343bb78a59f57"/><file name="Payment.php" hash="c4a38f6567da81b5a82dbd8bcae468d2"/><file name="Session.php" hash="2837a2b6ad2982f4644ef707246f302c"/></dir><dir name="sql"><dir name="amazonpayments_setup"><file name="mysql4-install-0.1.2.php" hash="71fb9c0a3d06728f779f46986cca93f5"/><file name="mysql4-upgrade-0.1.0-0.1.1.php" hash="71fb9c0a3d06728f779f46986cca93f5"/><file name="mysql4-upgrade-0.1.1-0.1.2.php" hash="167669a93e777cc44a0ec1d1a6fbba34"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mage_AmazonPayments.xml" hash="cad0b4e1dacbc06dcc23d10f290c0ad1"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies/>
18
+ </package>