Skip to content

Commit

Permalink
Merge pull request #1331 from angelleye/PFW-409
Browse files Browse the repository at this point in the history
Product Level Sandbox Mode, PFW-409
  • Loading branch information
kcppdevelopers committed Jul 10, 2019
2 parents fdd0dfb + a536fb0 commit 4b5cfb8
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 25 deletions.
44 changes: 29 additions & 15 deletions angelleye-includes/angelleye-utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function add_ec_angelleye_paypal_php_library() {
return false;
}
if ($this->testmode == false) {
$this->testmode = AngellEYE_Utility::angelleye_paypal_for_woocommerce_is_set_sandbox_product();
$this->testmode = AngellEYE_Utility::angelleye_paypal_for_woocommerce_is_set_sandbox_product($this->order_id);
}
if ($this->testmode == true) {
$this->api_username = $gateway_obj->get_option('sandbox_api_username');
Expand Down Expand Up @@ -1666,23 +1666,37 @@ public function angelleye_paypal_for_woocommerce_billing_agreement_details($orde
<p> <?php echo $billing_agreement_id; ?></p> <?php
}

public static function angelleye_paypal_for_woocommerce_is_set_sandbox_product() {
public static function angelleye_paypal_for_woocommerce_is_set_sandbox_product($order_id = null) {
global $product, $wp_query, $post;
$is_sandbox_set = false;
if (did_action('wp_loaded')) {
if (isset(WC()->cart) && sizeof(WC()->cart->get_cart()) > 0) {
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
$product_id = apply_filters('woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key);
$product_type = get_post_type($product_id);
if($product_type == 'product_variation') {
$product_id = wp_get_post_parent_id($product_id);
}
$_enable_sandbox_mode = get_post_meta($product_id, '_enable_sandbox_mode', true);
if ($_enable_sandbox_mode == 'yes') {
$is_sandbox_set = true;
return $is_sandbox_set;
}
if (isset(WC()->cart) && sizeof(WC()->cart->get_cart()) > 0) {
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
$product_id = apply_filters('woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key);
$product_type = get_post_type($product_id);
if($product_type == 'product_variation') {
$product_id = wp_get_post_parent_id($product_id);
}
$_enable_sandbox_mode = get_post_meta($product_id, '_enable_sandbox_mode', true);
if ($_enable_sandbox_mode == 'yes') {
$is_sandbox_set = true;
return $is_sandbox_set;
}
}
} elseif(isset( $wp_query ) && is_product() ) {
$product = wc_get_product( $post->ID );
$product_id = $product->get_id();
$product_type = get_post_type($product_id);
if($product_type == 'product_variation') {
$product_id = wp_get_post_parent_id($product_id);
}
$_enable_sandbox_mode = get_post_meta($product->get_id(), '_enable_sandbox_mode', true);
if ($_enable_sandbox_mode == 'yes') {
$is_sandbox_set = true;
return $is_sandbox_set;
}
} elseif (isset ($order_id) && !empty ($order_id)) {
$is_sandbox = get_post_meta($order_id, 'is_sandbox', true);
return $is_sandbox;
}
return $is_sandbox_set;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@ public function ec_enqueue_scripts_product_page($is_mini_cart = false) {
$this->button_color = 'darkblue';
$this->button_fundingicons = '';
}
if ($this->testmode == false) {
$this->testmode = AngellEYE_Utility::angelleye_paypal_for_woocommerce_is_set_sandbox_product();
}
$js_value = array('is_page_name' => '', 'enable_in_context_checkout_flow' => ( $this->enable_in_context_checkout_flow == 'yes' ? 'yes' : 'no'));
if ($this->angelleye_is_in_context_enable() == true) {
$cancel_url = !empty($this->cancel_page) ? get_permalink($this->cancel_page) : wc_get_cart_url();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,22 @@ public function angelleye_do_express_checkout_payment_request() {
}

public function angelleye_load_paypal_class($gateway, $current, $order_id = null) {
if ($this->testmode == false) {
$this->testmode = AngellEYE_Utility::angelleye_paypal_for_woocommerce_is_set_sandbox_product($order_id);
}
if ($this->testmode == true) {
$this->API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
$this->PAYPAL_URL = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
$this->api_username = $this->gateway->get_option('sandbox_api_username');
$this->api_password = $this->gateway->get_option('sandbox_api_password');
$this->api_signature = $this->gateway->get_option('sandbox_api_signature');
} else {
$this->API_Endpoint = "https://api-3t.paypal.com/nvp";
$this->PAYPAL_URL = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
$this->api_username = $this->gateway->get_option('api_username');
$this->api_password = $this->gateway->get_option('api_password');
$this->api_signature = $this->gateway->get_option('api_signature');
}
do_action('angelleye_paypal_for_woocommerce_multi_account_api_paypal_express', $gateway, $current, $order_id);
$this->credentials = array(
'Sandbox' => $this->testmode,
Expand Down
29 changes: 20 additions & 9 deletions classes/wc-gateway-braintree-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ public function angelleye_do_payment($order) {
$this->storeInVaultOnSuccess = true;
}
$request_data = array();
$this->angelleye_braintree_lib();
$this->angelleye_braintree_lib($order_id);

$billing_company = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_company : $order->get_billing_company();
$billing_first_name = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_first_name : $order->get_billing_first_name();
Expand Down Expand Up @@ -1303,7 +1303,7 @@ public function process_refund($order_id, $amount = null, $reason = '') {
return false;
}

$this->angelleye_braintree_lib();
$this->angelleye_braintree_lib($order_id);

try {
$transaction = Braintree_Transaction::find($order->get_transaction_id());
Expand Down Expand Up @@ -1379,7 +1379,17 @@ public function process_refund($order_id, $amount = null, $reason = '') {
}
}

public function angelleye_braintree_lib() {
public function angelleye_braintree_lib($order_id = null) {
if ($this->testmode == false) {
$this->testmode = AngellEYE_Utility::angelleye_paypal_for_woocommerce_is_set_sandbox_product($order_id);
}
if ($this->testmode == true) {
$this->sandbox = true;
$this->environment = $this->sandbox == false ? 'production' : 'sandbox';
$this->merchant_id = $this->sandbox == false ? $this->get_option('merchant_id') : $this->get_option('sandbox_merchant_id');
$this->private_key = $this->sandbox == false ? $this->get_option('private_key') : $this->get_option('sandbox_private_key');
$this->public_key = $this->sandbox == false ? $this->get_option('public_key') : $this->get_option('sandbox_public_key');
}
try {
require_once( 'lib/lib/Braintree.php' );
Braintree_Configuration::environment($this->environment);
Expand Down Expand Up @@ -1921,7 +1931,7 @@ public function braintree_create_customer($customer_id) {
}

public function subscription_process_payment($order_id) {
$this->angelleye_braintree_lib();
$this->angelleye_braintree_lib($order_id);
$order = new WC_Order($order_id);
$order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id();
if (isset($_POST['wc-braintree-payment-token']) && 'new' !== $_POST['wc-braintree-payment-token']) {
Expand Down Expand Up @@ -1998,7 +2008,7 @@ public function process_subscription_payment($order, $amount, $payment_token = n
$this->angelleye_reload_gateway_credentials_for_woo_subscription_renewal_order($order);
$order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id();
$request_data = array();
$this->angelleye_braintree_lib();
$this->angelleye_braintree_lib($order_id);

$billing_company = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_company : $order->get_billing_company();
$billing_first_name = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_first_name : $order->get_billing_first_name();
Expand Down Expand Up @@ -2152,7 +2162,7 @@ public function angelleye_braintree_get_merchant_account_id($order_id = null) {
}
}
}
$this->angelleye_braintree_lib();
$this->angelleye_braintree_lib($order_id);
try {
$gateway = Braintree_Configuration::gateway();
$merchantAccountIterator = $gateway->merchantAccount()->all();
Expand Down Expand Up @@ -2272,8 +2282,8 @@ 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();
$this->angelleye_braintree_lib($order_id);
$transaction_id = $order->get_transaction_id();
if (!empty($transaction_id)) {
$transaction = Braintree_Transaction::find($transaction_id);
Expand Down Expand Up @@ -2420,9 +2430,10 @@ public function get_braintree_exception_message($e) {
}

public function angelleye_save_payment_auth($order) {
$order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id();
$success = true;
$this->validate_fields();
$this->angelleye_braintree_lib();
$this->angelleye_braintree_lib($order_id);
$customer_id = get_current_user_id();
$braintree_customer_id = get_user_meta($customer_id, 'braintree_customer_id', true);
if (!empty($braintree_customer_id)) {
Expand Down Expand Up @@ -2700,7 +2711,7 @@ public function pfw_braintree_do_capture($request_data = array(), $order) {
}

public function subscription_change_payment($order_id) {
$this->angelleye_braintree_lib();
$this->angelleye_braintree_lib($order_id);
$order = new WC_Order($order_id);
$order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id();
if (isset($_POST['wc-braintree-payment-token']) && 'new' !== $_POST['wc-braintree-payment-token']) {
Expand Down
4 changes: 4 additions & 0 deletions classes/wc-gateway-paypal-advanced-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,10 @@ public function angelleye_reload_gateway_credentials_for_woo_subscription_renewa
$product_id = wp_get_post_parent_id($product_id);
}
if( !empty($product_id) ) {
$product_type = get_post_type($product_id);
if($product_type == 'product_variation') {
$product_id = wp_get_post_parent_id($product_id);
}
$_enable_sandbox_mode = get_post_meta($product_id, '_enable_sandbox_mode', true);
if ($_enable_sandbox_mode == 'yes') {
$this->testmode = true;
Expand Down
10 changes: 9 additions & 1 deletion classes/wc-gateway-paypal-pro-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -2122,6 +2122,14 @@ public function update_payment_status_by_paypal_responce($orderid, $result, $tra
}

public function angelleye_load_paypal_pro_class($gateway, $current, $order_id = null) {
if ($this->testmode == false) {
$this->testmode = AngellEYE_Utility::angelleye_paypal_for_woocommerce_is_set_sandbox_product($order_id);
}
if ($this->testmode == true) {
$this->api_username = $this->get_option('sandbox_api_username');
$this->api_password = $this->get_option('sandbox_api_password');
$this->api_signature = $this->get_option('sandbox_api_signature');
}
do_action('angelleye_paypal_for_woocommerce_multi_account_api_paypal_pro', $gateway, $current, $order_id);
if (!class_exists('Angelleye_PayPal_WC')) {
require_once( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/lib/angelleye/paypal-php-library/includes/paypal.class.php' );
Expand Down Expand Up @@ -2156,7 +2164,7 @@ public function subscription_change_payment($order_id) {
} else {
$this->validate_fields();
$card = $this->get_posted_card();
$this->angelleye_load_paypal_pro_class($this->gateway, $this, null);
$this->angelleye_load_paypal_pro_class($this->gateway, $this, $order_id);
$DPFields = array(
'paymentaction' => 'Authorization',
'ipaddress' => AngellEYE_Utility::get_user_ip(),
Expand Down
11 changes: 11 additions & 0 deletions classes/wc-gateway-paypal-pro-payflow-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,10 @@ function do_payment($order, $card_number, $card_exp, $card_csc) {
$cvv2_response_order_note .= sprintf(__('CVV2 Match: %s', 'paypal-for-woocommerce'), $cvv2_response_code);
if ($old_wc) {
update_post_meta($order_id, '_CVV2MATCH', $cvv2_response_code);
update_post_meta($order_id, 'is_sandbox', $this->testmode);
} else {
update_post_meta($order->get_id(), '_CVV2MATCH', $cvv2_response_code);
update_post_meta($order->get_id(), 'is_sandbox', $this->testmode);
}
$order->add_order_note($cvv2_response_order_note);
do_action('ae_add_custom_order_note', $order, $card, $token, $PayPalResult);
Expand Down Expand Up @@ -1657,6 +1659,15 @@ public function angelleye_paypal_pro_payflow_reference_transaction_notice() {
}

public function angelleye_load_paypal_payflow_class($gateway, $current, $order_id = null) {
if ($this->testmode == false) {
$this->testmode = AngellEYE_Utility::angelleye_paypal_for_woocommerce_is_set_sandbox_product($order_id);
}
if ($this->testmode == true) {
$this->paypal_vendor = $this->get_option('sandbox_paypal_vendor');
$this->paypal_partner = $this->get_option('sandbox_paypal_partner', 'PayPal');
$this->paypal_password = $this->get_option('sandbox_paypal_password');
$this->paypal_user = $this->get_option('sandbox_paypal_user', $this->paypal_vendor);
}
do_action('angelleye_paypal_for_woocommerce_multi_account_api_paypal_payflow', $gateway, $current, $order_id);
$this->credentials = array(
'Sandbox' => $this->testmode,
Expand Down

0 comments on commit 4b5cfb8

Please sign in to comment.