| @@ 563-595 (lines=33) @@ | ||
| 560 | * @param float $amount |
|
| 561 | * @return bool |
|
| 562 | */ |
|
| 563 | public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
| 564 | $order = wc_get_order( $order_id ); |
|
| 565 | ||
| 566 | if ( ! $order || ! $order->get_transaction_id() ) { |
|
| 567 | return false; |
|
| 568 | } |
|
| 569 | ||
| 570 | $body = array(); |
|
| 571 | ||
| 572 | if ( ! is_null( $amount ) ) { |
|
| 573 | $body['amount'] = $this->get_stripe_amount( $amount ); |
|
| 574 | } |
|
| 575 | ||
| 576 | if ( $reason ) { |
|
| 577 | $body['metadata'] = array( |
|
| 578 | 'reason' => $reason, |
|
| 579 | ); |
|
| 580 | } |
|
| 581 | ||
| 582 | WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" ); |
|
| 583 | ||
| 584 | $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
| 585 | ||
| 586 | if ( is_wp_error( $response ) ) { |
|
| 587 | WC_Stripe::log( "Error: " . $response->get_error_message() ); |
|
| 588 | return $response; |
|
| 589 | } elseif ( ! empty( $response->id ) ) { |
|
| 590 | $refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason ); |
|
| 591 | $order->add_order_note( $refund_message ); |
|
| 592 | WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
| 593 | return true; |
|
| 594 | } |
|
| 595 | } |
|
| 596 | } |
|
| 597 | ||
| @@ 712-744 (lines=33) @@ | ||
| 709 | * @param float $amount |
|
| 710 | * @return bool |
|
| 711 | */ |
|
| 712 | public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
| 713 | $order = wc_get_order( $order_id ); |
|
| 714 | ||
| 715 | if ( ! $order || ! $order->get_transaction_id() ) { |
|
| 716 | return false; |
|
| 717 | } |
|
| 718 | ||
| 719 | $body = array(); |
|
| 720 | ||
| 721 | if ( ! is_null( $amount ) ) { |
|
| 722 | $body['amount'] = $this->get_stripe_amount( $amount ); |
|
| 723 | } |
|
| 724 | ||
| 725 | if ( $reason ) { |
|
| 726 | $body['metadata'] = array( |
|
| 727 | 'reason' => $reason, |
|
| 728 | ); |
|
| 729 | } |
|
| 730 | ||
| 731 | WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" ); |
|
| 732 | ||
| 733 | $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
| 734 | ||
| 735 | if ( is_wp_error( $response ) ) { |
|
| 736 | WC_Stripe::log( "Error: " . $response->get_error_message() ); |
|
| 737 | return $response; |
|
| 738 | } elseif ( ! empty( $response->id ) ) { |
|
| 739 | $refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason ); |
|
| 740 | $order->add_order_note( $refund_message ); |
|
| 741 | WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
| 742 | return true; |
|
| 743 | } |
|
| 744 | } |
|
| 745 | ||
| 746 | /** |
|
| 747 | * Sends the failed order email to admin |
|