Virtuemart Paypal payment type with AwoCoupon

Introduction

If you are using Virtuemart with AwoCoupon and have Paypal's payment type set to Shopping Cart, then you may experience an error when using vouchers that inolve discounting tax.

Virtuemart payapl shopping cart

When using this option, Virtuemart uses the variables from paypal:
    discount_amount_cart: coupon discount
    handling_cart: shipping costs, tax, and payment costs

Reading through paypal documentation here, discount_amount_cart only discounts the cart products. As far as I am aware, there is no discount for handling. So even if the total is 0, the handling costs will always be carried over to paypal.

The Solution

There are 2 solutions. If shopping cart is not required, then change the payment type to Normal
Virtuemart payapl normal

If you require the use of shopping cart, then the only way to get it to work is to make a modification to the paypal code in Virtuemart. Here is the fix:

In www/plugins/vmpayment/paypal/paypal/helpers/paypalstd.php
On or around line 322 is this
<?php
        $post_variables
['currency_code'] = $this->currency_code_3;
        if (!empty(
$this->cart->cartPrices['salesPriceCoupon'])) {
            
$post_variables['discount_amount_cart'] = abs(vmPSPlugin::getAmountValueInCurrency($this->cart->cartPrices['salesPriceCoupon'], $this->_method->payment_currency));
        }
?>

Right after that declaration, add the following code:
<?php
        
# seyi_code
            
if ($this->cart->products) {
                
$total_product 0;
                foreach (
$this->cart->products as $key => $product) {
                    
$total_product += ( $this->getProductAmount$this->cart->cartPrices [$key ] ) * $product->quantity );
                }
                if ( 
$total_product $post_variables['discount_amount_cart'] && $post_variables["handling_cart"] > ) {
                    
$post_variables["handling_cart"] -= $post_variables['discount_amount_cart'] - $total_product;
                    
$post_variables['handling_cart'] = max0$post_variables['handling_cart'] );
                }
            }
        }
?>

This code change does work, but there is a caveat to it. The total to pay shows correctly in paypal, but the cart display is not correct. Assuming you have a product cost of 40, shipping of 7 and a discount of 45. It should display as such:
Product Total: 40
Handling Fee:   7
Discount:      45

Instead, in paypal, it will be displayed like this:
Product total: 40
Handling Fee:   2
Discount:      40


Comments (0)