mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-03-06 17:49:24 +00:00
Stripe has a newer API called Prices where you can create a price for any product and it can either be recurring or one-time. The easy part is existing Plans work with the Prices API by passing a Plan ID, but objects are returned in the slightly-different Prices API object format. This commit is a refactor to the new API to handle the data in its new form, and lays the foundation for a one time payment plan to be added to any subscriptions product.
36 lines
815 B
JavaScript
36 lines
815 B
JavaScript
import Plan from "discourse/plugins/discourse-subscriptions/discourse/models/plan";
|
|
|
|
QUnit.module("discourse-patrons:model:plan");
|
|
|
|
QUnit.test("subscriptionRate", assert => {
|
|
const plan = Plan.create({
|
|
unit_amount: "2399",
|
|
currency: "aud",
|
|
recurring: {
|
|
interval: "month"
|
|
}
|
|
});
|
|
|
|
assert.equal(
|
|
plan.get("subscriptionRate"),
|
|
"23.99 AUD / month",
|
|
"it returns the formatted subscription rate"
|
|
);
|
|
});
|
|
|
|
QUnit.test("amountDollars", assert => {
|
|
const plan = Plan.create({ unit_amount: 2399 });
|
|
|
|
assert.equal(
|
|
plan.get("amountDollars"),
|
|
23.99,
|
|
"it returns the formatted dollar amount"
|
|
);
|
|
});
|
|
|
|
QUnit.test("amount", assert => {
|
|
const plan = Plan.create({ amountDollars: "22.12" });
|
|
|
|
assert.equal(plan.get("unit_amount"), 2212, "it returns the cents amount");
|
|
});
|