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
096f14e7
Commit
096f14e7
authored
1 year ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Simplify product name. Fix plan creation
parent
b702aab9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Core/Payment/Stripe.php
+15
-21
15 additions, 21 deletions
CRM/Core/Payment/Stripe.php
tests/phpunit/CRM/Core/Payment/StripeTest.php
+1
-1
1 addition, 1 deletion
tests/phpunit/CRM/Core/Payment/StripeTest.php
with
16 additions
and
22 deletions
CRM/Core/Payment/Stripe.php
+
15
−
21
View file @
096f14e7
...
...
@@ -328,17 +328,18 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
switch
(
get_class
(
$e
))
{
case
'Stripe\Exception\CardException'
:
/** @var \Stripe\Exception\CardException $e */
// Since it's a decline, \Stripe\Exception\CardException will be caught
\Civi
::
log
(
'stripe'
)
->
error
(
$this
->
getLogPrefix
()
.
$op
.
': '
.
get_class
(
$e
)
.
': '
.
$e
->
getMessage
()
.
print_r
(
$e
->
getJsonBody
(),
TRUE
));
$error
[
'code'
]
=
$e
->
get
Error
()
->
code
;
$error
[
'message'
]
=
$e
->
get
Error
()
->
m
essage
;
$error
[
'code'
]
=
$e
->
get
StripeCode
()
;
$error
[
'message'
]
=
$e
->
get
M
essage
()
;
return
$error
;
case
'Stripe\Exception\RateLimitException'
:
// Too many requests made to the API too quickly
case
'Stripe\Exception\InvalidRequestException'
:
// Invalid parameters were supplied to Stripe's API
switch
(
$e
->
get
Error
()
->
code
)
{
switch
(
$e
->
get
StripeCode
()
)
{
case
'payment_intent_unexpected_state'
:
$genericError
[
'message'
]
=
E
::
ts
(
'An error occurred while processing the payment'
);
break
;
...
...
@@ -377,29 +378,22 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
* @return \Stripe\Plan
*/
public
function
createPlan
(
\Civi\Payment\PropertyBag
$propertyBag
,
int
$amount
)
:
\Stripe\Plan
{
$planId
=
"every-
{
$propertyBag
->
getRecurFrequencyInterval
()
}
-
{
$propertyBag
->
getRecurFrequencyUnit
()
}
-
{
$amount
}
-"
.
strtolower
(
$propertyBag
->
getCurrency
());
if
(
$this
->
_paymentProcessor
[
'is_test'
])
{
$planId
.
=
'-test'
;
}
$planID
=
"every-
{
$propertyBag
->
getRecurFrequencyInterval
()
}
-
{
$propertyBag
->
getRecurFrequencyUnit
()
}
-
{
$amount
}
-"
.
strtolower
(
$propertyBag
->
getCurrency
());
// Try and retrieve existing plan from Stripe
// If this fails, we'll create a new one
try
{
$plan
=
$this
->
stripeClient
->
plans
->
retrieve
(
$planI
d
);
$plan
=
$this
->
stripeClient
->
plans
->
retrieve
(
$planI
D
);
}
catch
(
\Stripe\Exception\InvalidRequestException
$e
)
{
// The following call is just for logging's sake.
$this
->
parseStripeException
(
'plan_retrieve'
,
$e
);
if
(
$e
->
getError
()
->
code
===
'resource_missing'
)
{
$formatted_amount
=
CRM_Utils_Money
::
formatLocaleNumericRoundedByCurrency
((
$amount
/
100
),
$propertyBag
->
getCurrency
());
$productName
=
"CiviCRM "
.
(
$propertyBag
->
has
(
'membership_name'
)
?
$propertyBag
->
getCustomProperty
(
'membership_name'
)
.
' '
:
''
)
.
"every
{
$propertyBag
->
getRecurFrequencyInterval
()
}
{
$propertyBag
->
getRecurFrequencyUnit
()
}
(s)
{
$propertyBag
->
getCurrency
()
}{
$formatted_amount
}
"
;
if
(
$this
->
_paymentProcessor
[
'is_test'
])
{
$productName
.
=
'-test'
;
}
if
(
$e
->
getStripeCode
()
===
'resource_missing'
)
{
$formattedAmount
=
CRM_Utils_Money
::
formatLocaleNumericRoundedByCurrency
((
$amount
/
100
),
$propertyBag
->
getCurrency
());
$productName
=
"
{
$propertyBag
->
getCurrency
()
}{
$formattedAmount
}
"
.
(
$propertyBag
->
has
(
'membership_name'
)
?
$propertyBag
->
getCustomProperty
(
'membership_name'
)
.
' '
:
''
)
.
"every
{
$propertyBag
->
getRecurFrequencyInterval
()
}
{
$propertyBag
->
getRecurFrequencyUnit
()
}
(s)"
;
$product
=
$this
->
stripeClient
->
products
->
create
([
"
name
"
=>
$productName
,
"
type
"
=>
"
service
"
'
name
'
=>
$productName
,
'
type
'
=>
'
service
'
]);
// Create a new Plan.
$stripePlan
=
[
...
...
@@ -407,15 +401,15 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
'interval'
=>
$propertyBag
->
getRecurFrequencyUnit
(),
'product'
=>
$product
->
id
,
'currency'
=>
$propertyBag
->
getCurrency
(),
'id'
=>
$planI
d
,
'id'
=>
$planI
D
,
'interval_count'
=>
$propertyBag
->
getRecurFrequencyInterval
(),
];
$plan
=
$this
->
stripeClient
->
plans
->
create
(
$stripePlan
);
}
}
return
$plan
;
}
/**
* Override CRM_Core_Payment function
*
...
...
This diff is collapsed.
Click to expand it.
tests/phpunit/CRM/Core/Payment/StripeTest.php
+
1
−
1
View file @
096f14e7
...
...
@@ -146,7 +146,7 @@ class CRM_Core_Payment_Stripe_Test extends CRM_Stripe_BaseTest {
$planNotFoundException
=
\Stripe\Exception\InvalidRequestException
::
factory
(
'mock message unused untested'
);
// , null, null, null, null,
// 'resource_missing');
$planNotFoundException
->
set
Error
((
object
)
[
'code'
=>
'resource_missing'
]
);
$planNotFoundException
->
set
StripeCode
(
'resource_missing'
);
$stripeClient
->
plans
->
method
(
'retrieve'
)
->
willThrowException
(
$planNotFoundException
);
$stripeClient
->
plans
->
method
(
'create'
)
->
willReturn
(
$mockPlan
);
...
...
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