سؤال

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 paypal page 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.

Here is a link to the original process.php file on the github repo: https://github.com/PrestaShop/PrestaShop-modules/blob/master/paypal/express_checkout/process.php

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

Comparing files process.php and PROCESS.PHP.BAK
***** process.php
private function setProductsList(&$fields, &$index, &$total) {
...
    $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
private function setProductsList(&$fields, &$index, &$total) {
...
    $fields['L_PAYMENTREQUEST_0_AMT'.$index] = Tools::ps_round($product['price_wt'], $this->decimals);
    $fields['L_PAYMENTREQUEST_0_QTY'.$index] = $product['quantity'];
*****
***** process.php
private function setPaymentValues(&$fields, &$index, &$total, &$taxes){
...
    else
            $shipping_cost_wt = $this->context->cart->getTotalShippingCost(null, false);
***** PROCESS.PHP.BAK
private function setPaymentValues(&$fields, &$index, &$total, &$taxes){
...
    else
        $shipping_cost_wt = $this->context->cart->getTotalShippingCost();
*****
***** process.php
private function setPaymentValues(&$fields, &$index, &$total, &$taxes) {
...
        $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
private function setPaymentValues(&$fields, &$index, &$total, &$taxes) {
...
        $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.

هل كانت مفيدة؟

المحلول 2

Ok, I finally fixed it. I could write up the specific code fix, but I feel it is too specialized to my situation and this version of prestashop. If someone requests it, I will add it.

The more important part is how I found the bug. Since the module sends a request and then has to find out from the response if there was an error, var_dump or echo were not possible for debugging.

Instead I wrote a simple custom log file to dump the values to in the process. I have read that doing so into the apache logs is frowned upon due to potential locking issues.

So TLDR: Use PHP file functions and log the totals and other vars to a file in the same directory.

نصائح أخرى

Add PAYMENTREQUEST_0_ITEMAMT with the sum of the $fields['L_PAYMENTREQUEST_0_AMT'.$index] to your API call.

I met this problem when I started to add shipping cost to PAYMENTREQUEST_0_AMT which is not exactly what is happening to you.

My best advice here is to add PAYMENTREQUEST_0_ITEMAMT whenever the sum of the item costs is different from PAYMENTREQUEST_0_AMT.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top