-
Notifications
You must be signed in to change notification settings - Fork 1
/
wcp-crypto-gateway-fair.php
175 lines (153 loc) · 6.88 KB
/
wcp-crypto-gateway-fair.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
// Exit if accessed directly
defined('ABSPATH') || die('Access Restricted!');
/*
* FairCoin payment gateway
*/
class WCP_FairCoin_FAIR extends WCP_Crypto
{
// -------------------------------------------------------------------
/**
* Constructor for the gateway.
*
* @access public
* @return void
*/
public function __construct()
{
parent::__construct();
}
public function get_payment_method_title()
{
return __('FairCoin', 'WCP_I18N_DOMAIN');
}
public function get_gateway_id()
{
return 'faircoin_' . strtolower($this->get_crypto_symbol());
}
public function get_settings_name()
{
return WCP_FAIR_SETTINGS;
}
public function get_crypto_symbol()
{
return 'fair';
}
public function get_icon_dir()
{
return '/images/checkout-icons/' . strtolower($this->get_crypto_symbol()) . '/';
}
public function get_electrum_util()
{
$get_mpk = esc_attr(get_option(WCP_FAIR_SETTINGS)['electrum_mpk']);
$get_starting_index = esc_attr(get_option(WCP_FAIR_SETTINGS)['starting_index_for_new_addresses']);
return new ElectrumFAIRUtil($get_mpk, $get_starting_index);
}
public function update_order_metadata($order_id, $ret_info_array)
{
$fair_address = @$ret_info_array['generated_fair_address'];
WCP__log_event(__FILE__, __LINE__, ' Generated unique faircoin ' . $this->get_crypto_symbol() . " address: '{$fair_address}' for order_id " . $order_id);
update_post_meta(
$order_id, // post id ($order_id)
'fair_address', // meta key
$fair_address // meta value. If array - will be auto-serialized
);
}
public function get_payment_instructions_description()
{
$payment_instructions_description = '
<p class="description" style="width:50%;float:left;width:45%;">
' . __('Specific instructions given to the customer to complete Faircoins payment.<br />You may change it, but make sure these tags will be present: <b>{{{FAIRCOINS_AMOUNT}}}</b>, <b>{{{FAIRCOINS_ADDRESS}}}</b>, <b>{{{FAIRCOINS_PAY_URL}}}</b> and <b>{{{EXTRA_INSTRUCTIONS}}}</b> as these tags will be replaced with customer - specific payment details.', 'WCP_I18N_DOMAIN') . '
</p>
<p class="description" style="width:50%;float:right;width:50%;">
' . __('Payment Instructions, original template (for reference):<br />', 'WCP_I18N_DOMAIN') . '
<textarea rows="2" onclick="this.focus();this.select()" readonly="readonly" style="width:100%;background-color:#f1f1f1;height:4em">' . $this->default_payment_instructions() . '</textarea>
</p>';
return $payment_instructions_description;
}
public function default_payment_instructions()
{
$payment_instructions = '
<table id="wcp-payment-instructions-table">
<tr>
<td colspan="2">' . __('Please send your Faircoin FAIR payment as follows:', 'WCP_I18N_DOMAIN') . '</td>
</tr>
<tr>
<td class="td-field">
' . __('Amount', 'WCP_I18N_DOMAIN') . ' (<strong>FAIR</strong>):
</td>
<td>
<div class="td-value">
{{{FAIRCOINS_AMOUNT}}}
</div>
</td>
</tr>
<tr>
<td class="td-field">
' . __('FairCoin Address', 'WCP_I18N_DOMAIN') . ':
</td>
<td>
<div class="td-value" id="crypto-address">
{{{FAIRCOINS_ADDRESS}}}
</div>
</td>
</tr>
<tr>
<td class="td-field">
' . __('QR code', 'WCP_I18N_DOMAIN') . ':
</td>
<td>
<div class="td-value">
<a href="{{{FAIRCOINS_PAY_URL}}}"><img src="https://api.qrserver.com/v1/create-qr-code/?color=000000&bgcolor=FFFFFF&data=faircoin%3A{{{FAIRCOINS_ADDRESS}}}%3Famount%3D{{{FAIRCOINS_AMOUNT}}}%26message%3D{{{PAYMENT_MESSAGE_URL_SAFE}}}&qzone=1&margin=0&size=120x120&ecc=L" style="vertical-align:middle;border:1px solid #888;" /></a>
</div>
</td>
</tr>
<tr>
<td class="td-field">
' . __('Status', 'WCP_I18N_DOMAIN') . ':
</td>
<td>
<div class="td-value">
<span id="status-msg">' . __('Waiting for payment...', 'WCP_I18N_DOMAIN') . '</span>
<div id="loader"></div>
<small id="check-time-msg">' . __('Check balance in', 'WCP_I18N_DOMAIN') . ' <span id="check-time">60</span> ' . __('seconds', 'WCP_I18N_DOMAIN') . '</small>
</div>
</td>
</tr>
</table>
' . __('Please note:', 'WCP_I18N_DOMAIN') . '
<ol>
<li>' . __('The payment method chosen ONLY accepts FairCoin! Any other payments (Bitcoin, LiteCoin etc) will not process and the money will be lost forever!', 'WCP_I18N_DOMAIN') . '</li>
<li>' . __('We are not responsible for lost funds if you send anything other than FAIR', 'WCP_I18N_DOMAIN') . '</li>
<li>' . __('You must initiate a payment within 1 hour, or your order may be cancelled', 'WCP_I18N_DOMAIN') . '</li>
<li>' . __('As soon as your payment is received in full you will receive email confirmation with order delivery details.', 'WCP_I18N_DOMAIN') . '</li>
<li>{{{EXTRA_INSTRUCTIONS}}}</li>
</ol>';
return $payment_instructions;
}
public function fill_in_instructions($order, $add_order_note = false)
{
// Assemble detailed instructions.
$order_total_in_fair = get_post_meta($order->get_id(), 'order_total_in_fair', true); // set single to true to receive properly unserialized array
$faircoins_address = get_post_meta($order->get_id(), 'fair_address', true); // set single to true to receive properly unserialized
$payment_message = urlencode(get_bloginfo('name') . ' Order number:' . $order->get_order_number());
$instructions = $this->instructions;
$instructions = str_replace('{{{FAIRCOINS_PAY_URL}}}', 'faircoin:{{{FAIRCOINS_ADDRESS}}}?amount={{{FAIRCOINS_AMOUNT}}}&message={{{PAYMENT_MESSAGE}}}', $instructions);
$instructions = str_replace('{{{FAIRCOINS_AMOUNT}}}', $order_total_in_fair, $instructions);
$instructions = str_replace('{{{FAIRCOINS_ADDRESS}}}', $faircoins_address, $instructions);
$instructions = str_replace('{{{PAYMENT_MESSAGE}}}', $payment_message, $instructions);
// we need to double urlencode because it needs to be urlencoded for the generated qr code and the get request
// for the qr code also needs it urlencoded
$instructions = str_replace('{{{PAYMENT_MESSAGE_URL_SAFE}}}', urlencode($payment_message), $instructions);
$instructions =
str_replace(
'{{{EXTRA_INSTRUCTIONS}}}',
$this->instructions_multi_payment_str,
$instructions
);
if ($add_order_note) {
$order->add_order_note(__("Order instructions: price={$order_total_in_fair} FAIR, incoming account:{$faircoins_address}", 'WCP_I18N_DOMAIN'));
}
return $instructions;
}
}