Skip to content

Commit 85ca7d0

Browse files
Merge pull request #32502 from mattwire/eventpaylater
Fix display of pay later instructions on thankyou and skipping when payment on confirmation page
2 parents eda7519 + dfff2fc commit 85ca7d0

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

CRM/Event/Form/Registration.php

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -556,23 +556,22 @@ public function assignToTemplate() {
556556

557557
$this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters($params));
558558

559-
if ($this->getSubmittedValue('credit_card_number')) {
560-
if (isset($params['credit_card_exp_date'])) {
561-
$date = CRM_Utils_Date::format($params['credit_card_exp_date']);
562-
$date = CRM_Utils_Date::mysqlToIso($date);
563-
}
564-
$this->assign('credit_card_exp_date', $date ?? NULL);
565-
$this->assign('credit_card_number',
566-
CRM_Utils_System::mungeCreditCard($params['credit_card_number'] ?? NULL)
567-
);
568-
}
559+
$this->assign('credit_card_type', $this->getSubmittedValue('credit_card_type'));
560+
if ($this->getSubmittedValue('credit_card_exp_date')) {
561+
$date = CRM_Utils_Date::format($this->getSubmittedValue('credit_card_exp_date'));
562+
$date = CRM_Utils_Date::mysqlToIso($date);
563+
}
564+
$this->assign('credit_card_exp_date', $date ?? NULL);
565+
$this->assign('credit_card_number',
566+
CRM_Utils_System::mungeCreditCard($this->getSubmittedValue('credit_card_number') ?? '')
567+
);
569568

570569
$this->assign('is_email_confirm', $this->_values['event']['is_email_confirm'] ?? NULL);
571570
// assign pay later stuff
572-
$params['is_pay_later'] ??= FALSE;
573-
$this->assign('is_pay_later', $params['is_pay_later']);
574-
$this->assign('pay_later_text', $params['is_pay_later'] ? $this->getPayLaterLabel() : FALSE);
575-
$this->assign('pay_later_receipt', $params['is_pay_later'] ? $this->_values['event']['pay_later_receipt'] : NULL);
571+
$isPayLater = empty($this->getSubmittedValue('payment_processor_id'));
572+
$this->assign('is_pay_later', $isPayLater);
573+
$this->assign('pay_later_text', $isPayLater ? $this->getPayLaterLabel() : FALSE);
574+
$this->assign('pay_later_receipt', $isPayLater ? $this->_values['event']['pay_later_receipt'] : NULL);
576575

577576
// also assign all participantIDs to the template
578577
// useful in generating confirmation numbers if needed
@@ -1607,15 +1606,17 @@ protected function validatePriceSet(array $params, $priceSetId, $priceSetDetails
16071606
* @return mixed|null
16081607
*/
16091608
public function getSubmittedValue(string $fieldName) {
1610-
$value = parent::getSubmittedValue($fieldName);
1611-
// Check for value as well in case the field has been added to the Confirm form
1612-
// I don't quite know how that works but something Matt has worked on.
1613-
if ($value || !in_array($this->getName(), ['Confirm', 'ThankYou'], TRUE)) {
1614-
return $value;
1615-
}
1616-
// If we are on the Confirm or ThankYou page then the submitted values
1617-
// were on the Register Page so we return them
1618-
$value = $this->controller->exportValue('Register', $fieldName);
1609+
if ($this->isShowPaymentOnConfirm() && in_array($this->getName(), ['Confirm', 'ThankYou'], TRUE)) {
1610+
$value = $this->controller->exportValue('Confirm', $fieldName);
1611+
}
1612+
else {
1613+
// If we are on the Confirm or ThankYou page then the submitted values
1614+
// were on the Register Page so we return them
1615+
$value = $this->controller->exportValue('Register', $fieldName);
1616+
}
1617+
if (!isset($value)) {
1618+
$value = parent::getSubmittedValue($fieldName);
1619+
}
16191620
if (in_array($fieldName, $this->submittableMoneyFields, TRUE)) {
16201621
return CRM_Utils_Rule::cleanMoney($value);
16211622
}

CRM/Event/Form/Registration/Confirm.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ public function buildQuickForm() {
252252
$this->assign('pay_later_receipt', '');
253253
// @fixme These functions all seem to do similar things but take one away and the house of cards falls down..
254254
$this->assignPaymentProcessor($this->_values['event']['is_pay_later']);
255+
// This is required only after the form is submitted to repopulate form fields so that eg. credit card fields
256+
// can be retrieved via getSubmittedValue() from the ThankYou page. Otherwise they are lost.
257+
$this->preProcessPaymentOptions();
255258
CRM_Core_Payment_ProcessorForm::buildQuickForm($this);
256259
$this->addPaymentProcessorFieldsToForm();
257260
}
@@ -453,13 +456,9 @@ public function postProcess() {
453456
}
454457
}
455458
if ($this->isShowPaymentOnConfirm()) {
456-
// "is_pay_later" may have been set by the registration page. Reset it here.
457-
$params[$participantNum]['is_pay_later'] = 0;
458-
// Again, here we have to use getSubmitValue because getSubmittedValue is not set.
459-
if ($this->getSubmitValue('hidden_processor') === NULL || $this->getSubmitValue('payment_processor_id') == 0) {
460-
// If we submitted with no payment processor then we must be pay later - set it here.
461-
$params[$participantNum]['is_pay_later'] = 1;
462-
}
459+
// If payment_processor_id is 0 or unset we are pay later.
460+
// Otherwise we are using a payment processor
461+
$params[$participantNum]['is_pay_later'] = $this->_values['event']['is_pay_later'] = empty($this->getSubmittedValue('payment_processor_id'));
463462
}
464463
}
465464
$taxAmount = $totalTaxAmount;

settings/Event.setting.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
'type' => 'Array',
4343
'default' => [],
4444
'add' => '5.58',
45-
'title' => ts('EXPERIMENTAL: Show Event Payment on Confirm?'),
45+
'title' => ts('Show Event Payment on Confirm?'),
4646
'html_type' => 'select',
4747
'html_attributes' => [
4848
'class' => 'crm-select2',

templates/CRM/Event/Form/Registration/ThankYou.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@
160160
{ts}Credit Card Information{/ts}
161161
</div>
162162
<div class="crm-section no-label credit_card_details-section">
163-
<div class="content">{$credit_card_type}</div>
164-
<div class="content">{$credit_card_number}</div>
165-
<div class="content">{if $credit_card_exp_date}{ts}Expires{/ts}: {$credit_card_exp_date|truncate:7:''|crmDate}{/if}</div>
163+
<div class="content credit_card_type">{$credit_card_type}</div>
164+
<div class="content credit_card_number">{$credit_card_number}</div>
165+
<div class="content credit_card_exp_date">{if $credit_card_exp_date}{ts}Expires{/ts}: {$credit_card_exp_date|truncate:7:''|crmDate}{/if}</div>
166166
<div class="clear"></div>
167167
</div>
168168
</div>

0 commit comments

Comments
 (0)