From 8c963794c1552da0d6c145a74f22fd2500c3eade Mon Sep 17 00:00:00 2001 From: ndeet Date: Fri, 20 Oct 2023 10:49:27 +0200 Subject: [PATCH] Ensure refund text does not exceed API field limit. --- btcpay-greenfield-for-woocommerce.php | 2 +- readme.txt | 5 ++++- src/Gateway/AbstractGateway.php | 8 ++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/btcpay-greenfield-for-woocommerce.php b/btcpay-greenfield-for-woocommerce.php index 9b8a617..bed110d 100644 --- a/btcpay-greenfield-for-woocommerce.php +++ b/btcpay-greenfield-for-woocommerce.php @@ -26,7 +26,7 @@ defined( 'ABSPATH' ) || exit(); -define( 'BTCPAYSERVER_VERSION', '2.3.0' ); +define( 'BTCPAYSERVER_VERSION', '2.3.1' ); define( 'BTCPAYSERVER_VERSION_KEY', 'btcpay_gf_version' ); define( 'BTCPAYSERVER_PLUGIN_FILE_PATH', plugin_dir_path( __FILE__ ) ); define( 'BTCPAYSERVER_PLUGIN_URL', plugin_dir_url(__FILE__ ) ); diff --git a/readme.txt b/readme.txt index 59f7d15..2a29cc3 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: bitcoin, btcpay, BTCPay Server, btcpayserver, WooCommerce, payment gateway Requires at least: 5.2 Tested up to: 6.3 Requires PHP: 7.4 -Stable tag: 2.3.0 +Stable tag: 2.3.1 License: MIT License URI: https://github.com/btcpayserver/woocommerce-greenfield-plugin/blob/master/license.txt @@ -104,6 +104,9 @@ You'll find extensive documentation and answers to many of your questions on [BT == Changelog == += 2.3.1 :: 2023-10-20 = +* Fix: Ensure refunds text does not exceed API field limit. + = 2.3.0 :: 2023-09-06 = * Support for high performance order storage (HPOS) diff --git a/src/Gateway/AbstractGateway.php b/src/Gateway/AbstractGateway.php index b715723..fb2f46b 100644 --- a/src/Gateway/AbstractGateway.php +++ b/src/Gateway/AbstractGateway.php @@ -180,7 +180,7 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) { // Make sure the refund amount is not greater than the invoice amount. if ($amount > $order->get_remaining_refund_amount()) { - $errAmount = __METHOD__ . ': the refund amount can not exceed the order amount, aborting.'; + $errAmount = __METHOD__ . ': the refund amount can not exceed the order amount, aborting. Remaining amount ' . $order->get_remaining_refund_amount(); Logger::debug($errAmount); return new \WP_Error('1', $errAmount); } @@ -200,13 +200,17 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) { $paymentMethods = array_diff($paymentMethods, ['BTC_LNURLPAY']); } + // Refund name is limited for 50 chars, but we do not have description field available until php lib v3 is out. + $refundName = __('Refund of order ', 'btcpay-greenfield-for-woocommerce') . $order->get_order_number() . '; ' . $reason; + $refundName = substr($refundName, 0, 50); + // Create the payout. try { $client = new PullPayment( $this->apiHelper->url, $this->apiHelper->apiKey); // todo: add reason to description with upcoming php lib v3 $pullPayment = $client->createPullPayment( $this->apiHelper->storeId, - __('Refund for order no.: ', 'btcpay-greenfield-for-woocommerce') . $order->get_order_number() . ' reason: ' . $reason, + $refundName, $refundAmount, $currency, null,