| @@ 1653-1669 (lines=17) @@ | ||
| 1650 | } |
|
| 1651 | ||
| 1652 | // Refund via API |
|
| 1653 | if ( $api_refund ) { |
|
| 1654 | if ( WC()->payment_gateways() ) { |
|
| 1655 | $payment_gateways = WC()->payment_gateways->payment_gateways(); |
|
| 1656 | } |
|
| 1657 | ||
| 1658 | $order = wc_get_order( $order_id ); |
|
| 1659 | ||
| 1660 | if ( isset( $payment_gateways[ $order->get_payment_method() ] ) && $payment_gateways[ $order->get_payment_method() ]->supports( 'refunds' ) ) { |
|
| 1661 | $result = $payment_gateways[ $order->get_payment_method() ]->process_refund( $order_id, $refund->get_refund_amount(), $refund->get_refund_reason() ); |
|
| 1662 | ||
| 1663 | if ( is_wp_error( $result ) ) { |
|
| 1664 | return $result; |
|
| 1665 | } elseif ( ! $result ) { |
|
| 1666 | 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 ); |
|
| 1667 | } |
|
| 1668 | } |
|
| 1669 | } |
|
| 1670 | ||
| 1671 | // HTTP 201 Created |
|
| 1672 | $this->server->send_status( 201 ); |
|
| @@ 2027-2042 (lines=16) @@ | ||
| 2024 | } |
|
| 2025 | ||
| 2026 | // Refund via API |
|
| 2027 | if ( $api_refund ) { |
|
| 2028 | if ( WC()->payment_gateways() ) { |
|
| 2029 | $payment_gateways = WC()->payment_gateways->payment_gateways(); |
|
| 2030 | } |
|
| 2031 | if ( isset( $payment_gateways[ $order->get_payment_method() ] ) && $payment_gateways[ $order->get_payment_method() ]->supports( 'refunds' ) ) { |
|
| 2032 | $result = $payment_gateways[ $order->get_payment_method() ]->process_refund( $order_id, $refund_amount, $refund_reason ); |
|
| 2033 | ||
| 2034 | do_action( 'woocommerce_refund_processed', $refund, $result ); |
|
| 2035 | ||
| 2036 | if ( is_wp_error( $result ) ) { |
|
| 2037 | throw new Exception( $result->get_error_message() ); |
|
| 2038 | } elseif ( ! $result ) { |
|
| 2039 | throw new Exception( __( 'Refund failed', 'woocommerce' ) ); |
|
| 2040 | } |
|
| 2041 | } |
|
| 2042 | } |
|
| 2043 | ||
| 2044 | // restock items |
|
| 2045 | foreach ( $line_item_qtys as $item_id => $qty ) { |
|