Skip to content

Commit

Permalink
Merge pull request #2 from graphql-editor/gei-stripe-init
Browse files Browse the repository at this point in the history
Gei stripe init
  • Loading branch information
Matnabru committed Jul 24, 2023
2 parents 883ba37 + b6319b2 commit df9a73b
Show file tree
Hide file tree
Showing 80 changed files with 15,639 additions and 3,139 deletions.
5,932 changes: 2,799 additions & 3,133 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion packages/integrations/gei-stripe/.graphql-editor.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
"backendSrc": "./src",
"backendLib": "./lib",
"schemaDir": "./",
"integrationPath": "./src/index.ts"
"integrationPath": "./src/index.ts",
"registry": "https://registry.npmjs.org/",
"npmPackage": "gei-stripe"
}
12 changes: 8 additions & 4 deletions packages/integrations/gei-stripe/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"name": "gei-stripe",
"version": "0.6.2",
"version": "0.0.3",
"description": "Automatically generated by graphql-editor-cli",
"main": "lib/index.js",
"scripts": {
"start": "gecli dev",
"build": "tsc",
"watch": "tsc --watch",
"update": "gecli codegen models && gecli schema && gecli codegen typings"
"update": "gecli codegen models && gecli schema && gecli codegen typings",
"integrate": "gecli gei integrate",
"publish": "gecli gei publish",
"integrate:env": "dotenv -e .env npm run integrate"
},
"author": "GraphQL Editor Centaur Generator",
"license": "ISC",
Expand All @@ -21,12 +24,13 @@
"form-data": "^4.0.0",
"googleapis": "^111.0.0",
"graphql-editor-cli": "^0.8.5",
"i-graphql": "^0.1.1",
"i-graphql": "^0.1.2",
"jsonwebtoken": "^9.0.0",
"jwt-decode": "^3.1.2",
"mailgun.js": "^8.0.6",
"mongodb": "^4.13.0",
"mongodb": "^5.1.0",
"node-fetch": "^3.3.0",
"stripe": "^11.4.0",
"stucco-js": "^0.10.18",
"ws": "^8.12.0"
}
Expand Down
305 changes: 305 additions & 0 deletions packages/integrations/gei-stripe/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@


type Query{
store: Store!
stripeCustomerQueryOps(
customerId: String!
): StripeCustomerQueryOps
}

type StripeCustomerQueryOps{
getCustomerInfo: StripeCustomer
}

type Mutation {
initStripeCustomer(
initStripeCustomerInput: InitStripeCustomerInput!
): Boolean!
stripeCustomerMutationOps(
customerId: String!
): StripeCustomerMutationOps
createPaymentSession(
payload: CreatePaymentSessionPayload!
): String!
createCustomerPortal(
payload: CreateCustomerPortalPayload!
): String!
"""
entry point for Weebhooks.
"""
webhook: String
}

type User {
stripeId: String
email: String!
}

type StripeCustomerMutationOps{
generateBillingPortal(
returnUrl: String!
): String
generateCheckoutSession(
generateCheckoutSessionInput: GenerateCheckoutSessionInput!
): String
}

input GenerateCheckoutSessionInput {
productIds: [String!]!
success_url: String!
cancel_url: String!
}

input InitStripeCustomerInput {
email: String!
name: String
phone: String
address: AddressInput
}

input CreatePaymentSessionPayload{
userEmail: String!
"""
Return url after successful transaction
"""
successUrl: String!
cancelUrl: String!
products: [StripeProductInput!]!
}

input StripeProductInput{
productId: String!
quantity: Int!
}

input CreateCustomerPortalPayload{
userEmail: String!
returnUrl: String!
}

input AddressInput {
"""
City, district, suburb, town, village, or ward.
"""
city: String!
"""
Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
"""
country: String!
"""
Address line 1 (e.g., street, block, PO Box, or company name).
"""
line1: String!
"""
Address line 2 (e.g., apartment, suite, unit, or building).
"""
line2: String!
"""
ZIP or postal code.
"""
postal_code: String!
"""
State, county, province, prefecture, or region.
"""
state: String!
}

