robvankeilegom / firefly-III-paypal-importer

PayPal Data Importer for Firefly III
48 stars 3 forks source link

Retrieve id of existing accounts. #4

Closed robvankeilegom closed 2 years ago

robvankeilegom commented 2 years ago

There's a change that the importer tries to create an account with a name that already exists in Firefly.

In this case we should retrieve the existing account instead of trying to create a new one.

m4t7 commented 2 years ago

The import run approx 3 minutes then I received this issue. I have approx 300 transactions in firefly now.

root@7bc27f9fbf27:/var/www/html# php artisan sync
Start pulling data from PayPal
Pushing data to Firefly

In Firefly.php line 58:

  Attempt to read property "firefly_expense_id" on null
robvankeilegom commented 2 years ago

@m4t7 I pushed a change to skip transactions without payer. This way you should be able to get most transactions in Firefly. The sync keeps track of the Firefly id so you'll be able to run php artisan sync:firefly again without getting duplicate transactions in Firefly.

I did add a warning in the log (storage/logs) with the id of the transaction without payer. If you could check out whats wrong with that transaction that would be great.

Some explanation about the PayPal transaction: image Those 4 records in the transactions table are a single transaction. This app combines them to create a single transaction in Firefly. In this example the first line with code T0006 is actual transaction. The other records will have the pp_id of this transaction in the reference_id field. T0300 is the amount PayPal took from my linked bank account and both T0200 records are the conversion from my currency to the receivers currency.

In Firefly you'll the them as a single transaction with a conversion: image

As you can see only the first record has a payer_id. Its fine if the others are empty.

This also means its possible to have 700 records in your database and only 300 in Firefly. At this moments all records with codes T00xx (PayPal account to PayPal account payments), T1106 (payment reversal) and T1107 (payment refund) are pushed to Firefly. If you're missing any records in Firefly, let me know and ill add the code to be included in the push.

m4t7 commented 2 years ago

New Issue

Hmmm, I receive now this issue.

oot@7bc27f9fbf27:/var/www/html# php artisan sync:firefly
Pushing data to Firefly

In RequestException.php line 113:

  Client error: `POST https://......./api/v1/transactions` resulted in a `422 Unprocessable Entity` response:                          
  {"message":"The given data was invalid.","errors":{"transactions.0.foreign_currency_code":["transactions.0.foreign_curre (truncated...)  

Log

storage lumen log ``` [2022-03-26 11:43:42] local.WARNING: Transaction with id 570 doesn't have a payer. Skipping. [2022-03-26 11:43:43] local.ERROR: Client error: `POST https://....../api/v1/transactions` resulted in a `422 Unprocessable Entity` response: {"message":"The given data was invalid.","errors":{"transactions.0.foreign_currency_code":["transactions.0.foreign_curre (truncated...) {"exception":"[object] (GuzzleHttp\\Exception\\ClientException(code: 422): Client error: `POST https://....../api/v1/transactions` resulted in a `422 Unprocessable Entity` response: {\"message\":\"The given data was invalid.\",\"errors\":{\"transactions.0.foreign_currency_code\":[\"transactions.0.foreign_curre (truncated...) at /var/www/html/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113) [stacktrace] #0 /var/www/html/vendor/guzzlehttp/guzzle/src/Middleware.php(69): GuzzleHttp\\Exception\\RequestException::create(Object(GuzzleHttp\\Psr7\\Request), Object(GuzzleHttp\\Psr7\\Response), NULL, Array, NULL) #1 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(204): GuzzleHttp\\Middleware::GuzzleHttp\\{closure}(Object(GuzzleHttp\\Psr7\\Response)) #2 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(153): GuzzleHttp\\Promise\\Promise::callHandler(1, Object(GuzzleHttp\\Psr7\\Response), NULL) #3 /var/www/html/vendor/guzzlehttp/promises/src/TaskQueue.php(48): GuzzleHttp\\Promise\\Promise::GuzzleHttp\\Promise\\{closure}() #4 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(248): GuzzleHttp\\Promise\\TaskQueue->run(true) #5 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(224): GuzzleHttp\\Promise\\Promise->invokeWaitFn() #6 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(269): GuzzleHttp\\Promise\\Promise->waitIfPending() #7 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(226): GuzzleHttp\\Promise\\Promise->invokeWaitList() #8 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\\Promise\\Promise->waitIfPending() #9 /var/www/html/vendor/guzzlehttp/guzzle/src/Client.php(187): GuzzleHttp\\Promise\\Promise->wait() #10 /var/www/html/vendor/guzzlehttp/guzzle/src/ClientTrait.php(95): GuzzleHttp\\Client->request('POST', 'transactions', Array) #11 /var/www/html/app/Firefly.php(144): GuzzleHttp\\Client->post('transactions', Array) #12 /var/www/html/app/Sync.php(112): App\\Firefly->sync(Object(Illuminate\\Database\\Eloquent\\Collection)) #13 /var/www/html/app/Console/Commands/SyncFirefly.php(34): App\\Sync->syncFirefly() #14 /var/www/html/vendor/illuminate/container/BoundMethod.php(36): App\\Console\\Commands\\SyncFirefly->handle() #15 /var/www/html/vendor/illuminate/container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}() #16 /var/www/html/vendor/illuminate/container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure)) #17 /var/www/html/vendor/illuminate/container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Laravel\\Lumen\\Application), Array, Object(Closure)) #18 /var/www/html/vendor/illuminate/container/Container.php(653): Illuminate\\Container\\BoundMethod::call(Object(Laravel\\Lumen\\Application), Array, Array, NULL) #19 /var/www/html/vendor/illuminate/console/Command.php(136): Illuminate\\Container\\Container->call(Array) #20 /var/www/html/vendor/symfony/console/Command/Command.php(298): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle)) #21 /var/www/html/vendor/illuminate/console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle)) #22 /var/www/html/vendor/symfony/console/Application.php(1015): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #23 /var/www/html/vendor/symfony/console/Application.php(299): Symfony\\Component\\Console\\Application->doRunCommand(Object(App\\Console\\Commands\\SyncFirefly), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #24 /var/www/html/vendor/symfony/console/Application.php(171): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #25 /var/www/html/vendor/illuminate/console/Application.php(94): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #26 /var/www/html/vendor/laravel/lumen-framework/src/Console/Kernel.php(116): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #27 /var/www/html/artisan(35): Laravel\\Lumen\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #28 {main} "} ```

Regarding your records explanation I have in total 36 missing records.

Transaction ID 570

Here Is the JSON Output from the faulty transaction. It contains PHP as currency_code.

PHP = Philippine peso https://developer.paypal.com/api/rest/reference/currency-codes/

transaction_contains_PHP_as_currency

Transaction ID 574

second_transaction

Database

database_transaction_id_570

Here are all my faulty PHP transactions, these are all transactions from the same paypal email address.

all_transactions_with_PHP

m4t7 commented 2 years ago

Ok, it was an issue on my end. I had not created PHP as a currency in firefly. The import works now and I do not face any issue.

root@b72f20d3595e:/var/www/html# php artisan sync:firefly
Pushing data to Firefly
Done

Thanks for all your help and support. :+1:

robvankeilegom commented 2 years ago

@m4t7 No problem, if there's anything else, let me know.

I created a separate issue to add a more clear error message when the currency isn't available in Firefly. I'm gonna close this issue.