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
b2114a2b
Commit
b2114a2b
authored
4 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Fix
#126
setting user locale for stripe elements
parent
bc18062a
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CRM/Core/Payment/Stripe.php
+1
-1
1 addition, 1 deletion
CRM/Core/Payment/Stripe.php
CRM/Stripe/Api.php
+33
-0
33 additions, 0 deletions
CRM/Stripe/Api.php
js/civicrm_stripe.js
+1
-0
1 addition, 0 deletions
js/civicrm_stripe.js
stripe.php
+1
-1
1 addition, 1 deletion
stripe.php
with
36 additions
and
2 deletions
CRM/Core/Payment/Stripe.php
+
1
−
1
View file @
b2114a2b
...
...
@@ -386,7 +386,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
'publishableKey'
=>
CRM_Core_Payment_Stripe
::
getPublicKeyById
(
$form
->
_paymentProcessor
[
'id'
]),
'jsDebug'
=>
(
boolean
)
\Civi
::
settings
()
->
get
(
'stripe_jsdebug'
),
'paymentProcessorTypeID'
=>
$form
->
_paymentProcessor
[
'payment_processor_type_id'
],
'locale'
=>
CRM_
Core_I18n
::
get
Locale
(),
'locale'
=>
CRM_
Stripe_Api
::
mapCiviCRMLocaleToStripe
Locale
(),
'apiVersion'
=>
CRM_Stripe_Check
::
API_VERSION
,
'csrfToken'
=>
class_exists
(
'\Civi\Firewall\Firewall'
)
?
\Civi\Firewall\Firewall
::
getCSRFToken
()
:
NULL
,
'country'
=>
\Civi
::
settings
()
->
get
(
'stripe_country'
),
...
...
This diff is collapsed.
Click to expand it.
CRM/Stripe/Api.php
+
33
−
0
View file @
b2114a2b
...
...
@@ -208,4 +208,37 @@ class CRM_Stripe_Api {
$amount
=
round
(
$amount
,
CRM_Utils_Money
::
getCurrencyPrecision
(
$currency
));
return
$amount
;
}
/**
* We have to map CiviCRM locales to a specific set of Stripe locales for elements to set the user language correctly.
* Reference: https://stripe.com/docs/js/appendix/supported_locales
* @param string $civiCRMLocale (eg. en_GB).
*
* @return string
*/
public
static
function
mapCiviCRMLocaleToStripeLocale
(
$civiCRMLocale
=
''
)
{
if
(
empty
(
$civiCRMLocale
))
{
$civiCRMLocale
=
CRM_Core_I18n
::
getLocale
();
}
$localeMap
=
[
'en_AU'
=>
'en'
,
'en_CA'
=>
'en'
,
'en_GB'
=>
'en-GB'
,
'en_US'
=>
'en'
,
'es_ES'
=>
'es'
,
'es_MX'
=>
'es-419'
,
'es_PR'
=>
'es-419'
,
'fr_FR'
=>
'fr'
,
'fr_CA'
=>
'fr-CA'
,
'pt_BR'
=>
'pt-BR'
,
'pt_PT'
=>
'pt'
,
'zh_CN'
=>
'zh'
,
'zh_HK'
=>
'zh-HK'
,
'zh_TW'
=>
'zh-TW'
];
if
(
array_key_exists
(
$civiCRMLocale
,
$localeMap
))
{
return
$localeMap
[
$civiCRMLocale
];
}
return
'auto'
;
}
}
This diff is collapsed.
Click to expand it.
js/civicrm_stripe.js
+
1
−
0
View file @
b2114a2b
...
...
@@ -396,6 +396,7 @@
debugging
(
'
New Stripe ID:
'
+
CRM
.
vars
.
stripe
.
id
+
'
pubKey:
'
+
CRM
.
vars
.
stripe
.
publishableKey
);
stripe
=
Stripe
(
CRM
.
vars
.
stripe
.
publishableKey
);
debugging
(
'
locale:
'
+
CRM
.
vars
.
stripe
.
locale
);
var
stripeElements
=
stripe
.
elements
({
locale
:
CRM
.
vars
.
stripe
.
locale
});
// By default we load paymentRequest button if we can, fallback to card element
...
...
This diff is collapsed.
Click to expand it.
stripe.php
+
1
−
1
View file @
b2114a2b
...
...
@@ -167,7 +167,7 @@ function stripe_civicrm_buildForm($formName, &$form) {
$jsVars
=
[
'id'
=>
$form
->
_paymentProcessor
[
'id'
],
'publishableKey'
=>
CRM_Core_Payment_Stripe
::
getPublicKeyById
(
$form
->
_paymentProcessor
[
'id'
]),
'locale'
=>
CRM_
Core_I18n
::
get
Locale
(),
'locale'
=>
CRM_
Stripe_Api
::
mapCiviCRMLocaleToStripe
Locale
(),
'apiVersion'
=>
CRM_Stripe_Check
::
API_VERSION
,
'jsDebug'
=>
(
boolean
)
\Civi
::
settings
()
->
get
(
'stripe_jsdebug'
),
'csrfToken'
=>
class_exists
(
'\Civi\Firewall\Firewall'
)
?
\Civi\Firewall\Firewall
::
getCSRFToken
()
:
NULL
,
...
...
This diff is collapsed.
Click to expand it.
mattwire
@mattwire
mentioned in issue
#126 (closed)
·
4 years ago
mentioned in issue
#126 (closed)
mentioned in issue #126
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