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

Line Item Details - Subtotal Mismatch Behavior Option Adjustment Needed : PFW-458 #1354

Merged
merged 9 commits into from
Sep 2, 2019
Merged
17 changes: 11 additions & 6 deletions angelleye-includes/angelleye-admin-order-payment-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,20 +622,25 @@ public function angelleye_reference_transaction_request_ec_pp_pf($order, $refere
);
$PayPalRequestData['ShippingAddress'] = $ShippingAddress;
}
$this->order_param = $this->gateway_calculation->order_calculation($order_id);
$this->send_items = 'yes' === $this->gateway->get_option('send_items', 'yes');
if( $this->send_items ) {
$this->order_param = $this->gateway_calculation->order_calculation($this->confirm_order_id);
} else {
$this->order_param = array('is_calculation_mismatch' => true);
}
if( $this->order_param['is_calculation_mismatch'] == false ) {
$Payment['order_items'] = $this->order_param['order_items'];
$PaymentDetails['taxamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['taxamt'], $order);
$PaymentDetails['shippingamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['shippingamt'], $order);
$PaymentDetails['itemamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['itemamt'], $order);
if( $order->get_total() != $PaymentDetails['shippingamt'] ) {
$PaymentDetails['shippingamt'] = $PaymentDetails['shippingamt'];
} else {
$PaymentDetails['shippingamt'] = 0.00;
}
} else {
$Payment['order_items'] = array();
}
if( $order->get_total() != $PaymentDetails['shippingamt'] ) {
$PaymentDetails['shippingamt'] = $PaymentDetails['shippingamt'];
} else {
$PaymentDetails['shippingamt'] = 0.00;
}
$PayPalRequestData['PaymentDetails'] = $PaymentDetails;
return $PayPalRequestData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class WC_Gateway_PayPal_Express_Request_AngellEYE {
public $confirm_order_id;
public $order_param;
public $user_email_address;
public $send_items;

public function __construct($gateway) {
try {
Expand All @@ -32,6 +33,7 @@ public function __construct($gateway) {
$this->email_notify_order_cancellations = $this->gateway->get_option('email_notify_order_cancellations', 'no');
$this->pending_authorization_order_status = $this->gateway->get_option('pending_authorization_order_status', 'On Hold');
$this->enable_in_context_checkout_flow = $this->gateway->get_option('enable_in_context_checkout_flow', 'yes');
$this->send_items = 'yes' === $this->gateway->get_option('send_items', 'yes');
$this->id = 'paypal_express';
if ($this->testmode == false) {
$this->testmode = AngellEYE_Utility::angelleye_paypal_for_woocommerce_is_set_sandbox_product();
Expand Down Expand Up @@ -485,7 +487,11 @@ public function angelleye_do_express_checkout_payment_request() {
} else {

}
$this->order_param = $this->gateway_calculation->order_calculation($this->confirm_order_id);
if( $this->send_items ) {
$this->order_param = $this->gateway_calculation->order_calculation($this->confirm_order_id);
} else {
$this->order_param = array('is_calculation_mismatch' => true);
}
$this->angelleye_load_paypal_class($this->gateway, $this, $this->confirm_order_id);
$paypal_express_checkout = WC()->session->get('paypal_express_checkout');
if (empty($paypal_express_checkout['token'])) {
Expand All @@ -502,9 +508,7 @@ public function angelleye_do_express_checkout_payment_request() {
$Payment = array(
'amt' => AngellEYE_Gateway_Paypal::number_format($order->get_total(), $order),
'currencycode' => version_compare(WC_VERSION, '3.0', '<') ? $order->get_order_currency() : $order->get_currency(),
'shippingdiscamt' => '',
'insuranceoptionoffered' => '',
'handlingamt' => '',
'desc' => '',
'custom' => apply_filters('ae_ppec_custom_parameter', json_encode(array('order_id' => version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id(), 'order_key' => version_compare(WC_VERSION, '3.0', '<') ? $order->order_key : $order->get_order_key()))),
'invnum' => $this->gateway->invoice_id_prefix . str_replace("#", "", $order->get_order_number()),
Expand All @@ -526,14 +530,15 @@ public function angelleye_do_express_checkout_payment_request() {
$Payment['taxamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['taxamt'], $order);
$Payment['shippingamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['shippingamt'], $order);
$Payment['itemamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['itemamt'], $order);
if( $order->get_total() != $Payment['shippingamt'] ) {
$Payment['shippingamt'] = $Payment['shippingamt'];
} else {
$Payment['shippingamt'] = 0.00;
}
} else {
$Payment['order_items'] = array();
}
if( $order->get_total() != $Payment['shippingamt'] ) {
$Payment['shippingamt'] = $Payment['shippingamt'];
} else {
$Payment['shippingamt'] = 0.00;
}

$REVIEW_RESULT = !empty($paypal_express_checkout['ExpresscheckoutDetails']) ? $paypal_express_checkout['ExpresscheckoutDetails'] : array();
$PaymentRedeemedOffers = array();
if ((isset($REVIEW_RESULT) && !empty($REVIEW_RESULT)) && isset($REVIEW_RESULT['WALLETTYPE0'])) {
Expand Down Expand Up @@ -645,7 +650,11 @@ public function angelleye_set_express_checkout_request() {
} else {
$order_id = wc_get_order_id_by_order_key($_GET['key']);
}
$this->cart_param = $this->gateway_calculation->order_calculation($order_id);
if( $this->send_items ) {
$this->cart_param = $this->gateway_calculation->order_calculation($order_id);
} else {
$this->cart_param = array('is_calculation_mismatch' => true);
}
$order = wc_get_order($order_id);
$order_total = $order->get_total();
if( !empty($_REQUEST['request_from']) && $_REQUEST['request_from'] == 'JSv4' ) {
Expand All @@ -668,7 +677,11 @@ public function angelleye_set_express_checkout_request() {
}
WC()->session->set('order_awaiting_payment', absint( wp_unslash( $order_id) ) );
} else {
$this->cart_param = $this->gateway_calculation->cart_calculation();
if( $this->send_items ) {
$this->cart_param = $this->gateway_calculation->cart_calculation();
} else {
$this->cart_param = array('is_calculation_mismatch' => true);
}
$order_total = WC()->cart->total;
}
$SECFields = array(
Expand Down Expand Up @@ -1361,17 +1374,10 @@ public function DoReferenceTransaction($order_id) {
$PaymentDetails = array(
'amt' => AngellEYE_Gateway_Paypal::number_format($order->get_total(), $order), // Required. Total amount of the order, including shipping, handling, and tax.
'currencycode' => version_compare(WC_VERSION, '3.0', '<') ? $order->get_order_currency() : $order->get_currency(), // A three-character currency code. Default is USD.
'itemamt' => '', // Required if you specify itemized L_AMT fields. Sum of cost of all items in this order.
'shippingamt' => '', // Total shipping costs for this order. If you specify SHIPPINGAMT you mut also specify a value for ITEMAMT.
'insuranceamt' => '',
'shippingdiscount' => '',
'handlingamt' => '', // Total handling costs for this order. If you specify HANDLINGAMT you mut also specify a value for ITEMAMT.
'taxamt' => '', // Required if you specify itemized L_TAXAMT fields. Sum of all tax items in this order.
'insuranceoptionoffered' => '', // If true, the insurance drop-down on the PayPal review page displays Yes and shows the amount.
'desc' => '', // Description of items on the order. 127 char max.
'custom' => apply_filters('ae_ppec_custom_parameter', json_encode(array('order_id' => version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id(), 'order_key' => version_compare(WC_VERSION, '3.0', '<') ? $order->order_key : $order->get_order_key()))), // Free-form field for your own use. 256 char max.
'invnum' => $this->gateway->invoice_id_prefix . str_replace("#", "", $order->get_order_number()), // Your own invoice or tracking number. 127 char max.
'buttonsource' => '' // URL for receiving Instant Payment Notifications
);
if (isset($this->gateway->notifyurl) && !empty($this->gateway->notifyurl)) {
$PaymentDetails['notifyurl'] = $this->gateway->notifyurl;
Expand All @@ -1396,20 +1402,24 @@ public function DoReferenceTransaction($order_id) {
);
$PayPalRequestData['ShippingAddress'] = $ShippingAddress;
}
$this->order_param = $this->gateway_calculation->order_calculation($order_id);
if( $this->send_items ) {
$this->order_param = $this->gateway_calculation->order_calculation($order_id);
} else {
$this->order_param = array('is_calculation_mismatch' => true);
}
if( $this->order_param['is_calculation_mismatch'] == false ) {
$Payment['order_items'] = $this->order_param['order_items'];
$PaymentDetails['taxamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['taxamt'], $order);
$PaymentDetails['shippingamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['shippingamt'], $order);
$PaymentDetails['itemamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['itemamt'], $order);
if( $order->get_total() != $PaymentDetails['shippingamt'] ) {
$PaymentDetails['shippingamt'] = $PaymentDetails['shippingamt'];
} else {
$PaymentDetails['shippingamt'] = 0.00;
}
} else {
$Payment['order_items'] = array();
}
if( $order->get_total() != $PaymentDetails['shippingamt'] ) {
$PaymentDetails['shippingamt'] = $PaymentDetails['shippingamt'];
} else {
$PaymentDetails['shippingamt'] = 0.00;
}
$PayPalRequestData['PaymentDetails'] = $PaymentDetails;
$this->paypal_response = $this->paypal->DoReferenceTransaction($PayPalRequestData);
AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_curl_error_handler($this->paypal_response, $methos_name = 'DoExpressCheckoutPayment', $gateway = 'PayPal Express Checkout', $this->gateway->error_email_notify);
Expand Down
8 changes: 7 additions & 1 deletion classes/wc-gateway-calculations-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ public function cart_calculation() {
$this->payment['discount_amount'] = AngellEYE_Gateway_Paypal::number_format(round($this->discount_amount, $this->decimals));
if ($this->taxamt < 0 || $this->shippingamt < 0) {
$this->payment['is_calculation_mismatch'] = true;
}
}
if($this->payment['itemamt'] <= 0) {
$this->payment['is_calculation_mismatch'] = true;
}
return $this->payment;
}

Expand Down Expand Up @@ -309,6 +312,9 @@ public function order_calculation($order_id) {
if ($this->taxamt < 0 || $this->shippingamt < 0) {
$this->payment['is_calculation_mismatch'] = true;
}
if($this->payment['itemamt'] <= 0) {
$this->payment['is_calculation_mismatch'] = true;
}
return $this->payment;
}

Expand Down
26 changes: 20 additions & 6 deletions classes/wc-gateway-paypal-advanced-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public function __construct() {
} else {
$this->subtotal_mismatch_behavior = $this->get_option('subtotal_mismatch_behavior', 'add');
}

if ($this->debug == 'yes')
$this->log = new WC_Logger();

Expand Down Expand Up @@ -503,7 +502,6 @@ public function get_secure_token($order) {
'USER1' => $order_id,
'INVNUM' => $this->invoice_id_prefix . str_replace("#", "", $order->get_order_number()),
'AMT' => number_format($order->get_total(), 2, '.', ''),
'FREIGHTAMT' => '',
'COMPANYNAME[' . strlen($billing_company) . ']' => $billing_company,
'CURRENCY' => version_compare(WC_VERSION, '3.0', '<') ? $order->get_order_currency() : $order->get_currency(),
'EMAIL' => $billing_email,
Expand Down Expand Up @@ -551,9 +549,11 @@ public function get_secure_token($order) {

$silentposturl = add_query_arg('wc-api', 'WC_Gateway_PayPal_Advanced_AngellEYE', add_query_arg('silent', 'true', $this->home_url));
$paypal_args['SILENTPOSTURL[' . strlen($silentposturl) . ']'] = $silentposturl;

$PaymentData = $this->calculation_angelleye->order_calculation($order_id);

if( $this->send_items ) {
$PaymentData = $this->calculation_angelleye->order_calculation($order_id);
} else {
$PaymentData = array('is_calculation_mismatch' => true);
}
if ($PaymentData['is_calculation_mismatch'] == false && ($length_error == 0 || count($PaymentData['order_items']) < 11 )) {
$paypal_args['ITEMAMT'] = 0;
$item_loop = 0;
Expand Down Expand Up @@ -732,6 +732,14 @@ public function admin_options() {
production.show();
}
}).change();
jQuery('#woocommerce_paypal_advanced_send_items').change(function () {
var advanced_subtotal_mismatch_behavior = jQuery('#woocommerce_paypal_advanced_subtotal_mismatch_behavior').closest('tr');
if (jQuery(this).is(':checked')) {
advanced_subtotal_mismatch_behavior.show();
} else {
advanced_subtotal_mismatch_behavior.hide();
}
}).change();
</script>
<?php
}
Expand Down Expand Up @@ -844,6 +852,13 @@ public function init_form_fields() {
'default' => '',
'desc_tip' => true,
),
'send_items' => array(
'title' => __('Send Item Details', 'paypal-for-woocommerce'),
'label' => __('Send line item details to PayPal', 'paypal-for-woocommerce'),
'type' => 'checkbox',
'description' => __('Include all line item details in the payment request to PayPal so that they can be seen from the PayPal transaction details page.', 'paypal-for-woocommerce'),
'default' => 'yes'
),
'subtotal_mismatch_behavior' => array(
'title' => __( 'Subtotal Mismatch Behavior', 'paypal-for-woocommerce' ),
'type' => 'select',
Expand Down Expand Up @@ -1265,7 +1280,6 @@ public function create_reference_transaction($token, $order) {
'USER1' => $order_id,
'INVNUM' => $this->invoice_id_prefix . str_replace("#", "", $order->get_order_number()),
'AMT' => number_format($order->get_total(), 2, '.', ''),
'FREIGHTAMT' => '',
'COMPANYNAME[' . strlen($billing_company) . ']' => $billing_company,
'CURRENCY' => version_compare(WC_VERSION, '3.0', '<') ? $order->get_order_currency() : $order->get_currency(),
'EMAIL' => $billing_email,
Expand Down
16 changes: 15 additions & 1 deletion classes/wc-gateway-paypal-express-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public function __construct() {
$this->disable_term = $this->get_option('disable_term', 'no');
$this->payment_action = $this->get_option('payment_action', 'Sale');
$this->billing_address = 'yes' === $this->get_option('billing_address', 'no');

if($this->send_items === false) {
$this->subtotal_mismatch_behavior = 'drop';
} else {
Expand Down Expand Up @@ -412,6 +411,14 @@ function is_funding_icon_should_show_php() {
production.show();
}
}).change();
jQuery('#woocommerce_paypal_express_send_items').change(function () {
var subtotal_mismatch_behavior = jQuery('#woocommerce_paypal_express_subtotal_mismatch_behavior').closest('tr');
if (jQuery(this).is(':checked')) {
subtotal_mismatch_behavior.show();
} else {
subtotal_mismatch_behavior.hide();
}
}).change();

jQuery('#woocommerce_paypal_express_disallowed_funding_methods').change(function () {
if( jQuery.inArray('credit', jQuery('#woocommerce_paypal_express_disallowed_funding_methods').val()) ) {
Expand Down Expand Up @@ -1006,6 +1013,13 @@ public function init_form_fields() {
'options' => $cancel_page,
'desc_tip' => true,
),
'send_items' => array(
'title' => __('Send Item Details', 'paypal-for-woocommerce'),
'label' => __('Send line item details to PayPal', 'paypal-for-woocommerce'),
'type' => 'checkbox',
'description' => __('Include all line item details in the payment request to PayPal so that they can be seen from the PayPal transaction details page.', 'paypal-for-woocommerce'),
'default' => 'yes'
),
'subtotal_mismatch_behavior' => array(
'title' => __( 'Subtotal Mismatch Behavior', 'paypal-for-woocommerce' ),
'type' => 'select',
Expand Down
Loading