Merge pull request #4 from jaafit/master
for the iframe option, don't display invoice if customer didn't choose bitpay
This commit is contained in:
commit
4f2eed65b7
|
@ -8,9 +8,25 @@ class Bitpay_Bitcoins_Block_Iframe extends Mage_Checkout_Block_Onepage_Payment
|
|||
parent::_construct();
|
||||
}
|
||||
|
||||
public function GetQuoteId()
|
||||
{
|
||||
$quote = $this->getQuote();
|
||||
$quoteId = $quote->getId();
|
||||
return $quoteId;
|
||||
}
|
||||
|
||||
|
||||
// create an invoice and return the url so that iframe.phtml can display it
|
||||
public function GetIframeUrl()
|
||||
{
|
||||
// are they using bitpay?
|
||||
if (!($quote = Mage::getSingleton('checkout/session')->getQuote())
|
||||
or !($payment = $quote->getPayment())
|
||||
or !($instance = $payment->getMethodInstance())
|
||||
or ($instance->getCode() != 'Bitcoins'))
|
||||
return 'notbitpay';
|
||||
|
||||
// fullscreen disabled?
|
||||
if (Mage::getStoreConfig('payment/Bitcoins/fullscreen'))
|
||||
return 'disabled';
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?
|
||||
<?php
|
||||
|
||||
class Bitpay_Bitcoins_Model_Source_Speed
|
||||
{
|
||||
|
|
|
@ -1,8 +1,16 @@
|
|||
<?
|
||||
<?php
|
||||
|
||||
// callback controller
|
||||
class Bitpay_Bitcoins_IndexController extends Mage_Core_Controller_Front_Action {
|
||||
|
||||
public function checkForPaymentAction()
|
||||
{
|
||||
$params = $this->getRequest()->getParams();
|
||||
$quoteId = $params['quote'];
|
||||
$paid = Mage::getModel('Bitcoins/ipn')->GetQuotePaid($quoteId);
|
||||
print json_encode(array('paid' => $paid));
|
||||
}
|
||||
|
||||
// bitpay's IPN lands here
|
||||
public function indexAction() {
|
||||
require 'lib/bitpay/bp_lib.php';
|
||||
|
@ -26,6 +34,8 @@ class Bitpay_Bitcoins_IndexController extends Mage_Core_Controller_Front_Action
|
|||
// save the ipn so that we can find it when the user clicks "Place Order"
|
||||
Mage::getModel('Bitcoins/ipn')->Record($invoice);
|
||||
|
||||
|
||||
|
||||
// update the order if it exists already
|
||||
if ($order->getId())
|
||||
switch($invoice['status']) {
|
||||
|
@ -42,6 +52,3 @@ class Bitpay_Bitcoins_IndexController extends Mage_Core_Controller_Front_Action
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -51,7 +51,7 @@
|
|||
<speed translate="label">
|
||||
<label>Transaction Speed</label>
|
||||
<frontend_type>select</frontend_type>
|
||||
<source_model>bitpay_bitcoins_model_source_speed</source_model>
|
||||
<source_model>Bitpay_Bitcoins_Model_Source_Speed</source_model>
|
||||
<sort_order>5</sort_order>
|
||||
<show_in_default>1</show_in_default>
|
||||
<show_in_website>1</show_in_website>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
$url = $this->GetIframeUrl();
|
||||
switch($url){
|
||||
case 'notbitpay': break; // customer is using another payment method
|
||||
case 'paid':
|
||||
echo 'Order payment received. Place Order to complete.'; break;
|
||||
case 'disabled':
|
||||
|
@ -10,4 +11,17 @@ switch($url){
|
|||
default:
|
||||
echo '<iframe src="'.$url.'" style="width: 500px; height: 150px; margin-left: 50px"> </iframe>'; break;
|
||||
}
|
||||
$quoteId = $this->GetQuoteId();
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
new PeriodicalExecuter(function() {new Ajax.Request("<? echo Mage::getUrl('bitpay_callback/index/checkForPayment/'); ?>?quote=<? echo $quoteId; ?>", {asynchronous:true, evalScripts:true, onComplete:function(request, json) {
|
||||
data = request.responseText.evalJSON();
|
||||
if (data.paid) {
|
||||
buttons = $$("button.btn-checkout");
|
||||
buttons.each(function(btn) { btn.click(); })
|
||||
}
|
||||
}})}, 5);
|
||||
|
||||
//]]>
|
||||
</script>
|
Loading…
Reference in New Issue