<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 5 |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019 |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM. |
- | |
- | CiviCRM is free software; you can copy, modify, and distribute it |
- | under the terms of the GNU Affero General Public License |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | Copyright CiviCRM LLC. All rights reserved. |
| |
- | CiviCRM is distributed in the hope that it will be useful, but |
- | WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
- | See the GNU Affero General Public License for more details. |
- | |
- | You should have received a copy of the GNU Affero General Public |
- | License and the CiviCRM Licensing Exception along |
- | with this program; if not, contact CiviCRM LLC |
- | at info[AT]civicrm[DOT]org. If you have questions about the |
- | GNU Affero General Public License or the licensing of CiviCRM, |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2019
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
*/
/**
protected $_subscriptionDetails = NULL;
- protected $_selfService = FALSE;
-
public $_bltID = NULL;
/**
* Set variables up before form is built.
+ *
+ * @throws \CRM_Core_Exception
*/
public function preProcess() {
parent::preProcess();
if ($this->_crid) {
- $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_crid);
-
// Are we cancelling a recurring contribution that is linked to an auto-renew membership?
if ($this->_subscriptionDetails->membership_id) {
$this->_mid = $this->_subscriptionDetails->membership_id;
if ($this->_coid) {
$this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_coid, 'contribute', 'info');
$this->_paymentProcessor['object'] = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_coid, 'contribute', 'obj');
- $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_coid, 'contribution');
}
if ($this->_mid) {
}
if ((!$this->_crid && !$this->_coid && !$this->_mid) || (!$this->_subscriptionDetails)) {
- CRM_Core_Error::fatal('Required information missing.');
- }
- if (!CRM_Core_Permission::check('edit contributions')) {
- if ($this->_subscriptionDetails->contact_id != $this->getContactID()) {
- CRM_Core_Error::statusBounce(ts('You do not have permission to cancel subscription.'));
- }
- $this->_selfService = TRUE;
+ throw new CRM_Core_Exception('Required information missing.');
}
if (!$this->_paymentProcessor['object']->supports('updateSubscriptionBillingInfo')) {
- CRM_Core_Error::fatal(ts("%1 processor doesn't support updating subscription billing details.",
- array(1 => $this->_paymentProcessor['object']->_processorName)
+ throw new CRM_Core_Exception(ts("%1 processor doesn't support updating subscription billing details.",
+ [1 => $this->_paymentProcessor['title']]
));
}
$this->assign('paymentProcessor', $this->_paymentProcessor);
* Default values
*/
public function setDefaultValues() {
- $this->_defaults = array();
+ $this->_defaults = [];
if ($this->_subscriptionDetails->contact_id) {
- $fields = array();
+ $fields = [];
$names = array(
'first_name',
'middle_name',
*/
public function buildQuickForm() {
$type = 'next';
- if ($this->_selfService) {
+ if ($this->isSelfService()) {
$type = 'submit';
}
* true if no errors, else array of errors
*/
public static function formRule($fields, $files, $self) {
- $errors = array();
+ $errors = [];
CRM_Core_Form::validateMandatoryFields($self->_fields, $fields, $errors);
// validate the payment instrument values (e.g. credit card number)
}
$fields["email-{$this->_bltID}"] = 1;
- $processorParams = array();
+ $processorParams = [];
foreach ($params as $key => $val) {
$key = str_replace('billing_', '', $key);
list($key) = explode('-', $key);
$processorParams['country'] = CRM_Core_PseudoConstant::country($params["billing_country_id-{$this->_bltID}"], FALSE);
$processorParams['month'] = $processorParams['credit_card_exp_date']['M'];
$processorParams['year'] = $processorParams['credit_card_exp_date']['Y'];
- $processorParams['subscriptionId'] = $this->_subscriptionDetails->subscription_id;
+ $processorParams['subscriptionId'] = $this->getSubscriptionDetails()->processor_id;
$processorParams['amount'] = $this->_subscriptionDetails->amount;
$updateSubscription = $this->_paymentProcessor['object']->updateSubscriptionBillingInfo($message, $processorParams);
if (is_a($updateSubscription, 'CRM_Core_Error')) {
// format new address for display
$addressParts = array("street_address", "city", "postal_code", "state_province", "country");
foreach ($addressParts as $part) {
- $addressParts[$part] = CRM_Utils_Array::value($part, $processorParams);
+ $addressParts[$part] = $processorParams[$part] ?? NULL;
}
$tplParams['address'] = CRM_Utils_Address::format($addressParts);
$addressParts = array("street_address", "city", "postal_code", "state_province", "country");
foreach ($addressParts as $part) {
$key = "{$part}-{$this->_bltID}";
- $addressParts[$part] = CRM_Utils_Array::value($key, $this->_defaults);
+ $addressParts[$part] = $this->_defaults[$key] ?? NULL;
}
$this->_defaults['address'] = CRM_Utils_Address::format($addressParts);