ChainPay - Version 1.1.1

Version Notes

Stable release of Bitcoin payment gateway software with ChainPay.

1.1.1: Fixed cancel button uri.

Download this release

Release Info

Developer James Carter
Extension ChainPay
Version 1.1.1
Comparing to
See all releases


Code changes from version 1.1.0 to 1.1.1

app/code/community/ChainPay/Payments/Model/PaymentMethod.php CHANGED
@@ -50,6 +50,7 @@ class ChainPay_Payments_Model_PaymentMethod extends Mage_Payment_Model_Method_Ab
50
 
51
  private function CreateInvoice($order, $amount)
52
  {
 
53
  $forwardOnPaidUri = \Mage::getUrl(\Mage::getStoreConfig('payment/chainpay/forwardonpaiduri'));
54
  $callbackUri = \Mage::getUrl(\Mage::getStoreConfig('payment/chainpay/callbackuri'));
55
 
@@ -58,7 +59,7 @@ class ChainPay_Payments_Model_PaymentMethod extends Mage_Payment_Model_Method_Ab
58
  'RequestCurrency' => $order->getBaseCurrencyCode(),
59
  'RequestAmount' => (float) $amount,
60
  'ForwardOnPaidUri' => $forwardOnPaidUri,
61
- 'ForwardOnCancelUri' => 'http://cancel',
62
  'CallbackUri' => $callbackUri
63
  );
64
 
@@ -149,4 +150,4 @@ class ChainPay_Payments_Model_PaymentMethod extends Mage_Payment_Model_Method_Ab
149
  return $response;
150
  }
151
  }
152
- ?>
50
 
51
  private function CreateInvoice($order, $amount)
52
  {
53
+ $forwardOnCancelUri = \Mage::getUrl('');
54
  $forwardOnPaidUri = \Mage::getUrl(\Mage::getStoreConfig('payment/chainpay/forwardonpaiduri'));
55
  $callbackUri = \Mage::getUrl(\Mage::getStoreConfig('payment/chainpay/callbackuri'));
56
 
59
  'RequestCurrency' => $order->getBaseCurrencyCode(),
60
  'RequestAmount' => (float) $amount,
61
  'ForwardOnPaidUri' => $forwardOnPaidUri,
62
+ 'ForwardOnCancelUri' => $forwardOnCancelUri,
63
  'CallbackUri' => $callbackUri
64
  );
65
 
150
  return $response;
151
  }
152
  }
