PluginProbe
MakeCommerce for WooCommerce / 3.0.2
MakeCommerce for WooCommerce v3.0.2
4.1.0 4.0.8 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 All 96 releases
makecommerce / payment / gateway / refund.php

refund.php in MakeCommerce for WooCommerce 3.0.2, at payment/gateway/refund.php

52 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MakeCommerce\Payment\Gateway;
4
5 trait Refund {
6
7 /**
8 * Processes refunds. Automatically called by \WC_Payment_Gateway
9 *
10 * @since 3.0.0
11 */
12 public function process_refund( $order_id, $amount = null, $comment = '' ) {
13
14 if ( $this->MK ) {
15
16 try {
17
18 $order = new \WC_Order( $order_id );
19 $transactionId = $order->get_transaction_id();
20
21 if ( empty( $transactionId ) ) {
22 $transactionId = get_post_meta( $order_id, '_makecommerce_transaction_id', true );
23 }
24
25 if ( $response = $this->MK->createRefund( $transactionId, array( 'amount' => sprintf( "%.2f", $amount ), 'comment' => ( $comment ? : 'refund' ) ) ) ) {
26 if ( $status = ( string )$response->transaction->status ) {
27
28 switch ( $status ) {
29 case "REFUNDED":
30 $order->add_order_note( sprintf( __( 'Refund completed for amount %s', 'wc_makecommerce_domain' ), $amount ) );
31 return true;
32 break;
33 case "PART_REFUNDED":
34 $order->add_order_note( sprintf( __( 'Partial refund completed for amount %s', 'wc_makecommerce_domain' ), $amount ) );
35 return true;
36 break;
37 }
38 }
39 }
40
41 return false;
42
43 } catch ( \Exception $e ) {
44 return new \WP_Error( 'makecommerce_refund_error', $e->getMessage() );
45 }
46
47 return false;
48 }
49
50 return false;
51 }
52 }