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
5c6d22c8
Commit
5c6d22c8
authored
6 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Handle deleted customer
parent
5ff3615e
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!10
5.x noemail noplan
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Core/Payment/Stripe.php
+8
-11
8 additions, 11 deletions
CRM/Core/Payment/Stripe.php
CRM/Core/Payment/StripeIPN.php
+4
-3
4 additions, 3 deletions
CRM/Core/Payment/StripeIPN.php
with
12 additions
and
14 deletions
CRM/Core/Payment/Stripe.php
+
8
−
11
View file @
5c6d22c8
...
...
@@ -151,7 +151,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
*
* @throws \CiviCRM_API3_Exception
*/
public
function
stripeCatchErrors
(
$op
=
'create_customer'
,
$stripe_params
,
$params
,
$ignores
=
array
())
{
public
function
stripeCatchErrors
(
$op
,
$stripe_params
,
$params
,
$ignores
=
array
())
{
$return
=
FALSE
;
// Check for errors before trying to submit.
try
{
...
...
@@ -179,10 +179,6 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
case
'retrieve_balance_transaction'
:
$return
=
\Stripe\BalanceTransaction
::
retrieve
(
$stripe_params
);
break
;
default
:
$return
=
\Stripe\Customer
::
create
(
$stripe_params
);
break
;
}
}
catch
(
Exception
$e
)
{
...
...
@@ -541,17 +537,18 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
// Customer was found in civicrm database, fetch from Stripe.
$stripeCustomer
=
$this
->
stripeCatchErrors
(
'retrieve_customer'
,
$stripeCustomerId
,
$params
);
if
(
!
empty
(
$stripeCustomer
))
{
if
(
$this
->
isErrorReturn
(
$stripeCustomer
))
{
if
(
(
$stripeCustomer
[
'type'
]
==
'invalid_request_error'
)
&&
(
$stripeCustomer
[
'code'
]
==
'resource_missing'
)
)
{
// Customer doesn't exist, create a new one
CRM_Stripe_Customer
::
delete
(
$customerParams
);
$stripeCustomer
=
CRM_Stripe_Customer
::
crea
te
(
$customerParams
,
$this
);
}
if
(
$stripeCustomer
->
isDeleted
()
||
(
$this
->
isErrorReturn
(
$stripeCustomer
)
&&
(
$stripeCustomer
[
'type'
]
==
'invalid_request_error'
)
&&
(
$stripeCustomer
[
'code'
]
==
'resource_missing'
)
))
{
// Customer doesn't exist, create a new one
CRM_Stripe_Customer
::
dele
te
(
$customerParams
);
$stripeCustomer
=
CRM_Stripe_Customer
::
create
(
$customerParams
,
$this
);
if
(
$this
->
isErrorReturn
(
$stripeCustomer
))
{
// We still failed to create a customer
self
::
handleErrorNotification
(
$stripeCustomer
,
$params
[
'stripe_error_url'
]);
return
$stripeCustomer
;
}
}
$stripeCustomer
->
card
=
$card_token
;
...
...
This diff is collapsed.
Click to expand it.
CRM/Core/Payment/StripeIPN.php
+
4
−
3
View file @
5c6d22c8
...
...
@@ -20,6 +20,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
public
$test_mode
;
public
$event_type
=
NULL
;
public
$subscription_id
=
NULL
;
public
$customer_id
=
NULL
;
public
$charge_id
=
NULL
;
public
$previous_plan_id
=
NULL
;
public
$plan_id
=
NULL
;
...
...
@@ -500,7 +501,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
financial_type_id, payment_instrument_id, contact_id
FROM civicrm_stripe_subscriptions s JOIN civicrm_contribution_recur r
ON s.contribution_recur_id = r.id
WHERE subscription_id = %1
WHERE
s.
subscription_id = %1
AND s.processor_id = %2"
;
$query_params
=
array
(
1
=>
array
(
$this
->
subscription_id
,
'String'
),
...
...
@@ -515,7 +516,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
financial_type_id, payment_instrument_id, contact_id
FROM civicrm_stripe_subscriptions s JOIN civicrm_contribution_recur r
ON s.contribution_recur_id = r.id
WHERE customer_id = %1
WHERE
s.
customer_id = %1
AND s.processor_id = %2"
;
$query_params
=
array
(
1
=>
array
(
$this
->
customer_id
,
'String'
),
...
...
@@ -542,7 +543,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
$this
->
payment_instrument_id
=
$dao
->
payment_instrument_id
;
$this
->
contact_id
=
$dao
->
contact_id
;
// Same approach as api repeattransaction. Find last contribution as
c
ociated
// Same approach as api repeattransaction. Find last contribution as
s
ociated
// with our recurring contribution.
$results
=
civicrm_api3
(
'contribution'
,
'getsingle'
,
array
(
'return'
=>
array
(
'id'
,
'contribution_status_id'
,
'total_amount'
),
...
...
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