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) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Pay Pal IPN and fees
Pages: 1 [2] 3

Author Topic: Pay Pal IPN and fees  (Read 7879 times)

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Pay Pal IPN and fees
January 10, 2013, 02:04:51 pm
http://paste2.org/p/2727676

This is what I'm trying without good results.
Try CiviTeacher: the online video tutorial CiviCRM learning library.

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Pay Pal IPN and fees
January 10, 2013, 03:29:30 pm
Hi everyone.  Lobo and I spent an hour or so today investigating this.

Here are the important facts that we found out:

1. Paypal Pro 'non-recurring' payments return less information compared to Paypal Standard and Paypal Pro recurring payments.  If you look at the Paypal documentation you can see that AMT (amount) is the only variable that is returned, wheras Paypal standard returns both a total and a fee.    This explains why fees have not been getting recorded with Paypal Pro transactions.   There is nothing we can change about the limited information Paypal chooses to return to us when the transaction is processed...but...

2. We can enhance CiviCRM's automated tasks to use the 'cron' to check back in with Paypal later.  It works like this:
    a. each hour or whatever, use CiviCRM's cron to ask paypal for information on contributions and give the transcation id#
    b. ask paypal for the fee amount
    c. go back retroactively to contributions with a blank fee, and "fill in the blank"

This is not a trivial task, but it's very doable according to Lobo.

He estimates between 5 and 15 hours of core team development work to make this a reality.    This issue hasn't been a priority in the past, the core team has been working on more pressing issues.   But this fee issue is important enough to your organization to see the paypal fees in your CiviCRM database, then please consider sponsoring this effort and talk to Lobo and Greenberg.  They might even set up an MIH if there is enough demand.


PS. the file that handles these Paypal Pro payments is Core/Payment/PayPalImpl.php
« Last Edit: January 10, 2013, 03:33:20 pm by Stoob »
Try CiviTeacher: the online video tutorial CiviCRM learning library.

grandesigns

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 1
  • CiviCRM version: 4.4.20
  • CMS version: Wordpress
Re: Pay Pal IPN and fees
January 19, 2013, 04:08:42 am
Quote from: Stoob on January 10, 2013, 03:29:30 pm
1. Paypal Pro 'non-recurring' payments return less information compared to Paypal Standard and Paypal Pro recurring payments.  If you look at the Paypal documentation you can see that AMT (amount) is the only variable that is returned, wheras Paypal standard returns both a total and a fee.    This explains why fees have not been getting recorded with Paypal Pro transactions.   There is nothing we can change about the limited information Paypal chooses to return to us when the transaction is processed...but...

2. We can enhance CiviCRM's automated tasks to use the 'cron' to check back in with Paypal later.  It works like this:
    a. each hour or whatever, use CiviCRM's cron to ask paypal for information on contributions and give the transcation id#
    b. ask paypal for the fee amount
    c. go back retroactively to contributions with a blank fee, and "fill in the blank"

This is not a trivial task, but it's very doable according to Lobo.

He estimates between 5 and 15 hours of core team development work to make this a reality. 

Stoob or Lobo - Maybe I'm being obtuse, but it seems to me that the whole cron approach is needlessly elaborate when CiviCRM is not only already being sent the appropriate data via the IPN but is also already using said IPN to update the contribution record (flagging the transaction as complete, rather than pending), etc.

Can either of you please explain why we would even try to get the fee data from the API instead of the IPN? That seems like a much more complicated (and time consuming) way to do it...

EDIT - Someone is thinking ahead of me/us, there is already code in the IPN handling process that *should* be doing exactly what needs to be happening with fees and net amounts. So, the question is, why isn't it working?
« Last Edit: January 19, 2013, 06:44:51 am by grandesigns »

grandesigns

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 1
  • CiviCRM version: 4.4.20
  • CMS version: Wordpress
Re: Pay Pal IPN and fees
January 19, 2013, 04:44:09 am
Ok, my "don't say that someone should do it, do the damn thing" bug kicked in... back shortly with a first attempt at tweaking the IPN code...
« Last Edit: January 19, 2013, 06:17:45 am by grandesigns »

