Jump to content

Customize Paypal Express Checkout Order Details


justinutherchris

Recommended Posts

I am trying to hack the paypal module to change the Order details that are sent via the Express Checkout API.

 

With PS 1.5.4 and the latest Paypal module the invoice looks like this:

 

Item Name				Amount + Tax
Item Description
Item Number
Item Price + Tax
Quantity

...

Item Total				   Total + Tax
Shipping And Handling			 Shipping + Tax
Total						Total

 

I would rather have it show prices before tax and then just have a total tax line like this:

 

Item Name				Amount
Item Description
Item Number
Item Price
Quantity

...

Item Total				   Total
Shipping And Handling			 Shipping
Total Tax				   Total Tax

Total					   Total

 

I have made modifications to process.php but I must be missing something because I am getting an error with my "hacked" process.php. When I switch it back to default it works fine though.

 

The diff of my hacked process.php and the backup of the original:

Comparing files process.php and PROCESS.PHP.BAK
***** process.php
   $fields['L_PAYMENTREQUEST_0_AMT'.$index] = Tools::ps_round($product['price'], $this->decimals);
   $fields['L_PAYMENTREQUEST_0_QTY'.$index] = $product['quantity'];

   $product_tax = $product['price_wt'] - $product['price'];
   $total = $total + (($fields['L_PAYMENTREQUEST_0_AMT'.$index] + $product_tax) * $product['quantity']);
***** PROCESS.PHP.BAK
   $fields['L_PAYMENTREQUEST_0_AMT'.$index] = Tools::ps_round($product['price_wt'], $this->decimals);
   $fields['L_PAYMENTREQUEST_0_QTY'.$index] = $product['quantity'];
*****
***** process.php
   else
	    $shipping_cost_wt = $this->context->cart->getTotalShippingCost(null, false);
***** PROCESS.PHP.BAK
   else
    $shipping_cost_wt = $this->context->cart->getTotalShippingCost();
*****
***** process.php
    $fields['PAYMENTREQUEST_0_AMT'] = $total + $fields['PAYMENTREQUEST_0_SHIPPINGAMT'];
    $fields['PAYMENTREQUEST_0_TAXAMT'] =   $this->context->cart->getOrderTotal() - $this->context->cart->getOrderTotal(
false);
   }
***** PROCESS.PHP.BAK
    $fields['PAYMENTREQUEST_0_AMT'] = $total + $fields['PAYMENTREQUEST_0_SHIPPINGAMT'];
   }
*****

 

Here is the error that I get.

Error occurred:
Please try to contact the merchant:
PayPal response:
TIMESTAMP -> 2013-04-04T09:09:42Z
L_ERRORCODE0 -> 10413
L_SHORTMESSAGE0 -> Transaction refused because of an invalid argument. See additional error messages for details.
L_LONGMESSAGE0 -> The totals of the cart item amounts do not match order amounts.
L_SEVERITYCODE0 -> Error

 

Anyone have any advice.

Edited by justinutherchris (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

Hey, I got it working.

 

The hardest part was the fact that you can't var_dump the totals because of the way the expresscheckout process works.

 

To get around that issue, I created a simple logging class that would write to a file in the same directory. By doing this, it was fairly easy to see where my mistake was.

 

Here is a link to a diff of the original and my custom process.php file.

http://diffchecker.com/yd5k93qi

The diff shows where I am doing the logging that led to finding the issue.

 

I can make no gaurantees that the code will work for subsequent versions of prestashop or the paypal module.

Edited by justinutherchris (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...