$this->_params,
$config->defaultCurrency
);
- $this->_params['payment_action'] = 'Sale';
+
if (!empty($this->_params['trxn_date'])) {
$this->_params['receive_date'] = CRM_Utils_Date::processDate($this->_params['trxn_date'], $this->_params['trxn_date_time']);
}
$this->_params,
CRM_Core_Config::singleton()->defaultCurrency
);
- $this->_params['payment_action'] = 'Sale';
+
if (!empty($this->_params['receive_date'])) {
$this->_params['receive_date'] = CRM_Utils_Date::processDate($this->_params['receive_date'], $this->_params['receive_date_time']);
}
// we use this here to incorporate any changes made by folks in hooks
$this->_params['currencyID'] = $config->defaultCurrency;
- $this->_params['payment_action'] = 'Sale';
-
// also merge all the other values from the profile fields
$values = $this->controller->exportValues('Main');
$skipFields = array(
$this->setFormAmountFields($this->_params['priceSetId']);
}
$this->_params['currencyID'] = $config->defaultCurrency;
- $this->_params['payment_action'] = 'Sale';
}
$this->_params['is_pay_later'] = $this->get('is_pay_later');
}
}
- // // hack to simplify credit card entry for testing
- // $this->_defaults['credit_card_type'] = 'Visa';
- // $this->_defaults['amount'] = 168;
- // $this->_defaults['credit_card_number'] = '4111111111111111';
- // $this->_defaults['cvv2'] = '000';
- // $this->_defaults['credit_card_exp_date'] = array('Y' => date('Y')+1, 'M' => '05');
-
- // // hack to simplify direct debit entry for testing
- // $this->_defaults['account_holder'] = 'Max Müller';
- // $this->_defaults['bank_account_number'] = '12345678';
- // $this->_defaults['bank_identification_number'] = '12030000';
- // $this->_defaults['bank_name'] = 'Bankname';
+ /*
+ * hack to simplify credit card entry for testing
+ *
+ * $this->_defaults['credit_card_type'] = 'Visa';
+ * $this->_defaults['amount'] = 168;
+ * $this->_defaults['credit_card_number'] = '4111111111111111';
+ * $this->_defaults['cvv2'] = '000';
+ * $this->_defaults['credit_card_exp_date'] = array('Y' => date('Y')+1, 'M' => '05');
+ * // hack to simplify direct debit entry for testing
+ * $this->_defaults['account_holder'] = 'Max Müller';
+ * $this->_defaults['bank_account_number'] = '12345678';
+ * $this->_defaults['bank_identification_number'] = '12030000';
+ * $this->_defaults['bank_name'] = 'Bankname';
+ */
//build set default for pledge overdue payment.
if (!empty($this->_values['pledge_id'])) {
*/
public static function formRule($fields, $files, $self) {
$errors = array();
- $amount = self::computeAmount($fields, $self);
+ $amount = self::computeAmount($fields, $self->_values);
if ((!empty($fields['selectMembership']) &&
$fields['selectMembership'] != 'no_thanks'
}
/**
+ * Compute amount to be paid.
+ *
* @param array $params
- * @param CRM_Core_Form $form
+ * @param array $formValues
*
* @return int|mixed|null|string
*/
- public static function computeAmount(&$params, &$form) {
- $amount = NULL;
+ public static function computeAmount($params, $formValues) {
- // first clean up the other amount field if present
+ // First clean up the other amount field if present.
if (isset($params['amount_other'])) {
$params['amount_other'] = CRM_Utils_Rule::cleanMoney($params['amount_other']);
}
}
}
else {
- if (!empty($form->_values['amount'])) {
+ if (!empty($formValues['amount'])) {
$amountID = CRM_Utils_Array::value('amount', $params);
if ($amountID) {
- $params['amount_level'] = CRM_Utils_Array::value('label', $form->_values[$amountID]);
- $amount = CRM_Utils_Array::value('value', $form->_values[$amountID]);
+ $params['amount_level'] = CRM_Utils_Array::value('label', $formValues[$amountID]);
+ $amount = CRM_Utils_Array::value('value', $formValues[$amountID]);
}
}
}
}
// from here on down, $params['amount'] holds a monetary value (or null) rather than an option ID
- $params['amount'] = self::computeAmount($params, $this);
+ $params['amount'] = self::computeAmount($params, $this->_values);
$params['separate_amount'] = $params['amount'];
$memFee = NULL;
if (!empty($params['selectMembership'])) {
if ($is_quick_config) {
foreach ($this->_values['fee'] as $key => & $val) {
if ($val['name'] == 'other_amount' && $val['html_type'] == 'Text' && !empty($params['price_' . $key])) {
- $params['price_' . $key] = CRM_Utils_Rule::cleanMoney($params['price_' . $key]); //Clean out any currency symbols
+ // Clean out any currency symbols.
+ $params['price_' . $key] = CRM_Utils_Rule::cleanMoney($params['price_' . $key]);
if ($params['price_' . $key] != 0) {
foreach ($val['options'] as $optionKey => & $options) {
$options['amount'] = CRM_Utils_Array::value('price_' . $key, $params);
$proceFieldAmount += $lineItem[$params['priceSetId']][$fieldOption]['tax_amount'];
}
if (!$this->_membershipBlock['is_separate_payment']) {
- $params['amount'] = $proceFieldAmount; //require when separate membership not used
+ //require when separate membership not used
+ $params['amount'] = $proceFieldAmount;
}
}
$this->set('lineItem', $lineItem);
array($this->_expressButtonName, $this->_expressButtonName . '_x', $this->_expressButtonName . '_y')
) && empty($params['is_pay_later'])
) {
- $this->set('contributeMode', 'express');
-
- $donateURL = CRM_Utils_System::url('civicrm/contribute', '_qf_Contribute_display=1');
- $params['cancelURL'] = CRM_Utils_System::url('civicrm/contribute/transact', "_qf_Main_display=1&qfKey={$params['qfKey']}", TRUE, NULL, FALSE);
- $params['returnURL'] = CRM_Utils_System::url('civicrm/contribute/transact', "_qf_Confirm_display=1&rfp=1&qfKey={$params['qfKey']}", TRUE, NULL, FALSE);
- $params['invoiceID'] = $invoiceID;
- $params['description'] = ts('Online Contribution') . ': ' . (($this->_pcpInfo['title']) ? $this->_pcpInfo['title'] : $this->_values['title']);
-
- //default action is Sale
- $params['payment_action'] = 'Sale';
-
- $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
- $token = $payment->setExpressCheckout($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);
+ $this->handlePaypalExpress($invoiceID, $params);
}
}
elseif ($this->_paymentProcessor &&
$form->assign('paymentProcessorID', $form->_paymentProcessorID);
}
+ /**
+ * @param $invoiceID
+ * @param $params
+ *
+ * @return mixed
+ */
+ protected function handlePaypalExpress($invoiceID, $params) {
+ $this->set('contributeMode', 'express');
+
+ $params['invoiceID'] = $invoiceID;
+ $params['description'] = ts('Online Contribution') . ': ' . (($this->_pcpInfo['title']) ? $this->_pcpInfo['title'] : $this->_values['title']);
+
+ $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
+ $token = $payment->setExpressCheckout($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);
+ }
+
}
);
}
+ /**
+ * Get base url dependent on component.
+ *
+ * @return string|void
+ */
+ protected function getBaseReturnUrl() {
+ if ($this->_component == 'event') {
+ $baseURL = 'civicrm/event/register';
+ }
+ else {
+ $baseURL = 'civicrm/contribute/transact';
+ }
+ return $baseURL;
+ }
+
+ /**
+ * Get url to return to after cancelled or failed transaction
+ *
+ * @param $qfKey
+ * @param $participantID
+ *
+ * @return string cancel url
+ */
+ protected function getCancelUrl($qfKey, $participantID) {
+ if ($this->_component == 'event') {
+ return CRM_Utils_System::url($this->getBaseReturnUrl(), array(
+ 'reset' => 1,
+ 'cc' => 'fail',
+ 'participantId' => $participantID,
+ ),
+ TRUE, NULL, FALSE
+ );
+ }
+
+ return CRM_Utils_System::url($this->getBaseReturnUrl(), array(
+ '_qf_Main_display' => 1,
+ 'qfKey' => $qfKey,
+ 'cancel' => 1,
+ ),
+ TRUE, NULL, FALSE
+ );
+ }
+
+ /**
+ * Get URL to return the browser to on success
+ *
+ * @param $qfKey
+ *
+ * @return string
+ */
+ protected function getReturnSuccessUrl($qfKey) {
+ return CRM_Utils_System::url($this->getBaseReturnUrl(), array(
+ '_qf_ThankYou_display' => 1,
+ 'qfKey' => $qfKey
+ ),
+ TRUE, NULL, FALSE
+ );
+ }
+
/**
* Calling this from outside the payment subsystem is deprecated - use doPayment.
*
$requestFields['transactionorigin'] = "Eci";
#32 character string
$requestFields['invoice_number'] = $params['invoiceID'];
- $requestFields['ordertype'] = $params['payment_action'];
+ $requestFields['ordertype'] = 'Sale';
$requestFields['comments'] = $params['description'];
//**********************set 'result' for live testing **************************
// $requestFields[ 'result' ] = ""; #set to "Good", "Decline" or "Duplicate"
$form->assign('profileAddressFields', $profileAddressFields);
}
- // $processor->buildForm appears to be an undocumented (possibly unused) option for payment processors
- // which was previously available only in some form flows
- if (!empty($form->_paymentProcessor) && !empty($form->_paymentProcessor['object']) && $form->_paymentProcessor['object']->isSupported('buildForm')) {
- if ($form->_paymentProcessor['object']->buildForm($form)) {
- return NULL;
- }
+ if ($processor['object']->buildForm($form)) {
+ return NULL;
}
self::setPaymentFieldsByProcessor($form, $processor, empty($isBillingDataOptional));
/* unused params: cvv not yet implemented, payment action ingored (should test for 'Sale' value?)
[cvv2] => 000
[ip_address] => 192.168.0.103
- [payment_action] => Sale
[contact_type] => Individual
[geo_coord_id] => 1 */
if ($this->_processorName == 'PayPal Express') {
CRM_Core_Region::instance('billing-block-post')->add(array(
'template' => 'CRM/Financial/Form/PaypalExpress.tpl',
+ 'name' => 'paypal_express',
));
}
if ($this->_processorName == 'PayPal Pro') {
$this->initialize($args, 'SetExpressCheckout');
- $args['paymentAction'] = $params['payment_action'];
+ $args['paymentAction'] = 'Sale';
$args['amt'] = $params['amount'];
$args['currencyCode'] = $params['currencyID'];
$args['desc'] = CRM_Utils_Array::value('description', $params);
$args['invnum'] = $params['invoiceID'];
- $args['returnURL'] = $params['returnURL'];
- $args['cancelURL'] = $params['cancelURL'];
+ $args['returnURL'] = $this->getReturnSuccessUrl($params['qfKey']);
+ $args['cancelURL'] = $this->getCancelUrl($params['qfKey'], NULL);
$args['version'] = '56.0';
//LCD if recurring, collect additional data and set some values
$args = array();
$this->initialize($args, 'DoExpressCheckoutPayment');
-
$args['token'] = $params['token'];
- $args['paymentAction'] = $params['payment_action'];
+ $args['paymentAction'] = 'Sale';
$args['amt'] = $params['amount'];
$args['currencyCode'] = $params['currencyID'];
$args['payerID'] = $params['payer_id'];
$args['invnum'] = $params['invoiceID'];
- $args['returnURL'] = CRM_Utils_Array::value('returnURL', $params);
- $args['cancelURL'] = CRM_Utils_Array::value('cancelURL', $params);
+ $args['returnURL'] = $this->getReturnSuccessUrl($params['qfKey']);
+ $args['cancelURL'] = $this->getCancelUrl($params['qfKey'], NULL);
$args['desc'] = $params['description'];
// add CiviCRM BN code
$start_date = date('Y-m-d\T00:00:00\Z', $start_time);
$args['token'] = $params['token'];
- $args['paymentAction'] = $params['payment_action'];
+ $args['paymentAction'] = 'Sale';
$args['amt'] = $params['amount'];
$args['currencyCode'] = $params['currencyID'];
$args['payerID'] = $params['payer_id'];
$this->initialize($args, 'DoDirectPayment');
- $args['paymentAction'] = $params['payment_action'];
+ $args['paymentAction'] = 'Sale';
$args['amt'] = $params['amount'];
$args['currencyCode'] = $params['currencyID'];
$args['invnum'] = $params['invoiceID'];
if (!isset($snippet['name'])) {
$snippet['name'] = count($this->_snippets);
}
+
$this->_snippets[$snippet['name']] = $snippet;
$this->_isSorted = FALSE;
return $snippet;
}
/**
+ * Get snippet.
+ *
* @param string $name
*
* @return mixed
*/
- public function &get($name) {
- return @$this->_snippets[$name];
+ public function get($name) {
+ return !empty($this->_snippets[$name]) ? $this->_snippets[$name] : NULL;
}
/**
}
$params['ip_address'] = CRM_Utils_System::ipAddress();
$params['currencyID'] = $config->defaultCurrency;
- $params['payment_action'] = 'Sale';
$payment = &CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
CRM_Core_Payment_Form::mapParams($this->_bltID, $params, $params, TRUE);
$this->_params['amount'] = $params['fee_amount'];
$this->_params['amount_level'] = $params['amount_level'];
$this->_params['currencyID'] = $config->defaultCurrency;
- $this->_params['payment_action'] = 'Sale';
$this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
// at this point we've created a contact and stored its address etc
}
$params['amount_level'] = $this->_params[0]['amount_level'];
$params['currencyID'] = $this->_params[0]['currencyID'];
- $params['payment_action'] = 'Sale';
// also merge all the other values from the profile fields
$values = $this->controller->exportValues('Register');
if ($this->_values['event']['is_monetary']) {
$registerParams['ip_address'] = CRM_Utils_System::ipAddress();
$registerParams['currencyID'] = $this->_params[0]['currencyID'];
- $registerParams['payment_action'] = 'Sale';
}
//assign back primary participant params.
$this->_params[0] = $registerParams;
if ($this->_values['event']['is_monetary']) {
$params['ip_address'] = CRM_Utils_System::ipAddress();
$params['currencyID'] = $config->defaultCurrency;
- $params['payment_action'] = 'Sale';
$params['invoiceID'] = $invoiceID;
}
$this->_params = $this->get('params');
);
$params['invoiceID'] = $invoiceID;
- //default action is Sale
- $params['payment_action'] = 'Sale';
-
$token = $payment->setExpressCheckout($params);
if (is_a($token, 'CRM_Core_Error')) {
CRM_Core_Error::displaySessionError($token);
$this->_params['amount'] = $params['total_amount'];
$this->_params['currencyID'] = $config->defaultCurrency;
$this->_params['description'] = ts('Office Credit Card Membership Signup Contribution');
- $this->_params['payment_action'] = 'Sale';
$this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
$this->_params['financial_type_id'] = $params['financial_type_id'];
$this->_params['ip_address'] = CRM_Utils_System::ipAddress();
$this->_params['amount'] = $formValues['total_amount'];
$this->_params['currencyID'] = $config->defaultCurrency;
- $this->_params['payment_action'] = 'Sale';
$this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
// at this point we've created a contact and stored its address etc