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
750e746d
Commit
750e746d
authored
3 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Support exception in handleError (requires mjwshared 1.2.2)
parent
6b0ae44b
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
+17
-17
17 additions, 17 deletions
CRM/Core/Payment/Stripe.php
CRM/Stripe/Customer.php
+10
-9
10 additions, 9 deletions
CRM/Stripe/Customer.php
api/v3/StripeCustomer.php
+1
-1
1 addition, 1 deletion
api/v3/StripeCustomer.php
with
28 additions
and
27 deletions
CRM/Core/Payment/Stripe.php
+
17
−
17
View file @
750e746d
...
...
@@ -259,10 +259,15 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
* @param array $err
* @param string $bounceURL
*
* @return string errorMessage
(or statusbounce if URL is specified)
* @return string errorMessage
*/
public
function
handleErrorNotification
(
$err
,
$bounceURL
=
NULL
)
{
return
self
::
handleError
(
"
{
$err
[
'type'
]
}
{
$err
[
'code'
]
}
"
,
$err
[
'message'
],
$bounceURL
);
try
{
self
::
handleError
(
"
{
$err
[
'type'
]
}
{
$err
[
'code'
]
}
"
,
$err
[
'message'
],
$bounceURL
);
}
catch
(
Exception
$e
)
{
return
$e
->
getMessage
();
}
}
/**
...
...
@@ -578,9 +583,9 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
try
{
$stripeCustomer
=
$this
->
stripeClient
->
customers
->
retrieve
(
$stripeCustomerId
);
}
catch
(
Exception
$e
)
{
$err
=
self
::
parseStripeException
(
'retrieve_customer'
,
$e
,
FALSE
);
$err
=
self
::
parseStripeException
(
'retrieve_customer'
,
$e
);
$errorMessage
=
$this
->
handleErrorNotification
(
$err
,
$propertyBag
->
getCustomProperty
(
'error_url'
));
throw
new
\Civi\Payment\Exception\
PaymentProcessorException
(
'Failed to retrieve Stripe Customer: '
.
$errorMessage
);
throw
new
PaymentProcessorException
(
'Failed to retrieve Stripe Customer: '
.
$errorMessage
);
}
if
(
$stripeCustomer
->
isDeleted
())
{
...
...
@@ -590,9 +595,9 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
$stripeCustomer
=
CRM_Stripe_Customer
::
create
(
$customerParams
,
$this
);
}
catch
(
Exception
$e
)
{
// We still failed to create a customer
$err
=
self
::
parseStripeException
(
'create_customer'
,
$e
,
FALSE
);
$err
=
self
::
parseStripeException
(
'create_customer'
,
$e
);
$errorMessage
=
$this
->
handleErrorNotification
(
$err
,
$propertyBag
->
getCustomProperty
(
'error_url'
));
throw
new
\Civi\Payment\Exception\
PaymentProcessorException
(
'Failed to create Stripe Customer: '
.
$errorMessage
);
throw
new
PaymentProcessorException
(
'Failed to create Stripe Customer: '
.
$errorMessage
);
}
}
}
...
...
@@ -772,7 +777,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
if
(
$stripeSubscription
->
status
===
'incomplete'
)
{
// For example with test card 4000000000000341 (Attaching this card to a Customer object succeeds, but attempts to charge the customer fail)
\Civi
::
log
()
->
warning
(
'Stripe subscription status=incomplete. ID:'
.
$stripeSubscription
->
id
);
throw
new
\Civi\Payment\Exception\
PaymentProcessorException
(
'Payment failed'
);
throw
new
PaymentProcessorException
(
'Payment failed'
);
}
// artfulrobot: Q. what do we normally get here?
...
...
@@ -861,7 +866,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
catch
(
Exception
$e
)
{
$err
=
self
::
parseStripeException
(
'retrieve_balance_transaction'
,
$e
,
FALSE
);
$errorMessage
=
$this
->
handleErrorNotification
(
$err
,
$params
[
'error_url'
]);
throw
new
\Civi\Payment\Exception\
PaymentProcessorException
(
'Failed to retrieve Stripe Balance Transaction: '
.
$errorMessage
);
throw
new
PaymentProcessorException
(
'Failed to retrieve Stripe Balance Transaction: '
.
$errorMessage
);
}
if
((
$stripeCharge
[
'currency'
]
!==
$stripeBalanceTransaction
->
currency
)
&&
(
!
empty
(
$stripeBalanceTransaction
->
exchange_rate
)))
{
...
...
@@ -889,11 +894,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
}
}
catch
(
Exception
$e
)
{
$errorMessage
=
$e
->
getMessage
();
$this
->
handleError
(
$e
->
getCode
(),
$errorMessage
,
$params
[
'error_url'
]);
if
(
$e
instanceof
\Stripe\Exception\CardException
)
{
throw
new
PaymentProcessorException
(
$errorMessage
);
}
$this
->
handleError
(
$e
->
getCode
(),
$e
->
getMessage
(),
$params
[
'error_url'
]);
}
finally
{
// Always update the paymentIntent in the CiviCRM database for later tracking
...
...
@@ -931,7 +932,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
if
(
!
isset
(
$params
[
$required
]))
{
$message
=
'Stripe doRefund: Missing mandatory parameter: '
.
$required
;
Civi
::
log
()
->
error
(
$message
);
throw
new
\Civi\Payment\Exception\
PaymentProcessorException
(
$message
);
throw
new
PaymentProcessorException
(
$message
);
}
}
...
...
@@ -944,7 +945,6 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
}
catch
(
Exception
$e
)
{
$this
->
handleError
(
$e
->
getCode
(),
$e
->
getMessage
());
Throw
new
\Civi\Payment\Exception\PaymentProcessorException
(
$e
->
getMessage
());
}
switch
(
$refund
->
status
)
{
...
...
@@ -1174,7 +1174,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
if
(
!
$propertyBag
->
has
(
'recurProcessorID'
))
{
$errorMessage
=
E
::
ts
(
'The recurring contribution cannot be cancelled (No reference (trxn_id) found).'
);
\Civi
::
log
()
->
error
(
$errorMessage
);
throw
new
\Civi\Payment\Exception\
PaymentProcessorException
(
$errorMessage
);
throw
new
PaymentProcessorException
(
$errorMessage
);
}
try
{
...
...
@@ -1186,7 +1186,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
catch
(
Exception
$e
)
{
$errorMessage
=
E
::
ts
(
'Could not delete Stripe subscription: %1'
,
[
1
=>
$e
->
getMessage
()]);
\Civi
::
log
()
->
error
(
$errorMessage
);
throw
new
\Civi\Payment\Exception\
PaymentProcessorException
(
$errorMessage
);
throw
new
PaymentProcessorException
(
$errorMessage
);
}
return
[
'message'
=>
E
::
ts
(
'Successfully cancelled the subscription at Stripe.'
)];
...
...
This diff is collapsed.
Click to expand it.
CRM/Stripe/Customer.php
+
10
−
9
View file @
750e746d
...
...
@@ -10,6 +10,7 @@
*/
use
Civi\Api4\Contact
;
use
Civi\Payment\Exception\PaymentProcessorException
;
use
CRM_Stripe_ExtensionUtil
as
E
;
/**
...
...
@@ -29,11 +30,11 @@ class CRM_Stripe_Customer {
$requiredParams
=
[
'processor_id'
];
foreach
(
$requiredParams
as
$required
)
{
if
(
empty
(
$params
[
$required
]))
{
throw
new
\Civi\Payment\Exception\
PaymentProcessorException
(
'Stripe Customer (find): Missing required parameter: '
.
$required
);
throw
new
PaymentProcessorException
(
'Stripe Customer (find): Missing required parameter: '
.
$required
);
}
}
if
(
empty
(
$params
[
'contact_id'
]))
{
throw
new
\Civi\Payment\Exception\
PaymentProcessorException
(
'Stripe Customer (find): contact_id is required'
);
throw
new
PaymentProcessorException
(
'Stripe Customer (find): contact_id is required'
);
}
$queryParams
=
[
1
=>
[
$params
[
'contact_id'
],
'String'
],
...
...
@@ -109,7 +110,7 @@ class CRM_Stripe_Customer {
$requiredParams
=
[
'contact_id'
,
'id'
,
'processor_id'
];
foreach
(
$requiredParams
as
$required
)
{
if
(
empty
(
$params
[
$required
]))
{
throw
new
\Civi\Payment\Exception\
PaymentProcessorException
(
'Stripe Customer (add): Missing required parameter: '
.
$required
);
throw
new
PaymentProcessorException
(
'Stripe Customer (add): Missing required parameter: '
.
$required
);
}
}
...
...
@@ -135,7 +136,7 @@ class CRM_Stripe_Customer {
$requiredParams
=
[
'contact_id'
,
'processor_id'
];
foreach
(
$requiredParams
as
$required
)
{
if
(
empty
(
$params
[
$required
]))
{
throw
new
\Civi\Payment\Exception\
PaymentProcessorException
(
'Stripe Customer (create): Missing required parameter: '
.
$required
);
throw
new
PaymentProcessorException
(
'Stripe Customer (create): Missing required parameter: '
.
$required
);
}
}
...
...
@@ -147,7 +148,7 @@ class CRM_Stripe_Customer {
catch
(
Exception
$e
)
{
$err
=
CRM_Core_Payment_Stripe
::
parseStripeException
(
'create_customer'
,
$e
,
FALSE
);
$errorMessage
=
$stripe
->
handleErrorNotification
(
$err
,
$params
[
'error_url'
]);
throw
new
\Civi\Payment\Exception\
PaymentProcessorException
(
'Failed to create Stripe Customer: '
.
$errorMessage
);
throw
new
PaymentProcessorException
(
'Failed to create Stripe Customer: '
.
$errorMessage
);
}
// Store the relationship between CiviCRM's email address for the Contact & Stripe's Customer ID.
...
...
@@ -174,7 +175,7 @@ class CRM_Stripe_Customer {
$requiredParams
=
[
'contact_id'
,
'processor_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
);
}
}
...
...
@@ -186,7 +187,7 @@ class CRM_Stripe_Customer {
catch
(
Exception
$e
)
{
$err
=
CRM_Core_Payment_Stripe
::
parseStripeException
(
'create_customer'
,
$e
,
FALSE
);
$errorMessage
=
$stripe
->
handleErrorNotification
(
$err
,
$params
[
'error_url'
]);
throw
new
\Civi\Payment\Exception\
PaymentProcessorException
(
'Failed to update Stripe Customer: '
.
$errorMessage
);
throw
new
PaymentProcessorException
(
'Failed to update Stripe Customer: '
.
$errorMessage
);
}
return
$stripeCustomer
;
}
...
...
@@ -241,11 +242,11 @@ class CRM_Stripe_Customer {
$requiredParams
=
[
'processor_id'
];
foreach
(
$requiredParams
as
$required
)
{
if
(
empty
(
$params
[
$required
]))
{
throw
new
\Civi\Payment\Exception\
PaymentProcessorException
(
'Stripe Customer (delete): Missing required parameter: '
.
$required
);
throw
new
PaymentProcessorException
(
'Stripe Customer (delete): Missing required parameter: '
.
$required
);
}
}
if
(
empty
(
$params
[
'contact_id'
])
&&
empty
(
$params
[
'id'
]))
{
throw
new
\Civi\Payment\Exception\
PaymentProcessorException
(
'Stripe Customer (delete): Missing required parameter: contact_id or id'
);
throw
new
PaymentProcessorException
(
'Stripe Customer (delete): Missing required parameter: contact_id or id'
);
}
if
(
!
empty
(
$params
[
'id'
]))
{
...
...
This diff is collapsed.
Click to expand it.
api/v3/StripeCustomer.php
+
1
−
1
View file @
750e746d
...
...
@@ -256,7 +256,7 @@ function civicrm_api3_stripe_customer_updatestripemetadata($params) {
$paymentProcessor
->
stripeClient
->
customers
->
retrieve
(
$customerId
);
}
catch
(
Exception
$e
)
{
$err
=
CRM_Core_Payment_Stripe
::
parseStripeException
(
'retrieve_customer'
,
$e
,
FALSE
);
$errorMessage
=
$paymentProcessor
->
handleErrorNotification
(
$err
,
NULL
);
$errorMessage
=
$paymentProcessor
->
handleErrorNotification
(
$err
);
throw
new
\Civi\Payment\Exception\PaymentProcessorException
(
'Failed to retrieve Stripe Customer: '
.
$errorMessage
);
}
...
...
This diff is collapsed.
Click to expand it.
mattwire
@mattwire
mentioned in merge request
!179 (closed)
·
3 years ago
mentioned in merge request
!179 (closed)
mentioned in merge request !179
Toggle commit list
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