Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoming committed Sep 14, 2023
1 parent 00f14ac commit 2397c23
Show file tree
Hide file tree
Showing 13 changed files with 1,047 additions and 781 deletions.
110 changes: 90 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,12 @@ The Reactjs application needs the `price_id` from Stripe to integrate with the S
},
"plans": [
{
"id": "free",
"title": "Free",
"popular": false,
"priceId": "price_1...",
"priceIds": [
"price_1..."
],
"currency": "$",
"price": 0,
"frequency": "week",
Expand All @@ -186,12 +189,17 @@ The Reactjs application needs the `price_id` from Stripe to integrate with the S
"2 GB of storage",
"Help center access",
"Email support"
]
],
"free": true,
"legacy": false
},
{
"title": "Weekly",
"id": "pro",
"title": "Pro",
"popular": true,
"priceId": "price_2...",
"priceIds": [
"price_2..."
],
"currency": "$",
"price": 10,
"frequency": "week",
Expand All @@ -200,21 +208,48 @@ The Reactjs application needs the `price_id` from Stripe to integrate with the S
"10 GB of storage",
"Help center access",
"Priority email support"
]
],
"free": false,
"legacy": false
},
{
"title": "Daily",
"id": "enterprise",
"title": "Enterprise",
"popular": false,
"priceId": "price_3...",
"priceIds": [
"price_3...",
"price_4..."
],
"currency": "$",
"price": 5,
"frequency": "day",
"price": 30,
"frequency": "week",
"description": [
"50 users included",
"30 GB of storage",
"Help center access",
"Phone & email support"
]
],
"free": false,
"legacy": false
},
{
"id": "legcy",
"title": "Gold",
"popular": true,
"priceIds": [
"price_2..."
],
"currency": "$",
"price": 10,
"frequency": "week",
"description": [
"20 users included",
"10 GB of storage",
"Help center access",
"Priority email support"
],
"free": false,
"legacy": true
}
],
"permissions": {
Expand Down Expand Up @@ -257,9 +292,12 @@ For sending new user invites, the `mailgun` JSON is needed. The details are cove
},
"plans": [
{
"id": "free",
"title": "Free",
"popular": false,
"priceId": "price_1...",
"priceIds": [
"price_1..."
],
"currency": "$",
"price": 0,
"frequency": "week",
Expand All @@ -268,12 +306,17 @@ For sending new user invites, the `mailgun` JSON is needed. The details are cove
"2 GB of storage",
"Help center access",
"Email support"
]
],
"free": true,
"legacy": false
},
{
"title": "Weekly",
"id": "pro",
"title": "Pro",
"popular": true,
"priceId": "price_2...",
"priceIds": [
"price_2..."
],
"currency": "$",
"price": 10,
"frequency": "week",
Expand All @@ -282,21 +325,48 @@ For sending new user invites, the `mailgun` JSON is needed. The details are cove
"10 GB of storage",
"Help center access",
"Priority email support"
]
],
"free": false,
"legacy": false
},
{
"title": "Daily",
"id": "enterprise",
"title": "Enterprise",
"popular": false,
"priceId": "price_3...",
"priceIds": [
"price_3...",
"price_4..."
],
"currency": "$",
"price": 5,
"frequency": "day",
"price": 30,
"frequency": "week",
"description": [
"50 users included",
"30 GB of storage",
"Help center access",
"Phone & email support"
]
],
"free": false,
"legacy": false
},
{
"id": "legcy",
"title": "Gold",
"popular": true,
"priceIds": [
"price_2..."
],
"currency": "$",
"price": 10,
"frequency": "week",
"description": [
"20 users included",
"10 GB of storage",
"Help center access",
"Priority email support"
],
"free": false,
"legacy": true
}
],
"permissions": {
Expand Down
14 changes: 7 additions & 7 deletions dist/cjs/components/ChangePlan.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ const ChangePlan = () => {
const selectPlan = plan => {
setProcessing(true);
setError(null);
if (plan.price === 0 || subscription.paymentMethod) {
if (plan.free || subscription.paymentMethod) {
// subscribe to the new plan
const changeSubscriptionPlan = (0, _functions.httpsCallable)(functionsInstance, 'fireactjsSaas-changeSubscriptionPlan');
changeSubscriptionPlan({
paymentMethodId: subscription.paymentMethod,
priceId: plan.priceId,
planId: plan.id,
subscriptionId: subscription.id
}).then(() => {
setSubscription(prevState => _objectSpread(_objectSpread({}, prevState), {}, {
plan: plan.title,
// title of the plan
stripePriceId: plan.priceId,
planId: plan.id,
// price ID in stripe
paymentCycle: plan.frequency,
price: plan.price,
Expand All @@ -82,7 +82,7 @@ const ChangePlan = () => {
const changeSubscriptionPlan = (0, _functions.httpsCallable)(functionsInstance, 'fireactjsSaas-changeSubscriptionPlan');
changeSubscriptionPlan({
paymentMethodId: paymentMethod.id,
priceId: selectedPlan.priceId,
planId: selectedPlan.id,
subscriptionId: subscription.id
}).then(() => {
const pmRef = (0, _firestore.doc)(firestoreInstance, 'users/' + authInstance.currentUser.uid + '/paymentMethods/' + paymentMethod.id);
Expand All @@ -99,7 +99,7 @@ const ChangePlan = () => {
setSubscription(prevState => _objectSpread(_objectSpread({}, prevState), {}, {
plan: selectedPlan.title,
// title of the plan
stripePriceId: selectedPlan.priceId,
planId: selectedPlan.id,
// price ID in stripe
paymentCycle: selectedPlan.frequency,
price: selectedPlan.price,
Expand All @@ -116,7 +116,7 @@ const ChangePlan = () => {
return /*#__PURE__*/_react.default.createElement(_material.Container, {
maxWidth: "lg"
}, /*#__PURE__*/_react.default.createElement(_core.SetPageTitle, {
title: "Change Plan" + (subscription.name !== "" ? " - " + subscription.name : "")
title: "Change Plan" + (subscription.name !== "" && typeof subscription.name !== 'undefined' ? " - " + subscription.name : "")
}), success ? /*#__PURE__*/_react.default.createElement(_material.Alert, {
severity: "success"
}, "Your subscription plan has been changed. Please go back to ", /*#__PURE__*/_react.default.createElement(_reactRouterDom.NavLink, {
Expand Down Expand Up @@ -148,7 +148,7 @@ const ChangePlan = () => {
}, "Choose a Plan"), error !== null && /*#__PURE__*/_react.default.createElement(_material.Alert, {
severity: "error"
}, error), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_PricingPlans.PricingPlans, {
selectedPriceId: subscription.stripePriceId,
selectedPlanId: subscription.planId,
selectPlan: selectPlan,
disabled: processing,
paymentMethod: subscription.paymentMethod
Expand Down
7 changes: 4 additions & 3 deletions dist/cjs/components/CreateSubscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ const CreateSubscription = () => {
const selectPlan = plan => {
setProcessing(true);
setError(null);
if (plan.price === 0) {
if (plan.free) {
// subscribe to free plans on selection
const createSubscription = (0, _functions.httpsCallable)(functionsInstance, 'fireactjsSaas-createSubscription');
createSubscription({
priceId: plan.priceId,
planId: plan.id,
paymentMethodId: null
}).then(res => {
if (res.data && res.data.subscriptionId) {
Expand All @@ -67,7 +68,7 @@ const CreateSubscription = () => {
let subscriptionId = null;
createSubscription({
paymentMethodId: paymentMethod.id,
priceId: selectedPlan.priceId
planId: selectedPlan.id
}).then(res => {
if (res.data && res.data.subscriptionId) {
subscriptionId = res.data.subscriptionId;
Expand Down
8 changes: 4 additions & 4 deletions dist/cjs/components/PricingPlans.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const PricingPlans = _ref => {
let {
selectedPriceId,
selectedPlanId,
disabled,
selectPlan,
paymentMethod
Expand All @@ -30,7 +30,7 @@ const PricingPlans = _ref => {
container: true,
spacing: 5,
alignItems: "flex-end"
}, plans.map((plan, i) => /*#__PURE__*/_react.default.createElement(_material.Grid, {
}, plans.map((plan, i) => plan.legacy === false && /*#__PURE__*/_react.default.createElement(_material.Grid, {
item: true,
key: i,
xs: 12,
Expand Down Expand Up @@ -80,11 +80,11 @@ const PricingPlans = _ref => {
key: line
}, line)))), /*#__PURE__*/_react.default.createElement(_material.CardActions, null, /*#__PURE__*/_react.default.createElement(_material.Button, {
fullWidth: true,
disabled: disabled || selectedPriceId === plan.priceId ? true : false,
disabled: disabled || selectedPlanId === plan.id ? true : false,
variant: plan.popular ? "contained" : "outlined",
onClick: e => {
selectPlan(plan);
}
}, plan.price === 0 || paymentMethod ? "Subscribe" : "Continue"))))));
}, plan.free || paymentMethod ? "Subscribe" : "Continue"))))));
};
exports.PricingPlans = PricingPlans;
1 change: 0 additions & 1 deletion dist/cjs/components/SubscriptionContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const SubscriptionProvider = _ref => {
if (docSnap.exists()) {
const sub = docSnap.data();
sub.id = subscriptionId;
console.log(sub);
setSubscription(sub);
} else {
// no subscription
Expand Down
14 changes: 7 additions & 7 deletions dist/esm/components/ChangePlan.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ export const ChangePlan = () => {
const selectPlan = plan => {
setProcessing(true);
setError(null);
if (plan.price === 0 || subscription.paymentMethod) {
if (plan.free || subscription.paymentMethod) {
// subscribe to the new plan
const changeSubscriptionPlan = httpsCallable(functionsInstance, 'fireactjsSaas-changeSubscriptionPlan');
changeSubscriptionPlan({
paymentMethodId: subscription.paymentMethod,
priceId: plan.priceId,
planId: plan.id,
subscriptionId: subscription.id
}).then(() => {
setSubscription(prevState => _objectSpread(_objectSpread({}, prevState), {}, {
plan: plan.title,
// title of the plan
stripePriceId: plan.priceId,
planId: plan.id,
// price ID in stripe
paymentCycle: plan.frequency,
price: plan.price,
Expand All @@ -73,7 +73,7 @@ export const ChangePlan = () => {
const changeSubscriptionPlan = httpsCallable(functionsInstance, 'fireactjsSaas-changeSubscriptionPlan');
changeSubscriptionPlan({
paymentMethodId: paymentMethod.id,
priceId: selectedPlan.priceId,
planId: selectedPlan.id,
subscriptionId: subscription.id
}).then(() => {
const pmRef = doc(firestoreInstance, 'users/' + authInstance.currentUser.uid + '/paymentMethods/' + paymentMethod.id);
Expand All @@ -90,7 +90,7 @@ export const ChangePlan = () => {
setSubscription(prevState => _objectSpread(_objectSpread({}, prevState), {}, {
plan: selectedPlan.title,
// title of the plan
stripePriceId: selectedPlan.priceId,
planId: selectedPlan.id,
// price ID in stripe
paymentCycle: selectedPlan.frequency,
price: selectedPlan.price,
Expand All @@ -107,7 +107,7 @@ export const ChangePlan = () => {
return /*#__PURE__*/React.createElement(Container, {
maxWidth: "lg"
}, /*#__PURE__*/React.createElement(SetPageTitle, {
title: "Change Plan" + (subscription.name !== "" ? " - " + subscription.name : "")
title: "Change Plan" + (subscription.name !== "" && typeof subscription.name !== 'undefined' ? " - " + subscription.name : "")
}), success ? /*#__PURE__*/React.createElement(Alert, {
severity: "success"
}, "Your subscription plan has been changed. Please go back to ", /*#__PURE__*/React.createElement(NavLink, {
Expand Down Expand Up @@ -139,7 +139,7 @@ export const ChangePlan = () => {
}, "Choose a Plan"), error !== null && /*#__PURE__*/React.createElement(Alert, {
severity: "error"
}, error), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(PricingPlans, {
selectedPriceId: subscription.stripePriceId,
selectedPlanId: subscription.planId,
selectPlan: selectPlan,
disabled: processing,
paymentMethod: subscription.paymentMethod
Expand Down
7 changes: 4 additions & 3 deletions dist/esm/components/CreateSubscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ export const CreateSubscription = () => {
const selectPlan = plan => {
setProcessing(true);
setError(null);
if (plan.price === 0) {
if (plan.free) {
// subscribe to free plans on selection
const createSubscription = httpsCallable(functionsInstance, 'fireactjsSaas-createSubscription');
createSubscription({
priceId: plan.priceId,
planId: plan.id,
paymentMethodId: null
}).then(res => {
if (res.data && res.data.subscriptionId) {
Expand All @@ -58,7 +59,7 @@ export const CreateSubscription = () => {
let subscriptionId = null;
createSubscription({
paymentMethodId: paymentMethod.id,
priceId: selectedPlan.priceId
planId: selectedPlan.id
}).then(res => {
if (res.data && res.data.subscriptionId) {
subscriptionId = res.data.subscriptionId;
Expand Down
Loading

0 comments on commit 2397c23

Please sign in to comment.