-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmerchant.html
525 lines (484 loc) · 29.3 KB
/
merchant.html
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
<div class="row">
<div class="col-lg-8">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>Merchant Tools</h5>
</div>
<div class="ibox-content">
<div class="generalbox">
<div id="merchant-setup-container">
<div id="merchant-setup-title">Setup your merchant account to accept cryptocurrency payments</div>
<div id="merchant-setup-form">
<div id="merchant-field-payment-type" class="merchant-field-title">Choose a payment type: <i class="fa fa-info-circle fa-tooltip" aria-hidden="true" onclick="notify('Choose between a one off single payment and a rebilled recurring payment. Recurring payments require purchaser to have a JSE account.');"></i></div>
<select onchange="togglePaymentType();" id="merchant-payment-type-select" class="merchant-select-input">
<option value="singlePayment">Single Payment</option>
<option value="recurringPayment">Recurring Payment</option>
</select>
<div id="merchant-field-item-name" class="merchant-field-title">Item Name / ID <i class="fa fa-info-circle fa-tooltip" aria-hidden="true" onclick="notify('Give your product or service a name or reference which will be logged in the transaction table below.');"></i></div>
<input type="text" id="merchant-item-name-value" class="merchant-text-input">
<div id="merchant-single-payment-pricing">
<div id="merchant-field-price" class="merchant-field-title">Price <i class="fa fa-info-circle fa-tooltip" aria-hidden="true" onclick="notify('Choose a price and currency. Currency conversion is calculated from current exchange rates at time of purchase.');"></i></div>
<input type="text" id="merchant-single-price-value" class="merchant-text-input merchant-price-input">
<select id="merchant-single-price-currency" class="merchant-text-input merchant-price-input">
<option value="JSE" selected>JSE</option>
<option value="BTC">BTC</option>
<option value="ETH">ETH</option>
<option value="USD">USD</option>
<option value="EUR">EUR</option>
<option value="JPY">JPY</option>
<option value="GBP">GBP</option>
<option value="AUD">AUD</option>
<option value="CAD">CAD</option>
<option value="CHF">CHF</option>
<option value="CNY">CNY</option>
<option value="SEK">SEK</option>
<option value="NZD">NZD</option>
<option value="MXN">MXN</option>
<option value="SGD">SGD</option>
<option value="HKD">HKD</option>
<option value="NOK">NOK</option>
<option value="KRW">KRW</option>
<option value="TRY">TRY</option>
<option value="RUB">RUB</option>
<option value="INR">INR</option>
<option value="BRL">BRL</option>
<option value="ZAR">ZAR</option>
</select>
</div>
<div id="merchant-recurring-payment-pricing">
<div id="merchant-field-initial-price" class="merchant-field-title">Initial Price</div>
<input type="text" id="merchant-initial-price-value" class="merchant-text-input merchant-price-input">
<select id="merchant-initial-price-currency" class="merchant-text-input merchant-price-input">
<option value="JSE" selected>JSE</option>
<option value="BTC">BTC</option>
<option value="ETH">ETH</option>
<option value="USD">USD</option>
<option value="EUR">EUR</option>
<option value="JPY">JPY</option>
<option value="GBP">GBP</option>
<option value="AUD">AUD</option>
<option value="CAD">CAD</option>
<option value="CHF">CHF</option>
<option value="CNY">CNY</option>
<option value="SEK">SEK</option>
<option value="NZD">NZD</option>
<option value="MXN">MXN</option>
<option value="SGD">SGD</option>
<option value="HKD">HKD</option>
<option value="NOK">NOK</option>
<option value="KRW">KRW</option>
<option value="TRY">TRY</option>
<option value="RUB">RUB</option>
<option value="INR">INR</option>
<option value="BRL">BRL</option>
<option value="ZAR">ZAR</option>
</select>
<div id="merchant-field-recurring-price" class="merchant-field-title">Recurring Price</div>
<input type="text" id="merchant-recurring-price-value" class="merchant-text-input merchant-price-input">
<select id="merchant-recurring-price-currency" class="merchant-text-input merchant-price-input">
<option value="JSE" selected>JSE</option>
<option value="BTC">BTC</option>
<option value="ETH">ETH</option>
<option value="USD">USD</option>
<option value="EUR">EUR</option>
<option value="JPY">JPY</option>
<option value="GBP">GBP</option>
<option value="AUD">AUD</option>
<option value="CAD">CAD</option>
<option value="CHF">CHF</option>
<option value="CNY">CNY</option>
<option value="SEK">SEK</option>
<option value="NZD">NZD</option>
<option value="MXN">MXN</option>
<option value="SGD">SGD</option>
<option value="HKD">HKD</option>
<option value="NOK">NOK</option>
<option value="KRW">KRW</option>
<option value="TRY">TRY</option>
<option value="RUB">RUB</option>
<option value="INR">INR</option>
<option value="BRL">BRL</option>
<option value="ZAR">ZAR</option>
</select>
<div id="merchant-field-rebill-frequency" class="merchant-field-title">Rebill frequency</div>
<input type="checkbox" value="1" class="merchant-checkboxes merchant-rebill-frequency-checkboxes" id="merchant-rebill-daily" onclick="rebillCheckBox('daily');" />
<label for="merchant-rebill-daily" class="merchant-checkbox-label">Daily</label>
<input type="checkbox" value="1" class="merchant-checkboxes merchant-rebill-frequency-checkboxes" id="merchant-rebill-weekly" onclick="rebillCheckBox('weekly');" />
<label for="merchant-rebill-weekly" class="merchant-checkbox-label">Weekly</label>
<input type="checkbox" value="1" class="merchant-checkboxes merchant-rebill-frequency-checkboxes" id="merchant-rebill-monthly" onclick="rebillCheckBox('monthly');" />
<label for="merchant-rebill-monthly" class="merchant-checkbox-label">Monthly</label>
<input type="checkbox" value="1" class="merchant-checkboxes merchant-rebill-frequency-checkboxes" id="merchant-rebill-annually" onclick="rebillCheckBox('annually');" />
<label for="merchant-rebill-annually" class="merchant-checkbox-label">Annually</label>
</div>
<div id="merchant-field-completion-url" class="merchant-field-title">Completion URL <i class="fa fa-info-circle fa-tooltip" aria-hidden="true" onclick="notify('After payment users will be sent back to this address. This is public so use the a secured IPN URL from advanced options to do any payment processing.');"></i></div>
<input type="text" id="merchant-completion-url-value" class="merchant-text-input merchant-url-input" placeholder="https://yoursite.com/checkoutcomplete.html" >
<div id="merchant-setup-buttons">
<button id="merchant-getcode-button" class="btn btn-primary" onclick="getMerchantCode();">Get Code</button> <a href="javascript:void(0)" class="merchant-advanced-link" onclick="showMerchantAdvanced();">Advanced</a>
<br><br>
<button class="btn btn-primary" onclick="merchantHelp();">Merchant Setup Help</button>
</div>
<div id="merchant-advanced-container">
<div class="merchant-field-title" id="merchant-advanced-title">Advanced Options</div>
<!--
<div class="mt5">
<input type="checkbox" class="merchant-checkboxes" id="merchant-checkbox-obfuscate-url" value="1" />
<label for="merchant-checkbox-obfuscate-url" class="merchant-checkbox-label">Obfuscate URL Data</label>
</div>
<div class="mt5">
<input type="checkbox" class="merchant-checkboxes" id="merchant-checkbox-hash-data" value="1" />
<label for="merchant-checkbox-hash-data" class="merchant-checkbox-label">Hash Obfuscated Data (Prevent manipulation)</label>
</div>
-->
<div class="mt5">
<input type="checkbox" class="merchant-checkboxes" id="merchant-checkbox-simple-url" value="1" />
<label for="merchant-checkbox-simple-url" class="merchant-checkbox-label">Simple URL (less secure) <i class="fa fa-info-circle fa-tooltip" aria-hidden="true" onclick="notify('This wont obfuscate or hash the URL which means buttons can more easily be dynamically generated. However this also means that clients can manipulate prices and descriptions so make sure you check incoming payments on the platform.');"></i></label>
</div>
<div class="mt5">
<input type="checkbox" class="merchant-checkboxes" id="merchant-checkbox-hide-address" value="1" />
<label for="merchant-checkbox-hide-address" class="merchant-checkbox-label">Auto-hide delivery address <i class="fa fa-info-circle fa-tooltip" aria-hidden="true" onclick="notify('Delivery address not required.');"></i></label>
</div>
<div class="mt5">
<input type="checkbox" class="merchant-checkboxes" id="merchant-checkbox-charity-account" value="1" />
<label for="merchant-checkbox-charity-account" class="merchant-checkbox-label">Send funds to charity account (useful for testing) <i class="fa fa-info-circle fa-tooltip" aria-hidden="true" onclick="notify('This will set up a button for payment to the charity account. This can be used for testing so you can use your own JSEcoin account as the purchaser.');"></i></label>
</div>
<div id="merchant-field-cancellation-url" class="merchant-field-title">Cancellation URL <i class="fa fa-info-circle fa-tooltip" aria-hidden="true" onclick="notify('Users are redirected to this web address if they cancel the payment.');"></i></div>
<input type="text" id="merchant-cancellation-url-value" class="merchant-text-input merchant-url-input" placeholder="https://yoursite.com/cancel.html">
<div id="merchant-field-ipn-url" class="merchant-field-title">IPN Postback URL <span class="merchant-field-optional-text">(or reference)</span> <i class="fa fa-info-circle fa-tooltip" aria-hidden="true" onclick="notify('A server-side GET request is made to the IPN URL on successful payment receipt. Once secured a reference will appear in the box which hides the actual URL from the client.');"></i></div>
<input type="text" id="merchant-ipn-url-value" class="merchant-text-input merchant-url-input" onchange="$(this).css('color', '#C00');" placeholder="https://yoursite.com/s2s.php?ref={item}">
<br>
<button class="btn btn-primary btn-sm" onclick="saveIPN();">Save and secure IPN URL</button>
<div id="merchant-field-logo-url" class="merchant-field-title">Merchant Logo URL <i class="fa fa-info-circle fa-tooltip" aria-hidden="true" onclick="notify('Include your company or website logo on the checkout page');"></i></div>
<input type="text" id="merchant-logo-url-value" class="merchant-text-input merchant-url-input" placeholder="https://yoursite.com/img/logo.jpg">
<div id="merchant-field-tracking-variables" class="merchant-field-title">Tracking Variables <i class="fa fa-info-circle fa-tooltip" aria-hidden="true" onclick="notify('Tracking variables can be used to pass through additional data to the payment processing URLs. Dynamic tokens for the URLs are {item} {price} {c1} {c2} {c3} {buyeremail} {reference}');"></i></div>
<input type="text" id="merchant-c1-value" class="merchant-text-input" placeholder="c1"><br>
<input type="text" id="merchant-c2-value" class="merchant-text-input" placeholder="c2"><br>
<input type="text" id="merchant-c3-value" class="merchant-text-input" placeholder="c3"><br>
</div>
</div>
<div id="merchant-code-container">
<div id="merchant-code-instructions" class="merchant-field-title">Copy and paste this code into your website HTML:</div>
<div id="merchant-code-div"><xmp id="merchant-code-xmp"></xmp></div>
<div id="merchant-code-buttons">
<button id="merchant-back-button" class="btn btn-primary" onclick="merchantCodeBack();">Back</button>
<button id="merchant-copy-clipboard" class="btn btn-primary" onclick="copyToClipboard('merchant-code-xmp');">Copy to Clipboard</button>
</div>
<div id="merchant-code-example-container">
<div class="merchant-field-title">Example:</div>
<div id="merchant-code-example-target"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="pull-right"><i class="fa fa-qrcode" aria-hidden="true"></i></span>
<h5>Merchant Payment Request</h5>
</div>
<div class="ibox-content">
<div id="payment-request-setup">
Value:<br>
<input type="text" id="payment-request-value" class="merchant-text-input merchant-price-input"> JSE<br>
Reference:<br>
<input type="text" id="payment-request-reference" class="merchant-text-input"><br><br>
<button class="btn btn-primary" onclick="paymentRequest();">Launch Payment Request</button>
</div>
</div>
</div>
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-primary pull-right">Sales</span>
<h5>Sales Lifetime</h5>
</div>
<div class="ibox-content">
<h1 class="saleslifetime">0</h1>
</div>
</div>
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-primary pull-right">Sales</span>
<h5>Sales 24 Hrs</h5>
</div>
<div class="ibox-content">
<h1 class="sales24hrs">0</h1>
</div>
</div>
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-primary pull-right">Subscriptions</span>
<h5>Active Subscriptions</h5>
</div>
<div class="ibox-content">
<h1 class="activesubscriptions">0</h1>
</div>
</div>
</div>
<div class="col-lg-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>Merchant Transactions</h5>
</div>
<div class="ibox-content mhtab">
<table class="table table-hover">
<thead>
<tr>
<th>Type</th>
<th>Date</th>
<th>Item</th>
<th>E-mail</th>
<th>Value</th>
<th>Transaction ID</th>
<th>Actions</th>
</tr>
</thead>
<tbody class="merchanttable"></tbody>
</table>
</div>
</div>
</div>
</div>
<script>
// Load Page
$('.titletext').html('Merchant Tools');
if (typeof user.merchantSales !== 'undefined') {
var transactionTable = '';
var reverseArray = [];
for (var i in user.merchantSales) {
reverseArray.push(user.merchantSales[i]);
}
var salesLifetime = 0;
var sales24hrs = 0;
var activeSubscriptions = 0;
for (var i = reverseArray.length - 1; i >= 0; i--) {
var t = reverseArray[i];
salesLifetime += 1;
var timeCheck = new Date().getTime();
if (t.completedTS > (timeCheck - 86400000)) {
sales24hrs += 1;
}
t.localTime = utcTS2local(t.completedTS);
t.niceAmount = '<img src="img/coin_gold.png" alt="" class="table-coin" /> '+t.amount+' <small>JSE</small>';
t.niceType = 'Single Payment';
t.actions = '<button class="btn btn-xs btn-primary" onclick="notify(\''+t.deliveryAddress+'\');" type="button">Delivery Address</button> <button class="btn btn-xs btn-primary" onclick="setupTransfer(\''+t.buyerEmail+'\',\''+t.amount+'\',\'Refund. '+t.item+'\');" type="button">Refund</button> ';
if (t.type === 'recurring') {
t.niceType = 'Subscription';
t.niceAmount = 'Initial: '+t.amount+' <small>JSE</small>, '+t.rebillFrequency+': '+t.recurringPrice+' <small>JSE</small><br>Due: '+utcTS2local(t.payableDate);
if (typeof t.cancelledTS !== 'undefined') {
t.niceType = 'Cancelled Subscription';
t.localTime += '<br><span style="color: #D00;">Cancelled: '+utcTS2local(t.cancelledTS)+'</span>';
} else {
t.actions += '<button class="btn btn-xs btn-primary" onclick="cancelSubscription(\''+t.reference+'\');" type="button">Cancel Subscription</button> ';
activeSubscriptions += 1;
}
}
if (typeof t.processedTS !== 'undefined') {
t.actions += '<button class="btn btn-xs btn-secondary" onclick="notify(\'This order has already been processed\');" type="button">Processed</button> ';
} else {
t.actions += '<button class="btn btn-xs btn-primary" onclick="processMerchantOrder(\''+t.reference+'\'); $(this).removeClass(\'btn-primary\'); $(this).addClass(\'btn-secondary\'); $(this).html(\'Processed\');" type="button">Process</button> ';
}
transactionTable += '<tr><td>'+t.niceType+'</td><td>'+t.localTime+'</td><td>'+t.item+'</td><td>'+t.buyerEmail+'</td><td>'+t.niceAmount+'</td><td>'+t.reference+'</td><td>'+t.actions+'</td></tr>';
}
$('.merchanttable').html(transactionTable);
}
$('.saleslifetime').html(salesLifetime);
$('.sales24hrs').html(sales24hrs);
$('.activesubscriptions').html(activeSubscriptions);
$('#merchant-payment-type-select').val('singlePayment');
$('#merchant-recurring-payment-pricing').hide();
$('#merchant-single-payment-pricing').show();
$('.merchant-rebill-frequency-checkboxes').prop('checked', false);
$('#merchant-rebill-monthly').prop('checked', true);
// Merchant code
var recurringPayment = false;
function togglePaymentType() {
if ($('#merchant-single-payment-pricing').is(":visible")) {
recurringPayment = true;
$('#merchant-single-payment-pricing').hide();
$('#merchant-recurring-payment-pricing').show();
} else {
recurringPayment = false;
$('#merchant-recurring-payment-pricing').hide();
$('#merchant-single-payment-pricing').show();
}
}
function saveIPN() {
var credentials = {};
credentials.session = user.session;
credentials.ipnURL = $('#merchant-ipn-url-value').val();
$.ajax({url:jseServer+'/account/saveIPN/',type:'POST',contentType:'application/json',data: JSON.stringify(credentials)}).done(function(data) {
var returnObj = JSON.parse(data);
if (returnObj.success) {
$('#merchant-ipn-url-value').val(returnObj.pushRef);
$('#merchant-ipn-url-value').css('color', '#0C0');
}
}).fail(function(data2) {
var failObj = JSON.parse(data2.responseText);
if (failObj && failObj.notification) { notify(failObj.notification); }
return false;
});
}
function merchantHelp() {
launchModal('Merchant Setup Help','The merchant tools enable webmasters to accept simple payments via their website. You don’t need programming knowledge to accept JSE payments via your website or app. Simply give your item a name or ID reference, set a price and provide a thank you page for visitors to return to. Then click “Get Code” and copy and paste the payment code to your website where you want the button to be displayed.<br><br>You will receive email notification and your sales will be displayed in the merchant table below the setup form where you can check delivery address and “process” the order which will send an email notification to the buyer that the order has been processed (this is an optional step).<br><br><b>Advanced options</b><br><br>As standard the data URL is hashed and obfuscated however it can be set to just a simple URL with editable parameters. This may be useful if you want to create buttons dynamically but please beware that price can be manipulated by the end user. You can also provide a cancellation URL to redirect users to if they cancel the order.<br><br>Tracking variables can be used to pass data to the merchant form and then back to the completion URL, IPN URL, or cancellation URL. This enables integration of the JSE payment gateway with 3rd party shopping cart applications by transferring session/cart/order variables. The IPN postback URL will be made as a simple GET request from the server side code which executes the order, this can be used as an instant notification of order to update 3rd party tracking and shopping cart software. To set this up enter a valid URL and click "Save and secure IPN URL", this will provide a referance and your IPN is saved remotely.<br><br>The dynamic tracking tokens to use in your URL are:-<br>{item} {price} {c1} {c2} {c3} {buyeremail} {reference}<br>(Note buyeremail and reference are only available in IPN postback and completion URL)<br><br>Example return URL: https://myshop.com/thankyou.html?cartID={c1}&cartValue={price}<br><br><b>Subscriptions</b><br><br>Many SaaS and Membership sites rely on rebill subscriptions to provide a steady income stream. You can now take daily, weekly, monthly or annual subscription payments with the JSEcoin merchant tools. Simply set the “Recurring Payment” option from the payment type drop down menu and complete the required forms. Initial payment will be taken at the time of checkout, this can be a $1 trial special offer for example. Recurring payment amount will be debited from the buyers account after the defined rebillFrequency has passed i.e. a month later for monthly subscriptions. A merchant or user can cancel their subscription at any time and email notifications will be provided.<br><br>If you have any problems our technical support team is available to help get the merchant tools platform setup on your site. Contact us at: <a href="https://jsecoin.com/en/support/contact/" target="_blank">https://jsecoin.com/en/support/contact/</a>');
}
function getMerchantCode() {
// validation checks
if (!$('#merchant-item-name-value').val()) { notify('Please enter an item description or ID number'); return false; }
if (recurringPayment === false) {
if (!$('#merchant-single-price-value').val()) { notify('Please enter the price in JSE for your item'); return false; }
} else {
if (!$('#merchant-initial-price-value').val()) { notify('Please enter the initial price in JSE for your item'); return false; }
if (!$('#merchant-recurring-price-value').val()) { notify('Please enter the recurring price in JSE for your item'); return false; }
if ($('#merchant-initial-price-currency').val() !== $('#merchant-recurring-price-currency').val()) { notify('Your initial and recurring currencies must match'); return false; }
}
if (!$('#merchant-completion-url-value').val()) { notify('Please enter a URL to send visitors back to your site after checkout'); return false; }
if ($('#merchant-completion-url-value').val().indexOf('http') == -1) { notify('Please enter a valid URL such as "https://yoursite.com/yourpage.html"'); return false; }
$('#merchant-setup-form').hide();
$('#merchant-code-container').show();
var merchantQueryString = 'uid='+user.uid;
merchantQueryString += '&sAuth='+user.apiKey.substring(0, 5);
if ($('#merchant-checkbox-charity-account').prop('checked')) {
merchantQueryString = 'uid=2895&sAuth=LP02h';
}
var currency = 'JSE';
merchantQueryString += '&item='+encodeURIComponent($('#merchant-item-name-value').val());
if (recurringPayment === false) {
merchantQueryString += '&singlePrice='+encodeURIComponent($('#merchant-single-price-value').val());
currency = $('#merchant-single-price-currency').val();
if (currency !== 'JSE') {
merchantQueryString += '¤cy='+encodeURIComponent($('#merchant-single-price-currency').val());
}
} else {
merchantQueryString += '&initialPrice='+encodeURIComponent($('#merchant-initial-price-value').val());
merchantQueryString += '&recurringPrice='+encodeURIComponent($('#merchant-recurring-price-value').val());
merchantQueryString += '&rebillFrequency='+rebillFrequency;
currency = $('#merchant-initial-price-currency').val(); // initital and recurring currencies must be same, check above
if (currency !== 'JSE') {
merchantQueryString += '¤cy='+encodeURIComponent($('#merchant-initial-price-currency').val());
}
}
var completionURL = encodeURIComponent($('#merchant-completion-url-value').val());
merchantQueryString += '&completionURL='+completionURL;
if ($('#merchant-cancellation-url-value').val()) {
var cancellationURL = encodeURIComponent($('#merchant-cancellation-url-value').val());
merchantQueryString += '&cancellationURL='+cancellationURL;
}
if ($('#merchant-ipn-url-value').val()) {
var ipnURL = encodeURIComponent($('#merchant-ipn-url-value').val());
merchantQueryString += '&ipnURL='+ipnURL;
}
if ($('#merchant-logo-url-value').val()) {
var logoURL = encodeURIComponent($('#merchant-logo-url-value').val());
merchantQueryString += '&logoURL='+logoURL;
}
if ($('#merchant-c1-value').val()) {
var c1 = encodeURIComponent($('#merchant-c1-value').val());
merchantQueryString += '&c1='+c1;
}
if ($('#merchant-c2-value').val()) {
var c2 = encodeURIComponent($('#merchant-c2-value').val());
merchantQueryString += '&c2='+c2;
}
if ($('#merchant-c3-value').val()) {
var c3 = encodeURIComponent($('#merchant-c3-value').val());
merchantQueryString += '&c3='+c3;
}
if ($('#merchant-checkbox-hide-address').prop('checked')) {
merchantQueryString += '&hideAddress=1';
}
if (!$('#merchant-checkbox-simple-url').prop('checked')) {
var encObj = {};
encObj.uid = user.uid;
encObj.sAuth = user.apiKey.substring(0, 5);
if ($('#merchant-checkbox-charity-account').prop('checked')) {
encObj.uid = 2895;
encObj.sAuth = 'LP02h';
}
encObj.item = $('#merchant-item-name-value').val();
if (recurringPayment === false) {
encObj.singlePrice = $('#merchant-single-price-value').val();
} else {
encObj.initialPrice = $('#merchant-initial-price-value').val();
encObj.recurringPrice = $('#merchant-recurring-price-value').val();
encObj.rebillFrequency = rebillFrequency;
}
if (currency !== 'JSE') {
encObj.currency = currency;
}
encObj.completionURL = $('#merchant-completion-url-value').val()
if ($('#merchant-cancellation-url-value').val()) {
encObj.cancellationURL = $('#merchant-cancellation-url-value').val()
}
if ($('#merchant-ipn-url-value').val()) {
encObj.ipnURL = $('#merchant-ipn-url-value').val()
}
if ($('#merchant-logo-url-value').val()) {
encObj.logoURL = $('#merchant-logo-url-value').val()
}
if ($('#merchant-c1-value').val()) {
encObj.c1 = $('#merchant-c1-value').val();
}
if ($('#merchant-c2-value').val()) {
encObj.c2 = $('#merchant-c2-value').val();
}
if ($('#merchant-c3-value').val()) {
encObj.c3 = $('#merchant-c3-value').val();
}
if ($('#merchant-checkbox-hide-address').prop('checked')) {
encObj.hideAddress = 1;
}
var encodedURL = encodeURIComponent(unescape(btoa(JSON.stringify(encObj))));
merchantQueryString = 'encoded='+encodedURL;
//if (!$('#merchant-checkbox-simple-url').prop('checked')) {
// SHA256 the data
var safeHashString = decodeURIComponent(encodedURL)+user.email+user.apiKey.substring(0, 10)+user.regip+user.registrationDate; // 10 digits public/private api sub-key mixed in with some user data to prevent brute force attack
console.log(safeHashString);
if ($('#merchant-checkbox-charity-account').prop('checked')) {
safeHashString = encodedURL+'charity@jsecoin.comLP02hxLkHl90.11.151.2401505205877100'; // exposes some charity account data but non-critical
}
var buffer = textEncoderUTF8(safeHashString);
crypto.subtle.digest("SHA-256", buffer).then(function (hash) { // async, will have to print out once complete
var sha256hash = hex(hash);
merchantQueryString += '&hash='+sha256hash;
printMerchantCode(merchantQueryString);
});
}
if (!safeHashString) {
printMerchantCode(merchantQueryString);
}
}
function printMerchantCode(merchantQueryString) {
var merchantCodeForm = '<a href="https://platform.jsecoin.com/checkout.html?'+merchantQueryString+'" target="_top"><img src="https://platform.jsecoin.com/img/pay-with-jse.png" style="border: 0; outline : none; heigth: 40px; width: 150px;" alt="Pay with Crypto" /></a>';
$('#merchant-code-xmp').text(merchantCodeForm);
$('#merchant-code-example-target').html(merchantCodeForm);
}
function showMerchantAdvanced() {
$('#merchant-advanced-container').toggle();
}
function merchantCodeBack() {
$('#merchant-code-container').hide();
$('#merchant-setup-form').show();
}
function paymentRequest() {
var paymentRequestValue = parseFloat($('#payment-request-value').val());
var paymentRequestReference = cleanString($('#payment-request-reference').val());
launchModal('Payment Request From '+user.email,`Please scan, click or tap the QR code to make a payment for ${paymentRequestValue} JSE.<br><div class="qrcontainer"><div id="payment-request-qrcode" style="width:300px; height:300px; margin: 0 auto;"></div></div><div id="payment-request-details"></div>`);
var qrElement = new QRCode(document.getElementById("payment-request-qrcode"), {
width : 300,
height : 300
});
var paymentRequestURL = 'https://platform.jsecoin.com/checkout.html?uid='+user.uid+'&sAuth='+user.apiKey.substring(0, 5)+'&item='+encodeURIComponent(paymentRequestReference)+'&singlePrice='+encodeURIComponent(paymentRequestValue)+'&completionURL=https%3A%2F%2Fjsecoin.com';
qrElement.makeCode(paymentRequestURL);
$('#payment-request-details').html('Value: '+paymentRequestValue+' JSE <br>Reference: '+paymentRequestReference+'<br><br><a href="'+paymentRequestURL+'" target="_blank">'+paymentRequestURL+'</a>');
$('#payment-request-qrcode').on('click', function(e){ window.open(paymentRequestURL, '_blank'); });
}
var rebillFrequency = 'monthly';
//"merchant-checkboxes merchant-rebill-frequency-checkboxes" id="merchant-rebill-daily" onclick="rebillCheckBox('daily')
function rebillCheckBox(timePeriod) {
$('.merchant-rebill-frequency-checkboxes').prop('checked', false);
$('#merchant-rebill-'+timePeriod).prop('checked', true);
rebillFrequency = timePeriod;
}
</script>