grandesigns

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 1
  • CiviCRM version: 4.4.20
  • CMS version: Wordpress
Re: Pay Pal IPN and fees
January 19, 2013, 06:08:24 am
Okay, two attempts down, neither successful. Possibly time for someone with more experience coding for the platform to take over, or at least give me some guidance. I'm working on an install of 4.2.4, if it matters.

My first attempt was to add the following to core/payments/PayPalProIPN.php around line 265 (in function single).

Code: [Select]
$contribution->fee_amount = $input['fee_amount'];
$contribution->net_amount = $input['amount'] - $input['fee_amount'];

When that didn't work, I looked a little closer and realized that:

a) What I wrote above more or less duplicates the following from function completeTransaction around line 427 from core/payments/BaseIPN.php

Code: [Select]
    if (CRM_Utils_Array::value('net_amount', $input, 0) == 0 &&
      CRM_Utils_Array::value('fee_amount', $input, 0) != 0
    ) {
      $input['net_amount'] = $input['amount'] - $input['fee_amount'];
    }

b) function getInput in core/payments/PayPalProIPN.php calls a nonexistent IPN value "settle_amount" around line 379, which I figured might be somehow producing a non-zero value that was preventing the above code from firing properly. In fact, there is no IPN value for net amount, so I replaced:

Code: [Select]
$input['net_amount'] = self::retrieve('settle_amount', 'Money', 'POST', FALSE);
with

Code: [Select]
$input['net_amount'] = 0;
This also didn't work. So... I'm left with two theories at the moment:

1. Due to my unfamiliarity with CiviCRM conventions, I've made mistakes with both attempts that prevent them from working despite being valid concepts.
2. $input['fee_amount'] is not getting set properly, or is not being properly passed to  function completeTransaction in core/payments/BaseIPN.php. I have no evidence of this (and I'm not sure how to log $input['fee_amount']'s value in the completeTransaction function - help?), but it would explain why the existing code that SHOULD be calculating the net amount from the fee and the amount and recording both is not doing so.

In conclusion, someone who knows what they're doing here more than I do, help/guidance please?
« Last Edit: January 19, 2013, 06:54:36 am by grandesigns »

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Pay Pal IPN and fees
January 19, 2013, 11:10:47 am
Granddesigns, I admire your ambition, but I think you may have misunderstood my previous post about the findings of Lobo and myself.  Let me make it super clear: the IPN for PayPalPro does not return the fee amount.   This was the result of our testing. 

You may not believe that, but that's why I included the link to the PaypalPro documentation.

While I would love to be mistaken and be proven wrong, I see from your posts that you are assuming that PaypalPro does return the fee in the IPN as PayPal Standard does.   But it doesn't.  That's the problem.

Also if you are going to tinker, you should tinker with the latest version of the software, not 4.2.4.
Try CiviTeacher: the online video tutorial CiviCRM learning library.

grandesigns

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 1
  • CiviCRM version: 4.4.20
  • CMS version: Wordpress
Re: Pay Pal IPN and fees
January 20, 2013, 03:04:01 am
Quote from: Stoob on January 19, 2013, 11:10:47 am
Granddesigns, I admire your ambition, but I think you may have misunderstood my previous post about the findings of Lobo and myself.  Let me make it super clear: the IPN for PayPalPro does not return the fee amount.   This was the result of our testing. 

You may not believe that, but that's why I included the link to the PaypalPro documentation.

While I would love to be mistaken and be proven wrong, I see from your posts that you are assuming that PaypalPro does return the fee in the IPN as PayPal Standard does.   But it doesn't.  That's the problem.

Stoob, you will be happy to hear that you and Lobo are indeed mistaken. PaypalPro returns fee information as part of the IPN, just as PayPal Standard does. The documentation you linked to pertains only to information returned via the Website Payments Pro NVP API, which is NOT the same thing.  Here is the correct documentation for you to be looking at.

To further illustrate this, I have included below the complete text of the IPNs from the last three (non-express) donations made through my live site, omitting only identifying details (replaced with ****). You will notice that the transaction fee is included as both mc_fee AND as payment_fee (though according to the documentation, mc_fee is the correct value to use).

