| @@ 1654-1670 (lines=17) @@ | ||
| 1651 | } |
|
| 1652 | ||
| 1653 | // Refund via API |
|
| 1654 | if ( $api_refund ) { |
|
| 1655 | if ( WC()->payment_gateways() ) { |
|
| 1656 | $payment_gateways = WC()->payment_gateways->payment_gateways(); |
|
| 1657 | } |
|
| 1658 | ||
| 1659 | $order = wc_get_order( $order_id ); |
|
| 1660 | ||
| 1661 | if ( isset( $payment_gateways[ $order->payment_method ] ) && $payment_gateways[ $order->payment_method ]->supports( 'refunds' ) ) { |
|
| 1662 | $result = $payment_gateways[ $order->payment_method ]->process_refund( $order_id, $refund->get_refund_amount(), $refund->get_refund_reason() ); |
|
| 1663 | ||
| 1664 | if ( is_wp_error( $result ) ) { |
|
| 1665 | return $result; |
|
| 1666 | } elseif ( ! $result ) { |
|
| 1667 | throw new WC_API_Exception( 'woocommerce_api_create_order_refund_api_failed', __( 'An error occurred while attempting to create the refund using the payment gateway API', 'woocommerce' ), 500 ); |
|
| 1668 | } |
|
| 1669 | } |
|
| 1670 | } |
|
| 1671 | ||
| 1672 | // HTTP 201 Created |
|
| 1673 | $this->server->send_status( 201 ); |
|
| @@ 2202-2217 (lines=16) @@ | ||
| 2199 | } |
|
| 2200 | ||
| 2201 | // Refund via API |
|
| 2202 | if ( $api_refund ) { |
|
| 2203 | if ( WC()->payment_gateways() ) { |
|
| 2204 | $payment_gateways = WC()->payment_gateways->payment_gateways(); |
|
| 2205 | } |
|
| 2206 | if ( isset( $payment_gateways[ $order->payment_method ] ) && $payment_gateways[ $order->payment_method ]->supports( 'refunds' ) ) { |
|
| 2207 | $result = $payment_gateways[ $order->payment_method ]->process_refund( $order_id, $refund_amount, $refund_reason ); |
|
| 2208 | ||
| 2209 | do_action( 'woocommerce_refund_processed', $refund, $result ); |
|
| 2210 | ||
| 2211 | if ( is_wp_error( $result ) ) { |
|
| 2212 | throw new Exception( $result->get_error_message() ); |
|
| 2213 | } elseif ( ! $result ) { |
|
| 2214 | throw new Exception( __( 'Refund failed', 'woocommerce' ) ); |
|
| 2215 | } |
|
| 2216 | } |
|
| 2217 | } |
|
| 2218 | ||
| 2219 | // restock items |
|
| 2220 | foreach ( $line_item_qtys as $item_id => $qty ) { |
|