serialize and order the plans
This commit is contained in:
parent
5fe08c110f
commit
3dfa261c19
|
@ -10,8 +10,11 @@ module DiscoursePatrons
|
||||||
begin
|
begin
|
||||||
plans = ::Stripe::Plan.list(active: true)
|
plans = ::Stripe::Plan.list(active: true)
|
||||||
|
|
||||||
# TODO: Serialize. Remove some attributes like meta.group_name
|
serialized = plans[:data].map do |plan|
|
||||||
render_json_dump plans.data
|
plan.to_h.slice(:id, :amount, :currency, :interval)
|
||||||
|
end.sort_by { |plan| plan[:amount] }
|
||||||
|
|
||||||
|
render_json_dump serialized
|
||||||
|
|
||||||
rescue ::Stripe::InvalidRequestError => e
|
rescue ::Stripe::InvalidRequestError => e
|
||||||
return render_json_error e.message
|
return render_json_error e.message
|
||||||
|
|
|
@ -13,7 +13,5 @@ export default Ember.Helper.helper(function(params) {
|
||||||
currencySign = "$";
|
currencySign = "$";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return currencySign + params.map(p => p.toUpperCase()).join(' ');
|
return currencySign + params.map(p => p.toUpperCase()).join(' ');
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,6 +9,24 @@ module DiscoursePatrons
|
||||||
::Stripe::Plan.expects(:list).with(active: true)
|
::Stripe::Plan.expects(:list).with(active: true)
|
||||||
get "/patrons/plans.json"
|
get "/patrons/plans.json"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "orders and serialises the plans" do
|
||||||
|
::Stripe::Plan.expects(:list).returns({
|
||||||
|
data: [
|
||||||
|
{ id: 'plan_id123', amount: 1220, currency: 'aud', interval: 'year', metadata: {} },
|
||||||
|
{ id: 'plan_id234', amount: 1399, currency: 'usd', interval: 'year', metadata: {} },
|
||||||
|
{ id: 'plan_id678', amount: 1000, currency: 'aud', interval: 'week', metadata: {} }
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
get "/patrons/plans.json"
|
||||||
|
|
||||||
|
expect(JSON.parse(response.body)).to eq([
|
||||||
|
{ "amount" => 1000, "currency" => "aud", "id" => "plan_id678", "interval"=>"week" },
|
||||||
|
{ "amount" => 1220, "currency" => "aud", "id" => "plan_id123", "interval"=>"year" },
|
||||||
|
{ "amount" => 1399, "currency" => "usd", "id" => "plan_id234", "interval"=>"year" }
|
||||||
|
])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue