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
09f8d997
Commit
09f8d997
authored
2 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Move charge.failed to new webhook events processor
parent
16935172
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!217
Implement Stripe Checkout (with support for SEPA and ACH)
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Core/Payment/StripeIPN.php
+4
-26
4 additions, 26 deletions
CRM/Core/Payment/StripeIPN.php
Civi/Stripe/Webhook/Events.php
+61
-4
61 additions, 4 deletions
Civi/Stripe/Webhook/Events.php
with
65 additions
and
30 deletions
CRM/Core/Payment/StripeIPN.php
+
4
−
26
View file @
09f8d997
...
...
@@ -411,6 +411,10 @@ class CRM_Core_Payment_StripeIPN {
$return
=
$webhookEventProcessor
->
doChargeRefunded
();
break
;
case
'charge.failed'
:
$return
=
$webhookEventProcessor
->
doChargeFailed
();
break
;
case
'invoice.payment_failed'
:
$return
=
$webhookEventProcessor
->
doInvoicePaymentFailed
();
break
;
...
...
@@ -466,34 +470,8 @@ class CRM_Core_Payment_StripeIPN {
* @throws \Stripe\Exception\ApiErrorException
*/
private
function
processEventType
()
{
$pendingContributionStatusID
=
(
int
)
CRM_Core_PseudoConstant
::
getKey
(
'CRM_Contribute_BAO_Contribution'
,
'contribution_status_id'
,
'Pending'
);
$failedContributionStatusID
=
(
int
)
CRM_Core_PseudoConstant
::
getKey
(
'CRM_Contribute_BAO_Contribution'
,
'contribution_status_id'
,
'Failed'
);
$statusesAllowedToComplete
=
[
$pendingContributionStatusID
,
$failedContributionStatusID
];
// NOTE: If you add an event here make sure you add it to the webhook or it will never be received!
switch
(
$this
->
eventType
)
{
// One-time donation and per invoice payment.
case
'charge.failed'
:
// If we don't have a customer_id we can't do anything with it!
// It's quite likely to be a fraudulent/spam so we ignore.
if
(
empty
(
CRM_Stripe_Api
::
getObjectParam
(
'customer_id'
,
$this
->
getData
()
->
object
)))
{
return
TRUE
;
}
if
(
!
$this
->
setInfo
())
{
// We could not find this contribution.
return
TRUE
;
}
$params
=
[
'contribution_id'
=>
$this
->
contribution
[
'id'
],
'order_reference'
=>
$this
->
invoice_id
??
$this
->
charge_id
,
'cancel_date'
=>
$this
->
receive_date
,
'cancel_reason'
=>
$this
->
retrieve
(
'failure_message'
,
'String'
),
];
$this
->
updateContributionFailed
(
$params
);
return
TRUE
;
case
'customer.subscription.updated'
:
// Subscription is updated. This used to be "implemented" but didn't work
return
TRUE
;
...
...
This diff is collapsed.
Click to expand it.
Civi/Stripe/Webhook/Events.php
+
61
−
4
View file @
09f8d997
...
...
@@ -271,6 +271,7 @@ class Events {
}
/**
* Webhook event: charge.succeeded / charge.captured
* We process charge.succeeded per charge.captured
*
* @return \stdClass
...
...
@@ -350,6 +351,7 @@ class Events {
}
/**
* Webhook event: charge.refunded
* Process the charge.refunded event from Stripe
*
* @return \stdClass
...
...
@@ -435,18 +437,73 @@ class Events {
'total_amount'
=>
$refundParams
[
'total_amount'
],
]);
if
(
!
empty
(
$refundPayment
[
'count'
]))
{
$return
->
message
=
'OK - r
efund already recorded. Contribution ID: '
.
$contribution
[
'id'
];
$return
->
message
=
__FUNCTION__
.
' R
efund already recorded. Contribution ID: '
.
$contribution
[
'id'
];
$return
->
ok
=
TRUE
;
}
else
{
$this
->
updateContributionRefund
(
$refundParams
);
$return
->
message
=
'OK - r
efund recorded. Contribution ID: '
.
$contribution
[
'id'
];
$return
->
message
=
__FUNCTION__
.
'R
efund recorded. Contribution ID: '
.
$contribution
[
'id'
];
$return
->
ok
=
TRUE
;
}
$lock
->
release
();
return
$return
;
}
/**
* Webhook event: charge.failed
* One-time donation and per invoice payment
*
* @return \stdClass
* @throws \CiviCRM_API3_Exception
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public
function
doChargeFailed
():
\stdClass
{
$return
=
$this
->
getResultObject
();
// Check we have the right data object for this event
if
((
$this
->
getData
()
->
object
[
'object'
]
??
''
)
!==
'charge'
)
{
$return
->
message
=
__FUNCTION__
.
' Invalid object type'
;
return
$return
;
}
// If we don't have a customer_id we can't do anything with it!
// It's quite likely to be a fraudulent/spam so we ignore.
if
(
empty
(
$this
->
getValueFromStripeObject
(
'customer_id'
,
'String'
)))
{
$return
->
message
=
__FUNCTION__
.
' ignoring - no customer_id'
;
$return
->
ok
=
TRUE
;
return
$return
;
}
// Charge ID is required
$chargeID
=
$this
->
getValueFromStripeObject
(
'charge_id'
,
'String'
);
if
(
!
$chargeID
)
{
$return
->
message
=
__FUNCTION__
.
' Missing charge_id'
;
return
$return
;
}
// Invoice ID is optional
$invoiceID
=
$this
->
getValueFromStripeObject
(
'invoice_id'
,
'String'
);
$contribution
=
$this
->
findContribution
(
$chargeID
,
$invoiceID
);
if
(
empty
(
$contribution
))
{
$return
->
message
=
__FUNCTION__
.
' Contribution not found'
;
return
$return
;
}
$failedContributionParams
=
[
'contribution_id'
=>
$contribution
[
'id'
],
'order_reference'
=>
$invoiceID
??
$chargeID
,
'cancel_date'
=>
$this
->
getValueFromStripeObject
(
'receive_date'
,
'String'
),
'cancel_reason'
=>
$this
->
getValueFromStripeObject
(
'failure_message'
,
'String'
),
];
$this
->
updateContributionFailed
(
$failedContributionParams
);
$return
->
message
=
__FUNCTION__
.
' contributionID: '
.
$contribution
[
'id'
];
$return
->
ok
=
TRUE
;
return
$return
;
}
/**
* Webhook event: checkout.session.completed
*
...
...
@@ -513,7 +570,7 @@ class Events {
}
/**
* Webhook event: invoice.paid
* Webhook event: invoice.paid
/ invoice.payment_succeeded
* Invoice changed to paid. This is nearly identical to invoice.payment_succeeded
*
* The invoice.payment_successful type Event object is created and sent to any webhook endpoints configured
...
...
@@ -632,7 +689,7 @@ class Events {
}
/**
* invoice.finalized
*
Webhook event:
invoice.finalized
*
* @return \stdClass
* @throws \CRM_Core_Exception
...
...
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