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=445516cb44cdf4175466a672851c138f91cff117;p=civicrm-core.git CRM-11338 retrieve fee_amount from paypal --- diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 3a45446495..7d44af4d39 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -537,6 +537,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 28ba5849bd..cf8337e00b 100644 --- a/CRM/Core/Payment/PayPalImpl.php +++ b/CRM/Core/Payment/PayPalImpl.php @@ -392,9 +392,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. *