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
e7ef5976
Commit
e7ef5976
authored
1 year ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Enhance tests to validate financialtrxn params including new 'available_on' field
parent
0b14c6e4
No related branches found
No related tags found
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
tests/phpunit/CRM/Stripe/BaseTest.php
+26
-0
26 additions, 0 deletions
tests/phpunit/CRM/Stripe/BaseTest.php
tests/phpunit/CRM/Stripe/IpnTest.php
+30
-5
30 additions, 5 deletions
tests/phpunit/CRM/Stripe/IpnTest.php
with
56 additions
and
5 deletions
tests/phpunit/CRM/Stripe/BaseTest.php
+
26
−
0
View file @
e7ef5976
...
...
@@ -343,6 +343,32 @@ abstract class CRM_Stripe_BaseTest extends \PHPUnit\Framework\TestCase implement
}
}
/**
* Sugar for checking things on the FinancialTrxn.
*
* @param array $expectations key => value pairs.
* @param int $contributionID
* - if null, use this->contributionID
* - if array, assume it's the result of a contribution.getsingle
* - if int, load that contrib.
*/
protected
function
checkFinancialTrxn
(
array
$expectations
,
int
$contributionID
)
{
$this
->
assertGreaterThan
(
0
,
$contributionID
);
$latestFinancialTrxn
=
\Civi\Api4\FinancialTrxn
::
get
(
FALSE
)
->
addSelect
(
'*'
,
'custom.*'
)
->
addJoin
(
'Contribution AS contribution'
,
'LEFT'
,
'EntityFinancialTrxn'
)
->
addWhere
(
'contribution.id'
,
'='
,
$contributionID
)
->
addWhere
(
'is_payment'
,
'='
,
TRUE
)
->
addOrderBy
(
'id'
,
'DESC'
)
->
execute
()
->
first
();
foreach
(
$expectations
as
$field
=>
$expect
)
{
$this
->
assertArrayHasKey
(
$field
,
$latestFinancialTrxn
);
$this
->
assertEquals
(
$expect
,
$latestFinancialTrxn
[
$field
],
"Expected FinancialTrxn.
$field
= "
.
json_encode
(
$expect
));
}
}
/**
* Sugar for checking things on the contribution recur.
*/
...
...
This diff is collapsed.
Click to expand it.
tests/phpunit/CRM/Stripe/IpnTest.php
+
30
−
5
View file @
e7ef5976
...
...
@@ -73,7 +73,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
]);
$this
->
assertEquals
(
TRUE
,
$success
,
'IPN did not return OK'
);
//
Ensure Contribution status is updat
ed
t
o co
mplete and that we now have both invoice ID and charge ID as the transaction ID.
//
charge is not yet captur
ed
s
o co
ntribution should remain pending
$this
->
checkContrib
([
'contribution_status_id'
=>
'Pending'
,
'trxn_id'
=>
'ch_mock'
,
...
...
@@ -336,6 +336,17 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
'trxn_id'
=>
'ch_mock'
,
'fee_amount'
=>
11.90
]);
// Check we set some values on the FinancialTrxn (payment)
$this
->
checkFinancialTrxn
([
'Payment_details.available_on'
=>
'2023-06-10 21:05:05'
,
'fee_amount'
=>
11.90
,
'total_amount'
=>
$this
->
total
,
'order_reference'
=>
'ch_mock'
,
'trxn_id'
=>
'ch_mock'
],
$this
->
contributionID
);
}
/**
...
...
@@ -734,11 +745,23 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
],
TRUE
);
// Check the contribution was updated.
$this
->
checkContrib
([
'contribution_status_id'
=>
'Completed'
,
'trxn_id'
=>
'in_mock_2,ch_mock_2'
,
'fee_amount'
=>
11.90
],
(
int
)
$contrib2
[
'id'
]);
'contribution_status_id'
=>
'Completed'
,
'trxn_id'
=>
'in_mock_2,ch_mock_2'
,
'fee_amount'
=>
11.90
],
(
int
)
$contrib2
[
'id'
]
);
// Check we set some values on the FinancialTrxn (payment)
$this
->
checkFinancialTrxn
([
'Payment_details.available_on'
=>
'2023-06-10 21:05:05'
,
'fee_amount'
=>
11.90
,
'total_amount'
=>
$this
->
total
,
'order_reference'
=>
'in_mock_2'
,
'trxn_id'
=>
'ch_mock_2'
],
(
int
)
$contrib2
[
'id'
]
);
}
/**
* It's possible that the payment_succeeded event comes in before finalized.
...
...
@@ -1222,6 +1245,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
'fee'
=>
1190
,
/* means $11.90 */
'status'
=>
'available'
,
'type'
=>
'charge'
,
'available_on'
=>
'1686427505'
// 2023-06-10 21:05:05
]);
$this
->
paymentObject
->
stripeClient
->
balanceTransactions
=
$this
->
createMock
(
'Stripe\\Service\\BalanceTransactionService'
);
...
...
@@ -1343,6 +1367,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
'currency'
=>
'usd'
,
'exchange_rate'
=>
NULL
,
'object'
=>
'balance_transaction'
,
'available_on'
=>
'1686427505'
// 2023-06-10 21:05:05
]));
$mockRefund
=
new
PropertySpy
(
'Refund'
,
[
...
...
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