diff --git a/modules/ppcp-wc-gateway/src/Admin/FeesRenderer.php b/modules/ppcp-wc-gateway/src/Admin/FeesRenderer.php index f3ef396d8..dd6c781a9 100644 --- a/modules/ppcp-wc-gateway/src/Admin/FeesRenderer.php +++ b/modules/ppcp-wc-gateway/src/Admin/FeesRenderer.php @@ -25,6 +25,19 @@ class FeesRenderer { */ public function render( WC_Order $wc_order ) : string { $breakdown = $wc_order->get_meta( PayPalGateway::FEES_META_KEY ); + $refund_breakdown = $wc_order->get_meta( PayPalGateway::REFUND_FEES_META_KEY ) ?: array(); + + $refund_breakdown = [ + 'paypal_fee' => [ + 'value' => 0.25, + 'currency_code' => 'EUR', + ], + 'net_amount' => [ + 'value' => 6.75, + 'currency_code' => 'EUR', + ], + ]; + if ( ! is_array( $breakdown ) ) { return ''; } @@ -42,6 +55,44 @@ class FeesRenderer { ); } + $refund_total = 0; + $refund_currency = null; + + $refund_fee = $refund_breakdown['paypal_fee'] ?? null; + if ( is_array( $refund_fee ) ) { + $refund_total += $refund_fee['value']; + $refund_currency = $refund_fee['currency_code']; + + $html .= $this->render_money_row( + __( 'PayPal Refund Fee:', 'woocommerce-paypal-payments' ), + __( 'The fee PayPal collects for the refund transactions.', 'woocommerce-paypal-payments' ), + $refund_fee['value'], + $refund_fee['currency_code'], + true, + 'refunded-total' + ); + } + + $refund_amount = $refund_breakdown['net_amount'] ?? null; + if ( is_array( $refund_amount ) ) { + $refund_total += $refund_amount['value']; + + if ( null === $refund_currency ) { + $refund_currency = $refund_fee['currency_code']; + } else if ( $refund_currency !== $refund_fee['currency_code'] ) { + $refund_currency = false; + } + + $html .= $this->render_money_row( + __( 'PayPal Refunded:', 'woocommerce-paypal-payments' ), + __( 'The net amount that was refunded.', 'woocommerce-paypal-payments' ), + $refund_amount['value'], + $refund_amount['currency_code'], + true, + 'refunded-total' + ); + } + $net = $breakdown['net_amount'] ?? null; if ( is_array( $net ) ) { $html .= $this->render_money_row( @@ -50,6 +101,15 @@ class FeesRenderer { $net['value'], $net['currency_code'] ); + + if ( ( $refund_total > 0.0 && $refund_currency === $net['currency_code'] ) ) { + $html .= $this->render_money_row( + __( 'PayPal Net Total:', 'woocommerce-paypal-payments' ), + __( 'The net total that will be credited to your PayPal account minus the refunds.', 'woocommerce-paypal-payments' ), + $net['value'] - $refund_total, + $net['currency_code'] + ); + } } return $html; @@ -63,9 +123,10 @@ class FeesRenderer { * @param string|float $value The money value. * @param string $currency The currency code. * @param bool $negative Whether to add the minus sign. + * @param string $html_class Html class to add to the elements. * @return string */ - private function render_money_row( string $title, string $tooltip, $value, string $currency, bool $negative = false ): string { + private function render_money_row( string $title, string $tooltip, $value, string $currency, bool $negative = false, string $html_class = '' ): string { /** * Bad type hint in WC phpdoc. * @@ -73,10 +134,10 @@ class FeesRenderer { */ return '