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
5bf3108b
Commit
5bf3108b
authored
5 years ago
by
mattwire
Committed by
mattwire
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Support partial refunds
parent
110c9b5f
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!78
6.3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Core/Payment/StripeIPN.php
+34
-22
34 additions, 22 deletions
CRM/Core/Payment/StripeIPN.php
CRM/Stripe/Check.php
+1
-1
1 addition, 1 deletion
CRM/Stripe/Check.php
with
35 additions
and
23 deletions
CRM/Core/Payment/StripeIPN.php
+
34
−
22
View file @
5bf3108b
...
...
@@ -72,12 +72,12 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
/**
* @var float The amount paid
*/
protected
$amount
=
NULL
;
protected
$amount
=
0.0
;
/**
* @var float The fee charged by Stripe
*/
protected
$fee
=
NULL
;
protected
$fee
=
0.0
;
/**
* @var array The current contribution (linked to Stripe charge(single)/invoice(subscription)
...
...
@@ -254,12 +254,21 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
};
// This charge was actually captured, so record the refund in CiviCRM
$this
->
setInfo
();
// This gives us the actual amount refunded
$amountRefunded
=
CRM_Stripe_Api
::
getObjectParam
(
'amount_refunded'
,
$this
->
_inputParameters
->
data
->
object
);
// This gives us the refund date + reason code
$refunds
=
\Stripe\Refund
::
all
([
'charge'
=>
$this
->
charge_id
,
'limit'
=>
1
]);
// This gets the fee refunded
$this
->
setBalanceTransactionDetails
(
$refunds
->
data
[
0
]
->
balance_transaction
);
$params
=
[
'id'
=>
$this
->
contribution
[
'id'
],
'payment_trxn_id'
=>
$this
->
charge_id
,
'cancel_reason'
=>
$refunds
->
data
[
0
]
->
reason
,
'cancel_date'
=>
date
(
'YmdHis'
,
$refunds
->
data
[
0
]
->
created
),
'contribution_id'
=>
$this
->
contribution
[
'id'
],
'total_amount'
=>
0
-
abs
(
$amountRefunded
),
'trxn_date'
=>
date
(
'YmdHis'
,
$refunds
->
data
[
0
]
->
created
),
'trxn_result_code'
=>
$refunds
->
data
[
0
]
->
reason
,
'fee_amount'
=>
0
-
abs
(
$this
->
fee
),
'trxn_id'
=>
$this
->
charge_id
,
'order_reference'
=>
$this
->
invoice_id
??
NULL
,
];
$this
->
updateContributionRefund
(
$params
);
return
TRUE
;
...
...
@@ -341,24 +350,9 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
$balanceTransactionID
=
CRM_Stripe_Api
::
getObjectParam
(
'balance_transaction'
,
$charge
);
}
else
{
$charge
=
$this
->
_inputParameters
->
data
->
object
;
$balanceTransactionID
=
CRM_Stripe_Api
::
getObjectParam
(
'balance_transaction'
,
$this
->
_inputParameters
->
data
->
object
);
}
// Gather info about the amount and fee.
// Get the Stripe charge object if one exists. Null charge still needs processing.
// If the transaction is declined, there won't be a balance_transaction_id.
$this
->
amount
=
0
;
$this
->
fee
=
0
;
if
(
$balanceTransactionID
)
{
try
{
$balanceTransaction
=
\Stripe\BalanceTransaction
::
retrieve
(
$balanceTransactionID
);
$this
->
amount
=
$charge
->
amount
/
100
;
$this
->
fee
=
$balanceTransaction
->
fee
/
100
;
}
catch
(
Exception
$e
)
{
$this
->
exception
(
'Error retrieving balance transaction. '
.
$e
->
getMessage
());
}
}
$this
->
setBalanceTransactionDetails
(
$balanceTransactionID
);
// Additional processing of values is only relevant if there is a subscription id.
if
(
$this
->
subscription_id
)
{
...
...
@@ -427,6 +421,24 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
}
}
private
function
setBalanceTransactionDetails
(
$balanceTransactionID
)
{
// Gather info about the amount and fee.
// Get the Stripe charge object if one exists. Null charge still needs processing.
// If the transaction is declined, there won't be a balance_transaction_id.
$this
->
amount
=
0.0
;
$this
->
fee
=
0.0
;
if
(
$balanceTransactionID
)
{
try
{
$balanceTransaction
=
\Stripe\BalanceTransaction
::
retrieve
(
$balanceTransactionID
);
$this
->
amount
=
$balanceTransaction
->
amount
/
100
;
$this
->
fee
=
$balanceTransaction
->
fee
/
100
;
}
catch
(
Exception
$e
)
{
$this
->
exception
(
'Error retrieving balance transaction. '
.
$e
->
getMessage
());
}
}
}
/**
* This allows us to end a subscription once:
* a) We've reached the end date / number of installments
...
...
This diff is collapsed.
Click to expand it.
CRM/Stripe/Check.php
+
1
−
1
View file @
5bf3108b
...
...
@@ -10,7 +10,7 @@ use CRM_Stripe_ExtensionUtil as E;
*/
class
CRM_Stripe_Check
{
const
MIN_VERSION_MJWSHARED
=
'0.
5
'
;
const
MIN_VERSION_MJWSHARED
=
'0.
6
'
;
public
static
function
checkRequirements
(
&
$messages
)
{
$extensions
=
civicrm_api3
(
'Extension'
,
'get'
,
[
...
...
This diff is collapsed.
Click to expand it.
mattwire
@mattwire
mentioned in issue
#111 (closed)
·
5 years ago
mentioned in issue
#111 (closed)
mentioned in issue #111
Toggle commit list
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