Skip to content

Commit

Permalink
Merge pull request #8156 from easydigitaldownloads/issue/6837
Browse files Browse the repository at this point in the history
Prevent negative fees from getting applied twice #6837
  • Loading branch information
ashleyfae committed Nov 30, 2020
2 parents 1074703 + eb84dd5 commit 6f2b75b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions includes/gateways/paypal-standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,21 @@ function edd_process_paypal_purchase( $purchase_data ) {
}
}

$price_before_discount = $purchase_data['price'];
if ( $discounted_amount > '0' ) {
$paypal_args['discount_amount_cart'] = edd_sanitize_amount( $discounted_amount );

/*
* Add the discounted amount back onto the price to get the "price before discount". We do this
* to avoid double applying any discounts below.
* @link https://github.com/easydigitaldownloads/easy-digital-downloads/issues/6837
*/
$price_before_discount += $paypal_args['discount_amount_cart'];
}

if( $paypal_sum > $purchase_data['price'] ) {
$difference = round( $paypal_sum - $purchase_data['price'], 2 );
// Check if there are any additional discounts we need to add that we haven't already accounted for.
if( $paypal_sum > $price_before_discount ) {
$difference = round( $paypal_sum - $price_before_discount, 2 );
if( ! isset( $paypal_args['discount_amount_cart'] ) ) {
$paypal_args['discount_amount_cart'] = 0;
}
Expand Down

0 comments on commit 6f2b75b

Please sign in to comment.