Skip to content

Commit

Permalink
Braintree - Refund not updating WC order status, ref #780
Browse files Browse the repository at this point in the history
  • Loading branch information
kcppdevelopers committed Aug 24, 2017
1 parent d7ff3d9 commit 5c626f8
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions classes/wc-gateway-braintree-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ function __construct() {
add_filter( 'clean_url', array( $this, 'adjust_fraud_script_tag' ) );
add_action( 'wp_print_footer_scripts', array( $this, 'render_fraud_js' ), 1 );
}

add_action('woocommerce_admin_order_data_after_order_details', array($this, 'woocommerce_admin_order_data_after_order_details'), 10, 1);

}

/**
Expand Down Expand Up @@ -1709,4 +1712,38 @@ public function angelleye_reload_gateway_credentials_for_woo_subscription_renewa
}
}
}

public function woocommerce_admin_order_data_after_order_details($order) {
$payment_method = version_compare( WC_VERSION, '3.0', '<' ) ? $order->payment_method : $order->get_payment_method();
if( 'braintree' == $payment_method && $order->get_status() != 'refunded') {
$this->angelleye_braintree_lib();
$order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id();
$transaction_id = $order->get_transaction_id();
$transaction = Braintree_Transaction::find($transaction_id);
if( !empty($transaction->refundIds) ) {
foreach ($transaction->refundIds as $key => $value) {
$braintree_refunded_id = get_post_meta($order_id, 'braintree_refunded_id', true);
if( empty($braintree_refunded_id) ) {
$braintree_refunded_id = array();
}
if(!in_array($value, $braintree_refunded_id)) {
$refund_transaction = Braintree_Transaction::find($value);
$default_args = array(
'amount' => $refund_transaction->amount,
'reason' => 'Data Synchronization from Braintree',
'order_id' => $order_id,
'refund_id' => 0,
'line_items' => array(),
'refund_payment' => false,
'restock_items' => false,
);
wc_create_refund( $default_args );
$order->add_order_note(sprintf(__('Refunded %s - Transaction ID: %s', 'paypal-for-woocommerce'), wc_price(number_format($refund_transaction->amount, 2, '.', '')), $value));
$braintree_refunded_id[$value] = $value;
update_post_meta($order_id, 'braintree_refunded_id', $braintree_refunded_id);
}
}
}
}
}
}

0 comments on commit 5c626f8

Please sign in to comment.