-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from graphql-editor/gei-stripe-init
Gei stripe init
- Loading branch information
Showing
80 changed files
with
15,639 additions
and
3,139 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/integrations/gei-stripe/src/Mutation/createCustomerPortal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
|
Oops, something went wrong.