Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit d2010c9cb7473e084ff0e9351e6aaf96cbf6106b @Schrank Schrank committed Oct 12, 2012
10 LICENSE
@@ -0,0 +1,10 @@
+/*
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42):
+ * <andreas.vogt@webvisum.de> and <blechschmidt@fabian-blechschmidt> and wrote
+ * this file. As long as you retain this notice you can do whatever you want
+ * with this stuff. If we meet some day, and you think this stuff is worth it,
+ * you can buy us a beer in return
+ * Andreas Vogt and Fabian Blechschmidt
+ * ----------------------------------------------------------------------------
+ */
26 README.md
@@ -0,0 +1,26 @@
+#Hackathon_PaypalRoundBugfix
+
+This module rewrites a block of Mage_Paypal to change the rounded values of the order to prevent the paypal cent bug.
+
+And it removes the functionality to refund orders with paypal, because there are bugs in it.
+
+##For Developers
+
+We rewrite
+
+ Mage_Paypal_Model_Ipn with Hackathon_PaypalRoundBugfix_Model_Paypal_Ipn
+and
+
+ Mage_Paypal_Block_Standard_Redirect with Hackathon_PaypalRoundBugfix_Block_Paypal_Standard_Redirect
+
+## Tested
+I added two Unittests to be sure that the files are rewritten
+
+For found bugs, I use TDD, so first write a test which fails and is ok after the fix.
+
+##Thanks
+
+Thanks to Andreas Vogt <andreas.vogt@webvisum.de> for the files. He made the work, I (Fabian Blechschmidt <blechschmidt@fabian-blechschmidt.de>) just made a magento module out of it.
+
+##Attention!
+This module changes the redirect to paypal and deactivates refunding!
93 app/code/community/Hackathon/PaypalRoundBugfix/Block/Paypal/Standard/Redirect.php
@@ -0,0 +1,93 @@
+<?php
+
+class Hackathon_PaypalRoundBugfix_Block_Paypal_Standard_Redirect
+ extends Mage_Paypal_Block_Standard_Redirect
+{
+ protected function _toHtml()
+ {
+ $standard = Mage::getModel('paypal/standard');
+
+ $form = new Varien_Data_Form();
+ $form->setAction($standard->getConfig()->getPaypalUrl())
+ ->setId('paypal_standard_checkout')
+ ->setName('paypal_standard_checkout')
+ ->setMethod('POST')
+ ->setUseContainer(true);
+
+ $fields = $standard->getStandardCheckoutFormFields();
+
+ $sumOne = (float)$fields["amount"] +
+ (float)$fields["tax"] - (float)$fields["discount_amount"];
+
+ $sumTwo = 0;
+ if (isset($fields["amount_1"])) {
+ $sumTwo += (float)$fields["amount_1"];
+ }
+ if (isset($fields["amount_2"])) {
+ $sumTwo += (float)$fields["amount_2"];
+ }
+ if (isset($fields["amount_3"])) {
+ $sumTwo += (float)$fields["amount_3"];
+ }
+ if (isset($fields["amount_4"])) {
+ $sumTwo += (float)$fields["amount_4"];
+ }
+ if (isset($fields["amount_5"])) {
+ $sumTwo += (float)$fields["amount_5"];
+ }
+ if (isset($fields["amount_6"])) {
+ $sumTwo += (float)$fields["amount_6"];
+ }
+ if (isset($fields["amount_7"])) {
+ $sumTwo += (float)$fields["amount_7"];
+ }
+ if (isset($fields["amount_8"])) {
+ $sumTwo += (float)$fields["amount_8"];
+ }
+ if (isset($fields["amount_9"])) {
+ $sumTwo += (float)$fields["amount_9"];
+ }
+ if (isset($fields["amount_10"])) {
+ $sumTwo += (float)$fields["amount_10"];
+ }
+ $sumTwo += (float)$fields["tax_cart"] -
+ (float)$fields["discount_amount_cart"];
+
+ //Wird noch programmatisch gelöst,
+ // bisher nur 10 Artikel hardcoded, deshalb Bremse
+ if ($sumOne <> $sumTwo && !array_key_exists('amount_11', $fields)) {
+ $fields["amount_1"] =
+ (string)(float)$fields["amount_1"] + ($sumOne - $sumTwo);
+ }
+
+ foreach ($fields as $field => $value) {
+ $form->addField(
+ $field, 'hidden', array('name' => $field, 'value' => $value)
+ );
+ }
+
+ $idSuffix = Mage::helper('core')->uniqHash();
+
+ $submitButton = new Varien_Data_Form_Element_Submit(
+ array(
+ 'value' => $this->__(
+ 'Click here if you are not redirected within 10 seconds...'
+ ),
+ )
+ );
+ $id = "submit_to_paypal_button_{$idSuffix}";
+ $submitButton->setId($id);
+ $form->addElement($submitButton);
+ $html = '<html><body>';
+ $html .= $this->__(
+ 'You will be redirected to the PayPal website in a few seconds.'
+ );
+ $html .= $form->toHtml();
+ $html .= '<script type="text/javascript">' .
+ 'document.getElementById("paypal_standard_checkout").submit();' .
+ '</script>';
+ $html .= '</body></html>';
+
+ return $html;
+ }
+}
19 app/code/community/Hackathon/PaypalRoundBugfix/Model/Paypal/Ipn.php
@@ -0,0 +1,19 @@
+<?php
+
+class Hackathon_PaypalRoundBugfix_Model_Paypal_Ipn
+ extends Mage_Paypal_Model_Ipn
+{
+
+ /**
+ * Process a refund or a chargeback
+ */
+ protected function _registerPaymentRefund()
+ {
+ $this->_order->addStatusHistoryComment(
+ Mage::helper('paypal')->__(
+ 'Manuelle Erstattung via Paypal ist erfolgt.'
+ )
+ )->setIsCustomerNotified(true)->save();
+ }
+
+}
35 app/code/community/Hackathon/PaypalRoundBugfix/Test/Config/RewriteTest.php
@@ -0,0 +1,35 @@
+<?php
+
+class Hackathon_PaypalRoundBugfix_Test_Config_RewriteTest
+ extends EcomDev_PHPUnit_Test_Case_Config
+{
+ /**
+ * Test wether the Ipn model is rewritten
+ *
+ * @test
+ */
+ public function checkRewriteOfIpnModel()
+ {
+ $this->assertModelAlias(
+ 'paypal/ipn', 'Hackathon_PaypalRoundBugfix_Model_Paypal_Ipn'
+ );
+
+ $model = Mage::getModel('paypal/ipn');
+ $this->assertInstanceOf(
+ 'Hackathon_PaypalRoundBugfix_Model_Paypal_Ipn', $model
+ );
+ }
+
+ /**
+ * Test wether the Redirect Block is rewritten
+ *
+ * @test
+ */
+ public function checkRewriteOfRedirectBlock()
+ {
+ $this->assertBlockAlias(
+ 'paypal/standard_redirect',
+ 'Hackathon_PaypalRoundBugfix_Block_Paypal_Standard_Redirect'
+ );
+ }
+}
42 app/code/community/Hackathon/PaypalRoundBugfix/etc/config.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+
+<config>
+ <modules>
+ <Hackathon_PaypalRoundBugfix>
+ <version>0.1.0</version>
+ </Hackathon_PaypalRoundBugfix>
+ </modules>
+ <global>
+ <models>
+ <hackathon_paypalroundbugfix>
+ <class>Hackathon_PaypalRoundBugfix_Model</class>
+ </hackathon_paypalroundbugfix>
+ <paypal>
+ <rewrite>
+ <!-- Mage_Paypal_Model_Ipn -->
+ <!-- Hackathon_PaypalRoundBugfix_Model_Paypal_Ipn -->
+ <ipn>Hackathon_PaypalRoundBugfix_Model_Paypal_Ipn</ipn>
+ </rewrite>
+ </paypal>
+ </models>
+ <blocks>
+ <hackathon_paypalroundbugfix>
+ <class>Hackathon_PaypalRoundBugfix_Block</class>
+ </hackathon_paypalroundbugfix>
+ <paypal>
+ <rewrite>
+ <!-- Mage_Paypal_Block_Standard_Redirect -->
+ <!-- Hackathon_PaypalRoundBugfix_Block_Paypal_Standard_Redirect -->
+ <standard_redirect>Hackathon_PaypalRoundBugfix_Block_Paypal_Standard_Redirect</standard_redirect>
+ </rewrite>
+ </paypal>
+ </blocks>
+ </global>
+ <phpunit>
+ <suite>
+ <modules>
+ <Hackathon_PaypalRoundBugfix/>
+ </modules>
+ </suite>
+ </phpunit>
+</config>
13 app/etc/modules/Hackathon_PaypalRoundBugfix.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<config>
+ <modules>
+ <Hackathon_PaypalRoundBugfix>
+ <active>true</active>
+ <codePool>community</codePool>
+ <depends>
+ <Mage_Paypal/>
+ </depends>
+ </Hackathon_PaypalRoundBugfix>
+ </modules>
+</config>
2 modman
@@ -0,0 +1,2 @@
+app/code/community/Hackathon/PaypalRoundBugfix/ app/code/community/Hackathon/PaypalRoundBugfix/
+app/etc/modules/Hackathon_PaypalRoundBugfix.xml app/etc/modules/Hackathon_PaypalRoundBugfix.xml

0 comments on commit d2010c9

Please sign in to comment.