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)

RachelWright

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 3
  • CiviCRM version: 4.2.7
  • CMS version: Joomla 2.5.17
  • MySQL version: 5.5.37
  • PHP version: 5.4.26
Pay Pal IPN and fees
November 05, 2012, 02:41:09 pm
I am using PayPal Pro as a payment processor and I need some help figuring out how civi records the PayPal fee and stores it in the database.

Currently, if you pay using your PayPal account, the fees are recorded in the database and show in the contribution records. But if you pay by credit card, the fees are not recorded (the database shows null) and the contribution page of course show nothing for the fee amount.

I have done some forum scouring and found some information on the PayPal IPN (and using mc_fee, this post for instance http://forum.civicrm.org/index.php/topic,16284.msg69540.html#msg69540). But none of what I have read do far has helped me get the fee to come thru a credit card trnx.

Any help would be greatly appreciated as I'd hate to have to force that field to be editable and manually enter fees.

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
November 05, 2012, 04:44:59 pm
i would debug it by forcing paypal to make another IPN call for both a credit card and a paypal account transaction (u should be able to do this from the paypal admin interface)

On the civi side, i would instrument the ipn code to basically just print the POST and GET values and exit. That would give u a good sense of what fields paypal is sending

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
November 21, 2012, 09:33:24 am
I have reproduced this on my site. Looking more closely at the transactions (and the IPNs thereof), it appears that for:

recurring transactions (eg. &txn_type=recurring_payment ) - Payment Fee is logged
express checkout transactions (eg. &txn_type=express_checkout) - Payment fee is logged
"normal" transactions (eg. &txn_type=web_accept ) - Payment Fee is NOT logged 

In all three cases, paypal sends the gross amount via mc_gross and payment_gross, and the fee amount via mc_fee and payment_fee. Looking at PayPalProIPN.php, CiviCRM is looking at mc_fee and mc_gross, and never checks the other two. CiviCRM has special code written to handle IPNs with "&txn_type=recurring_payment" but I cannot find anything to explain why &txn_type=express_checkout and &txn_type=web_accept should elicit different behaviors than each-other, since neither appears anywhere in the code.

I have attempted to reproduce this on the demo site, but I can't seem to coax it to accept the provided sandbox credit card number (it keeps spitting up "10001: Internal Error The transaction could not be loaded") - so if anyone wants to try that, more power to them. Still, this is looking like an actual bug, though I have no idea what the problem actually is.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Pay Pal IPN and fees
November 21, 2012, 06:54:50 pm
I'm not familiar w/ that code, and I'm a bit confused by the terms. What's the difference between mc_fee and payment_fee? Is this related to the original poster's distinction between a transaction using a PayPal account vs. a credit card?

If indeed payment_fee is 'name' used in the IPN's for a fee that needs to be logged by CiviCRM - it doesn't seem to be handled at all in either PayPalIPN.php or PayPalProIPN.php - and hence this is a bug. Would be great if you could nail this down, implement a fix, and file an issue w/ a patch on the issue tracker.
Protect your investment in CiviCRM by  becoming a Member!

grandesigns

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 1
  • CiviCRM version: 4.4.20
  • CMS version: Wordpress
Re: Pay Pal IPN and fees
November 27, 2012, 08:29:08 am
Quote from: Dave Greenberg on November 21, 2012, 06:54:50 pm
I'm not familiar w/ that code, and I'm a bit confused by the terms. What's the difference between mc_fee and payment_fee? Is this related to the original poster's distinction between a transaction using a PayPal account vs. a credit card?

If indeed payment_fee is 'name' used in the IPN's for a fee that needs to be logged by CiviCRM - it doesn't seem to be handled at all in either PayPalIPN.php or PayPalProIPN.php - and hence this is a bug. Would be great if you could nail this down, implement a fix, and file an issue w/ a patch on the issue tracker.

Dave - in this context, there seems to be no difference between mc_fee and payment_fee - they contain the exact same information in all the IPNs I have looked at. I apologize if I have confused matters a bit by referring to payment fee the generic piece of information (which both variables convey) in my last post with almost the same name as one of the variables (payment_fee).

That said, there is still a bug, which I will state here and add to the issue tracker, though I currently have no idea how to fix it:

When processing PaypalPro IPNs, CiviCRM does not record the value of mc_gross (the processing fee) for transactions where &txn_type=web_accept. I have not been able to find any reason in code for this to be the case, as it does record mc_gross when &txn_type=express_checkout, which triggers, to all appearances, the same process.
« Last Edit: November 27, 2012, 09:01:47 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
November 27, 2012, 09:01:00 am
Issue tracker entry here: http://issues.civicrm.org/jira/browse/CRM-11338

Eliet Henderson

  • I post occasionally
  • **
  • Posts: 49
  • Karma: 4
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 7
  • MySQL version: 5.0
  • PHP version: 5.2
Re: Pay Pal IPN and fees
January 02, 2013, 04:01:31 pm

I'm adding my two cents that I would really appreciate this fix. I spend a fair amount of time reconciling our Civi donation records with our Paypal payment records, and it would make things much easier to be able to see in Civi the accurate fee and net amount.

I don't have any programming skills but am happy to help test a fix.

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 02, 2013, 08:53:31 pm

eliet:

can u elaborate a bit more under what conditions are the fees recorded vs not recorded

we might want to add some debugging code to instrument what paypal sends back and see what has changed

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

Eliet Henderson

  • I post occasionally
  • **
  • Posts: 49
  • Karma: 4
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 7
  • MySQL version: 5.0
  • PHP version: 5.2
Re: Pay Pal IPN and fees
January 03, 2013, 11:04:00 am

Sure. My experience is similar to previous posters. We use PayPal Pro, which offers donors the option to enter a credit card payment on our contribution page, or to "check out with PayPal" by logging into his/her PayPal account and making a payment from there. When a donor makes a payment from his/her PayPal account, Civi records the accurate total amount, fee amount, and net amount.

If a donor makes a contribution by entering a credit card on our contribution page, Civi displays the accurate total amount, shows the fee amount as blank, and displays the net amount as the same as the total (i.e. no fee amount is removed from the net amount). But of course PayPal has taken their cut of these donations, which I can see if I log into my PayPal account.

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 05, 2013, 10:00:05 am
I'm going to take a look at this issue.

In comparing Core/Payment/PayPalProIPN.php and Core/Payment/PaypalIPN.php, I notice both have this code near the end of each file which appears to gather data and then insert it in the the Civi dB.   Is that a correct interpretation?

Code: [Select]
    $input['is_test']    = self::retrieve('test_ipn', 'Integer', 'POST', FALSE);
    $input['fee_amount'] = self::retrieve('mc_fee', 'Money', 'POST', FALSE);
    $input['net_amount'] = self::retrieve('settle_amount', 'Money', 'POST', FALSE);
    $input['trxn_id']    = self::retrieve('txn_id', 'String', 'POST', FALSE);

However, with PayPalPro.php it is apparently not working, as fees are never recorded.   See attached images?

As I get started, can you give me hints?

1. Can you think of reason the code would work in one case but not the other? 
2. Do you think the Paypal API has changed (or is different) for Pro?

Thanks!
Try CiviTeacher: the online video tutorial CiviCRM learning library.

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 06, 2013, 09:15:12 am

if i had to guess, most likely paypal is using two diffferent variable names for fee / net amount for Pro vs Standard

what i would do is:

1. Log the $_REQUEST variables in both IPN files (immediately after civi bootstrap)

2. Do a test (or real) payment in both Pro and Standard

see what paypal sends back

thanx

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

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 06, 2013, 12:18:15 pm
Thanks, can you please provide code examples of how to log specific variables?  I can see in the documentation how to print specific variables, but not log them.
Try CiviTeacher: the online video tutorial CiviCRM learning library.

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 06, 2013, 12:21:15 pm

once civi is bootstrapped the best way is:

Code: [Select]
CRM_Core_Error::debug_var( 'REQUEST', $_REQUEST );

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

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 06, 2013, 12:58:38 pm
For what it's worth, mc_fee does appear to be the variable used according to PayPal's API documentation.

Thanks Lobo, I'm sorry but you're talking at a level I don't understand.   Remember I don't do PHP debugging very often and rarely touch the CiviCRM PHP code.  What do you mean "bootstrapped"... isn't CiviCRM already bootstrapped?

If I'm going to research this, I'm afraid you'll really have to spell it out for me very literally how to get the variables from the request.  If you're rather not, I understand, but I can't find any documentation on this process you seem to describe.

I've edited the file to include your code, but that produces no results in the log.  Have I done it wrong?

Code: [Select]
  static
  function retrieve($name, $type, $location = 'POST', $abort = TRUE) {
    static $store = NULL;
    $value = CRM_Utils_Request::retrieve($name, $type, $store,
      FALSE, NULL, $location
    );
    CRM_Core_Error::debug_var( 'REQUEST', $_REQUEST );
    if ($abort && $value === NULL) {
      CRM_Core_Error::debug_log_message("Could not find an entry for $name in $location");
      echo "Failure: Missing Parameter<p>";
      exit();
    }
    return $value;
  }
Try CiviTeacher: the online video tutorial CiviCRM learning library.

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 07, 2013, 08:08:21 am

stoob:

might be easiest if you ping me on IRC and we can get this sorted

the code probably should go here:

extern/ipn.php

immediately after:

$config = CRM_Core_Config::singleton();

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.