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

Tweaks to default currency conversion

parent eaf77eb6
Branches
Tags
No related merge requests found
......@@ -723,12 +723,14 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
$errorMessage = $this->handleErrorNotification($err, $params['stripe_error_url']);
throw new \Civi\Payment\Exception\PaymentProcessorException('Failed to retrieve Stripe Balance Transaction: ' . $errorMessage);
}
if (($stripeCharge['currency'] !== $stripeBalanceTransaction['currency'])
&& (!empty($stripeBalanceTransaction['exchange_rate']))) {
if (($stripeCharge['currency'] !== $stripeBalanceTransaction->currency)
&& (!empty($stripeBalanceTransaction->exchange_rate))) {
$newParams['fee_amount'] = CRM_Stripe_Api::currencyConversion($stripeBalanceTransaction->fee, $stripeBalanceTransaction['exchange_rate'], $stripeCharge['currency']);
}
else {
$newParams['fee_amount'] = $stripeBalanceTransaction->fee / 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($stripeBalanceTransaction->fee / 100, CRM_Utils_Money::getCurrencyPrecision($stripeCharge['currency']));
}
// Success!
// Set the desired contribution status which will be set later (do not set on the contribution here!)
......
......@@ -448,8 +448,10 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
$this->amount = CRM_Stripe_Api::currencyConversion($balanceTransaction->amount, $balanceTransaction->exchange_rate, $currency);
$this->fee = CRM_Stripe_Api::currencyConversion($balanceTransaction->fee, $balanceTransaction->exchange_rate, $currency);
} else {
$this->amount = $balanceTransaction->amount / 100;
$this->fee = $balanceTransaction->fee / 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.
$this->amount = round($balanceTransaction->amount / 100, CRM_Utils_Money::getCurrencyPrecision($currency));
$this->fee = round($balanceTransaction->fee / 100, CRM_Utils_Money::getCurrencyPrecision($currency));
}
}
catch(Exception $e) {
......
......@@ -46,6 +46,9 @@ class CRM_Stripe_Api {
case 'captured':
return (bool) $stripeObject->captured;
case 'currency':
return (string) mb_strtoupper($stripeObject->currency);
}
break;
......@@ -192,14 +195,15 @@ class CRM_Stripe_Api {
}
return NULL;
}
/**
* Convert amount to a new currency
*
* @param type $amount
* @param type $exchangeRate
* @param type $currency
* @return type
*
* @param float $amount
* @param float $exchangeRate
* @param string $currency
*
* @return float
*/
public static function currencyConversion($amount, $exchangeRate, $currency) {
$amount = ($amount / $exchangeRate) / 100;
......
......@@ -30,9 +30,10 @@ Where:
#### Bugfixes:
* Make sure we generate backend contact links for customer metadata (previously they would sometimes get generated as frontend links).
* If Stripe is not using the same currency as the payment was made we need to convert the fees/net amounts back to the CiviCRM currency.
* Fix missing receipts for recurring subscription payment [#122](https://lab.civicrm.org/extensions/stripe/issues/122).
* Fix [#178](https://lab.civicrm.org/extensions/stripe/issues/122) recurring payments for webform_civicrm when "Interval of installments" is selected.
* Fix [#178](https://lab.civicrm.org/extensions/stripe/issues/178) recurring payments for webform_civicrm when "Interval of installments" is selected.
* If Stripe is not using the same currency as the payment was made we need to convert the fees/net amounts back to the CiviCRM currency.
* Fix [#196](https://lab.civicrm.org/extensions/stripe/issues/196) Recurring contributions with incorrect amount per default currency in stripe - if Stripe uses a different currency to CiviCRM the amounts for recurring contributions were not being recorded correctly in CiviCRM.
#### Behind the scenes:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment