Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payment Load Balancer, PFWMA-132 #57

Merged
merged 38 commits into from
Jun 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5994b89
Add logic for WC Vendors functionality, PFWMA-125
kcppdevelopers May 19, 2020
09e3573
Dokan compatibility, PFWMA-125
kcppdevelopers May 19, 2020
49d8fb9
add new hooks for dokan plugin, PFWMA-125
kcppdevelopers May 20, 2020
92ae5c1
Add tab, PFWMA-130
kcppdevelopers May 22, 2020
754a21a
convert to 3 tabs, PFWMA-130
kcppdevelopers May 22, 2020
bdc28fe
Add vendor plugin option, PFWMA-131
kcppdevelopers May 22, 2020
e5f4baa
Add vendor plugin option, PFWMA-131
kcppdevelopers May 22, 2020
7895fa7
Merge branch 'PFWMA-125' of https://github.com/angelleye/paypal-for-w…
kcppdevelopers May 22, 2020
5a129e3
Add sandbox vs live mode base on vendor option, PFWMA-131
kcppdevelopers May 22, 2020
643ddc9
Add function for count active/deactivate vendor account, PFWMA-131
kcppdevelopers May 22, 2020
fab5685
Add enable/disable auto generate rule button, PFWMA-131
kcppdevelopers May 25, 2020
66aac2a
update text, PFWMA-131
kcppdevelopers May 25, 2020
e3e4026
create multi-account rule when role change, PFWMA-131
kcppdevelopers Jun 1, 2020
c6a8690
Add Payment status, PFWMA-124
kcppdevelopers Jun 1, 2020
4b5cdbc
UI update base on payment load balancer, PFWMA-132
kcppdevelopers Jun 2, 2020
b19079e
add new hook for wc vendor free version, PFWMA-131
kcppdevelopers Jun 2, 2020
711b1bd
UI update, PFWMA-132
kcppdevelopers Jun 2, 2020
53c8f02
Add new hook for admin shop setting for wc vendor, PFWMA-131
kcppdevelopers Jun 3, 2020
5e3dcb8
Add new hook for dokan lite, PFWMA-131
kcppdevelopers Jun 3, 2020
4590ed1
Merge branch 'PFWMA-131' of https://github.com/angelleye/paypal-for-w…
kcppdevelopers Jun 3, 2020
a5740f1
Add Payment Balancer for express checkout, PFWMA-132
kcppdevelopers Jun 3, 2020
0931cc3
update order data, PFWMA-132
kcppdevelopers Jun 3, 2020
a14ea51
Add refund functionality for payment load balancer, PFWMA-132
kcppdevelopers Jun 4, 2020
9c5005b
Add load balancer for payflow, PFWMA-132
kcppdevelopers Jun 4, 2020
3650b58
Add load balancer for payflow, PFWMA-132
kcppdevelopers Jun 4, 2020
87f61a8
Add a tool tip against Payment Load Balancer on the settings page, PF…
kcppdevelopers Jun 5, 2020
470b576
Add Payment seq, PFWMA-132
kcppdevelopers Jun 5, 2020
b424961
Add Payment seq, PFWMA-132
kcppdevelopers Jun 5, 2020
13fd17a
add new hook when account delete, PFWMA-132
kcppdevelopers Jun 6, 2020
589839f
change comparison operation, PFWMA-132
kcppdevelopers Jun 6, 2020
9d185d6
Add vendor tag, PFWMA-132
kcppdevelopers Jun 6, 2020
875bbc5
Make sure PayPal for WooCommerce plugin is active, PFWMA-132
deepakmaurya Jun 6, 2020
39c4708
Regenerate multi-account sequence array issue resolved, PFWMA-132
deepakmaurya Jun 6, 2020
7af2944
Multi-account regenerate sequence array caching issue resolved, PFWMA…
deepakmaurya Jun 6, 2020
adc9c18
update payflow account if already exist and unset account if post del…
kcppdevelopers Jun 7, 2020
1f4168f
ignore default account before unset, PFWMA-132
kcppdevelopers Jun 7, 2020
6fb5d7d
remove if condition, PFWMA-132
kcppdevelopers Jun 7, 2020
3c1af73
Do not create a rule for new pending vendors by WC vendors, PFWMA-132
deepakmaurya Jun 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew
array(
'key' => 'woocommerce_paypal_express_enable',
'value' => 'on',
'compare' => 'LIKE'
'compare' => '='
),
array(
'key' => 'woocommerce_paypal_express_testmode',
'value' => ($gateways->testmode == true) ? 'on' : '',
'compare' => 'LIKE'
'compare' => '='
),
array(
'key' => 'woocommerce_priority',
Expand Down Expand Up @@ -518,7 +518,12 @@ public function angelleye_paypal_for_woocommerce_multi_account_api_paypal_expres
}
$payment_action = array('set_express_checkout', 'get_express_checkout_details', 'do_express_checkout_payment');
if (!empty($_GET['pp_action']) && ( in_array($_GET['pp_action'], $payment_action))) {
return $this->angelleye_get_account_for_ec_parallel_payments($gateways, $gateway_setting, $order_id, $request);
$angelleye_payment_load_balancer = get_option('angelleye_payment_load_balancer', '');
if($angelleye_payment_load_balancer != '') {
return $this->angelleye_get_account_for_ec_payment_load_balancer($gateways, $gateway_setting, $order_id, $request);
} else {
return $this->angelleye_get_account_for_ec_parallel_payments($gateways, $gateway_setting, $order_id, $request);
}
}
return $request;
}
Expand All @@ -533,12 +538,12 @@ public function angelleye_get_multi_account_details_by_api_user_name($gateway_se
array(
'key' => 'woocommerce_paypal_express_sandbox_api_username',
'value' => $_multi_account_api_username,
'compare' => 'LIKE'
'compare' => '='
),
array(
'key' => 'woocommerce_paypal_express_api_username',
'value' => $_multi_account_api_username,
'compare' => 'LIKE'
'compare' => '='
)
)
);
Expand Down Expand Up @@ -1244,9 +1249,14 @@ public function own_angelleye_express_checkout_order_data($paypal_response, $ord
if (empty($ec_parallel_data_map)) {
return false;
}
for ($payment = 1; $payment <= 10; $payment++) {
for ($payment = 0; $payment <= 10; $payment++) {
if (!empty($paypal_response['PAYMENTINFO_' . $payment . '_TRANSACTIONID'])) {
$order->add_order_note(sprintf(__('PayPal Express payment Transaction ID: %s', 'paypal-for-woocommerce-multi-account-management'), isset($paypal_response['PAYMENTINFO_' . $payment . '_TRANSACTIONID']) ? $paypal_response['PAYMENTINFO_' . $payment . '_TRANSACTIONID'] : ''));
} elseif(!empty($paypal_response['PAYMENTINFO_' . $payment . '_ERRORCODE'])) {
$long_message = !empty($paypal_response['PAYMENTINFO_' . $payment . '_LONGMESSAGE']) ? $paypal_response['PAYMENTINFO_' . $payment . '_LONGMESSAGE'] : '';
if( !empty($long_message) ) {
$order->add_order_note($long_message);
}
} else {
break;
}
Expand All @@ -1258,8 +1268,12 @@ public function own_angelleye_express_checkout_order_data($paypal_response, $ord
$PAYMENTREQUESTID_array = $paypal_response['PAYMENTINFO_' . $transaction_map . '_PAYMENTREQUESTID'];
$request_order_item_id = explode('-', $PAYMENTREQUESTID_array);
if( !empty($request_order_item_id[0]) && $ec_parallel_data['order_item_id'] == $request_order_item_id[0]) {
$PAYMENTREQUESTID_array = $ec_parallel_data_map[$ec_parallel_data['product_id']]['transaction_id'] = $paypal_response['PAYMENTINFO_' . $transaction_map . '_TRANSACTIONID'];
wc_update_order_item_meta($ec_parallel_data['order_item_id'], '_transaction_id', $paypal_response['PAYMENTINFO_' . $transaction_map . '_TRANSACTIONID']);
if( !empty($paypal_response['PAYMENTINFO_' . $transaction_map . '_TRANSACTIONID'])) {
$ec_parallel_data_map[$ec_parallel_data['product_id']]['transaction_id'] = $paypal_response['PAYMENTINFO_' . $transaction_map . '_TRANSACTIONID'];
wc_update_order_item_meta($ec_parallel_data['order_item_id'], '_transaction_id', $paypal_response['PAYMENTINFO_' . $transaction_map . '_TRANSACTIONID']);
} elseif(!empty($paypal_response['PAYMENTINFO_' . $payment . '_ERRORCODE'])) {
wc_update_order_item_meta($ec_parallel_data['order_item_id'], 'Payment Status', __('Not Paid', 'paypal-for-woocommerce-multi-account-management'));
}
}
}
}
Expand Down Expand Up @@ -1313,10 +1327,12 @@ public function own_angelleye_is_express_checkout_parallel_payment_handle($bool,
$refund_error_message_pre = __('We can not refund this order as the Express Checkout API keys are missing! Please go to multi-account setup and add API key to process the refund', 'paypal-for-woocommerce-multi-account-management');
$refund_error_message_after = array();
$angelleye_multi_account_ec_parallel_data_map = get_post_meta($order_id, '_angelleye_multi_account_ec_parallel_data_map', true);
foreach ($angelleye_multi_account_ec_parallel_data_map as $key => $value) {
if (!empty($value['product_id']) && isset($value['is_api_set']) && $value['is_api_set'] == false) {
$product = wc_get_product($value['product_id']);
$refund_error_message_after[] = $product->get_title();
if( !empty($angelleye_multi_account_ec_parallel_data_map) ) {
foreach ($angelleye_multi_account_ec_parallel_data_map as $key => $value) {
if (!empty($value['product_id']) && isset($value['is_api_set']) && $value['is_api_set'] == false) {
$product = wc_get_product($value['product_id']);
$refund_error_message_after[] = $product->get_title();
}
}
}
if (!empty($refund_error_message_after)) {
Expand Down Expand Up @@ -1538,4 +1554,104 @@ public function own_angelleye_multi_account_need_shipping($bool, $order_id = '',
return $bool;

}

public function angelleye_get_account_for_ec_payment_load_balancer($gateways, $gateway_setting, $order_id, $request) {
if (!isset($gateways->testmode)) {
return;
}
$found_account = false;
$found_email = '';
if ($gateways->testmode == true) {
$option_key = 'angelleye_multi_ec_payment_load_balancer_sandbox';
$session_key = 'angelleye_sandbox_payment_load_balancer_ec_email';
$session_key_account = 'angelleye_sandbox_payment_load_balancer_ec_account';
} else {
$option_key = 'angelleye_multi_ec_payment_load_balancer';
$session_key = 'angelleye_payment_load_balancer_ec_email';
$session_key_account = 'angelleye_payment_load_balancer_ec_account';
}
$found_email = WC()->session->get( $session_key );
if( empty($found_email) ) {
$found_email = '';
$express_checkout_accounts = get_option($option_key);
if(!empty($express_checkout_accounts)) {
foreach ($express_checkout_accounts as $key => $account) {
if(empty($account['is_used'])) {
if ( $key != 'default' && false === get_post_status( $key ) ) {
unset($express_checkout_accounts[$key]);
} else {
$found_email = $account['email'];
WC()->session->set($session_key, $account['email']);
$account['is_used'] = 'yes';
$express_checkout_accounts[$key] = $account;
WC()->session->set($session_key_account, $account);
update_option($option_key, $express_checkout_accounts);
$found_account = true;
break;
}
}
}
if($found_account == false) {
foreach ($express_checkout_accounts as $key => $account) {
$account['is_used'] = '';
$express_checkout_accounts[$key] = $account;
}
foreach ($express_checkout_accounts as $key => $account) {
if ( $key != 'default' && false === get_post_status( $key ) ) {
unset($express_checkout_accounts[$key]);
} else {
$found_email = $account['email'];
WC()->session->set($session_key, $account['email']);
$account['is_used'] = 'yes';
$express_checkout_accounts[$key] = $account;
WC()->session->set($session_key_account, $account);
update_option($option_key, $express_checkout_accounts);
$found_account = true;
break;
}
}
}
}
}

if( !empty($request)) {
if($found_email != 'default') {
$request['Payments'][0]['sellerpaypalaccountid'] = $found_email;
if( !empty($order_id)) {
$angelleye_payment_load_balancer_account = WC()->session->get( $session_key_account );
update_post_meta($order_id, '_angelleye_payment_load_balancer_account', $angelleye_payment_load_balancer_account);
}
}
}
return $request;
}

public function own_angelleye_is_payment_load_balancer_not_used($bool, $order_id) {
$angelleye_payment_load_balancer_account = get_post_meta($order_id, '_angelleye_payment_load_balancer_account', true);
if (!empty($angelleye_payment_load_balancer_account)) {
return false;
}
return $bool;
}

public function own_angelleye_is_express_checkout_payment_load_balancer_handle($bool, $order_id, $gateway) {
try {
$processed_transaction_id = array();
$refund_error_message_pre = __('We can not refund this order as the Express Checkout API keys are missing! Please go to multi-account setup and add API key to process the refund', 'paypal-for-woocommerce-multi-account-management');
$angelleye_payment_load_balancer_account = get_post_meta($order_id, '_angelleye_payment_load_balancer_account', true);
if (!empty($angelleye_payment_load_balancer_account)) {
if( !empty($angelleye_payment_load_balancer_account['is_api_set']) && $angelleye_payment_load_balancer_account['is_api_set'] === true) {
$_transaction_id = get_post_meta($order_id, '_transaction_id', true);
$angelleye_payment_load_balancer_account['transaction_id'] = $_transaction_id;
$this->angelleye_express_checkout_load_paypal($angelleye_payment_load_balancer_account, $gateway, $order_id);
return true;
} else {
return new WP_Error('invalid_refund', $refund_error_message_pre);
}
}
return $bool;
} catch (Exception $ex) {

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ public function angelleye_get_multi_account_by_order_total_latest($gateways, $ga
array(
'key' => 'woocommerce_paypal_pro_payflow_enable',
'value' => 'on',
'compare' => 'LIKE'
'compare' => '='
),
array(
'key' => 'woocommerce_paypal_pro_payflow_testmode',
'value' => ($gateways->testmode == true) ? 'on' : '',
'compare' => 'LIKE'
'compare' => '='
),
array(
'key' => 'woocommerce_priority',
Expand Down Expand Up @@ -346,7 +346,7 @@ public function angelleye_get_multi_account_by_order_total_latest($gateways, $ga
} elseif (count($this->final_associate_account) == 0) {
return $this->final_associate_account;
} else {
return $this->angelleye_get_closest_amount($this->final_associate_account, $order_total);
return angelleye_get_closest_amount($this->final_associate_account, $order_total);
}
}
}
Expand All @@ -371,12 +371,12 @@ public function angelleye_get_multi_account_by_order_total($gateways, $gateway_s
array(
'key' => 'woocommerce_paypal_pro_payflow_enable',
'value' => 'on',
'compare' => 'LIKE'
'compare' => '='
),
array(
'key' => 'woocommerce_paypal_pro_payflow_testmode',
'value' => ($gateways->testmode == true) ? 'on' : '',
'compare' => 'LIKE'
'compare' => '='
)
)
);
Expand All @@ -388,12 +388,12 @@ public function angelleye_get_multi_account_by_order_total($gateways, $gateway_s
array(
'key' => 'woocommerce_paypal_express_enable',
'value' => 'on',
'compare' => 'LIKE'
'compare' => '='
),
array(
'key' => 'woocommerce_paypal_express_testmode',
'value' => ($gateways->testmode == true) ? 'on' : '',
'compare' => 'LIKE'
'compare' => '='
)
)
);
Expand Down Expand Up @@ -443,7 +443,7 @@ public function angelleye_get_multi_account_by_order_total($gateways, $gateway_s
} elseif (count($this->final_associate_account) == 0) {
return $this->final_associate_account;
} else {
return $this->angelleye_get_closest_amount($this->final_associate_account, $order_total);
return angelleye_get_closest_amount($this->final_associate_account, $order_total);
}
}
}
Expand All @@ -466,7 +466,10 @@ public function angelleye_paypal_for_woocommerce_multi_account_api_paypal_payflo
return false;
}
}
if ($this->is_angelleye_multi_account_used($order_id)) {
$angelleye_payment_load_balancer = get_option('angelleye_payment_load_balancer', '');
if(!empty($angelleye_payment_load_balancer)) {
$microprocessing_value = $this->angelleye_get_account_for_payflow_payment_load_balancer($gateways, $gateway_setting, $order_id);
} elseif ($this->is_angelleye_multi_account_used($order_id)) {
$_multi_account_api_username = $this->angelleye_get_multi_account_api_user_name($order_id);
$microprocessing_value = $this->angelleye_get_multi_account_details_by_api_user_name($gateway_setting, $_multi_account_api_username);
} elseif (!empty($gateway_setting->id) && $gateway_setting->id == 'paypal_pro_payflow') {
Expand Down Expand Up @@ -525,12 +528,12 @@ public function angelleye_get_multi_account_details_by_api_user_name($gateway_se
array(
'key' => 'woocommerce_paypal_pro_payflow_sandbox_api_paypal_user',
'value' => $_multi_account_api_username,
'compare' => 'LIKE'
'compare' => '='
),
array(
'key' => 'woocommerce_paypal_pro_payflow_api_paypal_user',
'value' => $_multi_account_api_username,
'compare' => 'LIKE'
'compare' => '='
)
)
);
Expand Down Expand Up @@ -597,4 +600,71 @@ public function card_type_from_account_number($account_number) {
}
return null;
}

public function angelleye_get_account_for_payflow_payment_load_balancer($gateways, $gateway_setting, $order_id) {
if (!isset($gateways->testmode)) {
return;
}
if ($gateways->testmode == true) {
$option_key = 'angelleye_multi_payflow_payment_load_balancer_sandbox';
} else {
$option_key = 'angelleye_multi_payflow_payment_load_balancer';
}
$is_account_found = false;
$used_account = get_post_meta($order_id, '_multi_account_api_username_load_balancer', true);
if( $used_account == 'default' ) {
return;
}
if( empty($used_account)) {
$payflow_accounts = get_option($option_key);
if(!empty($payflow_accounts)) {
foreach ($payflow_accounts as $key => $account) {
if(empty($account['is_used'])) {
if ( $key != 'default' && false === get_post_status( $key ) ) {
unset($payflow_accounts[$key]);
} else {
$account['is_used'] = 'yes';
$is_account_found = true;
$payflow_accounts[$key] = $account;
$used_account = $account['multi_account_id'];
update_post_meta($order_id, '_multi_account_api_username_load_balancer', $used_account);
update_option($option_key, $payflow_accounts);
break;
}
}
}
if($is_account_found == false) {
foreach ($payflow_accounts as $key => $account) {
$account['is_used'] = '';
$payflow_accounts[$key] = $account;
}
foreach ($payflow_accounts as $key => $account) {
if ( $key != 'default' && false === get_post_status( $key ) ) {
unset($payflow_accounts[$key]);
} else {
$account['is_used'] = 'yes';
$payflow_accounts[$key] = $account;
$used_account = $account['multi_account_id'];
update_post_meta($order_id, '_multi_account_api_username_load_balancer', $used_account);
update_option($option_key, $payflow_accounts);
break;
}
}
}
}
}
if($used_account == 'default') {
return;
}
if(!empty($used_account)) {
$post_meta = get_post_meta($used_account);
if( !empty($post_meta) ) {
$microprocessing_value = array();
foreach ($post_meta as $key => $value) {
$microprocessing_value[$key] = isset($value[0]) ? $value[0] : '';
}
return $microprocessing_value;
}
}
}
}
Loading