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
3a75240e
Commit
3a75240e
authored
9 months ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Don't crash if we don't have write permission for stripe customer (to update metadata)
parent
801575e0
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
CRM/Core/Payment/Stripe.php
+9
-0
9 additions, 0 deletions
CRM/Core/Payment/Stripe.php
CRM/Stripe/BAO/StripeCustomer.php
+12
-6
12 additions, 6 deletions
CRM/Stripe/BAO/StripeCustomer.php
Civi/Api4/Action/StripeCustomer/UpdateStripe.php
+3
-2
3 additions, 2 deletions
Civi/Api4/Action/StripeCustomer/UpdateStripe.php
with
24 additions
and
8 deletions
CRM/Core/Payment/Stripe.php
+
9
−
0
View file @
3a75240e
...
...
@@ -363,6 +363,15 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
\Civi
::
log
(
'stripe'
)
->
error
(
$this
->
getLogPrefix
()
.
$op
.
': '
.
get_class
(
$e
)
.
': '
.
$e
->
getMessage
()
.
print_r
(
$e
->
getJsonBody
(),
TRUE
));
return
$e
->
getJsonBody
()[
'error'
]
??
$genericError
;
case
'Stripe\Exception\PermissionException'
:
// The client is probably setup with a restricted API key and does not have permission to do the requested action.
// We should not display the specific error to the end customer but we *do* want the details in the log.
// For example, if we have a readonly API key we won't be able to update Stripe customer metadata, but we may choose to continue!
\Civi
::
log
(
'stripe'
)
->
warning
(
$this
->
getLogPrefix
()
.
$op
.
': '
.
get_class
(
$e
)
.
': '
.
$e
->
getMessage
());
$genericError
[
'code'
]
=
$e
->
getStripeCode
();
$genericError
[
'message'
]
=
$e
->
getMessage
();
return
$genericError
;
default
:
// Something else happened, completely unrelated to Stripe
\Civi
::
log
(
'stripe'
)
->
error
(
$this
->
getLogPrefix
()
.
$op
.
' (unknown error): '
.
get_class
(
$e
)
.
': '
.
$e
->
getMessage
());
...
...
This diff is collapsed.
Click to expand it.
CRM/Stripe/BAO/StripeCustomer.php
+
12
−
6
View file @
3a75240e
...
...
@@ -4,6 +4,7 @@ use Civi\Api4\Contact;
use
Civi\Api4\Email
;
use
Civi\Api4\Extension
;
use
Civi\Api4\StripeCustomer
;
use
Civi\Payment\Exception\PaymentProcessorException
;
use
CRM_Stripe_ExtensionUtil
as
E
;
class
CRM_Stripe_BAO_StripeCustomer
extends
CRM_Stripe_DAO_StripeCustomer
{
...
...
@@ -72,15 +73,15 @@ class CRM_Stripe_BAO_StripeCustomer extends CRM_Stripe_DAO_StripeCustomer {
* @param \CRM_Core_Payment_Stripe $stripe
* @param string $stripeCustomerID
*
* @return
\Stripe\Customer
* @return
string
* @throws \CRM_Core_Exception
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public
static
function
updateMetadata
(
array
$params
,
\CRM_Core_Payment_Stripe
$stripe
,
string
$stripeCustomerID
)
{
public
static
function
updateMetadata
(
array
$params
,
\CRM_Core_Payment_Stripe
$stripe
,
string
$stripeCustomerID
)
:
string
{
$requiredParams
=
[
'contact_id'
];
foreach
(
$requiredParams
as
$required
)
{
if
(
empty
(
$params
[
$required
]))
{
throw
new
\Civi\Payment\Exception\
PaymentProcessorException
(
'Stripe Customer (updateMetadata): Missing required parameter: '
.
$required
);
throw
new
PaymentProcessorException
(
'Stripe Customer (updateMetadata): Missing required parameter: '
.
$required
);
}
}
...
...
@@ -91,10 +92,15 @@ class CRM_Stripe_BAO_StripeCustomer extends CRM_Stripe_DAO_StripeCustomer {
}
catch
(
Exception
$e
)
{
$err
=
$stripe
->
parseStripeException
(
'create_customer'
,
$e
);
\Civi
::
log
(
'stripe'
)
->
error
(
'Failed to create Stripe Customer: '
.
$err
[
'message'
]
.
'; '
.
print_r
(
$err
,
TRUE
));
throw
new
\Civi\Payment\Exception\PaymentProcessorException
(
'Failed to update Stripe Customer: '
.
$err
[
'code'
]);
if
(
$e
instanceof
\Stripe\Exception\PermissionException
)
{
\Civi
::
log
(
'stripe'
)
->
warning
(
'Could not update Stripe Customer metadata for StripeCustomerID: '
.
$stripeCustomerID
.
'; contactID: '
.
$params
[
'contact_id'
]);
}
else
{
\Civi
::
log
(
'stripe'
)
->
error
(
'Failed to create Stripe Customer: '
.
$err
[
'message'
]
.
'; '
.
print_r
(
$err
,
TRUE
));
throw
new
PaymentProcessorException
(
'Failed to update Stripe Customer: '
.
$err
[
'code'
]);
}
}
return
$stripeCustomer
;
return
$stripeCustomer
??
''
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
Civi/Api4/Action/StripeCustomer/UpdateStripe.php
+
3
−
2
View file @
3a75240e
...
...
@@ -94,9 +94,10 @@ class UpdateStripe extends \Civi\Api4\Generic\AbstractAction {
/** @var \CRM_Core_Payment_Stripe $paymentProcessor */
$paymentProcessor
=
\Civi\Payment\System
::
singleton
()
->
getById
(
$this
->
paymentProcessorID
);
$stripeCustomer
=
\CRM_Stripe_BAO_StripeCustomer
::
updateMetadata
([
'contact_id'
=>
$this
->
contactID
,
'description'
=>
$this
->
description
],
$paymentProcessor
,
$this
->
customerID
);
$stripeCustomer
ID
=
\CRM_Stripe_BAO_StripeCustomer
::
updateMetadata
([
'contact_id'
=>
$this
->
contactID
,
'description'
=>
$this
->
description
],
$paymentProcessor
,
$this
->
customerID
);
$result
->
exchangeArray
(
$stripeCustomer
->
toArray
());
// Return values may change!
$result
->
exchangeArray
([
'stripeCustomerID'
=>
$stripeCustomerID
]);
}
}
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