Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into Issue-761-ALL
  • Loading branch information
kcppdevelopers committed Jul 10, 2017
2 parents f3867d6 + bf74cfd commit 9bd6de0
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 325 deletions.
49 changes: 46 additions & 3 deletions angelleye-includes/angelleye-utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,17 @@ public function call_do_authorization($order) {

public function ec_add_log($message, $level = 'info') {
if ($this->ec_debug == 'yes') {
if (empty($this->log)) {
$this->log = wc_get_logger();
if (version_compare(WC_VERSION, '3.0', '<')) {
if (empty($this->log)) {
$this->log = new WC_Logger();
}
$this->log->add($this->payment_method, $message);
} else {
if (empty($this->log)) {
$this->log = wc_get_logger();
}
$this->log->log($level, $message, array('source' => $this->payment_method));
}
$this->log->log($level, $message, array('source' => $this->payment_method));
}
}

Expand Down Expand Up @@ -1862,4 +1869,40 @@ 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;
}

public static function is_display_angelleye_billing_agreement_notice($express_checkout) {
global $product;
global $post;
$is_display = false;
if(get_user_meta(get_current_user_id(), 'ignore_billing_agreement_notice')) {
return $is_display;
}
if( $express_checkout->enabled == 'no' ) {
return $is_display;
}
if (function_exists('get_current_screen')) {
$screen = get_current_screen();
if ('product' == $screen->post_type && 'post' == $screen->base) {
$_paypal_billing_agreement = get_post_meta($post->ID, '_paypal_billing_agreement', true);
if( $_paypal_billing_agreement == 'yes') {
return $is_display = true;
}
$product = wc_get_product( $post->ID );
if( class_exists( 'WC_Subscriptions_Product' ) && WC_Subscriptions_Product::is_subscription( $product ) ) {
return $is_display = true;
}
}
}
if( $express_checkout->enabled == 'yes' && (!empty($_GET['page']) && $_GET['page'] == 'wc-settings' ) && (!empty($_GET['tab']) && $_GET['tab'] == 'checkout' ) && $express_checkout->enable_tokenized_payments == 'yes' ) {
return $is_display = true;
}
return $is_display;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,18 @@ public function ec_get_version() {
}

public function angelleye_ec_save_payment_method_checkbox() {
return sprintf(
'<div class="angelleye_ec_save_to_accoount_box">
<p class="form-row woocommerce-SavedPaymentMethods-saveNew">
<label for="wc-%1$s-new-payment-method"><input id="wc-%1$s-new-payment-method" name="wc-%1$s-new-payment-method" type="checkbox" />%2$s</label>
</p>
</div>', esc_attr('paypal_express'), esc_html__('Save PayPal account for future use', 'paypal-for-woocommerce')
);
if( AngellEYE_Utility::is_cart_contains_subscription() == false ) {
return sprintf(
'<div class="angelleye_ec_save_to_accoount_box">
<p class="form-row woocommerce-SavedPaymentMethods-saveNew">
<label for="wc-%1$s-new-payment-method"><input id="wc-%1$s-new-payment-method" name="wc-%1$s-new-payment-method" type="checkbox" />%2$s</label>
</p>
</div>', esc_attr('paypal_express'), esc_html__('Save PayPal account for future use', 'paypal-for-woocommerce')
);
} else {
return '';
}

}

public function angelleye_paypal_for_woocommerce_needs_shipping($SECFields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function __construct($version) {
add_filter('woocommerce_order_button_html', array($this, 'angelleye_woocommerce_order_button_html'), 10, 1);
add_filter( 'woocommerce_coupons_enabled', array($this, 'angelleye_woocommerce_coupons_enabled'), 10, 1);
add_action( 'woocommerce_cart_shipping_packages', array( $this, 'maybe_add_shipping_information' ) );
add_action( 'admin_notices', array($this, 'angelleye_billing_agreement_notice') );
if (AngellEYE_Utility::is_express_checkout_credentials_is_set()) {
if ($this->button_position == 'bottom' || $this->button_position == 'both') {
add_action('woocommerce_proceed_to_checkout', array($this, 'woocommerce_paypal_express_checkout_button_angelleye'), 22);
Expand All @@ -104,6 +105,9 @@ public function __construct($version) {
require_once( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-function-angelleye.php' );
}
$this->function_helper = new WC_Gateway_PayPal_Express_Function_AngellEYE();
if( $this->function_helper->ec_is_express_checkout() ) {
remove_all_actions('woocommerce_review_order_before_payment');
}
$this->is_order_completed = true;
} catch (Exception $ex) {

Expand Down Expand Up @@ -656,4 +660,10 @@ public function maybe_add_shipping_information($packages) {
}
return $packages;
}

public function angelleye_billing_agreement_notice() {
if (AngellEYE_Utility::is_display_angelleye_billing_agreement_notice($this) == true) {
echo '<div class="error"><p>' . sprintf(__("PayPal Express Checkout Billing Agreements / Reference Transactions require specific approval by PayPal. Please contact PayPal to enable this feature before using it on your site. <a href=%s>%s</a>", 'paypal-for-woocommerce'), '"' . esc_url(add_query_arg("ignore_billing_agreement_notice", 0)) . '"', __("Hide this notice", 'paypal-for-woocommerce')) . '</p></div>';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ public function angelleye_do_express_checkout_payment() {
AngellEYE_Utility::angelleye_paypal_for_woocommerce_add_paypal_transaction($this->paypal_response, $order, $this->gateway->payment_action);
}
if ($this->response_helper->ec_is_response_success($this->paypal_response)) {
$post_data = WC()->session->get('post_data');
if( empty($post_data) ) {
apply_filters( 'woocommerce_payment_successful_result', array('result' => 'success'), $order_id );
}
do_action( 'woocommerce_before_pay_action', $order );
$this->angelleye_ec_get_customer_email_address($this->confirm_order_id);
$this->angelleye_ec_sellerprotection_handler($this->confirm_order_id);
$this->angelleye_ec_save_billing_agreement($order_id);
Expand Down Expand Up @@ -243,6 +248,11 @@ public function angelleye_do_express_checkout_payment() {
wp_redirect($this->gateway->get_return_url($order));
exit();
} elseif ($this->response_helper->ec_is_response_successwithwarning($this->paypal_response)) {
$post_data = WC()->session->get('post_data');
if( empty($post_data) ) {
apply_filters( 'woocommerce_payment_successful_result', array('result' => 'success'), $order_id );
}
do_action( 'woocommerce_before_pay_action', $order );
$this->angelleye_ec_get_customer_email_address($this->confirm_order_id);
$this->angelleye_ec_sellerprotection_handler($this->confirm_order_id);
$this->angelleye_ec_save_billing_agreement($order_id);
Expand Down Expand Up @@ -280,7 +290,7 @@ public function angelleye_do_express_checkout_payment() {
update_post_meta($order->get_id(), '_express_chekout_transactionid', isset($this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']) ? $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID'] : '' );
}

$order->add_order_note(sprintf(__('%s payment approved! Trnsaction ID: %s', 'paypal-for-woocommerce'), $this->gateway->title, $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']));
$order->add_order_note(sprintf(__('%s payment approved! Transaction ID: %s', 'paypal-for-woocommerce'), $this->gateway->title, $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']));

WC()->cart->empty_cart();
wc_clear_notices();
Expand Down Expand Up @@ -519,7 +529,14 @@ public function angelleye_set_express_checkout_request() {
} elseif (!empty($post_data['shipping_last_name'])) {
$shiptoname = $post_data['shipping_last_name'];
}
$Payment['shiptoname'] = $shiptoname;

if( !empty($post_data['shipping_company']) ) {
$shipping_company = $post_data['shipping_company'];
$Payment['shiptoname'] = $shipping_company .' - '. $shiptoname;
} else {
$Payment['shiptoname'] = $shiptoname;
}

$Payment['shiptostreet'] = !empty($post_data['shipping_address_1']) ? $post_data['shipping_address_1'] : '';
$Payment['shiptostreet2'] = !empty($post_data['shipping_address_2']) ? $post_data['shipping_address_2'] : '';
$Payment['shiptocity'] = !empty($post_data['shipping_city']) ? wc_clean(stripslashes($post_data['shipping_city'])) : '';
Expand All @@ -535,7 +552,14 @@ public function angelleye_set_express_checkout_request() {
} elseif (!empty($post_data['billing_last_name'])) {
$shiptoname = $post_data['billing_last_name'];
}
$Payment['shiptoname'] = $shiptoname;

if( !empty($post_data['billing_company']) ) {
$billing_company = $post_data['billing_company'];
$Payment['shiptoname'] = $billing_company .' - '. $shiptoname;
} else {
$Payment['shiptoname'] = $shiptoname;
}

$Payment['shiptostreet'] = !empty($post_data['billing_address_1']) ? $post_data['billing_address_1'] : '';
$Payment['shiptostreet2'] = !empty($post_data['billing_address_2']) ? $post_data['billing_address_2'] : '';
$Payment['shiptocity'] = !empty($post_data['billing_city']) ? wc_clean(stripslashes($post_data['billing_city'])) : '';
Expand Down Expand Up @@ -634,7 +658,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 @@ -808,7 +832,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 @@ -828,7 +854,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 @@ -1031,7 +1059,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 Expand Up @@ -1122,6 +1152,9 @@ public function angelleye_ec_force_to_display_checkout_page() {
if ($this->must_create_account) {
return apply_filters('angelleye_ec_force_to_display_checkout_page', true);
}
if(AngellEYE_Utility::is_cart_contains_subscription() == true) {
return apply_filters('angelleye_ec_force_to_display_checkout_page', true);
}
$paypal_express_terms = WC()->session->get('paypal_express_terms');
if (wc_get_page_id('terms') > 0 && apply_filters('woocommerce_checkout_show_terms', true)) {
if ($this->disable_term) {
Expand Down
10 changes: 9 additions & 1 deletion angelleye-includes/paypal-rest-api-utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public function __construct($gateway) {
$this->rest_client_id = $this->gateway->get_option('rest_client_id', false);
$this->rest_secret_id = $this->gateway->get_option('rest_secret_id', false);
}

if (class_exists('WC_Gateway_Calculation_AngellEYE')) {
$this->calculation_angelleye = new WC_Gateway_Calculation_AngellEYE();
} else {
require_once( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-calculations-angelleye.php' );
$this->calculation_angelleye = new WC_Gateway_Calculation_AngellEYE();
}
}

/**
Expand Down Expand Up @@ -238,7 +245,8 @@ public function set_trnsaction_obj_value($order, $card_data) {
* @param type $order
*/
public function set_item($order) {
$this->payment_data = AngellEYE_Gateway_Paypal::calculate($order, $this->send_items);
$order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id();
$this->payment_data = $this->calculation_angelleye->order_calculation($order_id);
foreach ($this->payment_data['order_items'] as $item) {
$this->item = new Item();
$this->item->setName($item['name']);
Expand Down
3 changes: 3 additions & 0 deletions assets/css/angelleye-express-checkout.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
.express-checkout .express-provided.hidden {
display: none !important
}
.express-checkout #order_payment_heading {
display: none;
}
.express-checkout.express-hide-terms .terms label[for="terms"],
.express-checkout.express-hide-terms .terms #terms {
display: none !important
Expand Down
18 changes: 13 additions & 5 deletions classes/wc-gateway-braintree-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -828,11 +828,19 @@ public function get_dependencies() {
return array('curl', 'dom', 'hash', 'openssl', 'SimpleXML', 'xmlwriter');
}

public function add_log($message) {
if ($this->debug == 'yes') {
if (empty($this->log))
$this->log = new WC_Logger();
$this->log->add('braintree', $message);
public function add_log($message, $level = 'info') {
if ($this->debug) {
if (version_compare(WC_VERSION, '3.0', '<')) {
if (empty($this->log)) {
$this->log = new WC_Logger();
}
$this->log->add('braintree', $message);
} else {
if (empty($this->log)) {
$this->log = wc_get_logger();
}
$this->log->log($level, $message, array('source' => 'braintree'));
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions classes/wc-gateway-calculations-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ public function cart_calculation() {
$this->order_items[] = $item;
$roundedPayPalTotal += round($amount * $values['quantity'], $this->decimals);
}
foreach (WC()->cart->get_fees() as $cart_item_key => $fee_values) {
$fee_item = array(
'name' => html_entity_decode( wc_trim_string( $fee_values->name ? $fee_values->name : __( 'Fee', 'paypal-for-woocommerce' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
'desc' => '',
'qty' => 1,
'amt' => $fee_values->amount,
'number' => ''
);
$this->order_items[] = $fee_item;
$roundedPayPalTotal += round($amount * 1, $this->decimals);

}
$this->taxamt = round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->decimals);
$this->shippingamt = round(WC()->cart->shipping_total, $this->decimals);
$this->itemamt = round(WC()->cart->cart_contents_total, $this->decimals) + $this->discount_amount;
Expand Down Expand Up @@ -131,6 +143,19 @@ public function order_calculation($order_id) {
$this->order_items[] = $item;
$roundedPayPalTotal += round($amount * $values['qty'], $this->decimals);
}
foreach ( $order->get_fees() as $cart_item_key => $fee_values) {
$fee_item_name = version_compare(WC_VERSION, '3.0', '<') ? $fee_values['name'] : $fee_values->get_name();
$amount = $order->get_line_total( $fee_values );
$fee_item = array(
'name' => html_entity_decode( wc_trim_string( $fee_item_name ? $fee_item_name : __( 'Fee', 'paypal-for-woocommerce' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
'desc' => '',
'qty' => 1,
'amt' => $amount,
'number' => ''
);
$this->order_items[] = $fee_item;
$roundedPayPalTotal += round($amount * 1, $this->decimals);
}
$this->taxamt = round($order->get_total_tax(), $this->decimals);
$this->shippingamt = round(( version_compare(WC_VERSION, '3.0', '<') ? $order->get_total_shipping() : $order->get_shipping_total()), $this->decimals);
$this->itemamt = round($order->get_subtotal(), $this->decimals);
Expand Down
Loading

0 comments on commit 9bd6de0

Please sign in to comment.