153
+ ?>
app/code/community/ChainPay/Payments/Model/PaymentMethod.php~ ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class ChainPay_Payments_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstract
4
+ {
5
+ protected $_code = 'chainpay';
6
+ protected $_isGateway = true;
7
+ protected $_canAuthorize = true;
8
+ protected $_canCapture = false;
9
+ protected $_canUseInternal = false;
10
+ protected $_isInitializeNeeded = false;
11
+ protected $_canFetchTransactionInfo = false;
12
+ protected $_canManagerRecurringProfiles = false;
13
+ protected $_canUseCheckout = true;
14
+ protected $_canUseForMultishipping = true;
15
+ protected $_canCapturePartial = false;
16
+ protected $_canRefund = false;
17
+ protected $_canVoid = false;
18
+ protected static $_redirectUrl;
19
+
20
+ public function createFormBlock($name)
21
+ {
22
+ $block = $this->getLayout()->createBlock('chainpay/form_chainpay', $name)
23
+ ->setMethod('chainpay')
24
+ ->setPayment($this->getPayment())
25
+ ->setTemplate('chainpay/formBlock.phtml');
26
+
27
+ return $block;
28
+ }
29
+
30
+ public function authorize(Varien_Object $payment, $amount)
31
+ {
32
+ if (false === isset($payment) || false === isset($amount) || true === empty($payment) || true === empty($amount)) {
33
+ $this->debugData('[ERROR] In ChainPay_Payments_Model_PaymentMethod::authorize(): missing payment or amount parameters.');
34
+ throw new \Exception('In ChainPay_Payments_Model_PaymentMethod::authorize(): missing payment or amount parameters.');
35
+ }
36
+
37
+ $order = $payment->getOrder();
38
+
39
+ $invoice = $this->CreateInvoice($order, $amount);
40
+
41
+ self::$_redirectUrl = $this->GetPaymentUri($invoice->Id);
42
+
43
+ return $this;
44
+ }
45
+
46
+ public function getOrderPlaceRedirectUrl()
47
+ {
48
+ return self::$_redirectUrl;
49
+ }
50
+
51
+ private function CreateInvoice($order, $amount)
52
+ {
53
+ $forwardOnCancelUri = \Mage::getUrl('/');
54
+ $forwardOnPaidUri = \Mage::getUrl(\Mage::getStoreConfig('payment/chainpay/forwardonpaiduri'));
55
+ $callbackUri = \Mage::getUrl(\Mage::getStoreConfig('payment/chainpay/callbackuri'));
56
+
57
+ $params = array(
58
+ 'Reference' => $order->getIncrementId(),
59
+ 'RequestCurrency' => $order->getBaseCurrencyCode(),
60
+ 'RequestAmount' => (float) $amount,
61
+ 'ForwardOnPaidUri' => $forwardOnPaidUri,
62
+ 'ForwardOnCancelUri' => $forwardOnCancelUri,
63
+ 'CallbackUri' => $callbackUri
64
+ );
65
+
66
+ $invoice = $this->ChainPay_Post($params, 'invoice');
67
+
68
+ if(!$invoice)
69
+ {
70
+ $this->debugData('In ChainPay_Payments_Model_PaymentMethod::CreateInvoice(): Could not create Invoice.');
71
+ throw new \Exception('In ChainPay_Payments_Model_PaymentMethod::CreateInvoice(): Could not create Invoice.');
72
+ }
73
+
74
+ return $invoice;
75
+ }
76
+
77
+ private function ChainPay_Post($params, $relativeUri)
78
+ {
79
+ $options = array(
80
+ 'http' => array(
81
+ 'method' => 'POST',
82
+ 'content' => json_encode( $params ),
83
+ 'header'=> "Content-Type: application/json\r\n" .
84
+ "Accept: application/json\r\n" .
85
+ "Authorization: " . \Mage::getStoreConfig('payment/chainpay/apikey') . "\r\n"
86
+ )
87
+ );
88
+
89
+ $absoluteUri = $this->GetApiUri() . $relativeUri . '.json';
90
+ $context = stream_context_create($options);
91
+ $result = file_get_contents($absoluteUri, false, $context);
92
+
93
+ if (strpos($http_response_header[0], '200') !== FALSE) {
94
+ $chainPayResult = $this->ChainPay_DecodeResponse($result);
95
+ if($chainPayResult)
96
+ {
97
+ $this->debugData('Successful call to ChainPay API: ' . $absoluteUri);
98
+ return $chainPayResult;
99
+ }
100
+
101
+ $this->debugData('Could not deserialize response: ' . $response);
102
+ }
103
+ else {
104
+ if(strpos($http_response_header[0], '401') !== FALSE)
105
+ {
106
+ $this->debugData('Unauthorized: Called ChainPay with invalid API Key. Please check your API Key in the Payment Method settings.');
107
+ }
108
+ else
109
+ {
110
+ $this->debugData('Error returned from ChainPay API. Called URI: ' . $absoluteUri
111
+ . '"\r\nWith data: ' . json_encode($params)
112
+ . '\r\nResponse:' . $response);
113
+ }
114
+ }
115
+
116
+ return false;
117
+ }
118
+
119
+ private function GetApiUri() {
120
+ if(\Mage::getStoreConfig('payment/chainpay/sandbox'))
121
+ {
122
+ return 'https://testapi.altxe.com/';
123
+ }
124
+ else
125
+ {
126
+ return 'https://api.altxe.com/';
127
+ }
128
+ }
129
+
130
+ private function GetPaymentUri($invoiceId) {
131
+ if(\Mage::getStoreConfig('payment/chainpay/sandbox'))
132
+ {
133
+ return 'https://testpay.chainpay.com/invoice?id=' . $invoiceId;
134
+ }
135
+ else
136
+ {
137
+ return 'https://pay.chainpay.com/invoice?id=' . $invoiceId;
138
+ }
139
+ }
140
+
141
+ private function ChainPay_DecodeResponse($data)
142
+ {
143
+ $response = json_decode( $data );
144
+ // Verify response is a JSON encoded object.
145
+ if( ! is_object( $response ) ) {
146
+ // Could not decode response.
147
+ return false;
148
+ }
149
+
150
+ return $response;
151
+ }
152
+ }
153
+ ?>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>ChainPay</name>
4
- <version>1.1.0</version>
5
  <stability>stable</stability>
