Topic: PayPal import issues

I am trying to use the PayPal import module using a csv file from a US account and I am having some issues.
I looked at the columns and they seem to match with the wiki documentation.
First of all when I have the 'Create Customers/Invoices:' checked in the PayPal import setup, the import creates the customer (at least some of them) but fails to create anything else.
The paypal.log shows an error creating the invoice:

[20-Apr-2015 22:39:32] WEB ACCEPT PAYMENT RECEIVED, gross:134, fee:-7.54, net:126.46, shipping:0, tax: 0
[20-Apr-2015 22:39:32] Memory, write_customer_invoices start:8101704
[20-Apr-2015 22:39:32] eCheque missing invoice, customer:4, net:126.46
[20-Apr-2015 22:39:32] Deposit, ref:, net:126.46

This is where the log stops.

Without the 'Create Customers/Invoices:' checked, the import creates entries only for the fees.
It seems to be parsing the entries properly as the paypal.log shows but fails to create the appropriate entries:

[20-Apr-2015 23:02:59] WEB ACCEPT PAYMENT RECEIVED, gross:134, fee:-7.54, net:126.46, shipping:0, tax: 0
[20-Apr-2015 23:02:59] Memory, write_bank_receipt start:8100720
[20-Apr-2015 23:02:59] Deposit, ref:9N743957MK081961F, net:126.46
[20-Apr-2015 23:02:59] Memory, write_bank_receipt end:9706312

Only the entry for 7.54 is created.

Anything that I can do to fix this?
What's the best way to debug this?
TIA
Ion

Re: PayPal import issues

I also noticed some errors in the error.log:

[22-Apr-2015 23:59:50 America/Toronto] 0:admin:payment_db.inc:31: array_combine(): Both parameters should have an equal number of elements
[22-Apr-2015 23:59:50 America/Toronto] 0:admin:payment_db.inc:31: array_combine(): Both parameters should have an equal number of elements
[22-Apr-2015 23:59:50 America/Toronto] <b>DATABASE ERROR :</b> no debtor trans found for given params<br>sql that failed was : SELECT trans.*,ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount AS Total,cust.name AS DebtorName, cust.address, cust.curr_code, cust.tax_id, com.memo_, shippers.shipper_name, sales_types.sales_type, sales_types.tax_included, branch.*, cust.discount, tax_groups.name AS tax_group_name, tax_groups.id AS tax_group_id  FROM debtor_trans trans
                    LEFT JOIN comments com ON trans.type=com.type AND trans.trans_no=com.id
                    LEFT JOIN shippers ON shippers.shipper_id=trans.ship_via,
                    debtors_master cust, sales_types, cust_branch branch, tax_groups  WHERE trans.trans_no=''
        AND trans.type='10'
        AND trans.debtor_no=cust.debtor_no AND sales_types.id = trans.tpe
            AND branch.branch_code = trans.branch_code
            AND branch.tax_group_id = tax_groups.id <br><br><br>

Re: PayPal import issues

Which version of the paypal extension are you using?
There was some feature reduction in a later version.

There could be some error in the file sales/includes/db/payment_db.inc since only 11 arguments are initialised in the code fragment from line 29-31:

    $args = func_get_args(); while (count($args) < 12) $args[] = 0;
    $args = (object)array_combine(array('trans_no', 'customer_id', 'branch_id', 'bank_account', 
        'date_', 'ref', 'amount', 'discount', 'memo_','rate','charge', 'bank_amount'), $args);

Try changing the first line above:

    $args = func_get_args(); while (count($args) < 12) $args[] = 0;

to

    $args = func_get_args(); while (count($args) <= 12) $args[] = 0;

and report the results.

Re: PayPal import issues

Hi Ap.Muthu,

I am running Import Paypal transactions version 2.3.10-3. FA is version 2.3.24.
I made the change you suggested but it did not make a difference. I think the code in sales/includes/db/payment_db.inc is correct.

