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
587e7407
Commit
587e7407
authored
2 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Switch to getAmountForStripeAPI() function
parent
828a2122
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!217
Implement Stripe Checkout (with support for SEPA and ACH)
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Core/Payment/Stripe.php
+20
-7
20 additions, 7 deletions
CRM/Core/Payment/Stripe.php
CRM/Stripe/PaymentIntent.php
+2
-1
2 additions, 1 deletion
CRM/Stripe/PaymentIntent.php
with
22 additions
and
8 deletions
CRM/Core/Payment/Stripe.php
+
20
−
7
View file @
587e7407
...
...
@@ -9,6 +9,7 @@
+--------------------------------------------------------------------+
*/
use
Brick\Money\Money
;
use
Civi\Api4\PaymentprocessorWebhook
;
use
CRM_Stripe_ExtensionUtil
as
E
;
use
Civi\Payment\PropertyBag
;
...
...
@@ -240,13 +241,22 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
*
* @return string
*/
p
ublic
function
getAmount
(
$params
=
[])
:
string
{
p
rotected
function
getAmount
(
$params
=
[])
{
$amount
=
number_format
((
float
)
$params
[
'amount'
]
??
0.0
,
CRM_Utils_Money
::
getCurrencyPrecision
(
$this
->
getCurrency
(
$params
)),
'.'
,
''
);
// Stripe amount required in cents.
$amount
=
preg_replace
(
'/[^\d]/'
,
''
,
strval
(
$amount
));
return
$amount
;
}
/**
* @param \Civi\Payment\PropertyBag $propertyBag
*
* @throws \Brick\Money\Exception\UnknownCurrencyException
*/
public
function
getAmountFormattedForStripeAPI
(
PropertyBag
$propertyBag
):
string
{
return
Money
::
of
(
$propertyBag
->
getAmount
(),
$propertyBag
->
getCurrency
())
->
getMinorAmount
()
->
getIntegralPart
();
}
/**
* Set API parameters for Stripe (such as identifier, api version, api key)
*/
...
...
@@ -550,7 +560,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
*/
public
function
doPayment
(
&
$paymentParams
,
$component
=
'contribute'
)
{
/* @var \Civi\Payment\PropertyBag $propertyBag */
$propertyBag
=
\Civi\Payment\
PropertyBag
::
cast
(
$paymentParams
);
$propertyBag
=
PropertyBag
::
cast
(
$paymentParams
);
$zeroAmountPayment
=
$this
->
processZeroAmountPayment
(
$propertyBag
);
if
(
$zeroAmountPayment
)
{
...
...
@@ -583,10 +593,11 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
$newParams
=
[];
CRM_Utils_Hook
::
alterPaymentProcessorParams
(
$this
,
$propertyBag
,
$newParams
);
$amountFormattedForStripe
=
$this
->
getAmountFormattedForStripeAPI
(
$propertyBag
);
// @fixme DO NOT SET ANYTHING ON $propertyBag or $params BELOW THIS LINE (we are reading from both)
$params
=
$this
->
getPropertyBagAsArray
(
$propertyBag
);
$amountFormattedForStripe
=
self
::
getAmount
(
$params
);
$email
=
$this
->
getBillingEmail
(
$params
,
$propertyBag
->
getContactID
());
// See if we already have a stripe customer
...
...
@@ -687,8 +698,8 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
$paymentIntentID
=
$propertyBag
->
getCustomProperty
(
'paymentIntentID'
);
}
$intent
=
$this
->
stripeClient
->
paymentIntents
->
retrieve
(
$paymentIntentID
);
if
(
$intent
->
amount
!=
$this
->
getAmount
(
$params
))
{
$intentParams
[
'amount'
]
=
$this
->
getAmount
(
$params
);
if
(
$intent
->
amount
!=
$this
->
getAmount
FormattedForStripeAPI
(
$propertyBag
))
{
$intentParams
[
'amount'
]
=
$this
->
getAmount
FormattedForStripeAPI
(
$propertyBag
);
}
$intent
=
$this
->
stripeClient
->
paymentIntents
->
update
(
$intent
->
id
,
$intentParams
);
}
...
...
@@ -979,10 +990,12 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
}
}
$propertyBag
=
PropertyBag
::
cast
(
$params
);
$refundParams
=
[
'charge'
=>
$params
[
'trxn_id'
],
];
$refundParams
[
'amount'
]
=
$this
->
getAmount
(
$params
);
$refundParams
[
'amount'
]
=
$this
->
getAmount
FormattedForStripeAPI
(
$propertyBag
);
try
{
$refund
=
$this
->
stripeClient
->
refunds
->
create
(
$refundParams
);
// Stripe does not refund fees - see https://support.stripe.com/questions/understanding-fees-for-refunded-payments
...
...
@@ -1203,7 +1216,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
* @return array|null[]
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public
function
doCancelRecurring
(
\Civi\Payment\
PropertyBag
$propertyBag
)
{
public
function
doCancelRecurring
(
PropertyBag
$propertyBag
)
{
// By default we always notify the processor and we don't give the user the option
// because supportsCancelRecurringNotifyOptional() = FALSE
if
(
!
$propertyBag
->
has
(
'isNotifyProcessorOnCancelRecur'
))
{
...
...
This diff is collapsed.
Click to expand it.
CRM/Stripe/PaymentIntent.php
+
2
−
1
View file @
587e7407
...
...
@@ -9,6 +9,7 @@
+--------------------------------------------------------------------+
*/
use
Civi\Payment\PropertyBag
;
use
CRM_Stripe_ExtensionUtil
as
E
;
/**
...
...
@@ -456,7 +457,7 @@ class CRM_Stripe_PaymentIntent {
if
(
!
empty
(
$params
[
'moto'
]))
{
$intentParams
[
'payment_method_options'
][
'card'
][
'moto'
]
=
TRUE
;
}
$intentParams
[
'amount'
]
=
$this
->
paymentProcessor
->
getAmount
([
'amount'
=>
$params
[
'amount'
],
'currency'
=>
$params
[
'currency'
]]);
$intentParams
[
'amount'
]
=
$this
->
paymentProcessor
->
getAmount
FormattedForStripeAPI
(
PropertyBag
::
cast
([
'amount'
=>
$params
[
'amount'
],
'currency'
=>
$params
[
'currency'
]])
)
;
$intentParams
[
'currency'
]
=
$params
[
'currency'
];
// authorize the amount but don't take from card yet
$intentParams
[
'capture_method'
]
=
'manual'
;
...
...
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