Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stripe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Extensions
Stripe
Commits
224f9b75
Commit
224f9b75
authored
5 years ago
by
mattwire
Committed by
mattwire
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Support multiple participant registration
parent
5bc088b0
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!82
6.3.1
,
!81
153 invalidint
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Core/Payment/Stripe.php
+31
-2
31 additions, 2 deletions
CRM/Core/Payment/Stripe.php
js/civicrm_stripe.js
+13
-5
13 additions, 5 deletions
js/civicrm_stripe.js
with
44 additions
and
7 deletions
CRM/Core/Payment/Stripe.php
+
31
−
2
View file @
224f9b75
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
js/civicrm_stripe.js
+
13
−
5
View file @
224f9b75
...
...
@@ -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
))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment