From 819c0bd6785d90fb6adfe3df10c6d7c8233b4eb6 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 7 May 2018 16:06:12 +1200 Subject: [PATCH] Fix enotices on paypal express (dev/financial/issues/14) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit For background - Paypal Express was not originally supported for recurring. It kind of snuck in the back door since it was actually not possible to block in when configuring paypal pro and people kept adding little fixes since they assumed it was broken rather than deliberately missing functionality. Somewhere along the line this function was probably copied & extracted from the main function - but it still contained a bunch of lines not required for paypal express. I took a look at what data is actually available in this function and removed reference to unavailable fields. This is from https://developer.paypal.com/docs/classic/api/merchant/CreateRecurringPaymentsProfile_API_Operation_NVP/ and from testing and from https://lab.civicrm.org/dev/financial/issues/14 The one are where I differed from logic from @carbar1103 @carbar1103   is the trxn_id - I retained the profile id which I think is consistent with use for other processsors, but needs testing --- CRM/Core/Payment/PayPalImpl.php | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/CRM/Core/Payment/PayPalImpl.php b/CRM/Core/Payment/PayPalImpl.php index 7ffa6f8a1a..642ee302ea 100644 --- a/CRM/Core/Payment/PayPalImpl.php +++ b/CRM/Core/Payment/PayPalImpl.php @@ -412,7 +412,6 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { */ public function createRecurringPayments(&$params) { $args = array(); - // @todo this function is riddled with enotices - perhaps use $this->mapPaypalParamsToCivicrmParams($fieldMap, $result) $this->initialize($args, 'CreateRecurringPaymentsProfile'); $start_time = strtotime(date('m/d/Y')); @@ -424,15 +423,12 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $args['currencyCode'] = $params['currencyID']; $args['payerID'] = $params['payer_id']; $args['invnum'] = $params['invoiceID']; - $args['returnURL'] = $params['returnURL']; - $args['cancelURL'] = $params['cancelURL']; $args['profilestartdate'] = $start_date; $args['method'] = 'CreateRecurringPaymentsProfile'; $args['billingfrequency'] = $params['frequency_interval']; $args['billingperiod'] = ucwords($params['frequency_unit']); $args['desc'] = $params['amount'] . " Per " . $params['frequency_interval'] . " " . $params['frequency_unit']; - //$args['desc'] = 'Recurring Contribution'; - $args['totalbillingcycles'] = $params['installments']; + $args['totalbillingcycles'] = CRM_Utils_Array::value('installments', $params); $args['version'] = '56.0'; $args['profilereference'] = "i={$params['invoiceID']}" . "&m=" . @@ -450,16 +446,19 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { return $result; } - /* Success */ - $params['trxn_id'] = $result['transactionid']; - $params['gross_amount'] = $result['amt']; - $params['fee_amount'] = $result['feeamt']; - $params['net_amount'] = $result['settleamt']; - if ($params['net_amount'] == 0 && $params['fee_amount'] != 0) { - $params['net_amount'] = number_format(($params['gross_amount'] - $params['fee_amount']), 2); - } - $params['payment_status'] = $result['paymentstatus']; - $params['pending_reason'] = $result['pendingreason']; + /* Success - result looks like" + * array ( + * 'profileid' => 'I-CP1U0PLG91R2', + * 'profilestatus' => 'ActiveProfile', + * 'timestamp' => '2018-05-07T03:55:52Z', + * 'correlationid' => 'e717999e9bf62', + * 'ack' => 'Success', + * 'version' => '56.0', + * 'build' => '39949200',) + */ + + $params['trxn_id'] = $result['profileid']; + $params['payment_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'); return $params; } -- 2.25.1