mirror of
https://github.com/vale981/Vulcan
synced 2025-03-05 09:31:43 -05:00
Add amount property to charges schema; add addSubscriptionProduct; various other fixes
This commit is contained in:
parent
926f155655
commit
5534ab7430
10 changed files with 42 additions and 25 deletions
|
@ -13,19 +13,4 @@ accounts-password@1.5.0
|
|||
# accounts-twitter
|
||||
# accounts-facebook
|
||||
|
||||
############ Your Packages ############
|
||||
|
||||
#tutorial-step-1 - You can follow along with the video here: http://docs.vulcanjs.org/example-simple.html
|
||||
# This is where you enable packages.
|
||||
|
||||
example-simple
|
||||
# example-movies
|
||||
# example-instagram
|
||||
# example-forum
|
||||
# example-customization
|
||||
# example-permissions
|
||||
# example-membership
|
||||
# example-interfaces
|
||||
# example-reactions
|
||||
|
||||
vulcan:debug
|
||||
|
|
|
@ -20,7 +20,7 @@ export const track = async (eventName, eventProperties, currentUser) => {
|
|||
await f(eventName, eventProperties, currentUser);
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`// ${f.name} track error`);
|
||||
console.log(`// ${f.name} track error for event ${eventName}`);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(error);
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@ export const createCollection = options => {
|
|||
|
||||
collection.getParameters = (terms = {}, apolloClient, context) => {
|
||||
|
||||
// debug(terms);
|
||||
// console.log(terms);
|
||||
|
||||
let parameters = {
|
||||
selector: {},
|
||||
|
@ -305,7 +305,7 @@ export const createCollection = options => {
|
|||
const maxDocuments = getSetting('maxDocumentsPerRequest', 1000);
|
||||
parameters.options.limit = (!terms.limit || terms.limit < 1 || terms.limit > maxDocuments) ? maxDocuments : terms.limit;
|
||||
|
||||
// debug(parameters);
|
||||
// console.log(parameters);
|
||||
|
||||
return parameters;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@ const ChargesDashboard = props =>
|
|||
name: 'createdAtFormattedShort',
|
||||
label: 'Created At',
|
||||
},
|
||||
'user',
|
||||
'user',
|
||||
'amount',
|
||||
'type',
|
||||
'source',
|
||||
'productKey',
|
||||
|
|
|
@ -113,7 +113,7 @@ Checkout.contextTypes = {
|
|||
Checkout.propTypes = {
|
||||
productKey: PropTypes.string,
|
||||
currentUser: PropTypes.object,
|
||||
button: PropTypes.func,
|
||||
button: PropTypes.object,
|
||||
coupon: PropTypes.string,
|
||||
associatedDocument: PropTypes.object,
|
||||
customAmount: PropTypes.number,
|
||||
|
|
|
@ -94,6 +94,16 @@ const schema = {
|
|||
|
||||
// GraphQL only
|
||||
|
||||
amount: {
|
||||
type: Number,
|
||||
optional: true,
|
||||
viewableBy: ['admins'],
|
||||
resolveAs: {
|
||||
type: 'Int',
|
||||
resolver: charge => charge.data.amount,
|
||||
}
|
||||
},
|
||||
|
||||
createdAtFormatted: {
|
||||
type: String,
|
||||
optional: true,
|
||||
|
|
|
@ -28,6 +28,7 @@ registerFragment(`
|
|||
# pageUrl
|
||||
# }
|
||||
|
||||
amount
|
||||
properties
|
||||
stripeId
|
||||
stripeChargeUrl
|
||||
|
|
|
@ -1,5 +1,25 @@
|
|||
export const Products = {};
|
||||
|
||||
export const addProduct = (productKey, product) => {
|
||||
Products[productKey] = product;
|
||||
export const addProduct = (productKey, product, productType = 'product') => {
|
||||
|
||||
let productWithType;
|
||||
|
||||
// if product is a function, set it to a new function that returns the same thing except
|
||||
// with `type` set to `productType`
|
||||
if (typeof product === 'function') {
|
||||
productWithType = document => {
|
||||
const returnValue = product(document);
|
||||
returnValue.type = 'subscription';
|
||||
return returnValue;
|
||||
}
|
||||
} else {
|
||||
productWithType = product;
|
||||
productWithType.type = 'subscription';
|
||||
}
|
||||
|
||||
Products[productKey] = productWithType;
|
||||
};
|
||||
|
||||
export const addSubscriptionProduct = (productKey, product) => {
|
||||
addProduct(productKey, product, 'subscription');
|
||||
};
|
||||
|
|
|
@ -74,8 +74,8 @@ export const performAction = async (args) => {
|
|||
|
||||
metadata = await runCallbacks('stripe.charge.sync', metadata, user, product, collection, document, args);
|
||||
|
||||
if (product.plan) {
|
||||
// if product has a plan, subscribe user to it
|
||||
if (product.type === 'subscription') {
|
||||
// if product is a subscription product, subscribe user to its plan
|
||||
returnDocument = await createSubscription({ user, product, collection, document, metadata, args });
|
||||
} else {
|
||||
// else, perform charge
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
pointer-events: none;
|
||||
}
|
||||
.spinner{
|
||||
display: block;
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue