set the currency in the plan
This commit is contained in:
parent
1671d00ffe
commit
709aebb593
|
@ -42,7 +42,9 @@ module DiscoursePatrons
|
|||
begin
|
||||
plan = ::Stripe::Plan.retrieve(params[:id])
|
||||
|
||||
render_json_dump plan
|
||||
serialized = plan.to_h.merge(currency: plan[:currency].upcase)
|
||||
|
||||
render_json_dump serialized
|
||||
|
||||
rescue ::Stripe::InvalidRequestError => e
|
||||
return render_json_error e.message
|
||||
|
|
|
@ -2,6 +2,9 @@ import computed from "ember-addons/ember-computed-decorators";
|
|||
import DiscourseURL from "discourse/lib/url";
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
// Also defined in settings.
|
||||
currencies: ['AUD', 'CAD', 'EUR', 'GBP', 'USD'],
|
||||
|
||||
@computed("model.plan.isNew")
|
||||
planFieldDisabled(isNew) {
|
||||
return !isNew;
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
export default Ember.Helper.helper(function(params) {
|
||||
let currencySign;
|
||||
|
||||
switch (Discourse.SiteSettings.discourse_patrons_currency) {
|
||||
switch (params[0]) {
|
||||
case "EUR":
|
||||
case "eur":
|
||||
currencySign = "€";
|
||||
break;
|
||||
case "GBP":
|
||||
case "gbp":
|
||||
currencySign = "£";
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -13,6 +13,7 @@ export default Discourse.Route.extend({
|
|||
plan = AdminPlan.create({
|
||||
active: true,
|
||||
isNew: true,
|
||||
currency: Discourse.SiteSettings.discourse_patrons_currency,
|
||||
product: product.get("id")
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -22,7 +22,12 @@
|
|||
</p>
|
||||
<p>
|
||||
<label for="amount">{{i18n 'discourse_patrons.admin.plans.plan.amount'}}</label>
|
||||
{{input type="text" name="name" value=model.plan.amountDollars disabled=planFieldDisabled}}
|
||||
{{#if planFieldDisabled}}
|
||||
{{input class="plan-amount plan-currency" disabled=true value=model.plan.currency}}
|
||||
{{else}}
|
||||
{{combo-box disabled=planFieldDisabled content=currencies value=model.plan.currency}}
|
||||
{{/if}}
|
||||
{{input class="plan-amount" type="text" name="name" value=model.plan.amountDollars disabled=planFieldDisabled}}
|
||||
</p>
|
||||
<p>
|
||||
<label for="trial">
|
||||
|
|
|
@ -16,6 +16,14 @@ textarea[readonly] {
|
|||
}
|
||||
}
|
||||
|
||||
.plan-amount {
|
||||
position: relative;
|
||||
top: 2px;
|
||||
}
|
||||
.plan-currency {
|
||||
width: 70px;
|
||||
}
|
||||
|
||||
.td-right {
|
||||
text-align: right;
|
||||
}
|
||||
|
|
|
@ -88,6 +88,20 @@ module DiscoursePatrons
|
|||
end
|
||||
end
|
||||
|
||||
describe "show" do
|
||||
it "shows a plan" do
|
||||
::Stripe::Plan.expects(:retrieve).with('plan_12345')
|
||||
get "/patrons/admin/plans/plan_12345.json"
|
||||
expect(response.status).to eq 200
|
||||
end
|
||||
|
||||
it "upcases the currency" do
|
||||
::Stripe::Plan.expects(:retrieve).with('plan_12345').returns(currency: 'aud')
|
||||
get "/patrons/admin/plans/plan_12345.json"
|
||||
expect(response.body).to eq '{"currency":"AUD"}'
|
||||
end
|
||||
end
|
||||
|
||||
describe "create" do
|
||||
it "creates a plan with a nickname" do
|
||||
::Stripe::Plan.expects(:create).with(has_entry(:nickname, 'Veg'))
|
||||
|
|
Loading…
Reference in New Issue