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
d143e5d8
Commit
d143e5d8
authored
2 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Add test for full refund via webhook
parent
4acab742
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/phpunit/CRM/Stripe/BaseTest.php
+10
-1
10 additions, 1 deletion
tests/phpunit/CRM/Stripe/BaseTest.php
tests/phpunit/CRM/Stripe/IpnTest.php
+68
-2
68 additions, 2 deletions
tests/phpunit/CRM/Stripe/IpnTest.php
with
78 additions
and
3 deletions
tests/phpunit/CRM/Stripe/BaseTest.php
+
10
−
1
View file @
d143e5d8
...
...
@@ -131,8 +131,16 @@ abstract class CRM_Stripe_BaseTest extends \PHPUnit\Framework\TestCase implement
/**
* Submit to stripe
*
* @param array $params
*
* @return array The result from PaymentProcessor->doPayment
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @throws \Civi\Payment\Exception\PaymentProcessorException
* @throws \Stripe\Exception\ApiErrorException
*/
public
function
doPayment
(
$params
=
[])
{
public
function
doPayment
(
array
$params
=
[])
:
array
{
// Send in credit card to get payment method. xxx mock here
$paymentMethod
=
$this
->
paymentObject
->
stripeClient
->
paymentMethods
->
create
([
'type'
=>
'card'
,
...
...
@@ -210,6 +218,7 @@ abstract class CRM_Stripe_BaseTest extends \PHPUnit\Framework\TestCase implement
$this
->
processorID
=
$dao
->
processor_id
;
}
}
return
$ret
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
tests/phpunit/CRM/Stripe/IpnTest.php
+
68
−
2
View file @
d143e5d8
...
...
@@ -113,6 +113,51 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
]);
}
/**
* Test creating a one-off contribution and
* update it after creation.
*/
public
function
testNewOneOffChargeRefundedFull
()
{
$doPaymentResult
=
$this
->
mockOneOffPaymentSetup
();
if
(
$doPaymentResult
[
'payment_status'
]
===
'Completed'
)
{
$result
=
civicrm_api3
(
'Payment'
,
'create'
,
[
'trxn_id'
=>
$doPaymentResult
[
'trxn_id'
],
'total_amount'
=>
$this
->
total
,
'fee_amount'
=>
$doPaymentResult
[
'fee_amount'
],
'order_reference'
=>
$doPaymentResult
[
'order_reference'
],
'contribution_id'
=>
$this
->
contributionID
,
]);
}
$this
->
simulateEvent
([
'type'
=>
'charge.refunded'
,
'id'
=>
'evt_mock'
,
'object'
=>
'event'
,
// ?
'livemode'
=>
FALSE
,
'pending_webhooks'
=>
0
,
'request'
=>
[
'id'
=>
NULL
],
'data'
=>
[
'object'
=>
[
'id'
=>
'ch_mock'
,
'object'
=>
'charge'
,
'customer'
=>
'cus_mock'
,
'charge'
=>
'ch_mock'
,
'created'
=>
time
(),
'amount_refunded'
=>
$this
->
total
*
100
,
'status'
=>
'succeeded'
,
"captured"
=>
TRUE
,
]
],
]);
// Ensure Contribution status is updated to complete and that we now have both invoice ID and charge ID as the transaction ID.
$this
->
checkContrib
([
'contribution_status_id'
=>
'Refunded'
,
'trxn_id'
=>
'ch_mock,re_mock'
,
]);
}
/**
* Test creating a recurring contribution and
* update it after creation. @todo The membership should also be updated.
...
...
@@ -829,8 +874,14 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
* - ch_mock Charge
* - txn_mock Balance transaction
* - sub_mock Subscription
*
* @return array The result from doPayment()
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @throws \Civi\Payment\Exception\PaymentProcessorException
* @throws \Stripe\Exception\ApiErrorException
*/
protected
function
mockOneOffPaymentSetup
()
{
protected
function
mockOneOffPaymentSetup
()
:
array
{
PropertySpy
::
$buffer
=
'none'
;
// Set this to 'print' or 'log' maybe more helpful in debugging but for
// generally running tests 'exception' suits as we don't expect any output.
...
...
@@ -936,6 +987,19 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
'object'
=>
'balance_transaction'
,
]));
$mockRefund
=
new
PropertySpy
(
'Refund'
,
[
'amount_refunded'
=>
$this
->
total
*
100
,
'charge_id'
=>
'ch_mock'
,
//xxx
'created'
=>
time
(),
'currency'
=>
'usd'
,
'id'
=>
're_mock'
,
'object'
=>
'refund'
,
]);
$stripeClient
->
refunds
=
$this
->
createMock
(
'Stripe\\Service\\RefundService'
);
$stripeClient
->
refunds
->
method
(
'all'
)
->
willReturn
(
new
PropertySpy
(
'refunds.all'
,
[
'data'
=>
[
$mockRefund
]
]));
$this
->
setupTransaction
();
// Submit the payment.
$payment_extra_params
=
[
...
...
@@ -943,7 +1007,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
'paymentIntentID'
=>
'pi_mock'
,
];
$this
->
doPayment
(
$payment_extra_params
);
$doPaymentResult
=
$this
->
doPayment
(
$payment_extra_params
);
//
// Check the Contribution
...
...
@@ -954,6 +1018,8 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
'contribution_status_id'
=>
'Pending'
,
'trxn_id'
=>
'ch_mock'
,
]);
return
$doPaymentResult
;
}
/**
...
...
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