Quote
mc_gross=50.00&invoice=****&protection_eligibility=Ineligible&payer_id=****&tax=0.00&payment_date=10:52:13 Jan 19, 2013 PST&payment_status=Completed&charset=windows-1252&first_name=****&mc_fee=1.40&notify_version=3.7&custom=&payer_status=unverified&business=****&quantity=1&verify_sign=****&payer_email=****&txn_id=****&payment_type=instant&last_name=****&receiver_email=****&payment_fee=1.40&receiver_id=****&txn_type=web_accept&item_name=Online Contribution: Give a few dollars. Make a big difference.&mc_currency=USD&item_number=&residence_country=US&receipt_id=****&handling_amount=0.00&transaction_subject=&payment_gross=50.00&shipping=0.00&ipn_track_id=****

Quote
mc_gross=25.00&invoice=****&protection_eligibility=Ineligible&payer_id=****&tax=0.00&payment_date=09:06:26 Jan 19, 2013 PST&payment_status=Completed&charset=windows-1252&first_name=****&mc_fee=0.85&notify_version=3.7&custom=&payer_status=unverified&business=****&quantity=1&verify_sign=****&payer_email=****&txn_id=****&payment_type=instant&last_name=****&receiver_email=****&payment_fee=0.85&receiver_id=****&txn_type=web_accept&item_name=Online Contribution: Give a few dollars. Make a big difference.&mc_currency=USD&item_number=&residence_country=US&receipt_id=****&handling_amount=0.00&transaction_subject=&payment_gross=25.00&shipping=0.00&ipn_track_id=****

Quote
mc_gross=1.00&invoice=****&protection_eligibility=Ineligible&payer_id=****&tax=0.00&payment_date=06:51:55 Jan 19, 2013 PST&payment_status=Completed&charset=windows-1252&first_name=****&mc_fee=0.32&notify_version=3.7&custom=&payer_status=unverified&business=****&quantity=1&verify_sign=****&payer_email=****&txn_id=****&payment_type=instant&last_name=****&receiver_email=****&payment_fee=0.32&receiver_id=****&txn_type=web_accept&item_name=Online Contribution: Give a few dollars. Make a big difference.&mc_currency=USD&item_number=&residence_country=US&receipt_id=****&handling_amount=0.00&transaction_subject=&payment_gross=1.00&shipping=0.00&ipn_track_id=****

I hope that proves the point beyond a reasonable doubt?
« Last Edit: January 20, 2013, 04:18:19 am by grandesigns »

grandesigns

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 1
  • CiviCRM version: 4.4.20
  • CMS version: Wordpress
Re: Pay Pal IPN and fees
January 20, 2013, 03:33:48 am
On a possibly related note, looking at my logs, I notice that every single transaction seems to be triggering the log message "Could not get module name from request url" from the bottom of extern/ipn.php. Could this possibly be relevant to our issue?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Pay Pal IPN and fees
January 20, 2013, 03:46:39 pm
are we talking of a single payment via paypal pro or a recurring payment via paypal pro?

if the former, then civi does not have code that implement IPN for paypal pro. we use the doDirectPayment functionaltiy via NVP as u mentioned
e this
Based on your prior post, seems like it is. But civi is not expecting one and hence has not sent any info to paypal with regard to format of IPN (which include module name, contribution id etc) and hence we ignore it

bottom line, for civi to handle paypal pro ipn's someone will need to investigate this and submit a patch to take advantage of this

lobo
« Last Edit: January 20, 2013, 03:57:48 pm by Donald Lobo »
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

grandesigns

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 1
  • CiviCRM version: 4.4.20
  • CMS version: Wordpress
Re: Pay Pal IPN and fees
January 20, 2013, 08:39:31 pm
Quote from: Donald Lobo on January 20, 2013, 03:46:39 pm
are we talking of a single payment via paypal pro or a recurring payment via paypal pro?

if the former, then civi does not have code that implement IPN for paypal pro. we use the doDirectPayment functionaltiy via NVP as u mentioned

Based on your prior post, seems like it is. But civi is not expecting one and hence has not sent any info to paypal with regard to format of IPN (which include module name, contribution id etc) and hence we ignore it

