Skip to content

Commit

Permalink
Merge pull request #15291 from mattwire/formatpaymentparams_addccip
Browse files Browse the repository at this point in the history
REF Move ipAddress and CC expiry date to prepareParamsForPaymentProcessor
  • Loading branch information
seamuslee001 authored Oct 9, 2019
2 parents f736b6b + b0efa39 commit af4916a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 27 deletions.
4 changes: 1 addition & 3 deletions CRM/Contribute/Form/AbstractEditPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,7 @@ protected function beginPostProcess() {
$this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
}
$this->assign('credit_card_exp_date', CRM_Utils_Date::mysqlToIso(CRM_Utils_Date::format($this->_params['credit_card_exp_date'])));
$this->assign('credit_card_number',
CRM_Utils_System::mungeCreditCard($this->_params['credit_card_number'])
);
$this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($this->_params['credit_card_number']));
$this->assign('credit_card_type', CRM_Utils_Array::value('credit_card_type', $this->_params));
}
$this->_params['ip_address'] = CRM_Utils_System::ipAddress();
Expand Down
13 changes: 11 additions & 2 deletions CRM/Core/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -862,15 +862,24 @@ protected function prepareParamsForPaymentProcessor($params) {
$params = array_merge($params, $addressParams);
}

// @fixme it would be really nice to have a comment here so I had a clue why we are setting $fields[$name] = 1
// Also how does relate to similar code in CRM_Contact_BAO_Contact::addBillingNameFieldsIfOtherwiseNotSet()
// How does this relate to similar code in CRM_Contact_BAO_Contact::addBillingNameFieldsIfOtherwiseNotSet()?
$nameFields = ['first_name', 'middle_name', 'last_name'];
foreach ($nameFields as $name) {
if (array_key_exists("billing_$name", $params)) {
$params[$name] = $params["billing_{$name}"];
$params['preserveDBName'] = TRUE;
}
}

// For legacy reasons we set these creditcard expiry fields if present
if (isset($params['credit_card_exp_date'])) {
$params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($params);
$params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($params);
}

// Assign IP address parameter
$params['ip_address'] = CRM_Utils_System::ipAddress();

return $params;
}

Expand Down
15 changes: 3 additions & 12 deletions CRM/Event/Cart/Form/Checkout/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,21 +597,12 @@ public function postProcess() {
* @throws Exception
*/
public function make_payment(&$params) {
$config = CRM_Core_Config::singleton();
if (isset($params["billing_state_province_id-{$this->_bltID}"]) && $params["billing_state_province_id-{$this->_bltID}"]) {
$params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($params["billing_state_province_id-{$this->_bltID}"]);
}

if (isset($params["billing_country_id-{$this->_bltID}"]) && $params["billing_country_id-{$this->_bltID}"]) {
$params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($params["billing_country_id-{$this->_bltID}"]);
}
$params['ip_address'] = CRM_Utils_System::ipAddress();
$params['currencyID'] = $config->defaultCurrency;
$params = $this->prepareParamsForPaymentProcessor($params);
$params['currencyID'] = CRM_Core_Config::singleton()->defaultCurrency;

$payment = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
CRM_Core_Payment_Form::mapParams($this->_bltID, $params, $params, TRUE);
$params['month'] = $params['credit_card_exp_date']['M'];
$params['year'] = $params['credit_card_exp_date']['Y'];

try {
$result = $payment->doPayment($params);
}
Expand Down
5 changes: 0 additions & 5 deletions CRM/Event/Form/Registration/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,7 @@ public function preProcess() {
$registerParams = $this->_params[0];
$registerParams = $this->prepareParamsForPaymentProcessor($registerParams);

if (isset($registerParams['credit_card_exp_date'])) {
$registerParams['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($registerParams);
$registerParams['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($registerParams);
}
if ($this->_values['event']['is_monetary']) {
$registerParams['ip_address'] = CRM_Utils_System::ipAddress();
$registerParams['currencyID'] = $this->_params[0]['currencyID'];
}
//assign back primary participant params.
Expand Down
5 changes: 0 additions & 5 deletions CRM/Event/Form/Registration/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -1107,12 +1107,7 @@ public function postProcess() {
// This code is duplicated multiple places and should be consolidated.
$params = $this->prepareParamsForPaymentProcessor($params);

if (isset($params['credit_card_exp_date'])) {
$params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($params);
$params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($params);
}
if ($this->_values['event']['is_monetary']) {
$params['ip_address'] = CRM_Utils_System::ipAddress();
$params['currencyID'] = $config->defaultCurrency;
$params['invoiceID'] = $invoiceID;
}
Expand Down

0 comments on commit af4916a

Please sign in to comment.