-
-
Notifications
You must be signed in to change notification settings - Fork 827
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
Fix display of pay later instructions on thankyou and skipping when payment on confirmation page #32502
Conversation
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
Quick links for reviewers...
|
CRM/Event/Form/Registration.php
Outdated
$this->assign('is_pay_later', $params['is_pay_later']); | ||
$this->assign('pay_later_text', $params['is_pay_later'] ? $this->getPayLaterLabel() : FALSE); | ||
$this->assign('pay_later_receipt', $params['is_pay_later'] ? $this->_values['event']['pay_later_receipt'] : NULL); | ||
$isPayLater = ($this->_values['event']['is_pay_later'] ?? FALSE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$params actually comes from the first event participant, we should be looking at the actual event data.
Also, $params seems to get reset to values from Register form (ie. throwing away changes on the Confirm form) when loaded on the ThankYou page so is_pay_later value is unreliable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been using $this->getEventValue('is_pay_later')
rather than _values
- the former is a direct apiv4 lookup with some caching whereas the latter seems a bit magic to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(also getEventValue()
is supported for extensions to use so good to model it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's pretty horrible the way event/participant params are passed around those forms. The problem is that both participant params and event (_values) are modified during form submission. The database value of is_pay_later is 1 for the event because pay later is enabled. But by the time we get to this point is_pay_later has been set to FALSE because we've submitted the form with a paymentprocessor. If you use the event value from the DB/API4 then you get contributions etc. with is_pay_later set to true when they are not..
I'd love to find another way of getting the form submission is_pay_later value but I couldn't find anything that didn't involve a massive refactoring of the params being passed around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh that's dark - but does that mean is_pay_later
=== !$this->getSubmittedValue('payment_processor_id')
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's an idea.. getSubmittedValue() wasn't working properly but I fixed that as part of this PR so may now be a better option!
// If we submitted with no payment processor then we must be pay later - set it here. | ||
$params[$participantNum]['is_pay_later'] = 1; | ||
$params[$participantNum]['is_pay_later'] = $this->_values['event']['is_pay_later'] = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set the pay later status based on the payment processor used on the confirm form
@@ -42,7 +42,7 @@ | |||
'type' => 'Array', | |||
'default' => [], | |||
'add' => '5.58', | |||
'title' => ts('EXPERIMENTAL: Show Event Payment on Confirm?'), | |||
'title' => ts('Show Event Payment on Confirm?'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think it's time to remove the Experimental label...
$this->assign('credit_card_type', $this->getSubmittedValue('credit_card_type')); | ||
if ($this->getSubmittedValue('credit_card_exp_date')) { | ||
$date = CRM_Utils_Date::format($this->getSubmittedValue('credit_card_exp_date')); | ||
$date = CRM_Utils_Date::mysqlToIso($date); | ||
} | ||
$this->assign('credit_card_exp_date', $date ?? NULL); | ||
$this->assign('credit_card_number', | ||
CRM_Utils_System::mungeCreditCard($this->getSubmittedValue('credit_card_number') ?? '') | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should always be getting these fields from the original submitted values and not via a passed around $params array (which is actually first participant params with some extra sprinkled in)
$value = $this->controller->exportValue('Register', $fieldName); | ||
} | ||
if (!isset($value)) { | ||
$value = parent::getSubmittedValue($fieldName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fallback to generic function if we didn't find what we needed.
// were on the Register Page so we return them | ||
$value = $this->controller->exportValue('Register', $fieldName); | ||
if ($this->isShowPaymentOnConfirm() && in_array($this->getName(), ['Confirm', 'ThankYou'], TRUE)) { | ||
$value = $this->controller->exportValue('Confirm', $fieldName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll find payment fields on Confirm if payment was made on Confirm. Otherwise they'll be on Register
@@ -252,6 +252,7 @@ public function buildQuickForm() { | |||
$this->assign('pay_later_receipt', ''); | |||
// @fixme These functions all seem to do similar things but take one away and the house of cards falls down.. | |||
$this->assignPaymentProcessor($this->_values['event']['is_pay_later']); | |||
$this->preProcessPaymentOptions(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is required only after the form is submitted to repopulate form fields so that eg. credit card fields can be retrieved via getSubmittedValue() from the ThankYou page. Otherwise they are lost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattwire maybe we need an incode comment to that effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eileenmcnaughton good idea. Added
<div class="content credit_card_type">{$credit_card_type}</div> | ||
<div class="content credit_card_number">{$credit_card_number}</div> | ||
<div class="content credit_card_exp_date">{if $credit_card_exp_date}{ts}Expires{/ts}: {$credit_card_exp_date|truncate:7:''|crmDate}{/if}</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Purely cosmetic but seems nice to be able to target each field separately.
…ayment on confirmation page
Just one thing outstanding - possible improvement of the code comments per comment above |
…akes card details info show correctly on ThankYou page)
Tested this patch on localdev and on a staging site, and it seems to work as expected and resolve the issue. Thank You, Both! |
thanks for testing @marcusjwilson |
Overview
When a payment processor and pay later are enabled pay later instructions are always displayed on the ThankYou page.
Before
is_pay_later always set on ThankYou page.
After
Set per actual pay later status.
Technical Details
Explained via comments on this PR
Comments