Version Notes
* Update CoinGate PHP Merchant Class to 1.0.2
* Set Extension User Agent
Download this release
Release Info
Developer | CoinGate |
Extension | CoinGate_For_Magento |
Version | 1.0.1 |
Comparing to | |
See all releases |
Code changes from version 1.0.0 to 1.0.1
- app/code/community/Mage/Coingate/.DS_Store +0 -0
- app/code/community/Mage/Coingate/Block/Callback.php +12 -0
- app/code/community/Mage/Coingate/Block/Form.php +11 -0
- app/code/community/Mage/Coingate/Block/Redirect.php +75 -0
- app/code/community/Mage/Coingate/Model/CoingateFactory.php +115 -0
- app/code/community/Mage/Coingate/Model/ReceiveCurrencies.php +13 -0
- app/code/community/Mage/Coingate/controllers/PayController.php +58 -0
- app/code/community/Mage/Coingate/etc/config.xml +66 -0
- app/code/community/Mage/Coingate/etc/system.xml +85 -0
- app/code/community/Mage/Coingate/lib/coingate_merchant.class.php +104 -0
- app/etc/modules/Mage_Coingate.xml +11 -0
- package.xml +8 -7
app/code/community/Mage/Coingate/.DS_Store
ADDED
Binary file
|
app/code/community/Mage/Coingate/Block/Callback.php
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mage_Coingate_Block_Callback extends Mage_Core_Block_Abstract
|
4 |
+
{
|
5 |
+
protected function _toHtml()
|
6 |
+
{
|
7 |
+
$coingate = Mage::getModel('coingate/CoingateFactory');
|
8 |
+
echo $coingate->validateCallback();
|
9 |
+
|
10 |
+
return $coingate->validateCallback();
|
11 |
+
}
|
12 |
+
}
|
app/code/community/Mage/Coingate/Block/Form.php
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mage_Coingate_Block_Form extends Mage_Payment_Block_Form
|
4 |
+
{
|
5 |
+
protected function _construct()
|
6 |
+
{
|
7 |
+
$this->setTemplate('coingate/form.phtml');
|
8 |
+
|
9 |
+
parent::_construct();
|
10 |
+
}
|
11 |
+
}
|
app/code/community/Mage/Coingate/Block/Redirect.php
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Magento
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* DISCLAIMER
|
17 |
+
*
|
18 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
19 |
+
* versions in the future. If you wish to customize Magento for your
|
20 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
21 |
+
*
|
22 |
+
* @category Mage
|
23 |
+
* @package Mage_Paypal
|
24 |
+
* @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
class Mage_Coingate_Block_Redirect extends Mage_Core_Block_Abstract
|
28 |
+
{
|
29 |
+
protected $_formBlockType = 'coingate/form';
|
30 |
+
|
31 |
+
protected function _toHtml()
|
32 |
+
{
|
33 |
+
$coingate = Mage::getModel('coingate/PaymentMethod');
|
34 |
+
|
35 |
+
//$mok_bud = $info->getAdditionalInformation('mok_bud');
|
36 |
+
|
37 |
+
$form = new Varien_Data_Form();
|
38 |
+
$form->setAction($coingate->getPayURL())
|
39 |
+
->setId('coingate_checkout')
|
40 |
+
->setName('coingate_checkout')
|
41 |
+
->setMethod('POST')
|
42 |
+
->setUseContainer(true);
|
43 |
+
foreach ($coingate->getRequest() as $field => $value) {
|
44 |
+
$form->addField($field, 'hidden', array('name' => $field, 'value' => $value));
|
45 |
+
}
|
46 |
+
$html = '<html><head>';
|
47 |
+
$html .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
|
48 |
+
$html .= '</head><body>';
|
49 |
+
$html .= $this->__('...');
|
50 |
+
$html .= $form->toHtml();
|
51 |
+
$html .= '<script type="text/javascript">document.getElementById("coingate_checkout").submit();</script>';
|
52 |
+
$html .= '</body></html>';
|
53 |
+
|
54 |
+
return $html;
|
55 |
+
|
56 |
+
$coingate = Mage::getModel('coingate/CoingateFactory');
|
57 |
+
$form = new Varien_Data_Form();
|
58 |
+
$form->setAction($tco->getUrl())
|
59 |
+
->setId('pay')
|
60 |
+
->setName('pay')
|
61 |
+
->setMethod('POST')
|
62 |
+
->setUseContainer(true);
|
63 |
+
$tco->getFormFields();
|
64 |
+
foreach ($tco->getFormFields() as $field=>$value) {
|
65 |
+
$form->addField($field, 'hidden', array('name'=>$field, 'value'=>$value));
|
66 |
+
}
|
67 |
+
$html = '<html><body>';
|
68 |
+
$html.= $tco->getRedirectMessage();
|
69 |
+
$html.= $form->toHtml();
|
70 |
+
$html.= $this->__('Please wait while we redirect you to payment');
|
71 |
+
$html.= '<script type="text/javascript">document.getElementById("pay").submit();</script>';
|
72 |
+
$html.= '</body></html>';
|
73 |
+
return $html;
|
74 |
+
}
|
75 |
+
}
|
app/code/community/Mage/Coingate/Model/CoingateFactory.php
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once(Mage::getBaseDir() . '/app/code/community/Mage/Coingate/lib/coingate_merchant.class.php');
|
4 |
+
|
5 |
+
define('COINGATE_MAGENTO_VERSION', '1.0.1');
|
6 |
+
|
7 |
+
class Mage_Coingate_Model_CoingateFactory extends Mage_Payment_Model_Method_Abstract
|
8 |
+
{
|
9 |
+
protected $_isGateway = TRUE;
|
10 |
+
protected $_canAuthorize = TRUE;
|
11 |
+
|
12 |
+
protected $_code = 'coingate';
|
13 |
+
|
14 |
+
public function getOrderPlaceRedirectUrl()
|
15 |
+
{
|
16 |
+
return Mage::getUrl('coingate/pay/redirect');
|
17 |
+
}
|
18 |
+
|
19 |
+
public function getRequest()
|
20 |
+
{
|
21 |
+
$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
|
22 |
+
|
23 |
+
$token = substr(md5(rand()), 0, 32);
|
24 |
+
|
25 |
+
$payment = $order->getPayment();
|
26 |
+
$payment->setAdditionalInformation('coingate_order_token', $token);
|
27 |
+
$payment->save();
|
28 |
+
|
29 |
+
$title = Mage::app()->getWebsite()->getName();
|
30 |
+
|
31 |
+
$description = array();
|
32 |
+
|
33 |
+
foreach ($order->getAllItems() as $item) {
|
34 |
+
$description[] = number_format($item->getQtyOrdered(), 0) . ' × ' . $item->getName();
|
35 |
+
}
|
36 |
+
|
37 |
+
$cgConfig = Mage::getStoreConfig('payment/coingate');
|
38 |
+
|
39 |
+
$coingate = $this->initCoingateMerchantClass($cgConfig);
|
40 |
+
|
41 |
+
$coingate->create_order(array(
|
42 |
+
'order_id' => $order->increment_id,
|
43 |
+
'price' => number_format($order->grand_total, 2, '.', ''),
|
44 |
+
'currency' => $order->order_currency_code,
|
45 |
+
'receive_currency' => $cgConfig['receive_currency'],
|
46 |
+
'success_url' => Mage::getUrl('coingate/pay/success'),
|
47 |
+
'cancel_url' => Mage::getUrl('coingate/pay/cancel'),
|
48 |
+
'callback_url' => Mage::getUrl('coingate/pay/callback') . '?token=' . $token,
|
49 |
+
'title' => $title . ' Order #' . $order->increment_id,
|
50 |
+
'description' => join($description, ', ')
|
51 |
+
));
|
52 |
+
|
53 |
+
if ($coingate->success) {
|
54 |
+
$coingate_response = json_decode($coingate->response, TRUE);
|
55 |
+
|
56 |
+
return $coingate_response['payment_url'];
|
57 |
+
}
|
58 |
+
|
59 |
+
return FALSE;
|
60 |
+
}
|
61 |
+
|
62 |
+
public function validateCallback()
|
63 |
+
{
|
64 |
+
try {
|
65 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($_REQUEST['order_id']);
|
66 |
+
|
67 |
+
if (!$order || !$order->increment_id)
|
68 |
+
throw new Exception('Order #' . $_REQUEST['order_id'] . ' does not exists');
|
69 |
+
|
70 |
+
$payment = $order->getPayment();
|
71 |
+
$token = $payment->getAdditionalInformation('coingate_order_token');
|
72 |
+
|
73 |
+
if ($token == '' || $_GET['token'] != $token)
|
74 |
+
throw new Exception('Token: 1:' . $_GET['token'] . ' : 2:' . $token . ' do not match');
|
75 |
+
|
76 |
+
$cgConfig = Mage::getStoreConfig('payment/coingate');
|
77 |
+
|
78 |
+
$coingate = $this->initCoingateMerchantClass($cgConfig);
|
79 |
+
|
80 |
+
$coingate->get_order($_REQUEST['id']);
|
81 |
+
|
82 |
+
if (!$coingate->success)
|
83 |
+
throw new Exception('CoinGate Order #' . $order->increment_id . ' does not exists');
|
84 |
+
|
85 |
+
$coingate_response = json_decode($coingate->response, TRUE);
|
86 |
+
|
87 |
+
if (!is_array($coingate_response))
|
88 |
+
throw new Exception('Something wrong with callback');
|
89 |
+
|
90 |
+
if ($coingate_response['status'] == 'paid') {
|
91 |
+
$order->sendNewOrderEmail()
|
92 |
+
->setState(Mage_Sales_Model_Order::STATE_PROCESSING, TRUE)
|
93 |
+
->save();
|
94 |
+
} elseif (in_array($coingate_response['status'], array('invalid', 'expired', 'canceled'))) {
|
95 |
+
$order->sendNewOrderEmail()
|
96 |
+
->setState(Mage_Sales_Model_Order::STATE_CANCELED, TRUE)
|
97 |
+
->save();
|
98 |
+
}
|
99 |
+
} catch (Exception $e) {
|
100 |
+
echo get_class($e) . ': ' . $e->getMessage();
|
101 |
+
}
|
102 |
+
}
|
103 |
+
|
104 |
+
private function initCoingateMerchantClass($cgConfig) {
|
105 |
+
return new CoingateMerchant(
|
106 |
+
array(
|
107 |
+
'app_id' => $cgConfig['app_id'],
|
108 |
+
'api_key' => $cgConfig['api_key'],
|
109 |
+
'api_secret' => $cgConfig['api_secret'],
|
110 |
+
'mode' => $cgConfig['test'] == '1' ? 'sandbox' : 'live',
|
111 |
+
'user_agent' => 'CoinGate - Magento Extension v' . COINGATE_MAGENTO_VERSION
|
112 |
+
)
|
113 |
+
);
|
114 |
+
}
|
115 |
+
}
|
app/code/community/Mage/Coingate/Model/ReceiveCurrencies.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mage_Coingate_Model_ReceiveCurrencies
|
4 |
+
{
|
5 |
+
public function toOptionArray()
|
6 |
+
{
|
7 |
+
return array(
|
8 |
+
array('value' => 'eur', 'label' => 'Euros (€)'),
|
9 |
+
array('value' => 'usd', 'label' => 'US Dollars ($)'),
|
10 |
+
array('value' => 'btc', 'label' => 'Bitcoin (฿)'),
|
11 |
+
);
|
12 |
+
}
|
13 |
+
}
|
app/code/community/Mage/Coingate/controllers/PayController.php
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mage_Coingate_PayController extends Mage_Core_Controller_Front_Action
|
4 |
+
{
|
5 |
+
|
6 |
+
public function getCheckout()
|
7 |
+
{
|
8 |
+
return Mage::getSingleton('checkout/session');
|
9 |
+
}
|
10 |
+
|
11 |
+
public function getQuote()
|
12 |
+
{
|
13 |
+
return $this->getCheckout()->getQuote();
|
14 |
+
}
|
15 |
+
|
16 |
+
public function redirectAction()
|
17 |
+
{
|
18 |
+
$session = Mage::getSingleton('checkout/session');
|
19 |
+
$session->setPayQuoteId($session->getQuoteId());
|
20 |
+
$session->unsQuoteId();
|
21 |
+
|
22 |
+
$coingate = Mage::getModel('coingate/CoingateFactory');
|
23 |
+
|
24 |
+
$this->_redirectUrl($coingate->getRequest());
|
25 |
+
}
|
26 |
+
|
27 |
+
public function callbackAction()
|
28 |
+
{
|
29 |
+
$this->getResponse()->setBody($this->getLayout()->createBlock('coingate/callback')->toHtml());
|
30 |
+
}
|
31 |
+
|
32 |
+
public function cancelAction()
|
33 |
+
{
|
34 |
+
$session = Mage::getSingleton('checkout/session');
|
35 |
+
$session->setQuoteId($session->getPayQuoteId(TRUE));
|
36 |
+
$this->_redirect('checkout/cart');
|
37 |
+
}
|
38 |
+
|
39 |
+
public function successAction()
|
40 |
+
{
|
41 |
+
$session = Mage::getSingleton('checkout/session');
|
42 |
+
$session->setQuoteId($session->getPayQuoteId(TRUE));
|
43 |
+
Mage::getSingleton('checkout/session')->getQuote()->setIsActive(FALSE)->save();
|
44 |
+
$this->_redirect('checkout/onepage/success', array('_secure' => TRUE));
|
45 |
+
}
|
46 |
+
|
47 |
+
public function failAction()
|
48 |
+
{
|
49 |
+
$order = Mage::getModel('sales/order');
|
50 |
+
$order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
|
51 |
+
|
52 |
+
if ($order->getId()) {
|
53 |
+
$order->setStatus('canceled')->save();
|
54 |
+
}
|
55 |
+
|
56 |
+
$this->_redirect('checkout/onepage/failure');
|
57 |
+
}
|
58 |
+
}
|
app/code/community/Mage/Coingate/etc/config.xml
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Mage_Coingate>
|
5 |
+
<version>1.0.1</version>
|
6 |
+
</Mage_Coingate>
|
7 |
+
</modules>
|
8 |
+
|
9 |
+
<global>
|
10 |
+
<blocks>
|
11 |
+
<coingate>
|
12 |
+
<class>Mage_Coingate_Block</class>
|
13 |
+
</coingate>
|
14 |
+
</blocks>
|
15 |
+
<models>
|
16 |
+
<coingate>
|
17 |
+
<class>Mage_Coingate_Model</class>
|
18 |
+
</coingate>
|
19 |
+
</models>
|
20 |
+
<resources>
|
21 |
+
<coingate_setup>
|
22 |
+
<setup>
|
23 |
+
<module>Mage_Coingate</module>
|
24 |
+
</setup>
|
25 |
+
<connection>
|
26 |
+
<use>core_setup</use>
|
27 |
+
</connection>
|
28 |
+
</coingate_setup>
|
29 |
+
<coingate_write>
|
30 |
+
<connection>
|
31 |
+
<use>core_write</use>
|
32 |
+
</connection>
|
33 |
+
</coingate_write>
|
34 |
+
<coingate_read>
|
35 |
+
<connection>
|
36 |
+
<use>core_read</use>
|
37 |
+
</connection>
|
38 |
+
</coingate_read>
|
39 |
+
</resources>
|
40 |
+
</global>
|
41 |
+
<frontend>
|
42 |
+
<routers>
|
43 |
+
<coingate>
|
44 |
+
<use>standard</use>
|
45 |
+
<args>
|
46 |
+
<module>Mage_Coingate</module>
|
47 |
+
<frontName>coingate</frontName>
|
48 |
+
</args>
|
49 |
+
</coingate>
|
50 |
+
</routers>
|
51 |
+
</frontend>
|
52 |
+
<default>
|
53 |
+
<payment>
|
54 |
+
<coingate>
|
55 |
+
<active>0</active>
|
56 |
+
<model>coingate/coingateFactory</model>
|
57 |
+
<app_id>Your APP ID</app_id>
|
58 |
+
<api_key>Your API Key</api_key>
|
59 |
+
<api_secret>Your API Secret</api_secret>
|
60 |
+
<test>0</test>
|
61 |
+
<title>Bitcoin</title>
|
62 |
+
<desc>Pay with Bitcoin via CoinGate</desc>
|
63 |
+
</coingate>
|
64 |
+
</payment>
|
65 |
+
</default>
|
66 |
+
</config>
|
app/code/community/Mage/Coingate/etc/system.xml
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<sections>
|
4 |
+
<payment>
|
5 |
+
<groups>
|
6 |
+
<coingate translate="label" module="paygate">
|
7 |
+
<label>Bitcoin via CoinGate.com</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 |
+
<desc translate="label">
|
31 |
+
<label>Description</label>
|
32 |
+
<frontend_type>text</frontend_type>
|
33 |
+
<sort_order>3</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 |
+
</desc>
|
38 |
+
<app_id translate="label">
|
39 |
+
<label>App ID</label>
|
40 |
+
<frontend_type>text</frontend_type>
|
41 |
+
<sort_order>4</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 |
+
</app_id>
|
46 |
+
<api_key translate="label">
|
47 |
+
<label>API Key</label>
|
48 |
+
<frontend_type>text</frontend_type>
|
49 |
+
<sort_order>5</sort_order>
|
50 |
+
<show_in_default>1</show_in_default>
|
51 |
+
<show_in_website>1</show_in_website>
|
52 |
+
<show_in_store>0</show_in_store>
|
53 |
+
</api_key>
|
54 |
+
<api_secret translate="label">
|
55 |
+
<label>API Secret</label>
|
56 |
+
<frontend_type>text</frontend_type>
|
57 |
+
<sort_order>6</sort_order>
|
58 |
+
<show_in_default>1</show_in_default>
|
59 |
+
<show_in_website>1</show_in_website>
|
60 |
+
<show_in_store>0</show_in_store>
|
61 |
+
</api_secret>
|
62 |
+
<receive_currency translate="label">
|
63 |
+
<label>Currency you want to receive</label>
|
64 |
+
<frontend_type>select</frontend_type>
|
65 |
+
<source_model>coingate/receiveCurrencies</source_model>
|
66 |
+
<sort_order>7</sort_order>
|
67 |
+
<show_in_default>1</show_in_default>
|
68 |
+
<show_in_website>1</show_in_website>
|
69 |
+
<show_in_store>0</show_in_store>
|
70 |
+
</receive_currency>
|
71 |
+
<test translate="label">
|
72 |
+
<label>Test mode?</label>
|
73 |
+
<frontend_type>select</frontend_type>
|
74 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
75 |
+
<sort_order>8</sort_order>
|
76 |
+
<show_in_default>1</show_in_default>
|
77 |
+
<show_in_website>1</show_in_website>
|
78 |
+
<show_in_store>0</show_in_store>
|
79 |
+
</test>
|
80 |
+
</fields>
|
81 |
+
</coingate>
|
82 |
+
</groups>
|
83 |
+
</payment>
|
84 |
+
</sections>
|
85 |
+
</config>
|
app/code/community/Mage/Coingate/lib/coingate_merchant.class.php
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* PHP CoinGate Merchant Class
|
5 |
+
*
|
6 |
+
* @author CoinGate <info@coingate.com>
|
7 |
+
* @version 1.0.2
|
8 |
+
* @link http://developer.coingate.com
|
9 |
+
* @license MIT
|
10 |
+
*/
|
11 |
+
|
12 |
+
define('CLASS_VERSION', '1.0.2');
|
13 |
+
|
14 |
+
class CoingateMerchant {
|
15 |
+
private $app_id = '';
|
16 |
+
private $api_key = '';
|
17 |
+
private $api_secret = '';
|
18 |
+
private $mode = 'sandbox'; // live or sandbox
|
19 |
+
private $version = 'v1';
|
20 |
+
private $api_url = '';
|
21 |
+
private $user_agent = '';
|
22 |
+
private $user_agent_origin = 'CoinGate PHP Merchant Class';
|
23 |
+
|
24 |
+
public function __construct($options = array())
|
25 |
+
{
|
26 |
+
foreach($options as $key => $value)
|
27 |
+
{
|
28 |
+
if (in_array($key, array('app_id', 'api_key', 'api_secret', 'mode', 'user_agent')))
|
29 |
+
{
|
30 |
+
$this->$key = trim($value);
|
31 |
+
}
|
32 |
+
|
33 |
+
if (empty($this->user_agent)) {
|
34 |
+
$this->user_agent = $this->user_agent_origin . ' v' . CLASS_VERSION;
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
$this->set_api_url();
|
39 |
+
}
|
40 |
+
|
41 |
+
public function create_order($params = array())
|
42 |
+
{
|
43 |
+
$this->request('/orders', 'POST', $params);
|
44 |
+
}
|
45 |
+
|
46 |
+
public function get_order($order_id)
|
47 |
+
{
|
48 |
+
$this->request('/orders/' . $order_id);
|
49 |
+
}
|
50 |
+
|
51 |
+
public function request($url, $method = 'GET', $params = array())
|
52 |
+
{
|
53 |
+
$url = $this->api_url . $url;
|
54 |
+
$nonce = $this->nonce();
|
55 |
+
$message = $nonce . $this->app_id . $this->api_key;
|
56 |
+
$signature = hash_hmac('sha256', $message, $this->api_secret);
|
57 |
+
|
58 |
+
$headers = array();
|
59 |
+
$headers[] = 'Access-Key: ' . $this->api_key;
|
60 |
+
$headers[] = 'Access-Nonce: ' . $nonce;
|
61 |
+
$headers[] = 'Access-Signature: ' . $signature;
|
62 |
+
|
63 |
+
$curl = curl_init();
|
64 |
+
|
65 |
+
$curl_options = array(
|
66 |
+
CURLOPT_RETURNTRANSFER => 1,
|
67 |
+
CURLOPT_URL => $url
|
68 |
+
);
|
69 |
+
|
70 |
+
if ($method == 'POST')
|
71 |
+
{
|
72 |
+
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
|
73 |
+
|
74 |
+
array_merge($curl_options, array(CURLOPT_POST => 1));
|
75 |
+
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params));
|
76 |
+
}
|
77 |
+
|
78 |
+
curl_setopt_array($curl, $curl_options);
|
79 |
+
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
80 |
+
curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);
|
81 |
+
|
82 |
+
$response = curl_exec($curl);
|
83 |
+
$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
84 |
+
|
85 |
+
curl_close($curl);
|
86 |
+
|
87 |
+
$this->success = $http_status == 200;
|
88 |
+
$this->status_code = $http_status;
|
89 |
+
$this->response = $response;
|
90 |
+
}
|
91 |
+
|
92 |
+
private function nonce()
|
93 |
+
{
|
94 |
+
return time();
|
95 |
+
}
|
96 |
+
|
97 |
+
private function set_api_url()
|
98 |
+
{
|
99 |
+
$this->api_url = strtolower($this->mode) == 'live' ? 'https://coingate.com/api/' : 'https://sandbox.coingate.com/api/';
|
100 |
+
$this->api_url .= $this->version;
|
101 |
+
}
|
102 |
+
}
|
103 |
+
|
104 |
+
?>
|
app/etc/modules/Mage_Coingate.xml
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<config>
|
2 |
+
<modules>
|
3 |
+
<Mage_Coingate>
|
4 |
+
<active>true</active>
|
5 |
+
<codePool>community</codePool>
|
6 |
+
<depends>
|
7 |
+
<Mage_Payment/>
|
8 |
+
</depends>
|
9 |
+
</Mage_Coingate>
|
10 |
+
</modules>
|
11 |
+
</config>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>CoinGate_For_Magento</name>
|
4 |
-
<version>1.0.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="https://github.com/coingate/magento-plugin/blob/master/LICENSE.md">MIT</license>
|
7 |
<channel>community</channel>
|
@@ -10,11 +10,12 @@
|
|
10 |
<description>Bitcoin is an innovative payment network and a new kind of money. It uses peer-to-peer technology to operate with no central authority or banks. Bitcoin is open-source; its design is public, nobody owns or controls Bitcoin and everyone can take part.
|
11 |

