-
-
Save lsmith77/d42f57f7fa605542359ebafe7520ddb3 to your computer and use it in GitHub Desktop.
multi currency in Spark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/resources/views/vendor/spark/auth/register-common.blade.php b/resources/views/vendor/spark/auth/register-common.blade.php | |
index 4c78546..30cd926 100644 | |
--- a/resources/views/vendor/spark/auth/register-common.blade.php | |
+++ b/resources/views/vendor/spark/auth/register-common.blade.php | |
@@ -95,7 +95,7 @@ | |
</span> | |
<span v-else class="table-plan-text"> | |
- <strong class="table-plan-price">@{{ plan.price | currency }}</strong> | |
+ <strong class="table-plan-price">@{{ plan.price | currency(plan.attributes.currency, plan.attributes.currencyLocale) }}</strong> | |
@{{ plan.type == 'user' && spark.chargesUsersPerSeat ? '/ '+ spark.seatName : '' }} | |
@{{ plan.type == 'user' && spark.chargesUsersPerTeam ? '/ '+ __('teams.team') : '' }} | |
@{{ plan.type == 'team' && spark.chargesTeamsPerSeat ? '/ '+ spark.teamSeatName : '' }} | |
diff --git a/resources/views/vendor/spark/auth/register.blade.php b/resources/views/vendor/spark/auth/register.blade.php | |
index 91fe0d0..da26f96 100644 | |
--- a/resources/views/vendor/spark/auth/register.blade.php | |
+++ b/resources/views/vendor/spark/auth/register.blade.php | |
@@ -97,10 +97,10 @@ | |
<div class="col-md-6"> | |
<div class="alert alert-info" style="margin: 0;"> | |
- <strong>{{__('Tax')}}:</strong> @{{ taxAmount(selectedPlan) | currency }} | |
+ <strong>{{__('Tax')}}:</strong> @{{ taxAmount(selectedPlan) | currency(selectedPlan.attributes.currency, selectedPlan.attributes.currencyLocale) }} | |
<br><br> | |
<strong>{{__('Total Price Including Tax')}}:</strong> | |
- @{{ priceWithTax(selectedPlan) | currency }} | |
+ @{{ priceWithTax(selectedPlan) | currency(selectedPlan.attributes.currency, selectedPlan.attributes.currencyLocale) }} | |
@{{ selectedPlan.type == 'user' && spark.chargesUsersPerSeat ? '/ '+ spark.seatName : '' }} | |
@{{ selectedPlan.type == 'user' && spark.chargesUsersPerTeam ? '/ '+ __('teams.team') : '' }} | |
@{{ selectedPlan.type == 'team' && spark.chargesTeamsPerSeat ? '/ '+ spark.teamSeatName : '' }} | |
diff --git a/resources/views/vendor/spark/kiosk/metrics.blade.php b/resources/views/vendor/spark/kiosk/metrics.blade.php | |
index cbbe166..37705b9 100644 | |
--- a/resources/views/vendor/spark/kiosk/metrics.blade.php | |
+++ b/resources/views/vendor/spark/kiosk/metrics.blade.php | |
@@ -21,11 +21,11 @@ | |
{{__('Recurring Revenue')}} | |
</h2> | |
<p class="metric-stat mb-0"> | |
- @{{ monthlyRecurringRevenue | currency }} | |
+ @{{ monthlyRecurringRevenue | currency() }} | |
<span class="metric-unit">/ {{__('mo')}}</span> | |
</p> | |
<p class="metric-stat-sm mb-0"> | |
- @{{ yearlyRecurringRevenue | currency }} / {{__('yr')}} | |
+ @{{ yearlyRecurringRevenue | currency() }} / {{__('yr')}} | |
</p> | |
</div> | |
</div> | |
@@ -42,7 +42,7 @@ | |
{{__('Total Volume')}} | |
</h2> | |
<p class="metric-stat"> | |
- @{{ totalVolume | currency }} | |
+ @{{ totalVolume | currency() }} | |
</p> | |
</div> | |
</div> | |
diff --git a/resources/views/vendor/spark/kiosk/profile.blade.php b/resources/views/vendor/spark/kiosk/profile.blade.php | |
index 2813feb..2118940 100644 | |
--- a/resources/views/vendor/spark/kiosk/profile.blade.php | |
+++ b/resources/views/vendor/spark/kiosk/profile.blade.php | |
@@ -58,7 +58,7 @@ | |
<!-- Total Revenue --> | |
<p> | |
- <strong>{{__('Total Revenue')}}:</strong> @{{ revenue | currency }} | |
+ <strong>{{__('Total Revenue')}}:</strong> @{{ revenue | currency() }} | |
</p> | |
</div> | |
</div> | |
diff --git a/resources/views/vendor/spark/settings/invoices/invoice-list.blade.php b/resources/views/vendor/spark/settings/invoices/invoice-list.blade.php | |
index 670bbd5..dacc3dd 100644 | |
--- a/resources/views/vendor/spark/settings/invoices/invoice-list.blade.php | |
+++ b/resources/views/vendor/spark/settings/invoices/invoice-list.blade.php | |
@@ -17,7 +17,7 @@ | |
<!-- Invoice Total --> | |
<td> | |
- @{{ invoice.total | currency }} | |
+ @{{ invoice.total | currency() }} | |
</td> | |
<!-- Invoice Download Button --> | |
diff --git a/resources/views/vendor/spark/settings/subscription/resume-subscription.blade.php b/resources/views/vendor/spark/settings/subscription/resume-subscription.blade.php | |
index 80ac745..ce50aa4 100644 | |
--- a/resources/views/vendor/spark/settings/subscription/resume-subscription.blade.php | |
+++ b/resources/views/vendor/spark/settings/subscription/resume-subscription.blade.php | |
@@ -74,7 +74,7 @@ | |
<!-- Plan Price --> | |
<td> | |
<div> | |
- <strong class="table-plan-price">@{{ priceWithTax(plan) | currency }}</strong> | |
+ <strong class="table-plan-price">@{{ priceWithTax(plan) | currency(plan.attributes.currency, plan.attributes.currencyLocale) }}</strong> | |
@{{ plan.type == 'user' && spark.chargesUsersPerSeat ? '/ '+ spark.seatName : '' }} | |
@{{ plan.type == 'user' && spark.chargesUsersPerTeam ? '/ '+ __('teams.team') : '' }} | |
@{{ plan.type == 'team' && spark.chargesTeamsPerSeat ? '/ '+ spark.teamSeatName : '' }} | |
diff --git a/resources/views/vendor/spark/settings/subscription/subscribe-common.blade.php b/resources/views/vendor/spark/settings/subscription/subscribe-common.blade.php | |
index 0ae5722..09c50c9 100644 | |
--- a/resources/views/vendor/spark/settings/subscription/subscribe-common.blade.php | |
+++ b/resources/views/vendor/spark/settings/subscription/subscribe-common.blade.php | |
@@ -64,7 +64,7 @@ | |
<!-- Plan Price --> | |
<td> | |
<span class="table-plan-text"> | |
- <strong class="table-plan-price">@{{ plan.price | currency }}</strong> | |
+ <strong class="table-plan-price">@{{ plan.price | currency(plan.attributes.currency, plan.attributes.currencyLocale) }}</strong> | |
@{{ plan.type == 'user' && spark.chargesUsersPerSeat ? '/ '+ spark.seatName : '' }} | |
@{{ plan.type == 'user' && spark.chargesUsersPerTeam ? '/ '+ __('teams.team') : '' }} | |
@{{ plan.type == 'team' && spark.chargesTeamsPerSeat ? '/ '+ spark.teamSeatName : '' }} | |
diff --git a/resources/views/vendor/spark/settings/subscription/subscribe.blade.php b/resources/views/vendor/spark/settings/subscription/subscribe.blade.php | |
index 094fe3e..4249492 100644 | |
--- a/resources/views/vendor/spark/settings/subscription/subscribe.blade.php | |
+++ b/resources/views/vendor/spark/settings/subscription/subscribe.blade.php | |
@@ -82,10 +82,10 @@ | |
<div class="col-md-6"> | |
<div class="alert alert-info" style="margin: 0;"> | |
- <strong>{{__('Tax')}}:</strong> @{{ taxAmount(selectedPlan) | currency }} | |
+ <strong>{{__('Tax')}}:</strong> @{{ taxAmount(selectedPlan) | currency(selectedPlan.attributes.currency, selectedPlan.attributes.currencyLocale) }} | |
<br><br> | |
<strong>{{__('Total Price Including Tax')}}:</strong> | |
- @{{ priceWithTax(selectedPlan) | currency }} | |
+ @{{ priceWithTax(selectedPlan) | currency(selectedPlan.attributes.currency, selectedPlan.attributes.currencyLocale) }} | |
@{{ selectedPlan.type == 'user' && spark.chargesUsersPerSeat ? '/ '+ spark.seatName : '' }} | |
@{{ selectedPlan.type == 'user' && spark.chargesUsersPerTeam ? '/ '+ __('teams.team') : '' }} | |
@{{ selectedPlan.type == 'team' && spark.chargesTeamsPerSeat ? '/ '+ spark.teamSeatName : '' }} | |
diff --git a/resources/views/vendor/spark/settings/subscription/update-subscription.blade.php b/resources/views/vendor/spark/settings/subscription/update-subscription.blade.php | |
index 05937b1..33bbb45 100644 | |
--- a/resources/views/vendor/spark/settings/subscription/update-subscription.blade.php | |
+++ b/resources/views/vendor/spark/settings/subscription/update-subscription.blade.php | |
@@ -83,7 +83,7 @@ | |
</span> | |
<span v-else> | |
- <strong class="table-plan-price">@{{ priceWithTax(plan) | currency }}</strong> | |
+ <strong class="table-plan-price">@{{ priceWithTax(plan) | currency(plan.attributes.currency, plan.attributes.currencyLocale) }}</strong> | |
@{{ plan.type == 'user' && spark.chargesUsersPerSeat ? '/ '+ spark.seatName : '' }} | |
@{{ plan.type == 'user' && spark.chargesUsersPerTeam ? '/ '+ __('teams.team') : '' }} | |
@{{ plan.type == 'team' && spark.chargesTeamsPerSeat ? '/ '+ spark.teamSeatName : '' }} | |
diff --git a/spark/resources/assets/js/filters.js b/spark/resources/assets/js/filters.js | |
index bfa3cfd..d103b1b 100644 | |
--- a/spark/resources/assets/js/filters.js | |
+++ b/spark/resources/assets/js/filters.js | |
@@ -40,11 +40,15 @@ Vue.filter('capitalize', value => { | |
/** | |
* Format the given money value. | |
*/ | |
-Vue.filter('currency', value => { | |
+Vue.filter('currency', (value, currency = null, currencyLocale = null) => { | |
+console.log(currency); | |
const Dinero = require('dinero.js').default | |
+ currency = currency ? currency : window.Spark.currency; | |
+ currencyLocale = currencyLocale ? currencyLocale : window.Spark.currencyLocale; | |
+ | |
return Dinero({ | |
amount: Math.round(value * 100), | |
- currency: window.Spark.currency | |
- }).setLocale(window.Spark.currencyLocale).toFormat('$0,0.00'); | |
-}); | |
\ No newline at end of file | |
+ currency: currency | |
+ }).setLocale(currencyLocale).toFormat('$0,0.00'); | |
+}); | |
diff --git a/spark/src/Plan.php b/spark/src/Plan.php | |
index 725bcd5..1dd23ca 100644 | |
--- a/spark/src/Plan.php | |
+++ b/spark/src/Plan.php | |
@@ -81,6 +81,11 @@ class Plan implements JsonSerializable | |
{ | |
$this->id = $id; | |
$this->name = $name; | |
+ | |
+ $this->attributes = [ | |
+ 'currency' => config('cashier.currency'), | |
+ 'currencyLocale' => config('cashier.currency_locale'), | |
+ ]; | |
} | |
/** |
actually it probably makes sense to simply send the plan attributes to the vue filter to handle the fallback there and then there is no need to force the attributes on the Plan object.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not sure if you think its ok to force the attributes on the plan in the constructor like that
also not sure if the currency filter should not just accept a plan instance and read the attributes itself rather than doing that in the template.