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] Throw exceptions from Authorize.net rather than return errors #17500

Merged
merged 1 commit into from
Jun 8, 2020
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
32 changes: 12 additions & 20 deletions CRM/Core/Payment/AuthorizeNet.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ public function doDirectPayment(&$params) {
}

if (!empty($params['is_recur']) && !empty($params['contributionRecurID'])) {
$result = $this->doRecurPayment();
if (is_a($result, 'CRM_Core_Error')) {
return $result;
}
$this->doRecurPayment();
return $params;
Copy link
Contributor

Choose a reason for hiding this comment

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

won't calling functions potentially miss error messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doRecurPayment won't return an error now - it will throw exceptions

}

Expand Down Expand Up @@ -237,36 +234,31 @@ public function doRecurPayment() {

$intervalLength = $this->_getParam('frequency_interval');
$intervalUnit = $this->_getParam('frequency_unit');
if ($intervalUnit == 'week') {
if ($intervalUnit === 'week') {
$intervalLength *= 7;
$intervalUnit = 'days';
}
elseif ($intervalUnit == 'year') {
elseif ($intervalUnit === 'year') {
$intervalLength *= 12;
$intervalUnit = 'months';
}
elseif ($intervalUnit === 'day') {
$intervalUnit = 'days';
}
elseif ($intervalUnit == 'month') {
$intervalUnit = 'months';
}

// interval cannot be less than 7 days or more than 1 year
if ($intervalUnit == 'days') {
// interval cannot be less than 7 days or more than 1 year
if ($intervalLength < 7) {
return self::error(9001, 'Payment interval must be at least one week');
throw new PaymentProcessorException('Payment interval must be at least one week', 9001);
}
elseif ($intervalLength > 365) {
return self::error(9001, 'Payment interval may not be longer than one year');
if ($intervalLength > 365) {
throw new PaymentProcessorException('Payment interval may not be longer than one year', 9001);
}
}
elseif ($intervalUnit == 'months') {
elseif ($intervalUnit === 'month') {
$intervalUnit = 'months';
if ($intervalLength < 1) {
return self::error(9001, 'Payment interval must be at least one week');
throw new PaymentProcessorException('Payment interval must be at least one week', 9001);
}
elseif ($intervalLength > 12) {
return self::error(9001, 'Payment interval may not be longer than one year');
if ($intervalLength > 12) {
throw new PaymentProcessorException('Payment interval may not be longer than one year', 9001);
}
}

Expand Down