commit
281c434b31
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
/*
|
||||
Plugin Name: Bitcoin Private Payment Gateway
|
||||
Plugin Name: Bitcoin Private for Woocommerce
|
||||
Description: BTCPPay.com WooCommerce Payment Gateway Integration for payments with Bitcoin Private
|
||||
Author: J62 & Mattpass
|
||||
Author: J62 & MattPass
|
||||
*/
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
|
@ -101,7 +101,7 @@ function init_custom_gateway_class()
|
|||
'title' => __('Description', $this->domain),
|
||||
'type' => 'textarea',
|
||||
'description' => __('Payment method description that the customer will see on your checkout.', $this->domain),
|
||||
'default' => __('Pay for your purchase with Bitcoin Private', $this->domain),
|
||||
'default' => __('Pay via Bitcoin Private', $this->domain),
|
||||
'desc_tip' => true
|
||||
),
|
||||
'instructions' => array(
|
||||
|
@ -161,68 +161,26 @@ function init_custom_gateway_class()
|
|||
|
||||
<p class="form-row form-row-wide">
|
||||
<input type="hidden" class="" name="i_payment_txref" id="i_payment_txref" placeholder="" value="">
|
||||
Clicking the Place Order button below, we'll establish the equivalent in BTCP and provide the address and QR code for payment.
|
||||
</p>
|
||||
|
||||
|
||||
<div class="fiat_totals">
|
||||
<div id="fiat_total" style="display:inline-block"><strong>Fiat Total:</strong></div>
|
||||
<div id="fiat_total_value" style="display:inline-block"></div>
|
||||
</div>
|
||||
|
||||
<div class="btcp_totals">
|
||||
<div id="btcp_total" style="display:inline-block"><strong>BTCP Total:</strong></div>
|
||||
<div id="btcp_total_value" style="display:inline-block"></div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<script id="convert">
|
||||
var btcPrivate;
|
||||
var btcpAmount;
|
||||
var btcpAmount2;
|
||||
var json = new XMLHttpRequest(); // start a new variable to store the JSON in
|
||||
json.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) { // if HTTP header 200 - ok
|
||||
var object = JSON.parse(this.responseText);
|
||||
btcPrivate = object[0].price_usd;
|
||||
var ValueUSD = '<?php echo WC()->cart->total; ?>';
|
||||
btcpAmount = ValueUSD / btcPrivate;
|
||||
btcpAmount2 = btcpAmount.toFixed(8)
|
||||
//document.getElementById('btcpprice').innerHTML += 'BTCP Price: ' + btcpAmount2;
|
||||
console.log("btcpAmount2 within function " + btcpAmount2);
|
||||
}
|
||||
};
|
||||
json.open(
|
||||
"GET", // method
|
||||
"https://api.coinmarketcap.com/v1/ticker/bitcoin-private/", // url
|
||||
true // async
|
||||
); // initialise the request
|
||||
json.send(); //send request
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
<script id="btcp_widget_data">
|
||||
var order_fiat_total = '<?php echo WC()->cart->total; ?>';
|
||||
console.log("order_fiat_total: " + order_fiat_total);
|
||||
var order_btcp_total = btcpAmount2
|
||||
document.getElementById('btcp_total_value').innerHTML = order_btcp_total;
|
||||
document.getElementById('fiat_total_value').innerHTML = order_fiat_total;
|
||||
|
||||
var btcpWidget = {};
|
||||
btcpWidget.data = {
|
||||
"id" : "btcp_widget",
|
||||
"buttonData" : "buy_A1_1",
|
||||
"buttonData" : "buy_A1_0",
|
||||
"hideButton" : true,
|
||||
"merchantid" : "343",
|
||||
"walletid" : "12",
|
||||
"amount" : order_btcp_total,
|
||||
"merchantid" : "414",
|
||||
"walletid" : "2",
|
||||
"amount" : <?php echo WC()->cart->total; ?>,
|
||||
"currency" : "<?php echo get_woocommerce_currency();?>",
|
||||
"itemid" : "0",
|
||||
"description" : "cart purchase",
|
||||
"description" : "Pepperoni Pizza",
|
||||
"transactiondetails" :
|
||||
{
|
||||
"itemId" : 0,
|
||||
"test" : "test item"
|
||||
"size" : "12 inch",
|
||||
"crust" : "stuffed",
|
||||
"pan" : "thin base"
|
||||
}
|
||||
};
|
||||
|
||||
|
|
27
widget.js
27
widget.js
|
@ -944,6 +944,9 @@ window.addEventListener("resize", function(event) {
|
|||
btcpWidget.processPayment = function() {
|
||||
// If we have a txID
|
||||
if ("undefined" != typeof btcpWidget.txID) {
|
||||
// Return onbeforeunload object value to permit closing tab/window
|
||||
btcpWidget.onBeforeUnloadHandler('unset');
|
||||
|
||||
// Unsubsribe from websockets
|
||||
socket.emit('unsubscribe', 'bitcoind/hashblock');
|
||||
socket.emit('unsubscribe', 'bitcoind/rawtransaction');
|
||||
|
@ -1039,6 +1042,22 @@ btcpWidget.cA.innerHTML = '<div id="wallet"></div><button class="copyButton" id=
|
|||
// Attach just after body
|
||||
document.body.insertAdjacentElement('afterend',btcpWidget.cA);
|
||||
|
||||
// Set/unset the onbeforeunload return
|
||||
btcpWidget.onBeforeUnloadHandler = function(setUnset) {
|
||||
if (setUnset == "set") {
|
||||
// Pickup previous object value
|
||||
btcpWidget.prevOnBeforeUnload = window.onbeforeunload;
|
||||
// Add unbeforeunload
|
||||
window.onbeforeunload = function() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (setUnset == "unset") {
|
||||
// Reset object value to what it was previously
|
||||
window.onbeforeunload = btcpWidget.prevOnBeforeUnload;
|
||||
}
|
||||
}
|
||||
|
||||
// On document load
|
||||
btcpWidget.startSocketsSubscriptions = function() {
|
||||
// Set modal displayed wallet address
|
||||
|
@ -1092,7 +1111,7 @@ btcpWidget.startSocketsSubscriptions = function() {
|
|||
// Apply that to button and QR code
|
||||
get('walletButton').href = btcpWidget.btcpURI;
|
||||
btcpWidget.generateQRCode(btcpWidget.btcpURI);
|
||||
// Paid too much (5000 sats or more under required amount)
|
||||
// Paid too much (5000 sats or more under required amount)
|
||||
} else if (o[i].satoshis > btcpWidget.amountToPay * (100000000 + 5000)) {
|
||||
// Set amount overpaid and alert user
|
||||
btcpWidget.amountToPay = ((o[i].satoshis / 100000000) - btcpWidget.amountToPay).toFixed(8) * 1;
|
||||
|
@ -1100,10 +1119,14 @@ btcpWidget.startSocketsSubscriptions = function() {
|
|||
// Permit order to proceed
|
||||
btcpWidget.paidEnough = true;
|
||||
btcpWidget.displayProcessingMessage();
|
||||
// Paid roughly right amount
|
||||
// Warn against closing tab/window
|
||||
btcpWidget.onBeforeUnloadHandler('set');
|
||||
// Paid roughly right amount
|
||||
} else {
|
||||
btcpWidget.paidEnough = true;
|
||||
btcpWidget.displayProcessingMessage();
|
||||
// Warn against closing tab/window
|
||||
btcpWidget.onBeforeUnloadHandler('set');
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue