}
/**
- * Legacy. Better for a method to work on its own PropertyBag,
- * but also, this function does not do very much.
+ * Get the submitted amount, padded to 2 decimal places, if needed.
*
* @param array $params
*
* @return string
- * @throws \CRM_Core_Exception
*/
protected function getAmount($params = []) {
if (!CRM_Utils_Rule::numeric($params['amount'])) {
CRM_Core_Error::deprecatedWarning('Passing Amount value that is not numeric is deprecated please report this in gitlab');
return CRM_Utils_Money::formatUSLocaleNumericRounded(filter_var($params['amount'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION), 2);
}
- return CRM_Utils_Money::formatUSLocaleNumericRounded($params['amount'], 2);
+ // Amount is already formatted to a machine-friendly format but may NOT have
+ // decimal places - eg. it could be 1000.1 so this would return 1000.10.
+ return Civi::format()->machineMoney($params['amount']);
}
/**
public function doPayment(&$params, $component = 'contribute') {
$propertyBag = \Civi\Payment\PropertyBag::cast($params);
$this->_component = $component;
- $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id', 'validate');
// If we have a $0 amount, skip call to processor and set payment_status to Completed.
// Conceivably a processor might override this - perhaps for setting up a token - but we don't
// have an example of that at the moment.
if ($propertyBag->getAmount() == 0) {
- $result['payment_status_id'] = array_search('Completed', $statuses);
- $result['payment_status'] = 'Completed';
+ $result = $this->setStatusPaymentCompleted([]);
return $result;
}
CRM_Core_Error::deprecatedFunctionWarning('doPayment', 'doTransferCheckout');
$result = $this->doTransferCheckout($params, $component);
if (is_array($result) && !isset($result['payment_status_id'])) {
- $result['payment_status_id'] = array_search('Pending', $statuses);
- $result['payment_status'] = 'Pending';
+ $result = $this->setStatusPaymentPending($result);
}
}
else {
if (is_array($result) && !isset($result['payment_status_id'])) {
if (!empty($params['is_recur'])) {
// See comment block.
- $result['payment_status_id'] = array_search('Pending', $statuses);
- $result['payment_status'] = 'Pending';
+ $result = $this->setStatusPaymentPending($result);
}
else {
- $result['payment_status_id'] = array_search('Completed', $statuses);
- $result['payment_status'] = 'Completed';
+ $result = $this->setStatusPaymentCompleted($result);
}
}
}
return $result;
}
+ /**
+ * Set the payment status to Pending
+ * @param \Civi\Payment\PropertyBag|array $params
+ *
+ * @return array
+ */
+ protected function setStatusPaymentPending($params) {
+ $params['payment_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
+ $params['payment_status'] = 'Pending';
+ return $params;
+ }
+
+ /**
+ * Set the payment status to Completed
+ * @param \Civi\Payment\PropertyBag|array $params
+ *
+ * @return array
+ */
+ protected function setStatusPaymentCompleted($params) {
+ $params['payment_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
+ $params['payment_status'] = 'Completed';
+ return $params;
+ }
+
/**
* Cancel a recurring subscription.
*
* it is better to standardise to being here.
*
* @param int $invoiceId The ID to check.
- *
- * @param null $contributionID
+ * @param int|null $contributionID
* If a contribution exists pass in the contribution ID.
*
* @return bool
/**
* Get url for users to manage this recurring contribution for this processor.
*
- * @param int $entityID
- * @param null $entity
+ * @param int|null $entityID
+ * @param string|null $entity
* @param string $action
*
* @return string|null
}
$url = 'civicrm/contribute/updaterecur';
break;
+
+ default:
+ $url = '';
+ break;
}
$userId = CRM_Core_Session::singleton()->get('userID');