Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial push

  • Loading branch information...
commit d0e824ba5224462f72a6676b1928ae41580ce45f 0 parents
@jalder authored
0  README
No changes.
68 public_html/app/code/local/Bitcoin/Paycoin/Block/Form.php
@@ -0,0 +1,68 @@
+<?php
+
+$dir = Mage::getBaseDir();
+
+require_once($dir.'/app/code/local/Bitcoin/Paycoin/Helper/jsonRPCClient.php');
+
+class Bitcoin_Paycoin_Block_Form extends Mage_Payment_Block_Form
+{
+
+ private $rpcurl;
+
+ protected function _construct()
+ {
+ parent::_construct();
+ $this->setTemplate('paycoin/form.phtml');
+ $this->rpcurl = $this->_getRpcUrl();
+ }
+
+ protected function _getRpcUrl()
+ {
+ $rpcurl = Mage::getSingleton('paycoin/paycoin')->getConfig()->getRpcUrl();
+ return $rpcurl;
+ }
+
+ protected function getAddress(){
+ $bitcoin = new jsonRPCClient($this->rpcurl);
+
+ try {
+ $bitcoin->getinfo();
+ } catch (Exception $e) {
+ $address = 'Error: Bitcoin server is down. Please email system administrator regarding your order after confirmation.';
+ return $address;
+ }
+
+ $info = Mage::getSingleton('checkout/cart')->getCustomerSession()->getCustomer();
+ if($info->email==''){
+
+ $address = 'GuestCheckout-';
+ }
+ else{
+ $address = $info->email.'-';
+ }
+
+ $qid = Mage::getSingleton('checkout/cart')->getCheckoutSession()->getQuoteId();
+ $info = Mage::getSingleton('sales/quote')->load($qid);
+ $info->reserveOrderId();
+ $address .= $info['reserved_order_id'];
+
+ $address = $bitcoin->getaccountaddress($address);
+
+ return $address;
+ }
+
+
+ /**
+ * Render block HTML
+ *
+ * @return string
+ */
+ protected function _toHtml()
+ {
+ $this->address = $this->getAddress();
+ Mage::dispatchEvent('payment_form_block_to_html_before', array(
+ 'block' => $this
+ ));
+ return parent::_toHtml();
+ }
+}
8 public_html/app/code/local/Bitcoin/Paycoin/Block/Index.php
@@ -0,0 +1,8 @@
+<?php
+class Bitcoin_Paycoin_Block_Index extends Mage_Core_Block_Template{
+
+
+
+
+
+}
6 public_html/app/code/local/Bitcoin/Paycoin/Block/Info.php
@@ -0,0 +1,6 @@
+<?php
+class Bitcoin_Paycoin_Block_Info extends Mage_Payment_Block_Info
+{
+
+
+}
8 public_html/app/code/local/Bitcoin/Paycoin/Block/left.php
@@ -0,0 +1,8 @@
+<?php
+class Bitcoin_Paycoin_Block_left extends Mage_Core_Block_Template{
+
+
+
+
+
+}
165 public_html/app/code/local/Bitcoin/Paycoin/Helper/jsonRPCClient.php
@@ -0,0 +1,165 @@
+<?php
+/*
+ COPYRIGHT
+
+Copyright 2007 Sergio Vaccaro <sergio@inservibile.org>
+
+This file is part of JSON-RPC PHP.
+
+JSON-RPC PHP is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+JSON-RPC PHP is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with JSON-RPC PHP; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+/**
+ * The object of this class are generic jsonRPC 1.0 clients
+ * http://json-rpc.org/wiki/specification
+ *
+ * @author sergio <jsonrpcphp@inservibile.org>
+ */
+class jsonRPCClient {
+
+ /**
+ * Debug state
+ *
+ * @var boolean
+ */
+ private $debug;
+
+ /**
+ * The server URL
+ *
+ * @var string
+ */
+ private $url;
+ /**
+ * The request id
+ *
+ * @var integer
+ */
+ private $id;
+ /**
+ * If true, notifications are performed instead of requests
+ *
+ * @var boolean
+ */
+ private $notification = false;
+
+ /**
+ * Takes the connection parameters
+ *
+ * @param string $url
+ * @param boolean $debug
+ */
+ public function __construct($url,$debug = false) {
+ // server URL
+ $this->url = $url;
+ // proxy
+ empty($proxy) ? $this->proxy = '' : $this->proxy = $proxy;
+ // debug state
+ empty($debug) ? $this->debug = false : $this->debug = true;
+ // message id
+ $this->id = 1;
+ }
+
+ /**
+ * Sets the notification state of the object. In this state, notifications are performed, instead of requests.
+ *
+ * @param boolean $notification
+ */
+ public function setRPCNotification($notification) {
+ empty($notification) ?
+ $this->notification = false
+ :
+ $this->notification = true;
+ }
+
+ /**
+ * Performs a jsonRCP request and gets the results as an array
+ *
+ * @param string $method
+ * @param array $params
+ * @return array
+ */
+ public function __call($method,$params) {
+
+ // check
+ if (!is_scalar($method)) {
+ throw new Exception('Method name has no scalar value');
+ }
+
+ // check
+ if (is_array($params)) {
+ // no keys
+ $params = array_values($params);
+ } else {
+ throw new Exception('Params must be given as array');
+ }
+
+ // sets notification or request task
+ if ($this->notification) {
+ $currentId = NULL;
+ } else {
+ $currentId = $this->id;
+ }
+
+ // prepares the request
+ $request = array(
+ 'method' => $method,
+ 'params' => $params,
+ 'id' => $currentId
+ );
+ $request = json_encode($request);
+ $this->debug && $this->debug.='***** Request *****'."\n".$request."\n".'***** End Of request *****'."\n\n";
+
+ // performs the HTTP POST
+ $opts = array ('http' => array (
+ 'method' => 'POST',
+ 'header' => 'Content-type: application/json',
+ 'content' => $request
+ ));
+ $context = stream_context_create($opts);
+ if ($fp = fopen($this->url, 'r', false, $context)) {
+ $response = '';
+ while($row = fgets($fp)) {
+ $response.= trim($row)."\n";
+ }
+ $this->debug && $this->debug.='***** Server response *****'."\n".$response.'***** End of server response *****'."\n";
+ $response = json_decode($response,true);
+ } else {
+ throw new Exception('Unable to connect to '.$this->url);
+ }
+
+ // debug output
+ if ($this->debug) {
+ echo nl2br($debug);
+ }
+
+ // final checks and return
+ if (!$this->notification) {
+ // check
+ if ($response['id'] != $currentId) {
+ throw new Exception('Incorrect response id (request id: '.$currentId.', response id: '.$response['id'].')');
+ }
+ if (!is_null($response['error'])) {
+ throw new Exception('Request error: '.$response['error']);
+ }
+
+ return $response['result'];
+
+ } else {
+ return true;
+ }
+ }
+}
+?>
22 public_html/app/code/local/Bitcoin/Paycoin/Model/Config.php
@@ -0,0 +1,22 @@
+<?php
+
+
+class Bitcoin_Paycoin_Model_Config
+{
+ protected static $_methods;
+
+ public function getRpcUrl($store=null)
+ {
+ $bitconf = $this->_getConf();
+
+ return $bitconf['rpcurl'];
+ }
+
+
+ private function _getConf($store=null){
+ $config = Mage::getStoreConfig('payment', $store);
+ $bitconf = $config['paycoin'];
+ return $bitconf;
+ }
+
+}
31 public_html/app/code/local/Bitcoin/Paycoin/Model/Observer.php
@@ -0,0 +1,31 @@
+<?php
+
+class Bitcoin_Paycoin_Model_Observer
+{
+ /**
+ * Set forced canCreditmemo flag
+ *
+ * @param Varien_Event_Observer $observer
+ * @return Bitcoin_Paycoin_Model_Observer
+ */
+ public function salesOrderBeforeSave($observer)
+ {
+ $order = $observer->getEvent()->getOrder();
+
+ if ($order->getPayment()->getMethodInstance()->getCode() != 'paypal') {
+ return $this;
+ }
+
+ if ($order->canUnhold()) {
+ return $this;
+ }
+
+ if ($order->isCanceled() ||
+ $order->getState() === Mage_Sales_Model_Order::STATE_CLOSED ) {
+ return $this;
+ }
+ $order->addStatusHistoryComment('Paid with BTC');
+ return $this;
+ }
+
+}
176 public_html/app/code/local/Bitcoin/Paycoin/Model/Paycoin.php
@@ -0,0 +1,176 @@
+<?php
+class Bitcoin_Paycoin_Model_Paycoin extends Mage_Payment_Model_Method_Abstract
+{
+ protected $_code = 'paycoin';
+ protected $_formBlockType = 'paycoin/form';
+ protected $_infoBlockType = 'paycoin/info';
+ protected $_isInitializeNeeded = true;
+ protected $_canUseInternal = false;
+ protected $_canUseForMultishipping = false;
+
+ /**
+ * Config instance
+ * @var Mage_Paypal_Model_Config
+ */
+ protected $_config = null;
+
+ /**
+ * Whether method is available for specified currency
+ *
+ * @param string $currencyCode
+ * @return bool
+ */
+ public function canUseForCurrency($currencyCode)
+ {
+ return true;
+ }
+
+ /**
+ * Get paypal session namespace
+ *
+ * @return Mage_Paypal_Model_Session
+ */
+// public function getSession()
+// {
+// return Mage::getSingleton('paypal/session');
+// }
+// public function processInvoice($invoice, $payment)
+// {
+// $invoice->setTransactionId('');
+// return $this;
+// }
+ /**
+ * Get checkout session namespace
+ *
+ * @return Mage_Checkout_Model_Session
+ */
+ public function getCheckout()
+ {
+ return Mage::getSingleton('checkout/session');
+ }
+
+ /**
+ * Get current quote
+ *
+ * @return Mage_Sales_Model_Quote
+ */
+ public function getQuote()
+ {
+ return $this->getCheckout()->getQuote();
+ }
+
+ /**
+ * Create main block for standard form
+ *
+ */
+ public function createFormBlock($name)
+ {
+ $block = $this->getLayout()->createBlock('bitcoin/paycoin_form', $name)
+ ->setMethod('paycoin');
+
+ return $block;
+ }
+ /**
+ * Retrieve block type for method form generation
+ *
+ * @return string
+ */
+ public function getFormBlockType()
+ {
+ return $this->_formBlockType;
+ }
+
+ /**
+ * Retrieve block type for display method information
+ *
+ * @return string
+ */
+ public function getInfoBlockType()
+ {
+ return $this->_infoBlockType;
+ }
+ /**
+ * Return Order place redirect url
+ *
+ * @return string
+ */
+ public function getOrderPlaceRedirectUrl()
+ {
+ return Mage::getUrl('/', array('_secure' => true));
+ }
+
+ /**
+ * Return form field array
+ *
+ * @return array
+ */
+ public function getStandardCheckoutFormFields()
+ {
+
+ }
+
+ /**
+ * Instantiate state and set it to state object
+ * @param string $paymentAction
+ * @param Varien_Object
+ */
+ public function initialize($paymentAction, $stateObject)
+ {
+ $state = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
+ $stateObject->setState($state);
+ $stateObject->setStatus('pending_payment');
+ $stateObject->setIsNotified(false);
+ }
+
+ /**
+ * Config instance getter
+ * @return Mage_Paypal_Model_Config
+ */
+ public function getConfig()
+ {
+ if (null === $this->_config) {
+ $params = array($this->_code);
+ if ($store = $this->getStore()) {
+ $params[] = is_object($store) ? $store->getId() : $store;
+ }
+ $this->_config = Mage::getModel('paycoin/config', $params);
+ }
+ return $this->_config;
+ }
+
+ /**
+ * Check whether payment method can be used
+ * @param Mage_Sales_Model_Quote
+ * @return bool
+ */
+ public function isAvailable($quote = null)
+ {
+ return true;
+ }
+
+ /**
+ * Custom getter for payment configuration
+ *
+ * @param string $field
+ * @param int $storeId
+ * @return mixed
+ */
+ public function getConfigData($field, $storeId = null)
+ {
+ return $this->getConfig()->$field;
+ }
+
+ /**
+ * Aggregated cart summary label getter
+ *
+ * @return string
+ */
+ private function _getAggregatedCartSummary()
+ {
+ if ($this->_config->lineItemsSummary) {
+ return $this->_config->lineItemsSummary;
+ }
+ return Mage::app()->getStore($this->getStore())->getFrontendName();
+ }
+}
+?>
9 public_html/app/code/local/Bitcoin/Paycoin/controllers/IndexController.php
@@ -0,0 +1,9 @@
+<?php
+class Bitcoin_Paycoin_IndexController extends Mage_Core_Controller_Front_Action{
+ public function IndexAction() {
+
+ $this->loadLayout();
+ $this->renderLayout();
+
+ }
+}
97 public_html/app/code/local/Bitcoin/Paycoin/etc/config.xml
@@ -0,0 +1,97 @@
+<?xml version="1.0"?>
+<config>
+ <modules>
+ <Bitcoin_Paycoin>
+ <version>0.1.0</version>
+ <active>true</active>
+ <codePool>local</codePool>
+ <depends><Mage_Payment /></depends>
+ </Bitcoin_Paycoin>
+ </modules>
+ <frontend>
+ <routers>
+ <paycoin>
+ <use>standard</use>
+ <args>
+ <module>Bitcoin_Paycoin_Block</module>
+ <frontName>paycoin</frontName>
+ </args>
+ </paycoin>
+ </routers>
+ <layout>
+ <updates>
+ <paycoin>
+ <file>paycoin.xml</file>
+ </paycoin>
+ </updates>
+ </layout>
+ </frontend>
+ <global>
+ <blocks>
+ <paycoin><class>Bitcoin_Paycoin_Block</class></paycoin>
+ </blocks>
+<!-- declare model group for new module -->
+ <models>
+<!-- model group alias to be used in Mage::getModel('newmodule/...') -->
+ <paycoin>
+<!-- base class name for the model group -->
+ <class>Bitcoin_Paycoin_Model</class>
+ </paycoin>
+ </models>
+
+<!-- declare resource setup for new module -->
+ <resources>
+<!-- resource identifier -->
+ <paycoin_setup>
+<!-- specify that this resource is a setup resource and used for upgrades -->
+ <setup>
+<!-- which module to look for install/upgrade files in -->
+ <module>Bitcoin_Paycoin</module>
+ </setup>
+<!-- specify database connection for this resource -->
+ <connection>
+<!-- do not create new connection, use predefined core setup connection -->
+ <use>core_setup</use>
+ </connection>
+ </paycoin_setup>
+ <paycoin_write>
+ <connection>
+ <use>core_write</use>
+ </connection>
+ </paycoin_write>
+ <paycoin_read>
+ <connection>
+ <use>core_read</use>
+ </connection>
+ </paycoin_read>
+ </resources>
+ <events>
+ <sales_order_save_before>
+ <observers>
+ <payment_sales_order_save_before>
+ <class>paycoin/observer</class>
+ <method>salesOrderBeforeSave</method>
+ </payment_sales_order_save_before>
+ </observers>
+ </sales_order_save_before>
+ </events>
+ </global>
+<!-- declare default configuration values for this module -->
+ <default>
+<!-- 'payment' configuration section (tab) -->
+ <payment>
+<!-- 'newmodule' configuration group (fieldset) -->
+ <paycoin>
+<!-- by default this payment method is inactive -->
+ <active>1</active>
+<!-- model to handle logic for this payment method -->
+ <model>paycoin/paycoin</model>
+<!-- order status for new orders paid by this payment method -->
+ <order_status>pending</order_status>
+<!-- default title for payment checkout page and order view page -->
+ <title>Bitcoin</title>
+ <allowspecific>1</allowspecific>
+ </paycoin>
+ </payment>
+ </default>
+</config>
63 public_html/app/code/local/Bitcoin/Paycoin/etc/system.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0"?>
+<config>
+ <sections>
+<!-- payment tab -->
+ <payment>
+ <groups>
+<!-- newmodule fieldset -->
+ <paycoin translate="label" module="paygate">
+<!-- will have title 'New Module' -->
+ <label>Bitcoin Paycoin</label>
+<!-- position between other payment methods -->
+ <sort_order>670</sort_order>
+<!-- do not show this configuration options in store scope -->
+ <show_in_default>1</show_in_default>
+ <show_in_website>1</show_in_website>
+ <show_in_store>1</show_in_store>
+ <fields>
+<!-- is this payment method active for the website? -->
+ <active translate="label">
+<!-- label for the field -->
+ <label>Enabled</label>
+<!-- input type for configuration value -->
+ <frontend_type>select</frontend_type>
+<!-- model to take the option values from -->
+ <source_model>adminhtml/system_config_source_yesno</source_model>
+<!-- field position -->
+ <sort_order>1</sort_order>
+<!-- do not show this field in store scope -->
+ <show_in_default>1</show_in_default>
+ <show_in_website>1</show_in_website>
+ <show_in_store>0</show_in_store>
+ </active>
+ <order_status translate="label">
+ <label>New order status</label>
+ <frontend_type>select</frontend_type>
+ <source_model>adminhtml/system_config_source_order_status_processing</source_model>
+ <sort_order>4</sort_order>
+ <show_in_default>1</show_in_default>
+ <show_in_website>1</show_in_website>
+ <show_in_store>0</show_in_store>
+ </order_status>
+ <title translate="label">
+ <label>Title</label>
+ <frontend_type>text</frontend_type>
+ <sort_order>2</sort_order>
+ <show_in_default>1</show_in_default>
+ <show_in_website>1</show_in_website>
+ <show_in_store>0</show_in_store>
+ </title>
+ <rpcurl translate="label">
+ <label>RPC Url</label>
+ <frontend_type>text</frontend_type>
+ <sort_order>3</sort_order>
+ <show_in_default>1</show_in_default>
+ <show_in_website>1</show_in_website>
+ <show_in_store>0</show_in_store>
+ </rpcurl>
+ </fields>
+ </paycoin>
+ </groups>
+ </payment>
+ </sections>
+</config>
7 public_html/app/design/frontend/base/default/template/paycoin/form.phtml
@@ -0,0 +1,7 @@
+<div id="">
+<h3>Bitcoin Paycoin Checkout</h3>
+<div>
+ <p>Your payment address is: <?php echo $this->address; ?></p>
+
+</div>
+</div>
Please sign in to comment.
Something went wrong with that request. Please try again.