eileenmcnaughton / nz.co.fuzion.civixero

Synchronisation between CiviCRM & Xero
7 stars 14 forks source link

Set invoice to 'Paid' via Xero payments API #99

Open pixel-paul opened 2 years ago

pixel-paul commented 2 years ago

Hi,

Thanks for providing this plugin, it is (almost!) exactly what we need.

We have two additional requirements:

  1. Mark an invoice as paid if a successful transaction has been made (e.g. via credit card). https://developer.xero.com/documentation/api/accounting/payments

  2. Send an invoice via Xero (instead of via CiviCRM) https://developer.xero.com/documentation/api/accounting/invoices

I am assuming that this functionality does not exist yet?

Many thanks,

Paul

eileenmcnaughton commented 2 years ago

In the first case- do you mean it would already be paid in CiviCM & then pushed up to Xero as paid - I think @agileware-fj added a setting that does that.

I'm not aware of any work having been done on sending invoices via Xero

pixel-paul commented 2 years ago

do you mean it would already be paid in CiviCM & then pushed up to Xero as paid

Yes, exactly.

I'm not aware of any work having been done on sending invoices via Xero

OK, thanks, I'll look into this a little more.

Upperholme commented 2 years ago

In my set-up, at .../civicrm/xero/settings there are options to set the status of contributions that will trigger a push up to Xero (see at the bottom of the attached screenshot). I'm assuming that by setting 'completed ' as one of these statuses, when a contribution gets marked as complete, that change is pushed up to Xero and the relevant invoice is marked as paid. In my case our book-keeper is recording payments in Xero first, and those changes certainly reflect back into Civi.

Screenshot 2022-09-14 at 12 08 12

pixel-paul commented 2 years ago

that change is pushed up to Xero and the relevant invoice is marked as paid

When I have tested this with 'Xero Default Invoice Status' set to 'Draft', the invoice would need to be 'Approved', and if I set it to 'Approved', the invoice is set to 'Awaiting Payment' in Xero. This still requires a manual step of applying a payment.

petednz commented 2 years ago

I may not understand your point, but in Xero you need to do a 'reconciliation' in order to join the incoming info from your bank/cc to the existing info about the trxn which civi has already pushed to xero. happy to be put right by Eileen but I don't know if it is possible to sidestep the need to do the physical reconciliation in Xero

agileware-fj commented 2 years ago

The API lets you set an invoice as PAID when it's submitted, but our patch to automatically authorise didn't include this - on the assumption that people would be doing bank reconciliations as @petednz described.

The reasoning for this is that people will want Xero to have records of income they actually have rather than what's been promised by a CC gateway. I'm not sure whether there's a different between an invoice which is just paid and an invoice that's been reconciled - so will leave that alone.

On a more technical note, implementing a PAID as a status is a little more involved than what we did as you'd want to be sure that you're only submitting invoices with a status that maps correctly to what's in CiviCRM - currently the "default" status is actually what's sent through for every invoice.

pixel-paul commented 1 year ago

I have pretty much completed the modifications we required to make this work. One of the complicated parts was that the Payment API is not within the Xero library being used, so I had to add this in. Is there a plan to move to the Xero SDK?

Once I was able to post to the Payment end point, I was able to update the record in Xero with the total using the Invoice ID. This then marks the invoice as 'Paid'.

Sending the invoice via email requires posting to the Invoice endpoint with the invoice ID (again I had to add this in to the Xero library).

I still need to work on the error handling and responses within the Xero library and also the front end UI to manage these features.

No idea if this is useful to anyone, however, if you'd like me to do a PR, I can once I have tidied things up a little more.

eileenmcnaughton commented 1 year ago

@pixel-paul I think we generally agree that switching to the Xero SDK would be better - but no-one has put the time into investigating it.

@mattwire has also been working on some improvements in this space.

I suspect the ability to send an invoice would be popular

mattwire commented 1 year ago

Yes it would be nice to switch to Xero SDK and would not be a huge job but is more than just a couple of tweaks because you'd be replacing the oauth stuff and all the communication with Xero. I'd say probably a couple of days work.