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
f6e848a1
Commit
f6e848a1
authored
1 year ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Check for fee in tests. Switch to getDetailsForBalanceTransaction() for all webhooks that use it
parent
4181358b
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!217
Implement Stripe Checkout (with support for SEPA and ACH)
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CRM/Core/Payment/StripeCheckout.php
+1
-1
1 addition, 1 deletion
CRM/Core/Payment/StripeCheckout.php
Civi/Stripe/Webhook/Events.php
+11
-29
11 additions, 29 deletions
Civi/Stripe/Webhook/Events.php
tests/phpunit/CRM/Stripe/IpnTest.php
+10
-0
10 additions, 0 deletions
tests/phpunit/CRM/Stripe/IpnTest.php
with
22 additions
and
30 deletions
CRM/Core/Payment/StripeCheckout.php
+
1
−
1
View file @
f6e848a1
...
...
@@ -252,7 +252,7 @@ class CRM_Core_Payment_StripeCheckout extends CRM_Core_Payment_Stripe {
* Takes the lineitems passed into doPayment and converts them into an array suitable for passing to Stripe Checkout
*
* @param array $civicrmLineItems
* @param
string $currency
* @param
\Civi\Payment\PropertyBag $propertyBag
*
* @return array
* @throws \Brick\Money\Exception\UnknownCurrencyException
...
...
This diff is collapsed.
Click to expand it.
Civi/Stripe/Webhook/Events.php
+
11
−
29
View file @
f6e848a1
...
...
@@ -154,33 +154,6 @@ class Events {
return
$contribution
??
[];
}
/**
* @param string $chargeID
*
* @return float
* @throws \CRM_Core_Exception
* @throws \Civi\Payment\Exception\PaymentProcessorException
* @throws \Stripe\Exception\ApiErrorException
*/
private
function
getFeeFromCharge
(
string
$chargeID
):
float
{
if
((
$this
->
getData
()
->
object
[
'object'
]
!==
'charge'
)
&&
(
!
empty
(
$chargeID
)))
{
$charge
=
$this
->
getPaymentProcessor
()
->
stripeClient
->
charges
->
retrieve
(
$chargeID
);
$balanceTransactionID
=
\CRM_Stripe_Api
::
getObjectParam
(
'balance_transaction'
,
$charge
);
}
else
{
$balanceTransactionID
=
$this
->
getValueFromStripeObject
(
'balance_transaction'
,
'String'
);
}
try
{
$balanceTransaction
=
$this
->
getPaymentProcessor
()
->
stripeClient
->
balanceTransactions
->
retrieve
(
$balanceTransactionID
);
}
catch
(
\Exception
$e
)
{
throw
new
\Civi\Payment\Exception\PaymentProcessorException
(
"Error retrieving balanceTransaction
{
$balanceTransactionID
}
. "
.
$e
->
getMessage
());
}
$fee
=
$this
->
getPaymentProcessor
()
->
getFeeFromBalanceTransaction
(
$balanceTransaction
,
$this
->
getValueFromStripeObject
(
'currency'
,
'String'
));
return
$fee
??
0.0
;
}
/**
* @param string $chargeID
*
...
...
@@ -305,6 +278,7 @@ class Events {
// We have a recurring contribution but no contribution so we'll repeattransaction
// Stripe has generated a new invoice (next payment in a subscription) so we
// create a new contribution in CiviCRM
$balanceTransactionDetails
=
$this
->
getDetailsFromBalanceTransaction
(
$chargeID
);
$repeatContributionParams
=
[
'contribution_recur_id'
=>
$contributionRecur
[
'id'
],
'contribution_status_id'
=>
\CRM_Core_PseudoConstant
::
getKey
(
'CRM_Contribute_BAO_Contribution'
,
'contribution_status_id'
,
'Pending'
),
...
...
@@ -312,8 +286,11 @@ class Events {
'order_reference'
=>
$invoiceID
,
'trxn_id'
=>
$chargeID
,
'total_amount'
=>
$this
->
getValueFromStripeObject
(
'amount'
,
'String'
),
'fee_amount'
=>
$this
->
getFeeFromCharge
(
$chargeID
),
//
'fee_amount'
Added below via $balanceTransactionDetails
];
foreach
(
$balanceTransactionDetails
as
$key
=>
$value
)
{
$repeatContributionParams
[
$key
]
=
$value
;
}
return
$this
->
repeatContribution
(
$repeatContributionParams
);
// Don't touch the contributionRecur as it's updated automatically by Contribution.repeattransaction
}
...
...
@@ -747,15 +724,20 @@ class Events {
// If contribution is in Pending or Failed state record payment and transition to Completed
if
(
in_array
(
$contribution
[
'contribution_status_id'
],
$statusesAllowedToComplete
))
{
$balanceTransactionDetails
=
$this
->
getDetailsFromBalanceTransaction
(
$chargeID
);
$contributionParams
=
[
'contribution_id'
=>
$contribution
[
'id'
],
'trxn_date'
=>
$this
->
getValueFromStripeObject
(
'receive_date'
,
'String'
),
'order_reference'
=>
$invoiceID
,
'trxn_id'
=>
$chargeID
,
'total_amount'
=>
$this
->
getValueFromStripeObject
(
'amount'
,
'String'
),
'fee_amount'
=>
$this
->
getFeeFromCharge
(
$chargeID
),
//
'fee_amount'
Added below via $balanceTransactionDetails
'contribution_status_id'
=>
$contribution
[
'contribution_status_id'
],
];
foreach
(
$balanceTransactionDetails
as
$key
=>
$value
)
{
$contributionParams
[
$key
]
=
$value
;
}
$this
->
updateContributionCompleted
(
$contributionParams
);
// Don't touch the contributionRecur as it's updated automatically by Contribution.completetransaction
}
...
...
This diff is collapsed.
Click to expand it.
tests/phpunit/CRM/Stripe/IpnTest.php
+
10
−
0
View file @
f6e848a1
...
...
@@ -159,6 +159,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
$this
->
checkContrib
([
'contribution_status_id'
=>
'Completed'
,
'trxn_id'
=>
'pi_mock,ch_mock'
,
'fee_amount'
=>
11.90
]);
}
...
...
@@ -295,6 +296,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
$this
->
checkContrib
([
'contribution_status_id'
=>
'Completed'
,
'trxn_id'
=>
'pi_mock,ch_mock'
,
'fee_amount'
=>
11.90
]);
}
...
...
@@ -332,6 +334,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
$this
->
checkContrib
([
'contribution_status_id'
=>
'Completed'
,
'trxn_id'
=>
'ch_mock'
,
'fee_amount'
=>
11.90
]);
}
...
...
@@ -496,6 +499,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
$this
->
checkContrib
([
'contribution_status_id'
=>
'Completed'
,
'trxn_id'
=>
'ch_mock'
,
'fee_amount'
=>
11.90
]);
$this
->
checkContribRecur
([
'contribution_status_id'
=>
'In Progress'
]);
}
...
...
@@ -533,6 +537,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
$this
->
checkContrib
([
'contribution_status_id'
=>
'Completed'
,
'trxn_id'
=>
'ch_mock'
,
'fee_amount'
=>
11.90
]);
$this
->
checkContribRecur
([
'contribution_status_id'
=>
'In Progress'
]);
}
...
...
@@ -731,6 +736,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
$this
->
checkContrib
([
'contribution_status_id'
=>
'Completed'
,
'trxn_id'
=>
'in_mock_2,ch_mock_2'
,
'fee_amount'
=>
11.90
],
(
int
)
$contrib2
[
'id'
]);
}
...
...
@@ -783,6 +789,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
$this
->
checkContrib
([
'contribution_status_id'
=>
'Completed'
,
'trxn_id'
=>
'in_mock_2,ch_mock_2'
,
'fee_amount'
=>
11.90
],
$contrib2
);
// Now trigger invoice.finalized. We expect that it does nothing?
...
...
@@ -810,6 +817,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
$this
->
checkContrib
([
'contribution_status_id'
=>
'Completed'
,
'trxn_id'
=>
'in_mock_2,ch_mock_2'
,
'fee_amount'
=>
11.90
],
$contrib2
);
}
...
...
@@ -1009,6 +1017,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
$this
->
checkContrib
([
'contribution_status_id'
=>
'Completed'
,
'trxn_id'
=>
'in_mock_2,ch_mock_3'
,
'fee_amount'
=>
11.90
],
$contributions
[
1
]);
}
...
...
@@ -1067,6 +1076,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
$this
->
checkContrib
([
'contribution_status_id'
=>
'Completed'
,
'trxn_id'
=>
'ch_mock'
,
'fee_amount'
=>
11.90
]);
}
...
...
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