From: eileenmcnaugton Date: Sun, 23 Aug 2015 20:49:22 +0000 (+1200) Subject: CRM-11338 retrieve fee_amount from paypal X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9d2f24ee82241815353d5fc7ddb951312c79bbed;p=civicrm-core.git CRM-11338 retrieve fee_amount from paypal --- diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 5c996ea152..39f5aa34a2 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -722,6 +722,24 @@ abstract class CRM_Core_Payment { return $result; } + /** + * Query payment processor for details about a transaction. + * + * @param array $params + * Array of parameters containing one of: + * - trxn_id Id of an individual transaction. + * - processor_id Id of a recurring contribution series as stored in the civicrm_contribution_recur table. + * + * @return array + * Extra parameters retrieved. + * Any parameters retrievable through this should be documented in the function comments at + * CRM_Core_Payment::doQuery. Currently: + * - fee_amount Amount of fee paid + */ + public function doQuery($params) { + return array(); + } + /** * This function checks to see if we have the right config values. * diff --git a/CRM/Core/Payment/PayPalImpl.php b/CRM/Core/Payment/PayPalImpl.php index 17e67782b4..a811b09675 100644 --- a/CRM/Core/Payment/PayPalImpl.php +++ b/CRM/Core/Payment/PayPalImpl.php @@ -516,9 +516,42 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $params['trxn_id'] = CRM_Utils_Array::value('transactionid', $result); $params['gross_amount'] = CRM_Utils_Array::value('amt', $result); + $params = array_merge($params, $this->doQuery($params)); return $params; } + /** + * Query payment processor for details about a transaction. + * + * For paypal see : https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/GetTransactionDetails_API_Operation_NVP/ + * + * @param array $params + * Array of parameters containing one of: + * - trxn_id Id of an individual transaction. + * - processor_id Id of a recurring contribution series as stored in the civicrm_contribution_recur table. + * + * @return array + * Extra parameters retrieved. + * Any parameters retrievable through this should be documented in the function comments at + * CRM_Core_Payment::doQuery. Currently + * - fee_amount Amount of fee paid + * + * @throws \Civi\Payment\Exception\PaymentProcessorException + */ + public function doQuery($params) { + if (empty($params['trxn_id'])) { + throw new \Civi\Payment\Exception\PaymentProcessorException('transaction id not set'); + } + $args = array( + 'TRANSACTIONID' => $params['trxn_id'], + ); + $this->initialize($args, 'GetTransactionDetails'); + $result = $this->invokeAPI($args); + return array( + 'fee_amount' => $result['feeamt'], + ); + } + /** * This function checks to see if we have the right config values. *