Skip to content

Commit

Permalink
Merge pull request #29 from ndeet/fix-refund-text-limit
Browse files Browse the repository at this point in the history
Ensure refund text does not exceed API field limit.
  • Loading branch information
ndeet authored Oct 20, 2023
2 parents a1220af + 8c96379 commit 134bd0e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion btcpay-greenfield-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__ ) );
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions src/Gateway/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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,
Expand Down

0 comments on commit 134bd0e

Please sign in to comment.