Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/ts 67 bug with issuing refund programmatically #19

Merged
merged 9 commits into from
Jun 22, 2022
8 changes: 8 additions & 0 deletions src/Gateways/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,14 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) {

$order = new WC_Order( $order_id );
$request = $this->prepare_request( $txn_type, $order );

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation looks good, but let's format it to respect the WooCommerce standards

if ( null != $amount ) {
$amount = str_replace(',', '.', $amount);
$amount = number_format((float)round($amount, 2, PHP_ROUND_HALF_UP), 2, '.', '');
if ( ! is_numeric($amount)) {
throw new Exception( __( 'Refund amount must be a valid number', 'globalpayments-gateway-provider-for-woocommerce' ) );
}
}
$request->set_request_data( array(
'refund_amount' => $amount,
'refund_reason' => $reason,
Expand Down