Do not save refund id after ppcp_refund_order

This commit is contained in:
Alex P 2023-03-17 17:23:33 +02:00
parent 3b1407aab4
commit 7a994f8d28
No known key found for this signature in database
GPG key ID: 54487A734A204D71
3 changed files with 14 additions and 9 deletions

View file

@ -73,21 +73,23 @@ function ppcp_capture_order( WC_Order $wc_order ): void {
} }
/** /**
* Refunds the order. * Refunds the PayPal order.
* Note that you can use wc_refund_payment() to trigger the refund in WC and PayPal.
* *
* @param WC_Order $wc_order The WC order. * @param WC_Order $wc_order The WC order.
* @param float $amount The refund amount. * @param float $amount The refund amount.
* @param string $reason The reason for the refund. * @param string $reason The reason for the refund.
* @return string The PayPal refund ID.
* @throws InvalidArgumentException When the order cannot be refunded. * @throws InvalidArgumentException When the order cannot be refunded.
* @throws Exception When the operation fails. * @throws Exception When the operation fails.
*/ */
function ppcp_refund_order( WC_Order $wc_order, float $amount, string $reason = '' ): void { function ppcp_refund_order( WC_Order $wc_order, float $amount, string $reason = '' ): string {
$order = ppcp_get_paypal_order( $wc_order ); $order = ppcp_get_paypal_order( $wc_order );
$refund_processor = PPCP::container()->get( 'wcgateway.processor.refunds' ); $refund_processor = PPCP::container()->get( 'wcgateway.processor.refunds' );
assert( $refund_processor instanceof RefundProcessor ); assert( $refund_processor instanceof RefundProcessor );
$refund_processor->refund( $order, $wc_order, $amount, $reason ); return $refund_processor->refund( $order, $wc_order, $amount, $reason );
} }
/** /**

View file

@ -103,7 +103,9 @@ class RefundProcessor {
switch ( $mode ) { switch ( $mode ) {
case self::REFUND_MODE_REFUND: case self::REFUND_MODE_REFUND:
$this->refund( $order, $wc_order, $amount, $reason ); $refund_id = $this->refund( $order, $wc_order, $amount, $reason );
$this->add_refund_to_meta( $wc_order, $refund_id );
break; break;
case self::REFUND_MODE_VOID: case self::REFUND_MODE_VOID:
@ -133,13 +135,14 @@ class RefundProcessor {
* @param string $reason The reason for the refund. * @param string $reason The reason for the refund.
* *
* @throws RuntimeException When operation fails. * @throws RuntimeException When operation fails.
* @return string The PayPal refund ID.
*/ */
public function refund( public function refund(
Order $order, Order $order,
WC_Order $wc_order, WC_Order $wc_order,
float $amount, float $amount,
string $reason = '' string $reason = ''
): void { ): string {
$payments = $this->get_payments( $order ); $payments = $this->get_payments( $order );
$captures = $payments->captures(); $captures = $payments->captures();
@ -157,9 +160,7 @@ class RefundProcessor {
) )
); );
$refund_id = $this->payments_endpoint->refund( $refund ); return $this->payments_endpoint->refund( $refund );
$this->add_refund_to_meta( $wc_order, $refund_id );
} }
/** /**

View file

@ -48,9 +48,11 @@ class OrderRefundTest extends ModularTestCase
$this->refundProcessor $this->refundProcessor
->expects('refund') ->expects('refund')
->andReturn('456qwe')
->once(); ->once();
ppcp_refund_order($wcOrder, 42.0, 'reason'); $refund_id = ppcp_refund_order($wcOrder, 42.0, 'reason');
$this->assertEquals('456qwe', $refund_id);
} }
public function testOrderWithoutId(): void { public function testOrderWithoutId(): void {