CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Looking for a payment hook for my Tax extension
Pages: [1]

Author Topic: Looking for a payment hook for my Tax extension  (Read 1198 times)

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Looking for a payment hook for my Tax extension
February 27, 2014, 11:00:50 pm
Hi Guys,

I'm back on task to finally get my Tax extension completed and one of the areas I need to attend to is to capture information when a payment transaction is made. I'd like to capture the following information:

Financial Type (Donation, Member Dues, Campaign Contribution, Event Fees, etc...)
Invoice ID
Amount

Is there a hook I can invoke in my extension that will deliver this info?

I'm leaning towards hook_civicrm_alterPaymentProcessorParams( $paymentObj,&$rawParams, &$cookedParams );

Any tips or direction would be helpful and appreciated

Thanks,
Andrew
 
« Last Edit: February 27, 2014, 11:28:21 pm by awasson »
My CiviCRM Extension Workshop: https://github.com/awasson

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Looking for a payment hook for my Tax extension
February 28, 2014, 01:46:03 am
Have you checked if there is a financial entity you can capture in the post hook?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Looking for a payment hook for my Tax extension
February 28, 2014, 04:50:10 pm
Thanks for the reply Erik. Your name looked familiar and then I noticed you and I were both reviewers for Tony Horrock's CiviCRM Cookbook. Small world!

I'm almost certain that the anwer lies in hook_civicrm_alterPaymentProcessorParams(): https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterPaymentProcessorParams

It would be super handy to use it because it fires when the contribution is confirmed so I can save data to my database for reporting right then and there. Furthermore, it references $paymentObj, &$rawParams, &$cookedParams so I should be able to grab my values, process the tax (calculate and add to the total) and then add it to the cookedParams for processing.

I'm scratching my head wondering how I can explore the $paymentObj and $rawParams but I'm not making any headway.
« Last Edit: February 28, 2014, 05:58:00 pm by awasson »
My CiviCRM Extension Workshop: https://github.com/awasson

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Looking for a payment hook for my Tax extension
March 01, 2014, 10:54:37 am
Ok, progress  ;D

I'm pretty happy with this little bit of progress.

I added hook_civicrm_alterPaymentProcessorParams($paymentObj, &$rawParams, &$cookedParams) to my extension and then because it fires at payment confirmation and redirects without hanging around, I lost my mind trying to figure out what was contained inside. To resolve that issue, I loaded the $rawParams array into a session object and used print_r() to place it in a modal popup I could review. Sure enough it contains all the good stuff I'm looking for:

$invoice_id = $rawParams['invoiceID'];
$total_amount = $rawParams['amount'];
$contributionType_accounting_code = $rawParams['contributionType_accounting_code'];

This is actually better than I expected because running a query against the civicrm_financial_account table I can pull out all the information about that particular financial type; ie: donation, member dues, etc...

Not only that but if I set up is_tax, tax_rate within the accounts admin section, I can apply taxes to those transactions with a couple of lines of code.

This is a good day!


My CiviCRM Extension Workshop: https://github.com/awasson

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Looking for a payment hook for my Tax extension
March 03, 2014, 12:11:10 am
Glad you are making progress!
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Looking for a payment hook for my Tax extension
March 03, 2014, 11:56:22 pm
Thanks Erik,

Yup, I've got the transaction part completely covered using that hook and I'm moving onto reporting.

Cheers,
Andrew
My CiviCRM Extension Workshop: https://github.com/awasson

Jens-Erik

  • I post occasionally
  • **
  • Posts: 60
  • Karma: 0
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.4
Re: Looking for a payment hook for my Tax extension
May 27, 2014, 10:34:21 am
Hi Andrew,

could you tell what your tax extension will do? I'm thinking about writing an invoice extension, as someone proposed to me. The invoice must fulfil the EU requirements like a unique id and it should include VAT ID, and the VAT depends on the country of the customer and if the customer gives his or her VAT id. Is your extension doing something similar?

Jens

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Looking for a payment hook for my Tax extension
May 27, 2014, 06:12:33 pm
Hi Jens,

The tax extension will charge one or more taxes to a civicrm_financial_type and then report the taxes charged in the detailed contribution report. At this time it doesn't differentiate regions or countries but with some effort it could certainly be leveraged to do so.

Have a look at what I've done and if you'd like to add to it by all means do so. It does pretty much what I needed it to do for my use case but as I've been working on it, I've had ideas for improvement and I've heard from people like yourself with more complex needs. There is another group working towards a more sophisticated tax system. I have no idea where they are in their work but you can see some of their documentation here: http://wiki.civicrm.org/confluence/pages/viewpage.action?pageId=83493410

Cheers,
Andrew
My CiviCRM Extension Workshop: https://github.com/awasson

Jens-Erik

  • I post occasionally
  • **
  • Posts: 60
  • Karma: 0
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.4
Re: Looking for a payment hook for my Tax extension
May 28, 2014, 01:11:19 am
Thanks for your information, Andrew!
Cheers,
Jens

jamien-www.compucorp.co.uk

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 3.4 / 4.0
  • CMS version: Drupal 7.0
  • MySQL version: 5.5
  • PHP version: 5.3.7
Re: Looking for a payment hook for my Tax extension
May 28, 2014, 03:27:10 am
Hi all,

Just a quick update on this.

VAT (% based sales tax) and invoicing support will be in version 4.5 of CiviCRM and will hopefully have a version that works with version 4.4 in the next few weeks (although this will not be publicly available for download initially).

We at Compucorp are working with the core team and Webaccess to develop this functionality.

The specification is available here:

http://wiki.civicrm.org/confluence/display/CRM/Sales+Taxes+and+Invoicing+-+Phase+1

and the new features will be available to test in the next few weeks.

I'll be making a blog post about this in the not too distant future now that we have some screen shots and more information

Best

Jamie

Jens-Erik

  • I post occasionally
  • **
  • Posts: 60
  • Karma: 0
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.4
Re: Looking for a payment hook for my Tax extension
June 03, 2014, 11:31:51 am
Thanks, Jamie,

 that sounds promising. Anyway, I have taken a look at the tutorial on extensions, and I will continue.

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Looking for a payment hook for my Tax extension
June 03, 2014, 02:33:32 pm
Jamie,

That is great news about the progress you're making with the tax support in Core. I've been following some of the work through the various wiki postings and I am really excited about that!

Let me know if you'd like to add me to your testing effort.

Cheers,
Andrew
My CiviCRM Extension Workshop: https://github.com/awasson

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Looking for a payment hook for my Tax extension

This forum was archived on 2017-11-26.