Skip to content
Snippets Groups Projects
Commit 224f9b75 authored by mattwire's avatar mattwire Committed by mattwire
Browse files

Support multiple participant registration

parent 5bc088b0
Branches
Tags
2 merge requests!826.3.1,!81153 invalidint
......@@ -408,7 +408,8 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
*/
public function doPayment(&$params, $component = 'contribute') {
$params = $this->beginDoPayment($params);
if (CRM_Utils_Array::value('is_recur', $params) && $this->getRecurringContributionId($params)) {
if ((CRM_Utils_Array::value('is_recur', $params) && $this->getRecurringContributionId($params))
|| $this->isPaymentForEventAdditionalParticipants()) {
$params = $this->getTokenParameter('paymentMethodID', $params, TRUE);
}
else {
......@@ -494,6 +495,8 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
// Handle recurring payments in doRecurPayment().
if (CRM_Utils_Array::value('is_recur', $params) && $this->getRecurringContributionId($params)) {
// We're processing a recurring payment - for recurring payments we first saved a paymentMethod via the browser js.
// Now we use that paymentMethod to setup a stripe subscription and take the first payment.
// This is where we save the customer card
// @todo For a recurring payment we have to save the card. For a single payment we'd like to develop the
// save card functionality but should not save by default as the customer has not agreed.
......@@ -505,8 +508,27 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
$params['payment_status_id'] = $pendingStatusId;
return $this->doRecurPayment($params, $amount, $stripeCustomer, $paymentMethod);
}
elseif ($this->isPaymentForEventAdditionalParticipants()) {
// We're processing an event registration for multiple participants - because we did not know
// the amount until now we process via a saved paymentMethod.
$paymentMethod = \Stripe\PaymentMethod::retrieve($params['paymentMethodID']);
$paymentMethod->attach(['customer' => $stripeCustomer->id]);
$stripeCustomer = \Stripe\Customer::retrieve($stripeCustomer->id);
$intent = \Stripe\PaymentIntent::create([
'payment_method' => $params['paymentMethodID'],
'customer' => $stripeCustomer->id,
'amount' => $amount,
'currency' => $this->getCurrency($params),
'confirmation_method' => 'automatic',
'capture_method' => 'manual',
// authorize the amount but don't take from card yet
'setup_future_usage' => 'off_session',
// Setup the card to be saved and used later
'confirm' => true,
]);
$params['paymentIntentID'] = $intent->id;
}
$contactContribution = $this->getContactId($params) . '-' . ($this->getContributionId($params) ?: 'XX');
$intentParams = [
'customer' => $stripeCustomer->id,
'description' => $this->getDescription($params, 'description'),
......@@ -538,6 +560,13 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
return $this->endDoPayment($params, $newParams);
}
/**
* @return bool
*/
private function isPaymentForEventAdditionalParticipants() {
return !empty($this->getParam('additional_participants'));
}
/**
* Submit a recurring payment using Stripe's PHP API:
* https://stripe.com/docs/api?lang=php
......
......@@ -84,7 +84,7 @@ CRM.$(function($) {
displayError(result);
}
else {
if (getIsRecur() === true) {
if (getIsRecur() || isEventAdditionalParticipants()) {
// Submit the form, if we need to do 3dsecure etc. we do it at the end (thankyou page) once subscription etc has been created
successHandler('paymentMethodID', result.paymentMethod);
}
......@@ -473,9 +473,8 @@ CRM.$(function($) {
function getTotalAmount() {
var totalFee = 0.0;
if ((document.getElementById('additional_participants') !== null) &&
(document.getElementById('additional_participants').value.length !== 0)) {
debugging('We don\'t know the final price - registering additional participants');
if (isEventAdditionalParticipants()) {
totalFee = null;
}
else if (document.getElementById('totalTaxAmount') !== null) {
totalFee = parseFloat(calculateTaxAmount());
......@@ -497,7 +496,7 @@ CRM.$(function($) {
// The input#total_amount field exists on backend contribution forms
totalFee = parseFloat(document.getElementById('total_amount').value);
}
debugging('getTotalAmount: ' + totalFee.toFixed(2));
debugging('getTotalAmount: ' + totalFee);
return totalFee;
}
......@@ -581,6 +580,15 @@ CRM.$(function($) {
}
}
function isEventAdditionalParticipants() {
if ((document.getElementById('additional_participants') !== null) &&
(document.getElementById('additional_participants').value.length !== 0)) {
debugging('We don\'t know the final price - registering additional participants');
return true;
}
return false;
}
function debugging(errorCode) {
// Uncomment the following to debug unexpected returns.
if ((typeof(CRM.vars.stripe) === 'undefined') || (Boolean(CRM.vars.stripe.jsDebug) === true)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment