-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 6 commits
46d3f2d
4c3daba
5540a48
04df182
b3d5faf
2397701
1d2951b
b75ac66
59f2210
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -315,7 +315,7 @@ public function tokenization_script() { | |
WC()->version, | ||
true | ||
); | ||
|
||
wp_localize_script( | ||
'globalpayments-helper', | ||
'globalpayments_helper_params', | ||
|
@@ -769,6 +769,41 @@ protected function add_hooks() { | |
'woocommerce_available_payment_gateways' | ||
) ); | ||
} | ||
|
||
add_action( 'woocommerce_api_globalpayments_test_refund', array( | ||
$this, | ||
'test_refund_programmatically' | ||
) ); | ||
} | ||
|
||
/** | ||
* Test endpoint for testing a programmatically refund instead of using admin | ||
* | ||
* URL ENDPOINT www.domain.com/?wc-api=globalpayments_test_refund&order-id=136&reason=something&amount=1 | ||
* | ||
* @param int $order-id // valid order-id from a refundable order. | ||
* | ||
* @param string $reason // reason of refund. | ||
* | ||
* @param int $amount // amount of refund , only integer for testing. | ||
* | ||
* @return array | ||
*/ | ||
public function test_refund_programmatically () { | ||
$data = array( | ||
'amount' => $_GET[ 'amount'] ?? null, | ||
'reason' => $_GET[ 'reason'] ?? null, | ||
'order_id' => $_GET[ 'order-id'] ?? null, | ||
'refund_payment' => true | ||
); | ||
|
||
$refund = wc_create_refund( $data ); | ||
if ( is_wp_error( $refund ) ) { | ||
echo '<pre>'; | ||
print_r( $refund->get_error_message() ); | ||
echo '</pre>'; | ||
} | ||
die; | ||
} | ||
|
||
/** | ||
|
@@ -831,6 +866,10 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) { | |
|
||
$order = new WC_Order( $order_id ); | ||
$request = $this->prepare_request( $txn_type, $order ); | ||
$request->set_request_data( array( | ||
'refund_amount' => $amount, | ||
'refund_reason' => $reason, | ||
)); | ||
$request_args = $request->get_args(); | ||
if ( 0 >= (float)$request_args[ RequestArg::AMOUNT ] ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should validate the refund amount. You can check https://github.heartlandapps.net/DevPortal/opencart-hybrid/blob/f29fe16495ce0bf62c70b94d94242d6aa6555f9a/upload/admin/controller/extension/payment/globalpayments_ucp.php#L411 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested, and if we pass a refund value > refundable order value, there will be an error the same as in the admin. { ["error"]=> array(1) { [0]=> string(22) "Invalid refund amount." } } is resolved. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @javiercrac I still consider that we need to do our own validation. |
||
throw new Exception( __( 'Refund amount must be greater than zero.', 'globalpayments-gateway-provider-for-woocommerce' ) ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javiercrac if we want to use this endpoint for QA, it shouldn't do any validation data. It should just send the data and print the response.
These are things that the process_refund method should be able to deal with and respond accordingly.
e.g. null amount, invalid amount format "0,99", etc.
In case of any error the endpoint response should replicate the response received after clicking "Refund" in the Admin Dashboard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed those validations in the endpoint.