Skip to content

Commit c41ecf8

Browse files
authored
Merge pull request #17
Fix the order state/status flow.…
2 parents 293e13f + 7fa8438 commit c41ecf8

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

app/code/community/RicardoMartins/PagBank/Model/Method/Billet.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ public function order(Varien_Object $payment, $amount)
5656
$addData['charge_id'] = $charges['id'];
5757

5858
$payment->setAdditionalData(serialize($addData));
59+
$payment->setSkipOrderProcessing(true);
5960
$payment->save();
6061
} else {
61-
Mage::throwException($this->_getHelper()->__("Erro na emissão do boleto!\nMotivo: " . $pay->error_description . ".\nPor favor tente novamente mais tarde!"));
62+
Mage::throwException($this->_getHelper()->__("Erro na emissão do boleto!.\nPor favor tente novamente mais tarde!"));
6263
}
6364

6465
return $this;

app/code/community/RicardoMartins/PagBank/Model/Method/Pix.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ public function order(Varien_Object $payment, $amount)
5252
$addData['pix']['created_at'] = $response['created_at'];
5353

5454
$payment->setAdditionalData(serialize($addData));
55+
$payment->setSkipOrderProcessing(true);
5556
$payment->save();
5657
} else {
57-
Mage::throwException($this->_getHelper()->__("Erro na geração do QR Code!\nMotivo: " . $pay->error_description . ".\nPor favor tente novamente mais tarde!"));
58+
Mage::throwException($this->_getHelper()->__("Erro na geração do QR Code!.\nPor favor tente novamente mais tarde!"));
5859
}
5960

6061
return $this;

app/code/community/RicardoMartins/PagBank/Model/Observer.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ public function salesOrderPaymentPlaceEnd($observer)
100100
$helper->writeLog(sprintf('Error handling PagBank return: %s', $e->getMessage()));
101101
}
102102
}
103+
104+
if ($method instanceof RicardoMartins_PagBank_Model_Method_Pix || $method instanceof RicardoMartins_PagBank_Model_Method_Billet) {
105+
try {
106+
$order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
107+
} catch (\Exception $e) {
108+
$helper = Mage::helper('ricardomartins_pagbank');
109+
$helper->writeLog(sprintf('Error handling PagBank return: %s', $e->getMessage()));
110+
}
111+
}
112+
103113
return $this;
104114
}
105115
}

app/code/community/RicardoMartins/PagBank/etc/config.xml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@
5252
</payment>
5353
</default>
5454
<global>
55+
<sales>
56+
<order>
57+
<states>
58+
<pending_payment>
59+
<visible_on_front>1</visible_on_front>
60+
</pending_payment>
61+
</states>
62+
</order>
63+
</sales>
5564
<models>
5665
<ricardomartins_pagbank>
5766
<class>RicardoMartins_PagBank_Model</class>
@@ -76,6 +85,14 @@
7685
</ricardomartins_pagbank>
7786
</observers>
7887
</admin_system_config_changed_section_payment>
88+
<sales_order_payment_place_end>
89+
<observers>
90+
<ricardomartins_pagbank>
91+
<class>ricardomartins_pagbank/observer</class>
92+
<method>salesOrderPaymentPlaceEnd</method>
93+
</ricardomartins_pagbank>
94+
</observers>
95+
</sales_order_payment_place_end>
7996
</events>
8097
</global>
8198
<frontend>
@@ -128,15 +145,6 @@
128145
</ricardomartins_pagbank>
129146
</observers>
130147
</payment_info_block_prepare_specific_information>
131-
<sales_order_payment_place_end>
132-
<observers>
133-
<ricardomartins_pagbank>
134-
<type>model</type>
135-
<class>ricardomartins_pagbank/observer</class>
136-
<method>salesOrderPaymentPlaceEnd</method>
137-
</ricardomartins_pagbank>
138-
</observers>
139-
</sales_order_payment_place_end>
140148
</events>
141149
</frontend>
142150
<adminhtml>

0 commit comments

Comments
 (0)