From 1961446846132ad5fc57ab47559d5aa5a22ed805 Mon Sep 17 00:00:00 2001 From: Kcppdevelopers Date: Fri, 23 Jun 2017 15:29:32 +0530 Subject: [PATCH] Express Checkout - Billing Agreement adjustment, ref #789 --- angelleye-includes/angelleye-utility.php | 8 ++++++++ ...wc-gateway-paypal-express-request-angelleye.php | 14 ++++++++++---- classes/wc-gateway-paypal-express-angelleye.php | 12 ++++++------ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/angelleye-includes/angelleye-utility.php b/angelleye-includes/angelleye-utility.php index 2b9ea1351..0e50d4976 100644 --- a/angelleye-includes/angelleye-utility.php +++ b/angelleye-includes/angelleye-utility.php @@ -1825,4 +1825,12 @@ public static function angelleye_express_checkout_validate_shipping_address($pay return $paypal_request; } + public static function is_cart_contains_subscription() { + $cart_contains_subscription = false; + if (class_exists('WC_Subscriptions_Order') && class_exists('WC_Subscriptions_Cart')) { + $cart_contains_subscription = WC_Subscriptions_Cart::cart_contains_subscription(); + } + return $cart_contains_subscription; + } + } diff --git a/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-request-angelleye.php b/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-request-angelleye.php index e66bd6b78..8b1192b4f 100644 --- a/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-request-angelleye.php +++ b/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-request-angelleye.php @@ -644,7 +644,7 @@ public function angelleye_add_billing_agreement_param($PayPalRequestData, $token $product_id = apply_filters('woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key); $_paypal_billing_agreement = get_post_meta($product_id, '_paypal_billing_agreement', true); $ec_save_to_account = WC()->session->get('ec_save_to_account'); - if ($_paypal_billing_agreement == 'yes' || ( isset($ec_save_to_account) && $ec_save_to_account == 'on') || AngellEYE_Utility::angelleye_paypal_for_woo_wc_autoship_cart_has_autoship_item()) { + if ($_paypal_billing_agreement == 'yes' || ( isset($ec_save_to_account) && $ec_save_to_account == 'on') || AngellEYE_Utility::angelleye_paypal_for_woo_wc_autoship_cart_has_autoship_item() || AngellEYE_Utility::is_cart_contains_subscription() == true) { $BillingAgreements = array(); $Item = array( 'l_billingtype' => '', @@ -818,7 +818,9 @@ public function angelleye_write_error_log_and_send_email_notification($paypal_ac $error_display_type_message = sprintf(__('There was a problem paying with PayPal. Please try another method.', 'paypal-for-woocommerce')); } $error_display_type_message = apply_filters('ae_ppec_error_user_display_message', $error_display_type_message, $ErrorCode, $ErrorLongMsg); - wc_add_notice($error_display_type_message, 'error'); + if( AngellEYE_Utility::is_cart_contains_subscription() == false ) { + wc_add_notice($error_display_type_message, 'error'); + } } public function angelleye_write_paypal_request_log($paypal_action_name) { @@ -838,7 +840,9 @@ public function angelleye_write_paypal_request_log($paypal_action_name) { public function angelleye_ec_load_customer_data_using_ec_details() { if (!empty($this->paypal_response['SHIPTOCOUNTRYCODE'])) { if (!array_key_exists($this->paypal_response['SHIPTOCOUNTRYCODE'], WC()->countries->get_allowed_countries())) { - wc_add_notice(sprintf(__('We do not sell in your country, please try again with another address.', 'paypal-for-woocommerce')), 'error'); + if( AngellEYE_Utility::is_cart_contains_subscription() == false ) { + wc_add_notice(sprintf(__('We do not sell in your country, please try again with another address.', 'paypal-for-woocommerce')), 'error'); + } wp_redirect(get_permalink(wc_get_page_id('cart'))); exit; } @@ -1041,7 +1045,9 @@ public function angelleye_ec_sellerprotection_handler($order_id) { } $this->gateway->process_refund($order_id, $order->get_total(), __('There was a problem processing your order. Please contact customer support.', 'paypal-for-woocommerce')); $order->update_status('cancelled'); - wc_add_notice(__('Thank you for your recent order. Unfortunately it has been cancelled and refunded. Please contact our customer support team.', 'paypal-for-woocommerce'), 'error'); + if( AngellEYE_Utility::is_cart_contains_subscription() == false ) { + wc_add_notice(__('Thank you for your recent order. Unfortunately it has been cancelled and refunded. Please contact our customer support team.', 'paypal-for-woocommerce'), 'error'); + } wp_redirect(get_permalink(wc_get_page_id('cart'))); exit(); } diff --git a/classes/wc-gateway-paypal-express-angelleye.php b/classes/wc-gateway-paypal-express-angelleye.php index 62775a738..af5ece5f2 100644 --- a/classes/wc-gateway-paypal-express-angelleye.php +++ b/classes/wc-gateway-paypal-express-angelleye.php @@ -802,10 +802,6 @@ public function handle_wc_api() { if (!isset($_GET['pp_action'])) { return; } - $cart_contains_subscription = false; - if (class_exists('WC_Subscriptions_Order') && class_exists('WC_Subscriptions_Cart')) { - $cart_contains_subscription = WC_Subscriptions_Cart::cart_contains_subscription(); - } if (!defined('WOOCOMMERCE_CHECKOUT')) { define('WOOCOMMERCE_CHECKOUT', true); } @@ -820,9 +816,11 @@ public function handle_wc_api() { WC()->customer->set_calculated_shipping(true); } - if (WC()->cart->cart_contents_total <= 0 && WC()->cart->total <= 0 && $cart_contains_subscription == false) { + if (WC()->cart->cart_contents_total <= 0 && WC()->cart->total <= 0 && AngellEYE_Utility::is_cart_contains_subscription() == false) { if( empty($_GET['pay_for_order']) ) { + if( AngellEYE_Utility::is_cart_contains_subscription() == false ) { wc_add_notice(__('your order amount is zero, We were unable to process your order, please try again.', 'paypal-for-woocommerce'), 'error'); + } $paypal_express_request->angelleye_redirect(); exit; } @@ -1133,7 +1131,9 @@ public function paypal_express_checkout_error_handler($request_name = '', $redir $error_display_type_message = sprintf(__('There was a problem paying with PayPal. Please try another method.', 'paypal-for-woocommerce')); } $error_display_type_message = apply_filters('ae_ppec_error_user_display_message', $error_display_type_message, $ErrorCode, $ErrorLongMsg); - wc_add_notice($error_display_type_message, 'error'); + if( AngellEYE_Utility::is_cart_contains_subscription() == false ) { + wc_add_notice($error_display_type_message, 'error'); + } if (!is_ajax()) { wp_redirect($redirect_url); exit;