Skip to content

Commit

Permalink
Order Authorization / Capture Improvements, ref #761
Browse files Browse the repository at this point in the history
  • Loading branch information
kcppdevelopers committed Jun 15, 2017
1 parent 91fcf91 commit b80adbf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
26 changes: 17 additions & 9 deletions angelleye-includes/angelleye-admin-order-payment-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,42 +70,50 @@ public function angelleye_show_order_payment_metabox() {
}

public function admin_order_reference_order($post) {
$is_disable_button = false;
$order_id = $post->ID;
$order = wc_get_order($order_id);
if ($this->angelleye_is_order_need_payment($order) && $this->angelleye_is_admin_order_payment_method_available($order) == true && $this->angelleye_is_order_created_by_create_new_reference_order($order) == false) {
$reason_array = $this->angelleye_get_reason_why_place_order_button_not_available($order);
if( count($reason_array) > 1 ) {
$is_disable_button = true;
}
$reason_message = $this->angelleye_reason_array_to_nice_message($reason_array);
$this->angelleye_create_order_button($reason_message);
$this->angelleye_create_order_button($reason_message, $is_disable_button);
$this->angelleye_show_reference_order_metabox();
} else {
$this->angelleye_hide_reference_order_metabox();
}
}

public function admin_order_payment_process($post) {
$is_disable_button = false;
$order_id = $post->ID;
$order = wc_get_order($order_id);
if ($this->angelleye_is_order_created_by_create_new_reference_order($order) && $this->angelleye_is_order_status_pending($order) == true) {
$reason_array = $this->angelleye_get_reason_why_place_order_button_not_available($order);
if( count($reason_array) > 1 ) {
$is_disable_button = true;
}
$reason_message = $this->angelleye_reason_array_to_nice_message($reason_array);
$this->angelleye_place_order_button($reason_message);
$this->angelleye_place_order_button($reason_message, $is_disable_button);
$this->angelleye_show_order_payment_metabox();
} else {
$this->angelleye_hide_order_payment_metabox();
}
}

public function angelleye_place_order_button($reason_message) {
public function angelleye_place_order_button($reason_message, $is_disable_button) {
$is_disable = '';
if (!empty($reason_message)) {
if ($is_disable_button == true) {
$is_disable = 'disabled';
}
echo '<div class="wrap angelleye_admin_payment_process">' . $reason_message . '<input type="hidden" name="angelleye_admin_order_payment_process_sec" value="' . wp_create_nonce('angelleye_admin_order_payment_process_sec') . '" /><input type="submit" ' . $is_disable . ' id="angelleye_admin_order_payment_process_submit_button" value="Process Reference Transaction" name="angelleye_admin_order_payment_process_submit_button" class="button button-primary"></div>';
}

public function angelleye_create_order_button($reason_message) {
public function angelleye_create_order_button($reason_message, $is_disable_button) {
$is_disable = '';
if (!empty($reason_message)) {
if ($is_disable_button == true) {
$is_disable = 'disabled';
}
$checkbox = '<br><label><input type="checkbox" name="copy_items_to_new_invoice">Copy items to new order?</label><br>';
Expand Down Expand Up @@ -320,9 +328,9 @@ public function angelleye_get_reason_why_place_order_button_not_available($order
if ($this->angelleye_is_order_need_payment($order) == false) {
$reason_array[] = __('Order total must be greater than zero to process a reference transaction.', 'paypal-for-woocommerce');
}
if (!empty($reason_array)) {
$reason_array[] = __("Make any necessary adjustments to the item(s) on the order and calculate totals. Remember to click Update if any adjustments were made, and then click Process Reference Transaction.", 'paypal-for-woocommerce');
}

$reason_array[] = __("Make any necessary adjustments to the item(s) on the order and calculate totals. Remember to click Update if any adjustments were made, and then click Process Reference Transaction.", 'paypal-for-woocommerce');

return $reason_array;
}

Expand Down
16 changes: 13 additions & 3 deletions angelleye-includes/angelleye-utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ public function angelleye_paypal_for_woocommerce_order_action_callback($post) {
'post_status' => 'any'
);
$order = wc_get_order($post->ID);

$order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id();
$payment_method = get_post_meta($post->ID, '_payment_method', true);
$payment_action = get_post_meta($post->ID, '_payment_action', true);

Expand Down Expand Up @@ -1011,6 +1011,7 @@ public function angelleye_paypal_for_woocommerce_order_action_callback($post) {

<div class="angelleye_authorization_box" style="display: none;">
<?php
$remain_capture = 0;
$payment_method = get_post_meta($post->ID, '_payment_method', true);
$remain_authorize_amount_text = '';
if ($payment_method == 'paypal_express') {
Expand All @@ -1019,9 +1020,17 @@ public function angelleye_paypal_for_woocommerce_order_action_callback($post) {
} else {
$remain_authorize_amount_text = '';
}
} elseif ($payment_method == 'paypal_pro_payflow') {
$this->total_DoVoid = self::get_total('DoVoid', '', $order_id);
$this->total_DoCapture = self::get_total('DoCapture', 'Completed', $order_id);
$remain_capture = $order->get_total() - ( $this->total_DoVoid + $this->total_DoCapture );
$remain_capture = self::number_format($remain_capture);
}


?>
<input type="text" placeholder="Enter amount <?php echo $remain_authorize_amount_text; ?>" id="_regular_price" name="_regular_price" class="short wc_input_price text-box" style="width: 220px">

<input type="text" placeholder="Enter amount <?php echo $remain_capture; ?>" id="_regular_price" name="_regular_price" <?php if($remain_capture > 0 ) { echo "value='$remain_capture'"; } ?>class="short wc_input_price text-box" style="width: 220px">
</div>
<?php $this->angelleye_express_checkout_transaction_capture_dropdownbox($post->ID); ?>
<input type="submit" id="angelleye_payment_submit_button" value="Submit" name="save" class="button button-primary" style="display: none">
Expand Down Expand Up @@ -1711,11 +1720,12 @@ public function call_paypal_pro_payflow_docapture($order, $transaction_id, $capt
' Delayed Capture AUTHORIZATIONID: ' . $transaction_id . ' )'
);

$payment_order_meta = array('_transaction_id' => $transaction_id);
$payment_order_meta = array('_transaction_id' => $do_delayed_capture_result['PNREF']);
self::angelleye_add_order_meta($order_id, $payment_order_meta);
self::angelleye_paypal_for_woocommerce_add_paypal_transaction($do_delayed_capture_result, $order, 'DoCapture');
$this->angelleye_get_transactionDetails($transaction_id);
$this->angelleye_paypal_for_woocommerce_order_status_handler($order);

} else {
$ErrorCode = urldecode($do_delayed_capture_result["RESULT"]);
$ErrorLongMsg = urldecode($do_delayed_capture_result["RESPMSG"]);
Expand Down

0 comments on commit b80adbf

Please sign in to comment.