Skip to content

Commit

Permalink
Move to Lightning Checkout repository
Browse files Browse the repository at this point in the history
  • Loading branch information
lightningcheckout authored Jun 18, 2023
1 parent 7901852 commit 50e3496
Show file tree
Hide file tree
Showing 20 changed files with 645 additions and 6 deletions.
12 changes: 6 additions & 6 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License
The MIT License (MIT)

Copyright (c) 2023 lightningcheckout
Copyright (c) 2021 Phaedrus and contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Binary file added assets/bitcoin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon-128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon-256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lightning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions includes/init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

require(dirname(__FILE__) . '/utils.php');
require(dirname(__FILE__) . '/lnbits_api.php');
41 changes: 41 additions & 0 deletions includes/lnbits_api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
namespace LightningCheckoutPlugin;


/**
* For calling LNBits API
*/
class LNBitsAPI {

protected $url;
protected $api_key;

public function __construct($url, $api_key) {
$this->url = $url;
$this->api_key = $api_key;
}

public function createInvoice($amount, $memo) {
$c = new CurlWrapper();
$data = array(
"out" => false,
"amount" => $amount,
"memo" => $memo,
"webhook" => "https://portal.lightningcheckout.eu/webhook/paymentupdate"
);
$headers = array(
'X-Api-Key' => $this->api_key,
'Content-Type' => 'application/json'
);
return $c->post($this->url.'/api/v1/payments', array(), $data, $headers);
}

public function checkInvoicePaid($payment_hash) {
$c = new CurlWrapper();
$headers = array(
'X-Api-Key' => $this->api_key,
'Content-Type' => 'application/json'
);
return $c->get($this->url.'/api/v1/payments/'.$payment_hash, array(), $headers);
}
}
58 changes: 58 additions & 0 deletions includes/utils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
namespace LightningCheckoutPlugin;


class Utils {
public static function convert_to_satoshis($amount, $currency) {
if(strtolower($currency) !== 'btc') {
error_log($amount . " " . $currency);
$c = new CurlWrapper();
$resp = $c->get('https://blockchain.info/tobtc', array(
'currency' => $currency,
'value' => $amount
), array());

if ($resp['status'] != 200) {
throw new \Exception('Blockchain.info request for currency conversion failed. Got status ' . $resp['status']);
}

return (int) round($resp['response'] * 100000000);
}
else {
return intval($amount * 100000000);
}
}
}

class CurlWrapper {

private function request($method, $url, $params, $headers, $data) {
$url = add_query_arg($params, $url);
$r = wp_remote_request($url, array(
'method' => $method,
'headers' => $headers,
'body' => $data ? json_encode($data) : ''
));

if (is_wp_error($r)) {
error_log('WP_Error: '.$r->get_error_message());
return array(
'status' => 500,
'response' => $r->get_error_message()
);
}

return array(
'status' => $r['response']['code'],
'response' => json_decode($r['body'], true)
);
}

public function get($url, $params, $headers) {
return $this->request('GET', $url, $params, $headers, null);
}

public function post($url, $params, $data, $headers) {
return $this->request('POST', $url, $params, $headers, $data);
}
}
28 changes: 28 additions & 0 deletions js/jquery.qrcode.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 50e3496

Please sign in to comment.