diff --git a/lnbits/extensions/satspay/templates/satspay/_api_docs.html b/lnbits/extensions/satspay/templates/satspay/_api_docs.html index b4bc201e..51a21fea 100644 --- a/lnbits/extensions/satspay/templates/satspay/_api_docs.html +++ b/lnbits/extensions/satspay/templates/satspay/_api_docs.html @@ -1,156 +1,169 @@ - - -

SatsPay: Create Onchain/LN charges. Includes webhooks!
- - Created by, Ben Arc -

-
+ + +

+ SatsPay: Create Onchain/LN charges. Includes webhooks!
+ + Created by, Ben Arc +

+
- - - - - - - GET /pay/api/v1/links -
Headers
- {"X-Api-Key": <invoice_key>}
-
Body (application/json)
-
- Returns 200 OK (application/json) -
- [<pay_link_object>, ...] -
Curl example
- curl -X GET {{ request.url_root }}pay/api/v1/links -H "X-Api-Key: {{ - g.user.wallets[0].inkey }}" - -
-
-
- - - - GET - /pay/api/v1/links/<pay_id> -
Headers
- {"X-Api-Key": <invoice_key>}
-
Body (application/json)
-
- Returns 201 CREATED (application/json) -
- {"lnurl": <string>} -
Curl example
- curl -X GET {{ request.url_root }}pay/api/v1/links/<pay_id> -H - "X-Api-Key: {{ g.user.wallets[0].inkey }}" - -
-
-
- - - POST /pay/api/v1/links -
Headers
- {"X-Api-Key": <invoice_key>}
-
Body (application/json)
- {"description": <string> "amount": <integer>} -
- Returns 201 CREATED (application/json) -
- { - "deliveryId": <string>, - "description": <string>, - "webhookId": <string>, - "originalDeliveryId": <string>, - "isRedelivery": <boolean>, - "type": <string>, - "timestamp": <int>, - "paytime": <int>, - "storeId": <string>, - "invoiceId": <string>, - "manuallyMarked": <boolean>, - "overPaid": <boolean>, - "afterExpiration": <boolean>, - "partiallyPaid": <boolean> - }
"type" can be InvoiceReceivedPayment, InvoicePaidInFull, InvoiceExpired, InvoiceConfirmed, and InvoiceInvalid
-
Curl example
- curl -X POST {{ request.url_root }}pay/api/v1/links -d - '{"description": <string>, "amount": <integer>}' -H - "Content-type: application/json" -H "X-Api-Key: {{ - g.user.wallets[0].adminkey }}" - -
-
+ + + + POST /satspay/api/v1/charge +
Headers
+ {"X-Api-Key": <admin_key>}
+
+ Body (application/json) +
+
+ Returns 200 OK (application/json) +
+ [<charge_object>, ...] +
Curl example
+ curl -X POST {{ request.url_root }}api/v1/charge -d + '{"onchainwallet": <string, watchonly_wallet_id>, + "description": <string>, "webhook":<string>, "time": + <integer>, "amount": <integer>, "lnbitswallet": + <string, lnbits_wallet_id>}' -H "Content-type: + application/json" -H "X-Api-Key: {{g.user.wallets[0].adminkey }}" + +
+
+
+ + + + GET + /pay/api/v1/links/<pay_id> +
Headers
+ {"X-Api-Key": <invoice_key>}
+
+ Body (application/json) +
+
+ Returns 201 CREATED (application/json) +
+ {"lnurl": <string>} +
Curl example
+ curl -X GET {{ request.url_root }}pay/api/v1/links/<pay_id> + -H "X-Api-Key: {{ g.user.wallets[0].inkey }}" + +
+
+
+ + + + POST /pay/api/v1/links +
Headers
+ {"X-Api-Key": <invoice_key>}
+
+ Body (application/json) +
+ {"description": <string> "amount": <integer>} +
+ Returns 201 CREATED (application/json) +
+ + { "deliveryId": <string>, "description": <string>, + "webhookId": <string>, "originalDeliveryId": <string>, + "isRedelivery": <boolean>, "type": <string>, + "timestamp": <int>, "paytime": <int>, "storeId": + <string>, "invoiceId": <string>, "manuallyMarked": + <boolean>, "overPaid": <boolean>, "afterExpiration": + <boolean>, "partiallyPaid": <boolean> }
"type" can be InvoiceReceivedPayment, InvoicePaidInFull, + InvoiceExpired, InvoiceConfirmed, and InvoiceInvalid +
+
Curl example
+ curl -X POST {{ request.url_root }}pay/api/v1/links -d + '{"description": <string>, "amount": <integer>}' -H + "Content-type: application/json" -H "X-Api-Key: {{ + g.user.wallets[0].adminkey }}" + +
+
+
+ + + + PUT + /pay/api/v1/links/<pay_id> +
Headers
+ {"X-Api-Key": <admin_key>}
+
+ Body (application/json) +
+ {"description": <string>, "amount": <integer>} +
+ Returns 200 OK (application/json) +
+ {"lnurl": <string>} +
Curl example
+ curl -X PUT {{ request.url_root }}pay/api/v1/links/<pay_id> + -d '{"description": <string>, "amount": <integer>}' -H + "Content-type: application/json" -H "X-Api-Key: {{ + g.user.wallets[0].adminkey }}" + +
+
+
+ + + + DELETE + /pay/api/v1/links/<pay_id> +
Headers
+ {"X-Api-Key": <admin_key>}
+
Returns 204 NO CONTENT
+ +
Curl example
+ curl -X DELETE {{ request.url_root + }}pay/api/v1/links/<pay_id> -H "X-Api-Key: {{ + g.user.wallets[0].adminkey }}" + +
+
+
- - - - PUT - /pay/api/v1/links/<pay_id> -
Headers
- {"X-Api-Key": <admin_key>}
-
Body (application/json)
- {"description": <string>, "amount": <integer>} -
- Returns 200 OK (application/json) -
- {"lnurl": <string>} -
Curl example
- curl -X PUT {{ request.url_root }}pay/api/v1/links/<pay_id> -d - '{"description": <string>, "amount": <integer>}' -H - "Content-type: application/json" -H "X-Api-Key: {{ - g.user.wallets[0].adminkey }}" - -
-
-
- - - - DELETE - /pay/api/v1/links/<pay_id> -
Headers
- {"X-Api-Key": <admin_key>}
-
Returns 204 NO CONTENT
- -
Curl example
- curl -X DELETE {{ request.url_root }}pay/api/v1/links/<pay_id> - -H "X-Api-Key: {{ g.user.wallets[0].adminkey }}" - -
-
-
-
+
diff --git a/lnbits/extensions/satspay/templates/satspay/index.html b/lnbits/extensions/satspay/templates/satspay/index.html index a4a2a431..32ba1e11 100644 --- a/lnbits/extensions/satspay/templates/satspay/index.html +++ b/lnbits/extensions/satspay/templates/satspay/index.html @@ -324,6 +324,18 @@ ChargesTable: { columns: [ + { + name: 'timeleft', + align: 'left', + label: 'Time left', + field: 'countdown' + }, + { + name: 'id', + align: 'left', + label: 'ID', + field: 'id' + }, { name: 'description', align: 'left', @@ -360,12 +372,6 @@ label: 'Time to Pay', field: 'time' }, - { - name: 'timeleft', - align: 'left', - label: 'Time left', - field: 'date' - }, ], pagination: { rowsPerPage: 10 @@ -386,8 +392,19 @@ } }, + computed: { + updateCountdowns() { + console.log("whatever") + Object.mapWalletLink(this.data).forEach(row => { + let datem = moment(row.time).format('YYYY-MM-DD HH:mm'); + row.countdown = countdown(new Date(datem).getTime()).toString(); + }) + } + }, + methods: { + getWalletLinks: function () { var self = this @@ -466,8 +483,8 @@ } self.ChargeLinks = response.data.map(function (obj) { - console.log(obj.timestamp) - console.log(Date.now()/1000) + + return mapCharge(obj) }) }) @@ -637,6 +654,8 @@ } }, 5000); getCharges() + + } }) diff --git a/lnbits/extensions/satspay/views_api.py b/lnbits/extensions/satspay/views_api.py index b99ab632..697d246f 100644 --- a/lnbits/extensions/satspay/views_api.py +++ b/lnbits/extensions/satspay/views_api.py @@ -17,19 +17,31 @@ from .crud import ( ) #############################CHARGES########################## -@satspay_ext.route("/api/v1/charges/balance/", methods=["GET"]) -@api_check_wallet_key("invoice") -async def api_charges_balance(charge_id): - charge = await check_address_balance(charge_id) - if not charge: - return ( - jsonify(""), - HTTPStatus.OK - ) + +@satspay_ext.route("/api/v1/charge", methods=["POST"]) +@satspay_ext.route("/api/v1/charge/", methods=["PUT"]) +@api_check_wallet_key("admin") +@api_validate_post_request( + schema={ + "onchainwallet": {"type": "string"}, + "lnbitswallet": {"type": "string"}, + "description": {"type": "string", "empty": False, "required": True}, + "webhook": {"type": "string", "empty": False, "required": True}, + "time": {"type": "integer", "min": 1, "required": True}, + "amount": {"type": "integer", "min": 1, "required": True}, + } +) +async def api_charge_create_or_update(charge_id=None): + + if not charge_id: + charge = await create_charge(user=g.wallet.user, **g.data) + return jsonify(charge._asdict()), HTTPStatus.CREATED else: + charge = await update_charge(user=g.wallet.user, **g.data) return jsonify(charge._asdict()), HTTPStatus.OK + @satspay_ext.route("/api/v1/charges", methods=["GET"]) @api_check_wallet_key("invoice") async def api_charges_retrieve(): @@ -47,37 +59,14 @@ async def api_charges_retrieve(): @satspay_ext.route("/api/v1/charge/", methods=["GET"]) @api_check_wallet_key("invoice") async def api_charge_retrieve(charge_id): - charge = get_charge(charge_id) - + charge = get_charge(charge_id) + if not charge: return jsonify({"message": "charge does not exist"}), HTTPStatus.NOT_FOUND return jsonify({charge}), HTTPStatus.OK -@satspay_ext.route("/api/v1/charge", methods=["POST"]) -@satspay_ext.route("/api/v1/charge/", methods=["PUT"]) -@api_check_wallet_key("invoice") -@api_validate_post_request( - schema={ - "onchainwallet": {"type": "string"}, - "lnbitswallet": {"type": "string"}, - "description": {"type": "string", "empty": False, "required": True}, - "webhook": {"type": "string", "empty": False, "required": True}, - "time": {"type": "integer", "min": 1, "required": True}, - "amount": {"type": "integer", "min": 1, "required": True}, - } -) -async def api_charge_create_or_update(charge_id=None): - - if not charge_id: - charge = await create_charge(user = g.wallet.user, **g.data) - return jsonify(charge), HTTPStatus.CREATED - else: - charge = await update_charge(user = g.wallet.user, **g.data) - return jsonify(charge), HTTPStatus.OK - - @satspay_ext.route("/api/v1/charge/", methods=["DELETE"]) @api_check_wallet_key("invoice") async def api_charge_delete(charge_id): @@ -90,8 +79,25 @@ async def api_charge_delete(charge_id): return "", HTTPStatus.NO_CONTENT + +#############################BALANCE########################## + +@satspay_ext.route("/api/v1/charges/balance/", methods=["GET"]) +@api_check_wallet_key("invoice") +async def api_charges_balance(charge_id): + + charge = await check_address_balance(charge_id) + if not charge: + return ( + jsonify(""), + HTTPStatus.OK + ) + else: + return jsonify(charge._asdict()), HTTPStatus.OK + #############################MEMPOOL########################## + @satspay_ext.route("/api/v1/mempool", methods=["PUT"]) @api_check_wallet_key("invoice") @api_validate_post_request( @@ -101,12 +107,13 @@ async def api_charge_delete(charge_id): ) async def api_update_mempool(): mempool = await update_mempool(user=g.wallet.user, **g.data) - return jsonify(mempool._asdict()), HTTPStatus.OK + return jsonify(mempool._asdict()), HTTPStatus.OK + @satspay_ext.route("/api/v1/mempool", methods=["GET"]) @api_check_wallet_key("invoice") async def api_get_mempool(): - mempool = await get_mempool(g.wallet.user) + mempool = await get_mempool(g.wallet.user) if not mempool: mempool = await create_mempool(user=g.wallet.user) - return jsonify(mempool._asdict()), HTTPStatus.OK \ No newline at end of file + return jsonify(mempool._asdict()), HTTPStatus.OK