Skip to content

Commit

Permalink
Express Checkout - Billing Agreement adjustment, ref #789
Browse files Browse the repository at this point in the history
  • Loading branch information
kcppdevelopers committed Jun 23, 2017
1 parent c8a9c1a commit 1961446
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
8 changes: 8 additions & 0 deletions angelleye-includes/angelleye-utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '',
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand Down
12 changes: 6 additions & 6 deletions classes/wc-gateway-paypal-express-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1961446

Please sign in to comment.