$this->set('invoiceID', $invoiceID);
$params['invoiceID'] = $invoiceID;
$params['description'] = ts('Online Contribution') . ': ' . (($this->_pcpInfo['title']) ? $this->_pcpInfo['title'] : $this->_values['title']);
-
+ $params['button'] = $this->controller->getButtonName();
// required only if is_monetary and valid positive amount
if ($this->_values['is_monetary'] &&
is_array($this->_paymentProcessor) &&
}
- /**
- * Handle pre approval for processors.
- *
- * This fits with the flow where a pre-approval is done and then confirmed in the next stage when confirm is hit.
- *
- * This applies to processors that
- * @param array $params
- */
- protected function handlePreApproval(&$params) {
- try {
- $payment = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
- $params['component'] = 'contribute';
- $result = $payment->doPreApproval($params);
- }
- catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
- CRM_Core_Error::displaySessionError($e->getMessage());
- CRM_Utils_System::redirect($params['cancelURL']);
- }
-
- $this->set('pre_approval_parameters', $result['pre_approval_parameters']);
- if (!empty($result['redirect_url'])) {
- CRM_Utils_System::redirect($result['redirect_url']);
- }
- }
-
/**
* Process confirm function and pass browser to the thank you page.
*/
$this->assign('paymentProcessorID', $this->_paymentProcessorID);
}
+ /**
+ * Handle pre approval for processors.
+ *
+ * This fits with the flow where a pre-approval is done and then confirmed in the next stage when confirm is hit.
+ *
+ * This function is shared between contribution & event forms & this is their common class.
+ *
+ * However, this should be seen as an in-progress refactor, the end goal being to also align the
+ * backoffice forms that action payments.
+ *
+ * @param array $params
+ */
+ protected function handlePreApproval(&$params) {
+ try {
+ $payment = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
+ $params['component'] = 'contribute';
+ $result = $payment->doPreApproval($params);
+ if (empty($result)) {
+ // This could happen, for example, when paypal looks at the button value & decides it is not paypal express.
+ return;
+ }
+ }
+ catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
+ CRM_Core_Error::displaySessionError($e->getMessage());
+ CRM_Utils_System::redirect($params['cancelURL']);
+ }
+
+ $this->set('pre_approval_parameters', $result['pre_approval_parameters']);
+ if (!empty($result['redirect_url'])) {
+ CRM_Utils_System::redirect($result['redirect_url']);
+ }
+ }
+
/**
* Setter function for options.
*
+--------------------------------------------------------------------+
*/
+use Civi\Payment\Exception\PaymentProcessorException;
+
/**
*
* @package CRM
* @return bool
*/
protected function supportsPreApproval() {
- if ($this->_processorName == ts('PayPal Express')) {
+ if ($this->_processorName == ts('PayPal Express') || $this->_processorName == ts('PayPal Pro')) {
return TRUE;
}
return FALSE;
* @return array
*/
public function getPreApprovalDetails($storedDetails) {
- return $this->getExpressCheckoutDetails($storedDetails['token']);
+ return empty($storedDetails['token']) ? array() : $this->getExpressCheckoutDetails($storedDetails['token']);
}
/**
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function doPayment(&$params, $component = 'contribute') {
- if ($this->_paymentProcessor['payment_processor_type'] != 'PayPal_Express') {
+ if ($this->_paymentProcessor['payment_processor_type'] != 'PayPal_Express'
+ && (!empty($params['credit_card_number']) && empty($params['token']))
+ ) {
return parent::doPayment($params, $component);
}
$this->_component = $component;
* - redirect_url (if set the browser will be redirected to this.
*/
public function doPreApproval(&$params) {
+ if (!isset($params['button']) || !stristr($params['button'], 'express')) {
+ return array();
+ }
$this->_component = $params['component'];
$token = $this->setExpressCheckOut($params);
return array(
}
/**
- * Check if profiles are complete when event registration occurs(CRM-9587)
+ * Check if profiles are complete when event registration occurs(CRM-9587).
+ *
+ * @param array $fields
+ * @param array $errors
+ * @param int $eventId
*/
public static function checkProfileComplete($fields, &$errors, $eventId) {
$email = '';
if (is_array($this->_paymentProcessor)) {
$payment = $this->_paymentProcessor['object'];
+ $payment->setBaseReturnUrl('civicrm/event/register');
}
// default mode is direct
$this->set('contributeMode', 'direct');
$params['invoiceID'] = $invoiceID;
}
$this->_params = $this->get('params');
+ // Set the button so we know what
+ $params['button'] = $this->controller->getButtonName();
if (!empty($this->_params) && is_array($this->_params)) {
$this->_params[0] = $params;
}
$this->_params[] = $params;
}
$this->set('params', $this->_params);
-
if ($this->_paymentProcessor &&
- $this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON
+ $this->_paymentProcessor['object']->supports('preApproval')
+ && !$this->_allowWaitlist &&
+ !$this->_requireApproval
) {
- //get the button name
- $buttonName = $this->controller->getButtonName();
- if (in_array($buttonName,
- array(
- $this->_expressButtonName,
- $this->_expressButtonName . '_x',
- $this->_expressButtonName . '_y',
- )
- ) && empty($params['is_pay_later']) &&
- !$this->_allowWaitlist &&
- !$this->_requireApproval
- ) {
- $this->set('contributeMode', 'express');
- // Send Event Name & Id in Params
- $params['eventName'] = $this->_values['event']['title'];
- $params['eventId'] = $this->_values['event']['id'];
-
- $params['cancelURL'] = CRM_Utils_System::url('civicrm/event/register',
- "_qf_Register_display=1&qfKey={$this->controller->_key}",
- TRUE, NULL, FALSE
- );
- if (CRM_Utils_Array::value('additional_participants', $params, FALSE)) {
- $urlArgs = "_qf_Participant_1_display=1&rfp=1&qfKey={$this->controller->_key}";
- }
- else {
- $urlArgs = "_qf_Confirm_display=1&rfp=1&qfKey={$this->controller->_key}";
- }
- $params['returnURL'] = CRM_Utils_System::url('civicrm/event/register',
- $urlArgs,
- TRUE, NULL, FALSE
- );
- $params['invoiceID'] = $invoiceID;
+ $this->handlePreApproval($params);
- $params['component'] = 'event';
- $token = $payment->doPreApproval($params);
- if (is_a($token, 'CRM_Core_Error')) {
- CRM_Core_Error::displaySessionError($token);
- CRM_Utils_System::redirect($params['cancelURL']);
- }
+ $this->set('contributeMode', 'express');
- $this->set('token', $token);
+ // Send Event Name & Id in Params
+ $params['eventName'] = $this->_values['event']['title'];
+ $params['eventId'] = $this->_values['event']['id'];
- $paymentURL = $this->_paymentProcessor['url_site'] . "/cgi-bin/webscr?cmd=_express-checkout&token=$token";
+ $params['cancelURL'] = CRM_Utils_System::url('civicrm/event/register',
+ "_qf_Register_display=1&qfKey={$this->controller->_key}",
+ TRUE, NULL, FALSE
+ );
+ if (CRM_Utils_Array::value('additional_participants', $params, FALSE)) {
+ $urlArgs = "_qf_Participant_1_display=1&rfp=1&qfKey={$this->controller->_key}";
+ }
+ else {
+ $urlArgs = "_qf_Confirm_display=1&rfp=1&qfKey={$this->controller->_key}";
+ }
+ $params['returnURL'] = CRM_Utils_System::url('civicrm/event/register',
+ $urlArgs,
+ TRUE, NULL, FALSE
+ );
+ $params['invoiceID'] = $invoiceID;
- CRM_Utils_System::redirect($paymentURL);
+ $params['component'] = 'event';
+ $token = $payment->doPreApproval($params);
+ if (is_a($token, 'CRM_Core_Error')) {
+ CRM_Core_Error::displaySessionError($token);
+ CRM_Utils_System::redirect($params['cancelURL']);
}
+
+ $this->set('token', $token);
+
+ $paymentURL = $this->_paymentProcessor['url_site'] . "/cgi-bin/webscr?cmd=_express-checkout&token=$token";
+ CRM_Utils_System::redirect($paymentURL);
}
elseif ($this->_paymentProcessor &&
$this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_NOTIFY
) {
$this->set('contributeMode', 'notify');
}
- }
- else {
- $session = CRM_Core_Session::singleton();
- $params['description'] = ts('Online Event Registration') . ' ' . $this->_values['event']['title'];
+ else {
+ $params['description'] = ts('Online Event Registration') . ' ' . $this->_values['event']['title'];
- $this->_params = array();
- $this->_params[] = $params;
- $this->set('params', $this->_params);
+ $this->_params = array();
+ $this->_params[] = $params;
+ $this->set('params', $this->_params);
- if (
- empty($params['additional_participants'])
- && !$this->_values['event']['is_confirm_enabled'] // CRM-11182 - Optional confirmation screen
- ) {
- self::processRegistration($this->_params);
+ if (
+ empty($params['additional_participants'])
+ && !$this->_values['event']['is_confirm_enabled'] // CRM-11182 - Optional confirmation screen
+ ) {
+ self::processRegistration($this->_params);
+ }
}
}
* @param array $params
* Form values.
* @param int $contactID
- *
- * @return void
*/
public function processRegistration($params, $contactID = NULL) {
$session = CRM_Core_Session::singleton();
$primaryContactId, $isTest, TRUE
);
- //lets carry all paticipant params w/ values.
+ //lets carry all participant params w/ values.
foreach ($additionalIDs as $participantID => $contactId) {
$participantNum = NULL;
if ($participantID == $registerByID) {
*
* @param array $fields
* The input form values(anonymous user).
- * @param array $self
+ * @param CRM_Event_Form_Registration_Register $self
* Event data.
* @param bool $isAdditional
* Treat isAdditional participants a bit differently.