| @@ 1631-1647 (lines=17) @@ | ||
| 1628 | } |
|
| 1629 | ||
| 1630 | // Refund via API |
|
| 1631 | if ( $api_refund ) { |
|
| 1632 | if ( WC()->payment_gateways() ) { |
|
| 1633 | $payment_gateways = WC()->payment_gateways->payment_gateways(); |
|
| 1634 | } |
|
| 1635 | ||
| 1636 | $order = wc_get_order( $order_id ); |
|
| 1637 | ||
| 1638 | if ( isset( $payment_gateways[ $order->payment_method ] ) && $payment_gateways[ $order->payment_method ]->supports( 'refunds' ) ) { |
|
| 1639 | $result = $payment_gateways[ $order->payment_method ]->process_refund( $order_id, $refund->get_refund_amount(), $refund->get_refund_reason() ); |
|
| 1640 | ||
| 1641 | if ( is_wp_error( $result ) ) { |
|
| 1642 | return $result; |
|
| 1643 | } elseif ( ! $result ) { |
|
| 1644 | 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 ); |
|
| 1645 | } |
|
| 1646 | } |
|
| 1647 | } |
|
| 1648 | ||
| 1649 | // HTTP 201 Created |
|
| 1650 | $this->server->send_status( 201 ); |
|
| @@ 2179-2194 (lines=16) @@ | ||
| 2176 | } |
|
| 2177 | ||
| 2178 | // Refund via API |
|
| 2179 | if ( $api_refund ) { |
|
| 2180 | if ( WC()->payment_gateways() ) { |
|
| 2181 | $payment_gateways = WC()->payment_gateways->payment_gateways(); |
|
| 2182 | } |
|
| 2183 | if ( isset( $payment_gateways[ $order->payment_method ] ) && $payment_gateways[ $order->payment_method ]->supports( 'refunds' ) ) { |
|
| 2184 | $result = $payment_gateways[ $order->payment_method ]->process_refund( $order_id, $refund_amount, $refund_reason ); |
|
| 2185 | ||
| 2186 | do_action( 'woocommerce_refund_processed', $refund, $result ); |
|
| 2187 | ||
| 2188 | if ( is_wp_error( $result ) ) { |
|
| 2189 | throw new Exception( $result->get_error_message() ); |
|
| 2190 | } elseif ( ! $result ) { |
|
| 2191 | throw new Exception( __( 'Refund failed', 'woocommerce' ) ); |
|
| 2192 | } |
|
| 2193 | } |
|
| 2194 | } |
|
| 2195 | ||
| 2196 | // restock items |
|
| 2197 | foreach ( $line_item_qtys as $item_id => $qty ) { |
|