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
0421cfd7
Commit
0421cfd7
authored
2 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Improve handling of already canceled payment intents
parent
5f2c46f5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/v3/Job/ProcessStripe.php
+14
-4
14 additions, 4 deletions
api/v3/Job/ProcessStripe.php
with
14 additions
and
4 deletions
api/v3/Job/ProcessStripe.php
+
14
−
4
View file @
0421cfd7
...
...
@@ -43,8 +43,11 @@ function civicrm_api3_job_process_stripe($params) {
$incompletePaymentintents
=
StripePaymentintent
::
get
(
FALSE
)
->
addWhere
(
'status'
,
'NOT IN'
,
[
'succeeded'
,
'cancelled'
,
'canceled'
,
'failed'
])
->
addWhere
(
'created_date'
,
'<'
,
$params
[
'cancel_incomplete'
])
->
addWhere
(
'stripe_intent_id'
,
'IS NOT EMPTY'
)
->
execute
();
->
addWhere
(
'stripe_intent_id'
,
'IS NOT EMPTY'
);
if
(
!
empty
(
$params
[
'stripe_paymentintent_id'
]))
{
$incompletePaymentintents
->
addWhere
(
'id'
,
'='
,
$params
[
'stripe_paymentintent_id'
]);
}
$incompletePaymentintents
=
$incompletePaymentintents
->
execute
();
$cancelledIDs
=
[];
foreach
(
$incompletePaymentintents
as
$incompletePaymentintent
)
{
...
...
@@ -52,7 +55,10 @@ function civicrm_api3_job_process_stripe($params) {
/** @var \CRM_Core_Payment_Stripe $paymentProcessor */
$paymentProcessor
=
Civi\Payment\System
::
singleton
()
->
getById
(
$incompletePaymentintent
[
'payment_processor_id'
]);
$intent
=
$paymentProcessor
->
stripeClient
->
paymentIntents
->
retrieve
(
$incompletePaymentintent
[
'stripe_intent_id'
]);
$intent
->
cancel
([
'cancellation_reason'
=>
'abandoned'
]);
// Check intent was not already cancelled - this could happen eg. at Stripe before we process it
if
(
$intent
->
status
!==
'canceled'
)
{
$intent
->
cancel
([
'cancellation_reason'
=>
'abandoned'
]);
}
$cancelledIDs
[]
=
$incompletePaymentintent
[
'id'
];
}
catch
(
Exception
$e
)
{
if
(
$e
instanceof
\Stripe\Exception\InvalidRequestException
)
{
...
...
@@ -62,7 +68,7 @@ function civicrm_api3_job_process_stripe($params) {
$cancelledIDs
[]
=
$incompletePaymentintent
[
'id'
];
}
}
\Civi
::
log
()
->
error
(
'
Stripe.process_stripe: Unable to cancel paymentIntent
. '
.
$e
->
getMessage
());
\Civi
::
log
()
->
error
(
"
Stripe.process_stripe: Unable to cancel paymentIntent
ID:
{
$incompletePaymentintent
[
'id'
]
}
: "
.
$e
->
getMessage
());
}
}
if
(
!
empty
(
$cancelledIDs
))
{
...
...
@@ -89,4 +95,8 @@ function _civicrm_api3_job_process_stripe_spec(&$params) {
$params
[
'cancel_incomplete'
][
'api.default'
]
=
'-1 hour'
;
$params
[
'cancel_incomplete'
][
'title'
]
=
'Cancel incomplete records after (default: -1hour)'
;
$params
[
'cancel_incomplete'
][
'description'
]
=
'Cancel incomplete paymentIntents in your stripe account. Specify 0 to disable. Default is "-1hour"'
;
$params
[
'stripe_paymentintent_id'
][
'title'
]
=
'ID of record from civicrm_stripe_paymentintent table'
;
$params
[
'stripe_paymentintent_id'
][
'description'
]
=
'If specified, only this record will be processed'
;
$params
[
'stripe_paymentintent_id'
][
'type'
]
=
CRM_Utils_Type
::
T_INT
;
}
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