Skip to content
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

[REF] Standardise methods of determining isTest #19417

Merged
merged 1 commit into from
Feb 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions CRM/Member/Form/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,7 @@ public static function emailReceipt($form, &$formValues, $membership) {
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function submit() {
$isTest = ($this->_mode === 'test') ? 1 : 0;
public function submit(): void {
$this->storeContactFields($this->_params);
$this->beginPostProcess();
$endDate = NULL;
Expand Down Expand Up @@ -1292,7 +1291,7 @@ public function submit() {
[
'contact_id' => $this->_contributorContactID,
'line_item' => $lineItem,
'is_test' => $isTest,
'is_test' => $this->isTest(),
'campaign_id' => $paymentParams['campaign_id'] ?? NULL,
'source' => CRM_Utils_Array::value('source', $paymentParams, CRM_Utils_Array::value('description', $paymentParams)),
'payment_instrument_id' => $paymentInstrumentID,
Expand Down Expand Up @@ -1363,7 +1362,7 @@ public function submit() {
);
$params['source'] = $formValues['source'] ?: $params['contribution_source'];
$params['trxn_id'] = $result['trxn_id'] ?? NULL;
$params['is_test'] = ($this->_mode === 'live') ? 0 : 1;
$params['is_test'] = $this->isTest();
if (!empty($formValues['send_receipt'])) {
$params['receipt_date'] = $now;
}
Expand Down Expand Up @@ -1938,7 +1937,6 @@ protected function processContribution(
* @return int
*/
protected function legacyProcessRecurringContribution(array $params, $contactID): int {
$form = $this;
Copy link
Member

Choose a reason for hiding this comment

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

safely deleted, no reference to $form present.


$recurParams = ['contact_id' => $contactID];
$recurParams['amount'] = $params['amount'] ?? NULL;
Expand All @@ -1950,12 +1948,7 @@ protected function legacyProcessRecurringContribution(array $params, $contactID)
$recurParams['currency'] = $params['currency'] ?? NULL;
$recurParams['payment_instrument_id'] = $params['payment_instrument_id'];

$recurParams['is_test'] = 0;
if (($form->_action & CRM_Core_Action::PREVIEW) ||
(isset($form->_mode) && ($form->_mode == 'test'))
Copy link
Member

Choose a reason for hiding this comment

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

ensured removing $form->_action & CRM_Core_Action::PREVIEW doesn't affect the test mode processing on membership backoffice form.

) {
$recurParams['is_test'] = 1;
}
$recurParams['is_test'] = $this->isTest();

$recurParams['start_date'] = $recurParams['create_date'] = $recurParams['modified_date'] = CRM_Utils_Time::date('YmdHis');
if (!empty($params['receive_date'])) {
Expand All @@ -1969,9 +1962,18 @@ protected function legacyProcessRecurringContribution(array $params, $contactID)
// in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
$recurParams['trxn_id'] = $params['trxn_id'] ?? $params['invoiceID'];

$campaignId = $params['campaign_id'] ?? $form->_values['campaign_id'] ?? NULL;
$campaignId = $params['campaign_id'] ?? $this->_values['campaign_id'] ?? NULL;
$recurParams['campaign_id'] = $campaignId;
return CRM_Contribute_BAO_ContributionRecur::add($recurParams)->id;
}

/**
* Is the form being submitted in test mode.
*
* @return bool
*/
protected function isTest(): int {
return ($this->_mode === 'test') ? TRUE : FALSE;
}

}