Skip to content

CRM-20392 (IIDA-108), Fixed submit Credit Card transaction for partia… #10271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2017

Conversation

eileenmcnaughton
Copy link
Contributor

@monishdeb FYI - calling $this->processBillingAddress(); if the way other forms have been handling all that billing profile code -

It should be called in the main processing routine to support config where billing address is required for pay later, it runs off whether the fields are set

@eileenmcnaughton
Copy link
Contributor Author

NB - I've just opened this to share with you in conjunction with the form tidy up on #10126 - will close later

@monishdeb monishdeb force-pushed the tidy branch 2 times, most recently from b903358 to 628e12b Compare April 28, 2017 11:29
@monishdeb
Copy link
Member

@eileenmcnaughton I have updated the PR with desired changes, please have a look

}

$defaults = array();
$contribution = civicrm_api3('Contribution', 'getsingle', array(
'return' => array("contribution_status_id"),
'id' => $this->_contributionId,
));
// store transaction date time instead of date only
$this->_params['trxn_date'] = CRM_Utils_Date::processDate($this->_params['trxn_date'], CRM_Utils_Array::value('trxn_date_time', $this->_params));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this

if (!$this->_mode) {
$js = array('onclick' => "return verify( );");

$this->add('select', 'payment_instrument_id',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these forms aren't actually showing on the credit card form anyway

Copy link
Member

@monishdeb monishdeb Apr 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya but I think that we shouldn't render these quickForm elements needlessly when its not in use.. So I thought why not to move the code here rather exposing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -211,9 +211,10 @@ public function buildQuickForm() {
}

CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE, CRM_Utils_Request::retrieve('payment_instrument_id', 'Integer'));
$this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, NULL);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this change do anything?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it's just shifting code to (from L216 to L214) meaningful place

$this->_contactId,
NULL, NULL,
$ctype
$fields = $this->formatParamsForPaymentProcessor($this->_params);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok - so using the parent function to create the profile contact outside the credit card processing didn't work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that comment was actually for the next line...

@@ -502,20 +461,24 @@ public function processCreditCard($submittedValues) {
$paymentParams['contactID'] = $this->_contactId;
CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);

// add some financial type details (as contributionType_name) to the params list
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we want to assign contributionType_name?

Copy link
Member

@monishdeb monishdeb Apr 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's used in few Payment processor, as per grep

CRM/Core/Payment/Elavon.php:105:     *  $params['contributionType_name'  ];
CRM/Core/Payment/FirstData.php:137:    //  $requestFields[       ''  ]          =  $params[ 'contributionType_name'  ];
CRM/Core/Payment/Realex.php:369:    $this->_setParam('varref', $params['contributionType_name']);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm - in a deprecated kind of a way - if it wasn't working from this form before & no-one has reported it as a problem I don't think we should add it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok lemme remove it then

CRM_Contact_BAO_Contact::createProfileContact($params, $fields,
$this->_contactId,
NULL, NULL,
$ctype
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->processBillingAddress() is the function I would expect to have already done createProfileContact

@@ -476,6 +432,8 @@ public function processCreditCard($submittedValues) {
$config->defaultCurrency
);

// take recieve_date as current or from trxn_date
$this->_params['receive_date'] = date('Ymd');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this right? contribution receive date would change?


// Get the required fields value only.
$params = $submittedValues;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't made sense of this part - if you have reviewed it I'm fine with that since I know Pradeep concluded it was cruft

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I have removed it after testing

// Add all the additional payment params we need.
$this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
$this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep - handled above

}
}

if ($result) {
$this->_params = array_merge($this->_params, $result);
// If payment is not completed then bounce approrptiate status message
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it more readable to keep all this in the catch block? I can't see anywhere else where $errorMessage is set.

) {
//set the contribution mode.
$urlParams = "action=add&cid={$this->_contactId}&id={$this->_contributionId}&component={$this->_component}&mode={$this->_mode}";
if (!$errorMessage) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could never be true

if (!$errorMessage) {
$errorMessage = ts('Payment from payment processor failed.');
}
CRM_Core_Session::singleton()->setStatus($errorMessage, ts('Payment Failed'), 'error');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any thoughts how this compares to using CRM_Core_Error::statusBounce from this line?

@@ -591,18 +562,25 @@ public function emailReceipt(&$params) {
// assign payment info here
$paymentConfig['confirm_email_text'] = CRM_Utils_Array::value('confirm_email_text', $params);
$this->assign('paymentConfig', $paymentConfig);

$this->assign('totalAmount', $this->_amtTotal);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is all this about?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a code shift as there always be $this->_amtTotal, so I just moved it from the IF-ELSE code below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I don't see isAmountzero being removed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I am talking about the code removed at L598 and L605

@@ -611,14 +589,10 @@ public function emailReceipt(&$params) {
// assign trxn details
$this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $params));
$this->assign('receive_date', CRM_Utils_Array::value('trxn_date', $params));
$paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
if (array_key_exists('payment_instrument_id', $params)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm - so this would be set for credit card too by now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

}
$paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument();
$this->assign('paidBy',
CRM_Utils_Array::value($params['payment_instrument_id'], $paymentInstruments)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->assign('paidBy', CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribute', 'payment_instrument_id, $params['payment_instrument_id']);

Is the way we are going on these

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops ya missed it

<div class="messages status no-popup">
<div class="icon inform-icon"></div>&nbsp;{ts}You will not be able to send an automatic email receipt for this payment because there is no email address recorded for this contact. If you want a receipt to be sent when this payment is recorded, click Cancel and then click Edit from the Summary tab to add an email address before recording the payment.{/ts}
</div>
<div class="messages status no-popup">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacey :-)

@@ -97,6 +97,20 @@
<td>
<span id='totalAmount'>{$form.currency.html|crmAddClass:eight}&nbsp;{$form.total_amount.html|crmAddClass:eight}</span>&nbsp; <span class="status">{if $paymentType EQ 'refund'}{ts}Refund Due{/ts}{else}{ts}Balance Owed{/ts}{/if}:&nbsp;{$paymentAmt|crmMoney}</span>
</td>
{if $email and $outBound_option != 2}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems fine - didn't Pradeep also rip out a tonne of js that is not required now

@monishdeb monishdeb force-pushed the tidy branch 2 times, most recently from 94b9f56 to 0a59a75 Compare April 28, 2017 12:39
}
}

if ($result) {
if (isset($result)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$result = NULL; means it is set - if !empty is probably better here

@monishdeb monishdeb force-pushed the tidy branch 2 times, most recently from 315492e to b203609 Compare April 28, 2017 12:46
@eileenmcnaughton
Copy link
Contributor Author

@monishdeb I'm calling it for tonight now - but once you've removed those lines around
isAmountZero & tidied up the commits & pull request name then go ahead & merge -

@eileenmcnaughton eileenmcnaughton changed the title [wip] form tidy ups CRM-20392 (IIDA-108), Fixed submit Credit Card transaction for partia… Apr 29, 2017
@eileenmcnaughton
Copy link
Contributor Author

@monishdeb I've taken out those few lines & tidied up the commit message/ squashed the commits & I'm going to merge this. I looked at whether #10126 should be closed but there is a section of cleanup which we have lost - ie. https://github.com/civicrm/civicrm-core/pull/10126/files#diff-bda4a97d68b9f968720ce192d5f960f9L196 & it would be good to get that merged. Also, is the test in that PR merged? I think it may be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants