commit cfebfbae19164cc719666582645b963262c36b3d
parent 18a96c4366609863c2f01b768e2c8e7ea7ed9b5c
Author: NicholasFarrow <nicholas.w.farrow@gmail.com>
Date: Thu, 14 Jan 2021 23:56:56 +1100
Add payment tracking with id
Diffstat:
4 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/gateways/btcpyment.php b/gateways/btcpyment.php
@@ -7,6 +7,9 @@
* Author URI: https://nickfarrow.com
* Version: 1.0.1
*
+*/
+
+/* Based on https://rudrastyh.com/woocommerce/payment-gateway-plugin.html */
/*
* This action hook registers our PHP class as a WooCommerce payment gateway
@@ -184,12 +187,13 @@ function btcpyment_init_gateway_class() {
// we need it to get any order detailes
$order = wc_get_order( $order_id );
-
/*
* Array with parameters for API interaction
*/
$args = array(
- 'amount' => 100
+ 'amount' => $order->get_total(),
+ 'id' => $order->get_id()
+ // HASH??? FOR SECURE PAYMENTS?
);
/*
@@ -197,7 +201,7 @@ function btcpyment_init_gateway_class() {
*/
$redir_url = add_query_arg(
$args,
- 'https://btcpyment.nickfarrow.com/payment'
+ 'https://btcpyment.nickfarrow.com/pay'
);
write_log($redir_url);
@@ -215,7 +219,7 @@ function btcpyment_init_gateway_class() {
return [
'result' => 'success',
'redirect' => $redir_url
- ];
+ ];
if( !is_wp_error( $response ) ) {
diff --git a/server.py b/server.py
@@ -25,8 +25,8 @@ def index():
@app.route('/pay')
def payment_page():
amount = request.args.get('amount')
- payload={'amount' : amount}
- return render_template('index.html', amount=amount, async_mode=socket_.async_mode)
+ id = amount = request.args.get('id')
+ return render_template('index.html', amount=amount, id=id, async_mode=socket_.async_mode)
# Basic return on initialisation
@socket_.on('initialise')
diff --git a/static/server_connection.js b/static/server_connection.js
@@ -1,5 +1,5 @@
// Websocket logic, talks to server.py pay
-function initiate(amount) {
+function initiate(amount, id) {
namespace = '/';
var socket = io(namespace);
@@ -21,7 +21,7 @@ function initiate(amount) {
cb();
});
- socket.emit('make_payment', {'amount': amount, 'label' : null});
+ socket.emit('make_payment', {'amount': amount, 'label' : id});
return false
}
diff --git a/templates/index.html b/templates/index.html
@@ -7,8 +7,10 @@
<script src="//code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.4/socket.io.js"></script>
<script src="{{ url_for('static', filename='server_connection.js') }}"></script>
+
+ <!-- Initate the payment websocket -->
<script type="text/javascript">
- initiate({{ amount }});
+ initiate({{ amount }}, {{ id }});
</script>