I found one of the issues: in modules/import_paypal/import_paypal_update.php at line 117, the call to write_customer_payment does not match with the definition in sales/includes/db/payment_db.inc. There are 13 arguments in the call, the function definition has only 12:

$payment_no = write_customer_payment(0, $customer_id, $branch_id,
          $paypal_bank_id, $recpt_date, $ref,
          $gross, 0, $company, 1, 0 - $fee, $gross, $paypal_fee_act);

I replaced the line with the following:

$payment_no = write_customer_payment(0, $customer_id, $branch_id,
          $paypal_bank_id, $recpt_date, $ref,
          $gross, 0, $company, 1, 0 - $fee, $paypal_fee_act);

Seems to be working, I don't get the Both parameters should have an equal number of elements error any more but I still get the database error.
Similarly, the calls to write_bank_transaction in modules/import_paypal/import_paypal_update.php have fewer arguments than defined in the definition.

I will investigate further and report back.
Ion

Re: PayPal import issues

I do not understand the function write_bank_receipt in modules/import_paypal/import_paypal_update.php.
Line 132 reads:

function write_bank_receipt($date, $ref, $name, $shipping, $insurance, $tax, $gross, $fee, $net) {

In my case the function is called with:
tax = 0
gross = 134
fee = -7.54
net = 126.46

By the end of the function call, the only entry that get's created is for the fee.
The gross and net are not handled.
I think it's missing the handling for the net amount.
Any thoughts?
Ion

6 (edited by apmuthu 04/25/2015 05:18:28 am)

Re: PayPal import issues

The write_bank_transaction() having less arguments in a call than defined in the function is okay here as the rest have default values defined in the function as well in gl/includes/db/gl_db_banking.inc.

You might want to check out any file differences between those in your import_paypal module install and those in my unofficial Github repo.

The function write_customer_payment() is defined in sales/includes/db/payment_db.inc with 12 arguments with the last 3 being optional with defaults provided. Furthermore, if there are less than 12 arguments, the rest are filled with zeroes in line 29 in it:

$args = func_get_args(); while (count($args) < 12) $args[] = 0;

The said function is called with 13 arguments in modules/import_paypal/import_paypal_update.php Lines 117 to 119 are:

      $payment_no = write_customer_payment(0, $customer_id, $branch_id,
          $paypal_bank_id, $recpt_date, $ref,
          $gross, 0, $company, 1, 0 - $fee, $gross, $paypal_fee_act);

The $gross appears twice.

Re: PayPal import issues

I have checked the files, they seem to be the same.
Ion

Re: PayPal import issues

I am still getting the database error:

[25-Apr-2015 01:34:17 America/Toronto] <b>DATABASE ERROR :</b> no debtor trans found for given params<br>sql that failed was : SELECT trans.*,ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount AS Total,cust.name AS DebtorName, cust.address, cust.curr_code, cust.tax_id, com.memo_, shippers.shipper_name, sales_types.sales_type, sales_types.tax_included, branch.*, cust.discount, tax_groups.name AS tax_group_name, tax_groups.id AS tax_group_id  FROM debtor_trans trans
                    LEFT JOIN comments com ON trans.type=com.type AND trans.trans_no=com.id
                    LEFT JOIN shippers ON shippers.shipper_id=trans.ship_via,
                    debtors_master cust, sales_types, cust_branch branch, tax_groups  WHERE trans.trans_no=''
        AND trans.type='10'
        AND trans.debtor_no=cust.debtor_no AND sales_types.id = trans.tpe
            AND branch.branch_code = trans.branch_code
            AND branch.tax_group_id = tax_groups.id <br><br><br>

Any suggestions?
Ion

9 (edited by apmuthu 04/25/2015 08:17:15 am)

Re: PayPal import issues

Try to execute the sql on your database in some MySQL client like SQLyog or phpMyAdmin:

SELECT 
   trans.*
  ,ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount AS Total
  ,cust.name AS DebtorName
  , cust.address
  , cust.curr_code
  , cust.tax_id
  , com.memo_
  , shippers.shipper_name
  , sales_types.sales_type
  , sales_types.tax_included
  , branch.*
  , cust.discount
  , tax_groups.name AS tax_group_name
  , tax_groups.id AS tax_group_id  
FROM debtor_trans trans
  LEFT JOIN comments com ON trans.type=com.type AND trans.trans_no=com.id
  LEFT JOIN shippers ON shippers.shipper_id=trans.ship_via
  , debtors_master cust
  , sales_types
  , cust_branch branch
  , tax_groups  
WHERE trans.trans_no=''
  AND trans.type='10'
  AND trans.debtor_no=cust.debtor_no 
  AND sales_types.id = trans.tpe
  AND branch.branch_code = trans.branch_code
  AND branch.tax_group_id = tax_groups.id;

and see what results you get.

Unless you used no Table Prefix, it seems to be missing here.

Re: PayPal import issues

If the TB_PREF = "1_", then execute :

SELECT 
   trans.*
  ,ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount AS Total
  ,cust.name AS DebtorName
  , cust.address
  , cust.curr_code
  , cust.tax_id
  , com.memo_
  , shippers.shipper_name
  , sales_types.sales_type
  , sales_types.tax_included
  , branch.*
  , cust.discount
  , tax_groups.name AS tax_group_name
  , tax_groups.id AS tax_group_id  
FROM 1_debtor_trans trans
  LEFT JOIN 1_comments com ON trans.type=com.type AND trans.trans_no=com.id
  LEFT JOIN 1_shippers shippers ON shippers.shipper_id=trans.ship_via
  , 1_debtors_master cust
  , 1_sales_types sales_types
  , 1_cust_branch branch
  , 1_tax_groups tax_groups
WHERE trans.trans_no=''
  AND trans.type='10'
  AND trans.debtor_no=cust.debtor_no 
  AND sales_types.id = trans.tpe
  AND branch.branch_code = trans.branch_code
  AND branch.tax_group_id = tax_groups.id;

Re: PayPal import issues

I did not use a table prefix.
Running the sql returns 0 rows.
Ion

12 (edited by apmuthu 04/25/2015 04:02:15 pm)

Re: PayPal import issues

If you have a backup prior to the paypal imoprt, then revert to it.
Then manually do the transactions necessary for 1 paypal transaction.
Take a backup.
Now revert back to previous db state.
Now import the same transaction using the import_paypal extension
Take a backup again.
Now compare the last 2 backups using a diff tool like WinMerge and see what is different.

The fact that the SQL executed without error incicates that the absence of transactions is a functional application error. Need to also contact the module author.

Re: PayPal import issues

I am not 100% sure what the code tries to do.
Here is my understanding of what the intent is:
- Create customer if it does not exist.
- Create invoice for the customer.
- Add customer payment.

Let me know if this is not right.
Will try based on these assumptions and report back.
Ion

14 (edited by apmuthu 04/28/2015 03:08:10 am)

Re: PayPal import issues

Actually Paypal Import Transactions is more of a payment transaction basically and not an invoice generation / customer creation transaction although the code sports it. The Customer and their Invoice should generally pre-exist for a PayPal transaction to effect payment allocation to it. It is therefore no wonder that no transactions are related to existing customers and is  either not imported at all or is imported as an orphan record. You can try to create the customer and invoice manually if they do not exist and then manually allocate / edit allocation of the payment.

Re: PayPal import issues

There is a option in the import paypal setup to create customers and invoices, I have that checked.
And when I run it it actually created some of the customers that were not in the system.
The problem is that at some point it fails and I can't figure out why.
If you don't have that option checked, it will only write a bank transaction even if you have the customer and the invoice.
Ion

Re: PayPal import issues

Try to slice the list of paypal import entries and verify failure on specific transaction - any extra characters, quotes, double quotes, etc....