| @@ 1651-1667 (lines=17) @@ | ||
| 1648 | } |
|
| 1649 | ||
| 1650 | // Refund via API |
|
| 1651 | if ( $api_refund ) { |
|
| 1652 | if ( WC()->payment_gateways() ) { |
|
| 1653 | $payment_gateways = WC()->payment_gateways->payment_gateways(); |
|
| 1654 | } |
|
| 1655 | ||
| 1656 | $order = wc_get_order( $order_id ); |
|
| 1657 | ||
| 1658 | if ( isset( $payment_gateways[ $order->payment_method ] ) && $payment_gateways[ $order->payment_method ]->supports( 'refunds' ) ) { |
|
| 1659 | $result = $payment_gateways[ $order->payment_method ]->process_refund( $order_id, $refund->get_refund_amount(), $refund->get_refund_reason() ); |
|
| 1660 | ||
| 1661 | if ( is_wp_error( $result ) ) { |
|
| 1662 | return $result; |
|
| 1663 | } elseif ( ! $result ) { |
|
| 1664 | 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 ); |
|
| 1665 | } |
|
| 1666 | } |
|
| 1667 | } |
|
| 1668 | ||
| 1669 | // HTTP 201 Created |
|
| 1670 | $this->server->send_status( 201 ); |
|
| @@ 2198-2213 (lines=16) @@ | ||
| 2195 | } |
|
| 2196 | ||
| 2197 | // Refund via API |
|
| 2198 | if ( $api_refund ) { |
|
| 2199 | if ( WC()->payment_gateways() ) { |
|
| 2200 | $payment_gateways = WC()->payment_gateways->payment_gateways(); |
|
| 2201 | } |
|
| 2202 | if ( isset( $payment_gateways[ $order->payment_method ] ) && $payment_gateways[ $order->payment_method ]->supports( 'refunds' ) ) { |
|
| 2203 | $result = $payment_gateways[ $order->payment_method ]->process_refund( $order_id, $refund_amount, $refund_reason ); |
|
| 2204 | ||
| 2205 | do_action( 'woocommerce_refund_processed', $refund, $result ); |
|
| 2206 | ||
| 2207 | if ( is_wp_error( $result ) ) { |
|
| 2208 | throw new Exception( $result->get_error_message() ); |
|
| 2209 | } elseif ( ! $result ) { |
|
| 2210 | throw new Exception( __( 'Refund failed', 'woocommerce' ) ); |
|
| 2211 | } |
|
| 2212 | } |
|
| 2213 | } |
|
| 2214 | ||
| 2215 | // restock items |
|
| 2216 | foreach ( $line_item_qtys as $item_id => $qty ) { |
|