Version Notes
Now supporting guest checkout
Download this release
Release Info
Developer | BitCredits.io |
Extension | BitCredits_BitcoinPayForm |
Version | 1.0.3 |
Comparing to | |
See all releases |
Code changes from version 1.0.2 to 1.0.3
- app/code/community/BitCredits/BitcoinPayform/Block/Form.php +9 -0
- app/code/community/BitCredits/BitcoinPayform/Block/Widget.php +10 -0
- app/code/community/BitCredits/BitcoinPayform/Model/PaymentMethod.php +153 -0
- app/code/community/BitCredits/BitcoinPayform/etc/config.xml +69 -0
- app/code/community/BitCredits/BitcoinPayform/etc/system.xml +51 -0
- app/design/frontend/base/default/template/bitcredits_bitcoinpayform/form.phtml +4 -0
- app/design/frontend/base/default/template/bitcredits_bitcoinpayform/widget.phtml +29 -0
- package.xml +4 -4
app/code/community/BitCredits/BitcoinPayform/Block/Form.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class BitCredits_BitcoinPayform_Block_Form extends Mage_Payment_Block_Form {
|
4 |
+
|
5 |
+
protected function _construct() {
|
6 |
+
parent::_construct();
|
7 |
+
$this->setTemplate('bitcredits_bitcoinpayform/form.phtml');
|
8 |
+
}
|
9 |
+
}
|
app/code/community/BitCredits/BitcoinPayform/Block/Widget.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class BitCredits_BitcoinPayform_Block_Widget extends Mage_Checkout_Block_Onepage_Payment {
|
4 |
+
|
5 |
+
protected function _construct() {
|
6 |
+
$this->setTemplate('bitcredits_bitcoinpayform/widget.phtml');
|
7 |
+
parent::_construct();
|
8 |
+
}
|
9 |
+
|
10 |
+
}
|
app/code/community/BitCredits/BitcoinPayform/Model/PaymentMethod.php
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Our test CC module adapter
|
5 |
+
*/
|
6 |
+
class BitCredits_BitcoinPayform_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstract
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* unique internal payment method identifier
|
10 |
+
*
|
11 |
+
* @var string [a-z0-9_]
|
12 |
+
*/
|
13 |
+
protected $_code = 'bitcredits_bitcoinpayform';
|
14 |
+
|
15 |
+
protected $_formBlockType = 'bitcredits_bitcoinpayform/form';
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Here are examples of flags that will determine functionality availability
|
19 |
+
* of this module to be used by frontend and backend.
|
20 |
+
*
|
21 |
+
* @see all flags and their defaults in Mage_Payment_Model_Method_Abstract
|
22 |
+
*
|
23 |
+
* It is possible to have a custom dynamic logic by overloading
|
24 |
+
* public function can* for each flag respectively
|
25 |
+
*/
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Is this payment method a gateway (online auth/charge) ?
|
29 |
+
*/
|
30 |
+
protected $_isGateway = true;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Can authorize online?
|
34 |
+
*/
|
35 |
+
protected $_canAuthorize = true;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Can capture funds online?
|
39 |
+
*/
|
40 |
+
protected $_canCapture = false;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Can capture partial amounts online?
|
44 |
+
*/
|
45 |
+
protected $_canCapturePartial = false;
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Can refund online?
|
49 |
+
*/
|
50 |
+
protected $_canRefund = false;
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Can void transactions online?
|
54 |
+
*/
|
55 |
+
protected $_canVoid = false;
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Can use this payment method in administration panel?
|
59 |
+
*/
|
60 |
+
protected $_canUseInternal = false;
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Can show this payment method as an option on checkout payment page?
|
64 |
+
*/
|
65 |
+
protected $_canUseCheckout = true;
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Is this payment method suitable for multi-shipping checkout?
|
69 |
+
*/
|
70 |
+
protected $_canUseForMultishipping = true;
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Can save credit card information for future processing?
|
74 |
+
*/
|
75 |
+
protected $_canSaveCc = false;
|
76 |
+
|
77 |
+
public function authorize(Varien_Object $payment, $amount) {
|
78 |
+
|
79 |
+
$key = Mage::getStoreConfig('payment/bitcredits_bitcoinpayform/api_key');//'IDIOTSGUIDEISNICEANDSWEET';
|
80 |
+
$endpoint = Mage::getStoreConfig('payment/bitcredits_bitcoinpayform/api_endpoint');//'http://api.bitcredits.local:6543';
|
81 |
+
|
82 |
+
if(!isset($_COOKIE['bitc'])){
|
83 |
+
Mage::throwException(Mage::helper('sales')->__('Could not place order.'));
|
84 |
+
}
|
85 |
+
|
86 |
+
$order = $payment->getOrder();
|
87 |
+
$quoteData = $order->getQuote()->getData();
|
88 |
+
|
89 |
+
$method = '/v1/transactions';
|
90 |
+
$data = array(
|
91 |
+
'api_key' => $key,
|
92 |
+
'src_token' => $_COOKIE['bitc'],
|
93 |
+
'dst_account' => '/magento/orders/'.$order->getRealOrderId(),
|
94 |
+
'dst_account_create' => true,
|
95 |
+
'amount' => $amount,
|
96 |
+
'data' => array(
|
97 |
+
'email' => $quoteData['customer_email'],
|
98 |
+
'firstname' => $quoteData['customer_firstname'],
|
99 |
+
'lastname' => $quoteData['customer_lastname'],
|
100 |
+
'order_id' => $order->getRealOrderId()
|
101 |
+
)
|
102 |
+
);
|
103 |
+
|
104 |
+
$ch = curl_init();
|
105 |
+
$data_string = json_encode($data);
|
106 |
+
curl_setopt($ch, CURLOPT_URL, $endpoint . $method);
|
107 |
+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
|
108 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
|
109 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
110 |
+
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string)));
|
111 |
+
$result = curl_exec($ch);
|
112 |
+
$res = json_decode($result, true);
|
113 |
+
|
114 |
+
if(
|
115 |
+
$res == null
|
116 |
+
|| !isset($res['status'])
|
117 |
+
){
|
118 |
+
Mage::throwException(Mage::helper('sales')->__('Transaction not completed.'));
|
119 |
+
}elseif($res['status'] == 'error'){
|
120 |
+
if(isset($res['message'])){
|
121 |
+
Mage::throwException(Mage::helper('sales')->__('Error while processing payment: ').$res['message']);
|
122 |
+
}else{
|
123 |
+
Mage::throwException(Mage::helper('sales')->__('Transaction not completed. No error message was provided.'));
|
124 |
+
}
|
125 |
+
}
|
126 |
+
|
127 |
+
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();
|
128 |
+
|
129 |
+
if (!count($order->getInvoiceCollection())) {
|
130 |
+
$invoice = $order->prepareInvoice()
|
131 |
+
->setTransactionId(1)
|
132 |
+
->addComment('Invoiced automatically by BitCredits/BitcoinPayForm/Model/PaymentMethod.php')
|
133 |
+
->register()
|
134 |
+
->pay();
|
135 |
+
|
136 |
+
$transactionSave = Mage::getModel('core/resource_transaction')
|
137 |
+
->addObject($invoice)
|
138 |
+
->addObject($invoice->getOrder());
|
139 |
+
|
140 |
+
$transactionSave->save();
|
141 |
+
try {
|
142 |
+
$order->sendNewOrderEmail();
|
143 |
+
} catch (Exception $e) {
|
144 |
+
Mage::logException($e);
|
145 |
+
}
|
146 |
+
} else {
|
147 |
+
//
|
148 |
+
}
|
149 |
+
|
150 |
+
return true;
|
151 |
+
}
|
152 |
+
}
|
153 |
+
?>
|
app/code/community/BitCredits/BitcoinPayform/etc/config.xml
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<config>
|
3 |
+
|
4 |
+
<frontend>
|
5 |
+
<layout>
|
6 |
+
<updates>
|
7 |
+
<bitcredits_bitcoinpayform>
|
8 |
+
<file>bitcredits_bitcoinpayform.xml</file>
|
9 |
+
</bitcredits_bitcoinpayform>
|
10 |
+
</updates>
|
11 |
+
</layout>
|
12 |
+
</frontend>
|
13 |
+
|
14 |
+
<modules>
|
15 |
+
<BitCredits_BitcoinPayform>
|
16 |
+
<version>1.0.0</version>
|
17 |
+
</BitCredits_BitcoinPayform>
|
18 |
+
</modules>
|
19 |
+
|
20 |
+
<global>
|
21 |
+
<blocks>
|
22 |
+
<bitcredits_bitcoinpayform>
|
23 |
+
<class>BitCredits_BitcoinPayform_Block</class>
|
24 |
+
</bitcredits_bitcoinpayform>
|
25 |
+
</blocks>
|
26 |
+
|
27 |
+
<models>
|
28 |
+
<bitcredits_bitcoinpayform>
|
29 |
+
<class>BitCredits_BitcoinPayform_Model</class>
|
30 |
+
</bitcredits_bitcoinpayform>
|
31 |
+
</models>
|
32 |
+
|
33 |
+
<resources>
|
34 |
+
<bitcredits_bitcoinpayform_setup>
|
35 |
+
<setup>
|
36 |
+
<module>BitCredits_BitcoinPayform</module>
|
37 |
+
</setup>
|
38 |
+
<connection>
|
39 |
+
<use>core_setup</use>
|
40 |
+
</connection>
|
41 |
+
</bitcredits_bitcoinpayform_setup>
|
42 |
+
<bitcredits_bitcoinpayform_write>
|
43 |
+
<connection>
|
44 |
+
<use>core_write</use>
|
45 |
+
</connection>
|
46 |
+
</bitcredits_bitcoinpayform_write>
|
47 |
+
<bitcredits_bitcoinpayform_read>
|
48 |
+
<connection>
|
49 |
+
<use>core_read</use>
|
50 |
+
</connection>
|
51 |
+
</bitcredits_bitcoinpayform_read>
|
52 |
+
</resources>
|
53 |
+
|
54 |
+
</global>
|
55 |
+
|
56 |
+
<default>
|
57 |
+
<payment>
|
58 |
+
<bitcredits_bitcoinpayform>
|
59 |
+
<active>1</active>
|
60 |
+
<model>bitcredits_bitcoinpayform/paymentMethod</model>
|
61 |
+
<title>Bitcoins through BitCredits.io</title>
|
62 |
+
<api_key></api_key>
|
63 |
+
<api_endpoint>https://api.bitcredits.io</api_endpoint>
|
64 |
+
<payment_action>authorize</payment_action>
|
65 |
+
</bitcredits_bitcoinpayform>
|
66 |
+
</payment>
|
67 |
+
</default>
|
68 |
+
|
69 |
+
</config>
|
app/code/community/BitCredits/BitcoinPayform/etc/system.xml
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<config>
|
3 |
+
<sections>
|
4 |
+
<payment>
|
5 |
+
<groups>
|
6 |
+
<bitcredits_bitcoinpayform translate="label" module="paygate">
|
7 |
+
<label>BitCredits.io Bitcoin PayForm</label>
|
8 |
+
<sort_order>670</sort_order>
|
9 |
+
<show_in_default>1</show_in_default>
|
10 |
+
<show_in_website>1</show_in_website>
|
11 |
+
<show_in_store>0</show_in_store>
|
12 |
+
<fields>
|
13 |
+
<active translate="label">
|
14 |
+
<label>Enabled</label>
|
15 |
+
<frontend_type>select</frontend_type>
|
16 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
17 |
+
<sort_order>1</sort_order>
|
18 |
+
<show_in_default>1</show_in_default>
|
19 |
+
<show_in_website>1</show_in_website>
|
20 |
+
<show_in_store>0</show_in_store>
|
21 |
+
</active>
|
22 |
+
<title translate="label">
|
23 |
+
<label>Title</label>
|
24 |
+
<frontend_type>text</frontend_type>
|
25 |
+
<sort_order>2</sort_order>
|
26 |
+
<show_in_default>1</show_in_default>
|
27 |
+
<show_in_website>1</show_in_website>
|
28 |
+
<show_in_store>0</show_in_store>
|
29 |
+
</title>
|
30 |
+
<api_key translate="label">
|
31 |
+
<label>API Key</label>
|
32 |
+
<frontend_type>text</frontend_type>
|
33 |
+
<sort_order>4</sort_order>
|
34 |
+
<show_in_default>1</show_in_default>
|
35 |
+
<show_in_website>1</show_in_website>
|
36 |
+
<show_in_store>0</show_in_store>
|
37 |
+
</api_key>
|
38 |
+
<api_endpoint translate="label">
|
39 |
+
<label>API Endpoint</label>
|
40 |
+
<frontend_type>text</frontend_type>
|
41 |
+
<sort_order>3</sort_order>
|
42 |
+
<show_in_default>1</show_in_default>
|
43 |
+
<show_in_website>1</show_in_website>
|
44 |
+
<show_in_store>0</show_in_store>
|
45 |
+
</api_endpoint>
|
46 |
+
</fields>
|
47 |
+
</bitcredits_bitcoinpayform>
|
48 |
+
</groups>
|
49 |
+
</payment>
|
50 |
+
</sections>
|
51 |
+
</config>
|
app/design/frontend/base/default/template/bitcredits_bitcoinpayform/form.phtml
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
<?php $_code=$this->getMethodCode() ?>
|
2 |
+
<div id="payment_form_<?php echo $_code ?>" style="display:none;">
|
3 |
+
You will be able to pay using your bitcoins on the <i>Order Review</i> step.
|
4 |
+
</div>
|
app/design/frontend/base/default/template/bitcredits_bitcoinpayform/widget.phtml
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div id="bitcredits-payment-zone" style="padding:10px;" class="clear">
|
2 |
+
<style scoped>
|
3 |
+
#bitcredits-payment-box{
|
4 |
+
float:right;
|
5 |
+
}
|
6 |
+
</style>
|
7 |
+
<div id="bitcredits-payment-box" style="opacity:0.7;">Loading Bitcoin payment...</div>
|
8 |
+
</div>
|
9 |
+
<?php $data = Mage::getSingleton('checkout/session')->getQuote()->getData(); ?>
|
10 |
+
<script type="text/javascript">
|
11 |
+
//<![CDATA[
|
12 |
+
if (document.getElementById("BitC") == null) {
|
13 |
+
var bitc=document.createElement('script');
|
14 |
+
bitc.type='text/javascript';
|
15 |
+
bitc.setAttribute("id", "BitC");
|
16 |
+
bitc.src = '<?php echo Mage::getStoreConfig('payment/bitcredits_bitcoinpayform/api_endpoint'); ?>/v1/bitcredits.js';
|
17 |
+
var s=document.getElementsByTagName('script')[0];
|
18 |
+
s.parentNode.insertBefore(bitc,s);
|
19 |
+
}
|
20 |
+
window.BitCredits = window.BitCredits || [];
|
21 |
+
window.BitCredits.push(['onConfigReady', function(){
|
22 |
+
window.BitCredits.push(['setupMagento', <?php $quoteData = $this->getQuote()->getData();echo $quoteData['grand_total']; ?>, <?php echo json_encode(array(
|
23 |
+
'email' => $data['customer_email'],
|
24 |
+
'firstname' => $data['customer_firstname'],
|
25 |
+
'lastname' => $data['customer_lastname']
|
26 |
+
)); ?>]);
|
27 |
+
}]);
|
28 |
+
//]]>
|
29 |
+
</script>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>BitCredits_BitcoinPayForm</name>
|
4 |
-
<version>1.0.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/MIT">MIT License</license>
|
7 |
<channel>community</channel>
|
@@ -10,9 +10,9 @@
|
|
10 |
<description>BitCredits.io allows your store to offer bitcoins as a payment option, while never having to hold them yourself. We take care of the legalities related to crypto-currencies.</description>
|
11 |
<notes>Now supporting guest checkout</notes>
|
12 |
<authors><author><name>BitCredits.io</name><user>bitcredits</user><email>admin@bitcredits.io</email></author></authors>
|
13 |
-
<date>2014-03-
|
14 |
-
<time>
|
15 |
-
<contents><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="bitcredits_bitcoinpayform.xml" hash="9494781d4e4b98bc13592c5ab40b25f8"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="BitCredits_BitcoinPayform.xml" hash="7067a98cfdd1b88f2c5f657ed0c05d57"/></dir></target></contents>
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.3.0</min><max>5.9.0</max></php></required></dependencies>
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>BitCredits_BitcoinPayForm</name>
|
4 |
+
<version>1.0.3</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/MIT">MIT License</license>
|
7 |
<channel>community</channel>
|
10 |
<description>BitCredits.io allows your store to offer bitcoins as a payment option, while never having to hold them yourself. We take care of the legalities related to crypto-currencies.</description>
|
11 |
<notes>Now supporting guest checkout</notes>
|
12 |
<authors><author><name>BitCredits.io</name><user>bitcredits</user><email>admin@bitcredits.io</email></author></authors>
|
13 |
+
<date>2014-03-20</date>
|
14 |
+
<time>14:29:39</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="BitCredits"><dir name="BitcoinPayform"><dir name="Block"><file name="Form.php" hash="063a3650c3de39e13ea373c4fa85d480"/><file name="Widget.php" hash="613f3cd3a2a43731561c50fad6859e04"/></dir><dir name="Model"><file name="PaymentMethod.php" hash="d2a14fc175949e534646c43f49fd6184"/></dir><dir name="etc"><file name="config.xml" hash="f68d838928a38fee30337e556a442a1b"/><file name="system.xml" hash="a7aef3dc412c83d7fd6ab6308983a334"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="bitcredits_bitcoinpayform.xml" hash="9494781d4e4b98bc13592c5ab40b25f8"/></dir><dir name="template"><dir name="bitcredits_bitcoinpayform"><file name="form.phtml" hash="ad330d110b5e6990efb784ae454a1b43"/><file name="widget.phtml" hash="519b05aa2614a433aad220f26b8a1823"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="BitCredits_BitcoinPayform.xml" hash="7067a98cfdd1b88f2c5f657ed0c05d57"/></dir></target></contents>
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.3.0</min><max>5.9.0</max></php></required></dependencies>
|
18 |
</package>
|