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
04e3198b
Commit
04e3198b
authored
6 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Don't update existing contribution that is completed
parent
2efff690
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!11
Support Cancellation and major refactor of backend / webhook processing
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Core/Payment/Stripe.php
+3
-2
3 additions, 2 deletions
CRM/Core/Payment/Stripe.php
CRM/Core/Payment/StripeIPN.php
+20
-24
20 additions, 24 deletions
CRM/Core/Payment/StripeIPN.php
with
23 additions
and
26 deletions
CRM/Core/Payment/Stripe.php
+
3
−
2
View file @
04e3198b
...
...
@@ -869,8 +869,9 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
$data_raw
=
file_get_contents
(
"php://input"
);
$data
=
json_decode
(
$data_raw
);
$ipnClass
=
new
CRM_Core_Payment_StripeIPN
(
$data
);
$ipnClass
->
main
();
http_response_code
(
200
);
if
(
$ipnClass
->
main
())
{
http_response_code
(
200
);
}
}
...
...
This diff is collapsed.
Click to expand it.
CRM/Core/Payment/StripeIPN.php
+
20
−
24
View file @
04e3198b
...
...
@@ -48,9 +48,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
protected
$amount
=
NULL
;
protected
$fee
=
NULL
;
protected
$net_amount
=
NULL
;
protected
$previous_contribution_id
=
NULL
;
protected
$previous_contribution_status_id
=
NULL
;
protected
$previous_contribution_total_amount
=
NULL
;
protected
$previous_contribution
=
[];
/**
* CRM_Core_Payment_StripeIPN constructor.
...
...
@@ -235,10 +233,10 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
// Successful recurring payment.
case
'invoice.payment_succeeded'
:
$this
->
setInfo
();
if
(
$this
->
previous_contribution_status_id
==
$pendingStatusId
)
{
if
(
$this
->
previous_contribution
[
'contribution
_status_id
'
]
==
$pendingStatusId
)
{
$this
->
completeContribution
();
}
else
{
else
if
(
$this
->
previous_contribution
[
'trxn_id'
]
!=
$this
->
charge_id
)
{
// The first contribution was completed, so create a new one.
// api contribution repeattransaction repeats the appropriate contribution if it is given
// simply the recurring contribution id. It also updates the membership for us.
...
...
@@ -259,17 +257,17 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
'failure_count'
=>
0
,
'contribution_status_id'
=>
'In Progress'
));
return
;
return
TRUE
;
// Failed recurring payment.
case
'invoice.payment_failed'
:
$this
->
setInfo
();
$failDate
=
date
(
'YmdHis'
);
if
(
$this
->
previous_contribution_status_id
==
$pendingStatusId
)
{
if
(
$this
->
previous_contribution
[
'contribution
_status_id
'
]
==
$pendingStatusId
)
{
// If this contribution is Pending, set it to Failed.
civicrm_api3
(
'Contribution'
,
'create'
,
array
(
'id'
=>
$this
->
previous_contribution
_id
,
'id'
=>
$this
->
previous_contribution
[
'id'
]
,
'contribution_status_id'
=>
"Failed"
,
'receive_date'
=>
$failDate
,
'is_email_receipt'
=>
$this
->
is_email_receipt
,
...
...
@@ -299,7 +297,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
'failure_count'
=>
$failureCount
,
'modified_date'
=>
$failDate
,
));
return
;
return
TRUE
;
// Subscription is cancelled
case
'customer.subscription.deleted'
:
...
...
@@ -308,7 +306,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
civicrm_api3
(
'ContributionRecur'
,
'cancel'
,
array
(
'id'
=>
$this
->
contribution_recur_id
,
));
return
;
return
TRUE
;
// One-time donation and per invoice payment.
case
'charge.failed'
:
...
...
@@ -321,7 +319,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
$note
=
$failureCode
.
' : '
.
$failureMessage
;
civicrm_api3
(
'Contribution'
,
'create'
,
[
'id'
=>
$contribution
[
'id'
],
'contribution_status_id'
=>
$failedStatusId
,
'note'
=>
$note
]);
}
return
;
return
TRUE
;
case
'charge.refunded'
:
$chargeId
=
$this
->
retrieve
(
'charge_id'
,
'String'
);
...
...
@@ -346,20 +344,20 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
}
}
}
return
;
return
TRUE
;
case
'charge.succeeded'
:
$this
->
setInfo
();
if
(
$this
->
previous_contribution_status_id
==
$pendingStatusId
)
{
if
(
$this
->
previous_contribution
[
'contribution
_status_id
'
]
==
$pendingStatusId
)
{
$this
->
completeContribution
();
}
return
;
return
TRUE
;
case
'customer.subscription.updated'
:
$this
->
setInfo
();
if
(
empty
(
$this
->
previous_plan_id
))
{
// Not a plan change...don't care.
return
;
return
TRUE
;
}
civicrm_api3
(
'ContributionRecur'
,
'create'
,
[
...
...
@@ -372,14 +370,14 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
]);
civicrm_api3
(
'Contribution'
,
'create'
,
[
'id'
=>
$this
->
previous_contribution
_id
,
'id'
=>
$this
->
previous_contribution
[
'id'
]
,
'total_amount'
=>
$this
->
plan_amount
,
'contribution_recur_id'
=>
$this
->
contribution_recur_id
,
]);
return
;
return
TRUE
;
}
// Unhandled event type.
return
;
return
TRUE
;
}
/**
...
...
@@ -390,14 +388,14 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
public
function
completeContribution
()
{
// Update the contribution to include the fee.
civicrm_api3
(
'Contribution'
,
'create'
,
array
(
'id'
=>
$this
->
previous_contribution
_id
,
'id'
=>
$this
->
previous_contribution
[
'id'
]
,
'total_amount'
=>
$this
->
amount
,
'fee_amount'
=>
$this
->
fee
,
'net_amount'
=>
$this
->
net_amount
,
));
// The last one was not completed, so complete it.
civicrm_api3
(
'Contribution'
,
'completetransaction'
,
array
(
'id'
=>
$this
->
previous_contribution
_id
,
'id'
=>
$this
->
previous_contribution
[
'id'
]
,
'trxn_date'
=>
$this
->
receive_date
,
'trxn_id'
=>
$this
->
charge_id
,
'total_amount'
=>
$this
->
amount
,
...
...
@@ -470,13 +468,11 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
// Same approach as api repeattransaction. Find last contribution associated
// with our recurring contribution.
$contribution
=
civicrm_api3
(
'contribution'
,
'getsingle'
,
array
(
'return'
=>
array
(
'id'
,
'contribution_status_id'
,
'total_amount'
),
'return'
=>
array
(
'id'
,
'contribution_status_id'
,
'total_amount'
,
'trxn_id'
),
'contribution_recur_id'
=>
$this
->
contribution_recur_id
,
'options'
=>
array
(
'limit'
=>
1
,
'sort'
=>
'id DESC'
),
));
$this
->
previous_contribution_id
=
$contribution
[
'id'
];
$this
->
previous_contribution_status_id
=
$contribution
[
'contribution_status_id'
];
$this
->
previous_contribution_total_amount
=
$contribution
[
'total_amount'
];
$this
->
previous_contribution
=
$contribution
;
}
catch
(
Exception
$e
)
{
$this
->
exception
(
'Cannot find recurring contribution for subscription ID: '
.
$this
->
subscription_id
.
'. '
.
$e
->
getMessage
());
...
...
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