bottom line, for civi to handle paypal pro ipn's someone will need to investigate this and submit a patch to take advantage of this

We are indeed talking about a single payment via paypal pro.

I am sufficiently intimidated by CiviCRM's complexity that I hold no illusions of being able to do this entirely on my own, but if you know of a more experienced hand who might be willing/able to help me though it, I'm game.

I don't think this should actually be that complicated a fix - the necessary code for parsing a PaypalPro IPN for the relevant data is already more or less in place in core/payments/PayPalProIPN.php (and related files), and should be usable for this purpose with little modification (which I might well be able to handle) - but I really don't know how to do what needs to happen in /core/payment/paypalimpl.php to make use of it. (I also don't fully grasp how the official patch system works here, which is another good reason for me to have a mentor...)

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Pay Pal IPN and fees
January 20, 2013, 10:14:11 pm
Fair enough, thanks.  Regardless of the approach, some effort is required by someone to create a patch.

Granddesigns, would you be kindly willing to financially sponsor the core team to create a patch and achieve this goal?  In the absence of directly created patches with your own hands, the project moves also moves forward with financial sponsorship for core team members to make patches.  I have financially sponsored many patches, although this one is not a priority for me personally.

Lobo's initial estimate was 5 to 15 hours.

« Last Edit: January 20, 2013, 10:23:18 pm by Stoob »
Try CiviTeacher: the online video tutorial CiviCRM learning library.

grandesigns

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 1
  • CiviCRM version: 4.4.20
  • CMS version: Wordpress
Re: Pay Pal IPN and fees
January 20, 2013, 10:40:56 pm
My willingness/ability to sponsor this would be dependent on two things:

1. A new estimate of the cost, based on the current understanding of the problem, since Lobo's initial estimate was based off of a totally different approach to resolving it. (Also, if we're talking the hourly rates listed here, my discretionary resources will almost certainly only cover a fraction of the cost, so we're realistically talking about a MIH, rather than a full sponsorship).

2. My ability to find a solution to the separate issue that recurring payments via PaypalPro stopped working  somewhere between 4.1.2 and 4.2.4. (Technically the payments are processed but the receipts and other associated e-mails do not send, so the process might as well be entirely broken in terms of its suitability for use on a production site...) If I can't find a way to resolve that problem, I will be blocked from participation in any updates past the last working version, which will pretty well torpedo my ability to invest in same.
« Last Edit: January 20, 2013, 10:49:13 pm by grandesigns »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Pay Pal IPN and fees
January 21, 2013, 02:57:56 pm

i think the estimate remains the same. In general our lowest estimate is always 10 hours. In this case, whoever does it still needs to get upto speed on the latest changes by paypal etc and add unit tests to the whole scheme while they are at it

regarding your other issue, you should upgrade to 4.2.7 and see if it is resolved there.

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

grandesigns

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 1
  • CiviCRM version: 4.4.20
  • CMS version: Wordpress
Re: Pay Pal IPN and fees
February 17, 2013, 09:29:13 am
Lobo - just FYI, 4.2.7 does not solve the "no e-mails associated with recurring donations" bug. Going to drop my site back to 4.1.6 (the last version before the self-service stuff was added, which I'm guessing is the problem). If that doesn't help, then I'm going back to 4.1.2, since that is the last version I know works, and I don't have time to try every intervening point release.

Either way, I am effectively blocked from using a current version of CiviCRM by this bug, and correspondingly precluded from future updates (which is a shame since 4.3 looks pretty nice otherwise), so I will not be able to invest any resources in improving said inaccessible versions.

However, I do still need to resolve the fee recording issue, so when I come up with a fix through other channels, I will share it here, just in case it is helpful for future development.
« Last Edit: February 17, 2013, 09:32:03 am by grandesigns »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Pay Pal IPN and fees
February 17, 2013, 04:57:04 pm

would be great if you could invest your resources in debugging and fixing the issue with "no emails associated ..."

In the long run sticking to a specific point release might not be a great situation, IMO

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: 1 [2] 3
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Pay Pal IPN and fees

This forum was archived on 2017-11-26.