type StripeCustomer {
customerId: String!
email: String!
name: String
address: Address
}

type Address {
city: String
country: String
line1: String
line2: String
postal_code: String
state: String
}

input ProductFilter{
active: Boolean
created: TimestampFilter
limit: Int
shippable: Boolean
ids: [ID!]
startingAfter: ID
endingBefore: ID
url: String
}

input RecurringFilter{
interval: Interval
usageType: UsageType
}

input PriceFilter{
active: Boolean
currency: String
product: ID
type: Type
created: TimestampFilter
limit: Int
startingAfter: ID
endingBefore: ID
recurring: RecurringFilter
}

type Store{
products(
filter: ProductFilter
): ProductsPage
prices(
filter: PriceFilter
): PricesPage
}

type Dimensions{
height: Float
length: Float
weight: Float
width: Float
}

type Product{
id: ID!
active: Boolean
created: Timestamp
defaultPrice: Price
description: String
images: [String!]
livemode: Boolean
metadata: AnyObject
name: String
packageDimensions: Dimensions
shippable: Boolean
statementDescriptor: String
taxCode: String
unitLabel: String
updated: Timestamp
url: String
prices: [Price!]
}

enum BillingScheme{
PER_UNIT
TIERED
}

"""
Offset measured in seconds since Unix epoch.
"""
scalar Timestamp

input TimestampFilter{
Gt: Timestamp
Gte: Timestamp
Lt: Timestamp
Lte: Timestamp
}

type CustomUnitAmount{
maximum: Int
minimum: Int
preset: Int
}

"""
Any value that can be represented as JSON object
"""
scalar AnyObject

enum AggregateUsage{
SUM
LAST_DURING_PERIOD
LAST_EVER
MAX
}

enum Interval{
MONTH
YEAR
WEEK
DAY
}

enum UsageType{
METERED
LICENSED
}

type PriceRecurring{
aggregateUsage: AggregateUsage
interval: Interval
intervalCount: Int
usageType: UsageType
trialPeriodDays: Int
}

enum TaxBehaviour{
INCLUSIVE
EXCLUSIVE
UNSPECIFIED
}

enum TiersMode{
GRADUATED
VOLUME
}

enum Round{
UP
DOWN
}

type TransformQuantity{
divideBy: Int
round: Round
}

enum Type{
RECURRING
ONE_TIME
}

type Price{
id: ID!
active: Boolean
billingScheme: BillingScheme
created: Timestamp
currency: String
customUnitAmount: CustomUnitAmount
livemode: Boolean
lookupKey: String
metadata: AnyObject
nickname: String
product: Product
recurring: PriceRecurring
taxBehavior: TaxBehaviour
tiersMode: TiersMode
transformQuantity: TransformQuantity
type: Type
unitAmount: Int
unitAmountDecimal: String
}

type ProductsPage{
products: [Product!]
startingAfter: ID
endingBefore: ID
}

type PricesPage{
products: [Price!]
startingAfter: ID
endingBefore: ID
}


schema{
query: Query
mutation: Mutation
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

import { FieldResolveInput } from 'stucco-js';
import { resolverFor } from '../zeus/index.js';
import { newStripe } from '../utils/utils.js';
import { MongoOrb } from '../db/orm.js';


export const handler = async (input: FieldResolveInput) =>
resolverFor('Mutation', 'createCustomerPortal', async ({ payload: { returnUrl, userEmail } }) => {
const stripe = newStripe();
const user = await MongoOrb('UserCollection').collection.findOne(
{ email: userEmail },
);
if (!user) {
throw new Error('Invalid product or customer');
}
if (!user.stripeId) {
throw new Error('Stripe customer not initialized');
}
const session = await stripe.billingPortal.sessions.create({
customer: user.stripeId,
return_url: returnUrl,
});
return session.url;
})(input.arguments, input.source);


Loading

0 comments on commit df9a73b

Please sign in to comment.