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

Negative Fees are applied again in PayPal Standard #6837

Closed
arturi opened this issue Aug 9, 2018 · 6 comments · Fixed by #8156
Closed

Negative Fees are applied again in PayPal Standard #6837

arturi opened this issue Aug 9, 2018 · 6 comments · Fixed by #8156
Milestone

Comments

@arturi
Copy link

arturi commented Aug 9, 2018

Bug Report

Expected behavior

When a discount is applied to total amount, it’s calculated in EDD, and then the discounted amount is passed to PayPal as is. Total amount is the same number between EDD and PayPal.

Actual behavior

When I add discounts via EDD()->fees->add_fee(), everything is shown correctly in cart and Purchase History, but then PayPal Standard calculates and adds the discount again. So total of $80 with a discount of -$20 shows as total $60 in cart, but then becomes $40 in PayPal.

This started happening recently when I upgraded EDD from 2.2.8 to 2.9.3. If I comment out the line

https://github.com/easydigitaldownloads/easy-digital-downloads/blob/74905fe92666c7b79e65d9db6b8e60e71912a7e3/includes/gateways/paypal-standard.php#L292-L294

everything works as expected / as it used to. I’m hoping you can recognize the issue and tell me what I might be doing wrong, if this is not a bug.

Thank you for EDD and for the help!

Information (if a specific version is affected):

PHP Version: 5.6.32-5.6.32+mh2

EDD Version (or branch): 2.9.3

WordPress Version: 4.9.8

@cklosowski cklosowski changed the title Discount is applied again in PayPal Standard Fees are applied again in PayPal Standard Aug 9, 2018
@cklosowski
Copy link
Contributor

I've updated the title. Since your example mentions using the Fees API.

@cklosowski cklosowski changed the title Fees are applied again in PayPal Standard Negative Fees are applied again in PayPal Standard Aug 9, 2018
@cklosowski
Copy link
Contributor

@arturi, can you provide the exact call to the Fees API you are using? Including all the arguments, so we can try and replicate the exact situation you are seeing.

@arturi
Copy link
Author

arturi commented Aug 9, 2018

Thanks for the quick reply!

...

function apply_discount($total_discount_ammount) {
  if ($total_discount_ammount != 0) {
    EDD()->fees->add_fee($total_discount_ammount, 'Discount', 'b_edd_discount_' . time());
  }
}

function calculate_discounts() {
  $cart_contents = (edd_get_cart_contents());
  if ($cart_contents) {
    remove_duplicate_items($cart_contents);
    remove_all_fees();
    $total_discount_ammount = multiple_licences_discount($cart_contents) + multiple_styles_discount($cart_contents) + full_family_licences_discount($cart_contents);
    apply_discount($total_discount_ammount);
  }
}

add_action('init', 'calculate_discounts');

@ashleyfae
Copy link
Contributor

ashleyfae commented Oct 21, 2020

More information / duplicates:

#7163
https://github.com/easydigitaldownloads/edd-rcp-member-discounts/issues/14
https://github.com/easydigitaldownloads/edd-discounts-pro/issues/153

This affects RCP Member Discounts and likely also Discounts Pro.

Steps to reproduce with RCP Member Discounts (not sure if exact numbers matter, but including my settings, which I copied from a customer):

  1. Set up a Member Discount for 30%.
  2. Set up a download for $14.
  3. At checkout, price is shown as $9.80.
    Screenshot from 2020-10-21 14-10-20
  4. Check out with PayPal Standard. Once landing on PayPal's page, discount has doubled.
    Screenshot from 2020-10-21 14-12-17

As a few others have already pointed out, the issue is that $payment_data['price'] here: https://github.com/easydigitaldownloads/easy-digital-downloads/blob/74905fe92666c7b79e65d9db6b8e60e71912a7e3/includes/gateways/paypal-standard.php#L173 is the price after discounts (negative fees) have been applied. So in this example, it is 9.8.

$paypal_sum is looping through the cart_details array, which doesn't have any discounts / fees. So the price there is the full 14.0. So at this point https://github.com/easydigitaldownloads/easy-digital-downloads/blob/74905fe92666c7b79e65d9db6b8e60e71912a7e3/includes/gateways/paypal-standard.php#L272, $paypal_sum is 14.0.

At this point: https://github.com/easydigitaldownloads/easy-digital-downloads/blob/74905fe92666c7b79e65d9db6b8e60e71912a7e3/includes/gateways/paypal-standard.php#L287 $discounted_amount gets populated and set to 4.20

We make it into this if statement: https://github.com/easydigitaldownloads/easy-digital-downloads/blob/74905fe92666c7b79e65d9db6b8e60e71912a7e3/includes/gateways/paypal-standard.php#L296 because $paypal_sum is 14.0 but $purchase_data['price'] is 9.8 . This effectively adds in the discount. But remember, we already got the discount via $discounted_amount.

@dgoldak
Copy link

dgoldak commented Nov 24, 2020

I replicated the issue with EDD master and RCP member discounts. Loaded issue/6837 and confirmed discount is correct when checking out with PayPal.

I was not able to replicate the Discounts Pro issue this time.

@ashleyfae
Copy link
Contributor

Thank you @dgoldak !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants