Skip to content

Commit

Permalink
Merge pull request #3 from cryptoteun/fix-webhook
Browse files Browse the repository at this point in the history
Fix webhook
  • Loading branch information
cryptoteun authored Dec 20, 2024
2 parents 7262812 + aee3178 commit 48e1074
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions includes/webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,23 @@ function handle_webhook($request) {
$api_endpoint = get_option("lnc_btcdonate_api_endpoint");
$api_key = get_option("lnc_btcdonate_api_key");

// Get payment data via payemnt hash
$data = $request->get_json_params();
$payment_response = wp_remote_get($api_endpoint . "/api/v1/payments/".$data['payment_hash'], [
"headers" => [
"Content-Type" => "application/json",
"X-API-KEY" => $api_key,
// Get payment data via payemnt hash
$jsonString = $request->get_json_params();

],
]);
$data = json_decode($jsonString, true);

// Check for errors in decoding
if (json_last_error() !== JSON_ERROR_NONE) {
echo 'Error parsing JSON: ' . json_last_error_msg();
} else {
// Retrieve the payment_hash
$payment_response = wp_remote_get($api_endpoint . "/api/v1/payments/".$data['payment_hash'], [
"headers" => [
"Content-Type" => "application/json",
"X-API-KEY" => $api_key,

]]);
}
if (is_wp_error($payment_response)) {
error_log("API Error: " . $payment_response->get_error_message());
} else {
Expand All @@ -81,3 +89,4 @@ function handle_webhook($request) {
}
return new WP_REST_Response(array('message' => 'Failed to publish donation.'), 500);
}

2 changes: 1 addition & 1 deletion wp-donate-lnbits.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Plugin Name: WP Donate LNbits
Description: Accept Bitcoin Donations on your Wordpress website. Initially created for bitcoin payment provider Lightning Checkout.
Version: 0.1
Version: 0.2
Author: cryptoteun
*/

Expand Down

0 comments on commit 48e1074

Please sign in to comment.