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
95d2e8b6
Commit
95d2e8b6
authored
3 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Fix StripePaymentintent.Process params
parent
2dd1c814
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/v3/StripePaymentintent.php
+24
-16
24 additions, 16 deletions
api/v3/StripePaymentintent.php
js/civicrmStripeConfirm.js
+1
-1
1 addition, 1 deletion
js/civicrmStripeConfirm.js
js/civicrm_stripe.js
+2
-2
2 additions, 2 deletions
js/civicrm_stripe.js
with
27 additions
and
19 deletions
api/v3/StripePaymentintent.php
+
24
−
16
View file @
95d2e8b6
...
...
@@ -99,13 +99,13 @@ function civicrm_api3_stripe_paymentintent_get($params) {
* @return void
*/
function
_civicrm_api3_stripe_paymentintent_process_spec
(
&
$spec
)
{
$spec
[
'payment_method_id'
][
'title'
]
=
E
::
ts
(
"
Stripe generated code used to create a payment intent.
"
);
$spec
[
'payment_method_id'
][
'title'
]
=
E
::
ts
(
"
Payment Method ID
"
);
$spec
[
'payment_method_id'
][
'type'
]
=
CRM_Utils_Type
::
T_STRING
;
$spec
[
'payment_method_id'
][
'api.default'
]
=
NULL
;
$spec
[
'payment_intent_id'
][
'title'
]
=
E
::
ts
(
"
The p
ayment
i
ntent
id itself, if available
."
);
$spec
[
'payment_intent_id'
][
'title'
]
=
E
::
ts
(
"
P
ayment
I
ntent
ID
."
);
$spec
[
'payment_intent_id'
][
'type'
]
=
CRM_Utils_Type
::
T_STRING
;
$spec
[
'payment_intent_id'
][
'api.default'
]
=
NULL
;
$spec
[
'amount'
][
'title'
]
=
E
::
ts
(
"
The p
ayment amount."
);
$spec
[
'amount'
][
'title'
]
=
E
::
ts
(
"
P
ayment amount."
);
$spec
[
'amount'
][
'type'
]
=
CRM_Utils_Type
::
T_STRING
;
$spec
[
'amount'
][
'api.default'
]
=
NULL
;
$spec
[
'capture'
][
'title'
]
=
E
::
ts
(
"Whether we should try to capture the amount, not just confirm it."
);
...
...
@@ -114,7 +114,7 @@ function _civicrm_api3_stripe_paymentintent_process_spec(&$spec) {
$spec
[
'description'
][
'title'
]
=
E
::
ts
(
"Describe the payment."
);
$spec
[
'description'
][
'type'
]
=
CRM_Utils_Type
::
T_STRING
;
$spec
[
'description'
][
'api.default'
]
=
NULL
;
$spec
[
'currency'
][
'title'
]
=
E
::
ts
(
"
Whether we should try to capture the amount, not just confirm it.
"
);
$spec
[
'currency'
][
'title'
]
=
E
::
ts
(
"
Currency (eg. EUR)
"
);
$spec
[
'currency'
][
'type'
]
=
CRM_Utils_Type
::
T_STRING
;
$spec
[
'currency'
][
'api.default'
]
=
CRM_Core_Config
::
singleton
()
->
defaultCurrency
;
$spec
[
'payment_processor_id'
][
'title'
]
=
E
::
ts
(
"The stripe payment processor id."
);
...
...
@@ -174,12 +174,20 @@ function civicrm_api3_stripe_paymentintent_process($params) {
$title
=
CRM_Utils_Type
::
validate
(
$params
[
'description'
],
'String'
);
$intentParams
[
'confirm'
]
=
TRUE
;
$currency
=
CRM_Utils_Type
::
validate
(
$params
[
'currency'
],
'String'
,
CRM_Core_Config
::
singleton
()
->
defaultCurrency
);
$processorID
=
CRM_Utils_Type
::
validate
((
int
)
$params
[
'id'
],
'Positive'
);
!
empty
(
$processorID
)
?:
_civicrm_api3_stripe_paymentintent_returnInvalid
();
$paymentProcessor
=
civicrm_api3
(
'PaymentProcessor'
,
'getsingle'
,
[
'id'
=>
$processorID
]);
(
$paymentProcessor
[
'class_name'
]
===
'Payment_Stripe'
)
?:
_civicrm_api3_stripe_paymentintent_returnInvalid
();
$processor
=
new
CRM_Core_Payment_Stripe
(
''
,
$paymentProcessor
);
$processor
->
setAPIParams
();
// Until 6.6.1 we were passing 'id' instead of the correct 'payment_processor_id' from js scripts. This retains
// compatibility with any 3rd-party scripts.
if
(
isset
(
$params
[
'id'
])
&&
!
isset
(
$params
[
'payment_processor_id'
]))
{
$params
[
'payment_processor_id'
]
=
$params
[
'id'
];
}
$paymentProcessorID
=
CRM_Utils_Type
::
validate
((
int
)
$params
[
'payment_processor_id'
],
'Positive'
);
!
empty
(
$paymentProcessorID
)
?:
_civicrm_api3_stripe_paymentintent_returnInvalid
();
/** @var CRM_Core_Payment_Stripe $paymentProcessor */
$paymentProcessor
=
\Civi\Payment\System
::
singleton
()
->
getById
(
$paymentProcessorID
);
(
$paymentProcessor
->
getPaymentProcessor
()[
'class_name'
]
===
'Payment_Stripe'
)
?:
_civicrm_api3_stripe_paymentintent_returnInvalid
();
$paymentProcessor
->
setAPIParams
();
$intentParams
[
'confirmation_method'
]
=
'manual'
;
if
(
empty
(
$paymentIntentID
)
&&
empty
(
$paymentMethodID
))
{
...
...
@@ -201,7 +209,7 @@ function civicrm_api3_stripe_paymentintent_process($params) {
// We don't yet have a PaymentIntent, create one using the
// Payment Method ID and attempt to confirm it too.
try
{
$intentParams
[
'amount'
]
=
$processor
->
getAmount
([
'amount'
=>
$amount
,
'currency'
=>
$currency
]);
$intentParams
[
'amount'
]
=
$p
aymentP
rocessor
->
getAmount
([
'amount'
=>
$amount
,
'currency'
=>
$currency
]);
$intentParams
[
'currency'
]
=
$currency
;
// authorize the amount but don't take from card yet
$intentParams
[
'capture_method'
]
=
'manual'
;
...
...
@@ -210,13 +218,13 @@ function civicrm_api3_stripe_paymentintent_process($params) {
if
(
$paymentMethodID
)
{
$intentParams
[
'payment_method'
]
=
$paymentMethodID
;
}
$intent
=
$processor
->
stripeClient
->
paymentIntents
->
create
(
$intentParams
);
}
catch
(
Exception
$e
)
{
$intent
=
$paymentProcessor
->
stripeClient
->
paymentIntents
->
create
(
$intentParams
);
}
catch
(
Exception
$e
)
{
// Save the "error" in the paymentIntent table in in case investigation is required.
$stripePaymentintentParams
=
[
'stripe_intent_id'
=>
'null'
,
'payment_processor_id'
=>
$processorID
,
'payment_processor_id'
=>
$p
aymentP
rocessorID
,
'status'
=>
'failed'
,
'description'
=>
"
{
$e
->
getRequestId
()
}
;
{
$e
->
getMessage
()
}
;
{
$title
}
"
,
'referrer'
=>
$_SERVER
[
'HTTP_REFERER'
],
...
...
@@ -240,7 +248,7 @@ function civicrm_api3_stripe_paymentintent_process($params) {
// Save the generated paymentIntent in the CiviCRM database for later tracking
$stripePaymentintentParams
=
[
'stripe_intent_id'
=>
$intent
->
id
,
'payment_processor_id'
=>
$processorID
,
'payment_processor_id'
=>
$p
aymentP
rocessorID
,
'status'
=>
$intent
->
status
,
'description'
=>
"
{
$title
}
"
,
'referrer'
=>
$_SERVER
[
'HTTP_REFERER'
],
...
...
This diff is collapsed.
Click to expand it.
js/civicrmStripeConfirm.js
+
1
−
1
View file @
95d2e8b6
...
...
@@ -108,7 +108,7 @@
CRM
.
api3
(
'
StripePaymentintent
'
,
'
Process
'
,
{
payment_intent_id
:
CRM
.
vars
.
stripe
.
paymentIntentID
,
capture
:
true
,
id
:
CRM
.
vars
.
stripe
.
id
,
payment_processor_
id
:
CRM
.
vars
.
stripe
.
id
,
description
:
document
.
title
,
csrfToken
:
CRM
.
vars
.
stripe
.
csrfToken
})
...
...
This diff is collapsed.
Click to expand it.
js/civicrm_stripe.js
+
2
−
2
View file @
95d2e8b6
...
...
@@ -237,7 +237,7 @@
payment_method_id
:
createPaymentMethodResult
.
paymentMethod
.
id
,
amount
:
CRM
.
payment
.
getTotalAmount
().
toFixed
(
2
),
currency
:
CRM
.
payment
.
getCurrency
(
CRM
.
vars
.
stripe
.
currency
),
id
:
CRM
.
vars
.
stripe
.
id
,
payment_processor_
id
:
CRM
.
vars
.
stripe
.
id
,
description
:
document
.
title
,
csrfToken
:
CRM
.
vars
.
stripe
.
csrfToken
,
extra_data
:
CRM
.
payment
.
getBillingEmail
()
+
CRM
.
payment
.
getBillingName
()
...
...
@@ -301,7 +301,7 @@
CRM
.
api3
(
'
StripePaymentintent
'
,
'
Process
'
,
{
amount
:
CRM
.
payment
.
getTotalAmount
().
toFixed
(
2
),
currency
:
CRM
.
payment
.
getCurrency
(
CRM
.
vars
.
stripe
.
currency
),
id
:
CRM
.
vars
.
stripe
.
id
,
payment_processor_
id
:
CRM
.
vars
.
stripe
.
id
,
description
:
document
.
title
,
csrfToken
:
CRM
.
vars
.
stripe
.
csrfToken
})
...
...
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