Skip to content
Snippets Groups Projects
Commit 58f661cd authored by mattwire's avatar mattwire
Browse files

Set the decimal places for the fee amount before saving

parent 0a6b63fc
Branches
Tags
1 merge request!1096.4
......@@ -10,6 +10,7 @@
*/
use CRM_Stripe_ExtensionUtil as E;
use Civi\Payment\PropertyBag;
/**
* Class CRM_Core_Payment_Stripe
......@@ -165,7 +166,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
*
* Handle any inconsistency about how it is passed in here.
*
* @param array $params
* @param array|PropertyBag $params
*
* @return string
*/
......@@ -432,7 +433,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
* https://stripe.com/docs/api?lang=php
* Payment processors should set payment_status_id.
*
* @param array $params
* @param array|PropertyBag $params
* Assoc array of input parameters for this transaction.
* @param string $component
*
......@@ -725,12 +726,13 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
if (($stripeCharge['currency'] !== $stripeBalanceTransaction['currency'])
&& (!empty($stripeBalanceTransaction['exchange_rate']))) {
$newParams['fee_amount'] = ($stripeBalanceTransaction->fee / $stripeBalanceTransaction['exchange_rate']) / 100;
$newParams['net_amount'] = ($stripeBalanceTransaction->net / $stripeBalanceTransaction['exchange_rate']) / 100;
}
else {
$newParams['fee_amount'] = $stripeBalanceTransaction->fee / 100;
$newParams['net_amount'] = $stripeBalanceTransaction->net / 100;
}
// We must round to currency precision otherwise payments may fail because Contribute BAO saves but then
// can't retrieve because it tries to use the full unrounded number when it only got saved with 2dp.
$newParams['fee_amount'] = round($newParams['fee_amount'], CRM_Utils_Money::getCurrencyPrecision($stripeCharge['currency']));
// Success!
// Set the desired contribution status which will be set later (do not set on the contribution here!)
$params['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment