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
5c60b46d
Commit
5c60b46d
authored
4 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Fix #126 setting user locale for stripe elements
parent
2f4c61ce
Branches
Branches containing commit
Tags
Tags containing commit
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 @
5c60b46d
...
...
@@ -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 @
5c60b46d
...
...
@@ -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 @
5c60b46d
...
...
@@ -314,6 +314,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
});
var
style
=
{
...
...
This diff is collapsed.
Click to expand it.
stripe.php
+
1
−
1
View file @
5c60b46d
...
...
@@ -172,7 +172,7 @@ function stripe_civicrm_buildForm($formName, &$form) {
'paymentIntentStatus'
=>
$intent
->
status
,
'paymentIntentMethod'
=>
$intent
->
confirmation_method
,
'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.
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