| @@ 1657-1673 (lines=17) @@ | ||
| 1654 | } |
|
| 1655 | ||
| 1656 | // Refund via API |
|
| 1657 | if ( $api_refund ) { |
|
| 1658 | if ( WC()->payment_gateways() ) { |
|
| 1659 | $payment_gateways = WC()->payment_gateways->payment_gateways(); |
|
| 1660 | } |
|
| 1661 | ||
| 1662 | $order = wc_get_order( $order_id ); |
|
| 1663 | ||
| 1664 | if ( isset( $payment_gateways[ $order->payment_method ] ) && $payment_gateways[ $order->payment_method ]->supports( 'refunds' ) ) { |
|
| 1665 | $result = $payment_gateways[ $order->payment_method ]->process_refund( $order_id, $refund->get_refund_amount(), $refund->get_refund_reason() ); |
|
| 1666 | ||
| 1667 | if ( is_wp_error( $result ) ) { |
|
| 1668 | return $result; |
|
| 1669 | } elseif ( ! $result ) { |
|
| 1670 | 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 ); |
|
| 1671 | } |
|
| 1672 | } |
|
| 1673 | } |
|
| 1674 | ||
| 1675 | // HTTP 201 Created |
|
| 1676 | $this->server->send_status( 201 ); |
|
| @@ 2228-2243 (lines=16) @@ | ||
| 2225 | } |
|
| 2226 | ||
| 2227 | // Refund via API |
|
| 2228 | if ( $api_refund ) { |
|
| 2229 | if ( WC()->payment_gateways() ) { |
|
| 2230 | $payment_gateways = WC()->payment_gateways->payment_gateways(); |
|
| 2231 | } |
|
| 2232 | if ( isset( $payment_gateways[ $order->payment_method ] ) && $payment_gateways[ $order->payment_method ]->supports( 'refunds' ) ) { |
|
| 2233 | $result = $payment_gateways[ $order->payment_method ]->process_refund( $order_id, $refund_amount, $refund_reason ); |
|
| 2234 | ||
| 2235 | do_action( 'woocommerce_refund_processed', $refund, $result ); |
|
| 2236 | ||
| 2237 | if ( is_wp_error( $result ) ) { |
|
| 2238 | throw new Exception( $result->get_error_message() ); |
|
| 2239 | } elseif ( ! $result ) { |
|
| 2240 | throw new Exception( __( 'Refund failed', 'woocommerce' ) ); |
|
| 2241 | } |
|
| 2242 | } |
|
| 2243 | } |
|
| 2244 | ||
| 2245 | // restock items |
|
| 2246 | foreach ( $line_item_qtys as $item_id => $qty ) { |
|