6
  <license>MITL</license>
7
  <channel>community</channel>
@@ -14,11 +14,13 @@ Bitcoin is a digital currency that millions of customers around the world are us
14
  After creating a ChainPay account, you can either withdraw your Bitcoin, or configure ChainPay to convert received Bitcoin into your native currency to be paid straight to your bank account.&#xD;
15
  &#xD;
16
  This means you get a lower charge compared to credit card processing, and your customers do not have to deliver credit card details. </description>
17
- <notes>Stable release of Bitcoin payment gateway software with ChainPay.</notes>
 
 
18
  <authors><author><name>James Carter</name><user>jcarter</user><email>james.carter@altxe.com</email></author></authors>
19
- <date>2015-04-26</date>
20
- <time>13:00:41</time>
21
- <contents><target name="magecommunity"><dir name="ChainPay"><dir name="Payments"><dir name="Block"><dir name="Form"><file name="chainpay.php" hash="46115edc3043e06422ebea76a455cdba"/></dir><file name="Info.php" hash="fc1b37d33a0e30a6ff5c7e8774392b03"/></dir><dir name="Helper"><file name="Data.php" hash="8a81facde74a6686558dcefb88fa36bd"/></dir><dir name="Model"><file name="PaymentMethod.php" hash="5609dee2518b1981a5c48ebfd6c3fb13"/></dir><dir name="controllers"><file name="CallbackController.php" hash="93ead30dde94e249719d602d2685dd12"/></dir><dir name="etc"><file name="config.xml" hash="407007cc4a001767dcac2e2960815945"/><file name="system.xml" hash="821dbcc6815e5314a1ec3fa643335638"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="ChainPay_Payments.xml" hash="bfbd31237ee80079a97df5b48cf365dc"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="chainpay"><file name="formBlock.phtml" hash="2fcfc7b65738536aa22169f7676fd389"/></dir></dir><dir name="layout"><file name="chainpay.xml" hash="ddf806ffbea95d30848d2649d62eab2f"/></dir></dir></dir></dir></target></contents>
22
  <compatible/>
23
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
24
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>ChainPay</name>
4
+ <version>1.1.1</version>
5
  <stability>stable</stability>
6
  <license>MITL</license>
7
  <channel>community</channel>
14
  After creating a ChainPay account, you can either withdraw your Bitcoin, or configure ChainPay to convert received Bitcoin into your native currency to be paid straight to your bank account.&#xD;
15
  &#xD;
16
  This means you get a lower charge compared to credit card processing, and your customers do not have to deliver credit card details. </description>
17
+ <notes>Stable release of Bitcoin payment gateway software with ChainPay.&#xD;
18
+ &#xD;
19
+ 1.1.1: Fixed cancel button uri.</notes>
20
  <authors><author><name>James Carter</name><user>jcarter</user><email>james.carter@altxe.com</email></author></authors>
21
+ <date>2015-05-12</date>
22
+ <time>17:34:02</time>
23
+ <contents><target name="magecommunity"><dir name="ChainPay"><dir name="Payments"><dir name="Block"><dir name="Form"><file name="chainpay.php" hash="46115edc3043e06422ebea76a455cdba"/></dir><file name="Info.php" hash="fc1b37d33a0e30a6ff5c7e8774392b03"/></dir><dir name="Helper"><file name="Data.php" hash="8a81facde74a6686558dcefb88fa36bd"/></dir><dir name="Model"><file name="PaymentMethod.php" hash="6a19036cb5b549c3acb92a860798b4c3"/><file name="PaymentMethod.php~" hash="77b0340e8a7eaf9a858393ac90db34a6"/></dir><dir name="controllers"><file name="CallbackController.php" hash="93ead30dde94e249719d602d2685dd12"/></dir><dir name="etc"><file name="config.xml" hash="407007cc4a001767dcac2e2960815945"/><file name="system.xml" hash="821dbcc6815e5314a1ec3fa643335638"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="ChainPay_Payments.xml" hash="bfbd31237ee80079a97df5b48cf365dc"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="chainpay"><file name="formBlock.phtml" hash="2fcfc7b65738536aa22169f7676fd389"/></dir></dir><dir name="layout"><file name="chainpay.xml" hash="ddf806ffbea95d30848d2649d62eab2f"/></dir></dir></dir></dir></target></contents>
24
  <compatible/>
25
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
26
  </package>