|
12 |
CoinGate is a bitcoin payment processor, which allows businesses to receive payments in euros and US dollars through the Bitcoin payment network, seamlessly connecting innovations of Bitcoin with comfort of familiar currencies and user-friendly interface.</description>
|
13 |
-
<notes
|
14 |
-
|
15 |
-
<
|
16 |
-
<
|
17 |
-
<
|
|
|
18 |
<compatible/>
|
19 |
-
<dependencies><required><php><min>5.
|
20 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>CoinGate_For_Magento</name>
|
4 |
+
<version>1.0.1</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="https://github.com/coingate/magento-plugin/blob/master/LICENSE.md">MIT</license>
|
7 |
<channel>community</channel>
|
10 |
<description>Bitcoin is an innovative payment network and a new kind of money. It uses peer-to-peer technology to operate with no central authority or banks. Bitcoin is open-source; its design is public, nobody owns or controls Bitcoin and everyone can take part.
|
11 |

|
12 |
CoinGate is a bitcoin payment processor, which allows businesses to receive payments in euros and US dollars through the Bitcoin payment network, seamlessly connecting innovations of Bitcoin with comfort of familiar currencies and user-friendly interface.</description>
|
13 |
+
<notes>* Update CoinGate PHP Merchant Class to 1.0.2
|
14 |
+
* Set Extension User Agent</notes>
|
15 |
+
<authors><author><name>CoinGate Team</name><user>CoinGate</user><email>info@coingate.com</email></author></authors>
|
16 |
+
<date>2015-07-24</date>
|
17 |
+
<time>13:21:32</time>
|
18 |
+
<contents><target name="magecommunity"><dir name="Mage"><dir name="Coingate"><dir name="Block"><file name="Callback.php" hash="0845222d4c5ce4457aab3eb14282ff8d"/><file name="Form.php" hash="ab93f50ac62fab7b986ccfe4732d63e4"/><file name="Redirect.php" hash="21b349e960636fd441b35d42facaf17d"/></dir><dir name="Model"><file name="CoingateFactory.php" hash="ba2676c3d712daba29cbbc8eb8b5393f"/><file name="ReceiveCurrencies.php" hash="94f7f39c759012b8e75ec8e6846cae5f"/></dir><dir name="controllers"><file name="PayController.php" hash="ffe09d0ff067e5247351990255d0c472"/></dir><dir name="etc"><file name="config.xml" hash="3c624a614d6d26fa7c77a91935da2512"/><file name="system.xml" hash="4b1348918fc79e11c9ea691ad8c09e4a"/></dir><dir name="lib"><file name="coingate_merchant.class.php" hash="a4be2b9580ecb4b6c5d2f89bcee8971f"/></dir><file name=".DS_Store" hash="1f14b8e5d4ef517cd3236642604885b0"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mage_Coingate.xml" hash="cc8a4080d714fd0c50eadf91a77be49c"/></dir></target></contents>
|
19 |
<compatible/>
|
20 |
+
<dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php><package><name>curl</name><channel>connect.magentocommerce.com/core</channel><min>7.37.1</min><max></max></package></required></dependencies>
|
21 |
</package>
|