Skip to content

Commit

Permalink
gei-stripe expanded payment type
Browse files Browse the repository at this point in the history
  • Loading branch information
Matnabru committed Aug 14, 2023
1 parent 01459de commit e7594ca
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 7 deletions.
32 changes: 31 additions & 1 deletion packages/integrations/gei-stripe/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,40 @@ type PaymentMethod {
id: String!
billing_details: PaymentBillingDetails!
customer: String!
metadata: AnyObject
metadata: AnyObject!
type: PaymentMethodType!
created: Timestamp!
livemode: Boolean!
card: Card
}

type Card {
brand: Card!
checks: CardChecks!
country: String!
exp_month: Int!
exp_year: Int!
fingerprint: String!
funding: String!
last4: String!
created: Timestamp!
networks: CardNetworks!
three_d_secure_usage: CardThreeDSecureUsage!
}

type CardThreeDSecureUsage {
supported: Boolean!
}

type CardNetworks {
preferred: String
available : [String!]
}

type CardChecks {
address_line1_check: String!
address_postal_code_check: String!
cvc_check: String!
}

enum PaymentMethodType {
Expand Down
12 changes: 12 additions & 0 deletions packages/integrations/gei-stripe/src/Customer/paymentMethods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

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

export const handler = async (input: FieldResolveInput) =>
resolverFor('Customer','paymentMethods',async (_, src: CustomerModel) => {
const cursor = MongoOrb('PaymentMethodCollection').collection.find({ customer: src.id });
const paymentMethods = await cursor.toArray();
return paymentMethods;
})(input.arguments, input.source);
4 changes: 3 additions & 1 deletion packages/integrations/gei-stripe/src/Mutation/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
externalAccountInsert,
externalAccountUpdate,
} from '../utils/webhookEvents/externalAccountEvents.js';
import { paymentMethodAttached, paymentMethodDetached } from '../utils/webhookEvents/paymentMethodEvents.js';
import { paymentMethodAttached, paymentMethodDetached, paymentMethodUpdated } from '../utils/webhookEvents/paymentMethodEvents.js';
import { ExternalAccount } from '../utils/customTypes/types.js';

export const handler = async (input: FieldResolveInput) =>
Expand Down Expand Up @@ -111,6 +111,8 @@ export const handler = async (input: FieldResolveInput) =>
return paymentMethodAttached(ev.data.object as Stripe.PaymentMethod);
case 'payment_method.detached':
return paymentMethodDetached(ev.data.object as Stripe.PaymentMethod);
case 'payment_method.updated':
return paymentMethodUpdated(ev.data.object as Stripe.PaymentMethod);
}
} catch (e) {
throw new Error('cannot authorize request');
Expand Down
8 changes: 8 additions & 0 deletions packages/integrations/gei-stripe/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { handler as setDefaultPaymentMethodHandler } from './Mutation/setDefault
import { handler as paymentIntentsHandler } from './Query/paymentIntents.js';
import { handler as invoicesHandler } from './Query/invoices.js';
import { handler as customerHandler } from './Query/customer.js';
import { handler as paymentMethodHandler } from './Customer/paymentMethods.js';

export const integration = NewIntegration({
Query: {
Expand Down Expand Up @@ -96,6 +97,13 @@ export const integration = NewIntegration({
description: 'Resolver for querying prices objects',
handler: productPricesHandler,
},
},
Customer: {
paymentMethods: {
name: 'paymentMethods',
description: 'Resolver for querying customer payment methods',
handler: paymentMethodHandler,
},
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ModelTypes } from '../zeus/index.js';

export type CardChecksModel = ModelTypes['CardChecks'];
3 changes: 3 additions & 0 deletions packages/integrations/gei-stripe/src/models/CardModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ModelTypes } from '../zeus/index.js';

export type CardModel = ModelTypes['Card'];
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ModelTypes } from '../zeus/index.js';

export type CardNetworksModel = ModelTypes['CardNetworks'];
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ModelTypes } from '../zeus/index.js';

export type CardThreeDSecureUsageModel = ModelTypes['CardThreeDSecureUsage'];
8 changes: 8 additions & 0 deletions packages/integrations/gei-stripe/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { ItemModel } from './ItemModel.js'
import { UserModel } from './UserModel.js'
import { CustomerModel } from './CustomerModel.js'
import { PaymentMethodModel } from './PaymentMethodModel.js'
import { CardModel } from './CardModel.js'
import { CardThreeDSecureUsageModel } from './CardThreeDSecureUsageModel.js'
import { CardNetworksModel } from './CardNetworksModel.js'
import { CardChecksModel } from './CardChecksModel.js'
import { PaymentBillingDetailsModel } from './PaymentBillingDetailsModel.js'
import { AddressModel } from './AddressModel.js'
import { DimensionsModel } from './DimensionsModel.js'
Expand All @@ -32,6 +36,10 @@ export type Models = {
UserModel: UserModel;
CustomerModel: CustomerModel;
PaymentMethodModel: PaymentMethodModel;
CardModel: CardModel;
CardThreeDSecureUsageModel: CardThreeDSecureUsageModel;
CardNetworksModel: CardNetworksModel;
CardChecksModel: CardChecksModel;
PaymentBillingDetailsModel: PaymentBillingDetailsModel;
AddressModel: AddressModel;
DimensionsModel: DimensionsModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ export const paymentMethodAttached = async (subEvent: Stripe.PaymentMethod) => {
});
};

export const paymentMethodUpdated = async (subEvent: Stripe.PaymentMethod) => {
const { id, ...subEventWithoutId } = subEvent;
return await MongoOrb('PaymentMethodCollection').collection.updateOne(
{ id: subEvent.id },
{ $set: subEventWithoutId },
{ upsert: true }
);
};

export const paymentMethodDetached = async (subEvent: Stripe.PaymentMethod) => {
return await MongoOrb('PaymentMethodCollection').collection.deleteOne({ id: subEvent.id });
};
28 changes: 27 additions & 1 deletion packages/integrations/gei-stripe/src/zeus/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,33 @@ export const ReturnTypes: Record<string,any> = {
metadata:"AnyObject",
type:"PaymentMethodType",
created:"Timestamp",
livemode:"Boolean"
livemode:"Boolean",
card:"Card"
},
Card:{
brand:"Card",
checks:"CardChecks",
country:"String",
exp_month:"Int",
exp_year:"Int",
fingerprint:"String",
funding:"String",
last4:"String",
created:"Timestamp",
networks:"CardNetworks",
three_d_secure_usage:"CardThreeDSecureUsage"
},
CardThreeDSecureUsage:{
supported:"Boolean"
},
CardNetworks:{
preferred:"String",
available:"String"
},
CardChecks:{
address_line1_check:"String",
address_postal_code_check:"String",
cvc_check:"String"
},
PaymentBillingDetails:{
address:"Address",
Expand Down
124 changes: 120 additions & 4 deletions packages/integrations/gei-stripe/src/zeus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,36 @@ createPayoutForConnectedAccount?: [{ payload: ValueTypes["createPayoutForConnect
type?:boolean | `@${string}`,
created?:boolean | `@${string}`,
livemode?:boolean | `@${string}`,
card?:ValueTypes["Card"],
__typename?: boolean | `@${string}`
}>;
["Card"]: AliasType<{
brand?:ValueTypes["Card"],
checks?:ValueTypes["CardChecks"],
country?:boolean | `@${string}`,
exp_month?:boolean | `@${string}`,
exp_year?:boolean | `@${string}`,
fingerprint?:boolean | `@${string}`,
funding?:boolean | `@${string}`,
last4?:boolean | `@${string}`,
created?:boolean | `@${string}`,
networks?:ValueTypes["CardNetworks"],
three_d_secure_usage?:ValueTypes["CardThreeDSecureUsage"],
__typename?: boolean | `@${string}`
}>;
["CardThreeDSecureUsage"]: AliasType<{
supported?:boolean | `@${string}`,
__typename?: boolean | `@${string}`
}>;
["CardNetworks"]: AliasType<{
preferred?:boolean | `@${string}`,
available?:boolean | `@${string}`,
__typename?: boolean | `@${string}`
}>;
["CardChecks"]: AliasType<{
address_line1_check?:boolean | `@${string}`,
address_postal_code_check?:boolean | `@${string}`,
cvc_check?:boolean | `@${string}`,
__typename?: boolean | `@${string}`
}>;
["PaymentMethodType"]:PaymentMethodType;
Expand Down Expand Up @@ -1479,6 +1509,36 @@ createPayoutForConnectedAccount?: [{ payload: ResolverInputTypes["createPayoutFo
type?:boolean | `@${string}`,
created?:boolean | `@${string}`,
livemode?:boolean | `@${string}`,
card?:ResolverInputTypes["Card"],
__typename?: boolean | `@${string}`
}>;
["Card"]: AliasType<{
brand?:ResolverInputTypes["Card"],
checks?:ResolverInputTypes["CardChecks"],
country?:boolean | `@${string}`,
exp_month?:boolean | `@${string}`,
exp_year?:boolean | `@${string}`,
fingerprint?:boolean | `@${string}`,
funding?:boolean | `@${string}`,
last4?:boolean | `@${string}`,
created?:boolean | `@${string}`,
networks?:ResolverInputTypes["CardNetworks"],
three_d_secure_usage?:ResolverInputTypes["CardThreeDSecureUsage"],
__typename?: boolean | `@${string}`
}>;
["CardThreeDSecureUsage"]: AliasType<{
supported?:boolean | `@${string}`,
__typename?: boolean | `@${string}`
}>;
["CardNetworks"]: AliasType<{
preferred?:boolean | `@${string}`,
available?:boolean | `@${string}`,
__typename?: boolean | `@${string}`
}>;
["CardChecks"]: AliasType<{
address_line1_check?:boolean | `@${string}`,
address_postal_code_check?:boolean | `@${string}`,
cvc_check?:boolean | `@${string}`,
__typename?: boolean | `@${string}`
}>;
["PaymentMethodType"]:PaymentMethodType;
Expand Down Expand Up @@ -1862,10 +1922,36 @@ export type ModelTypes = {
id: string,
billing_details: ModelTypes["PaymentBillingDetails"],
customer: string,
metadata?: ModelTypes["AnyObject"] | undefined,
metadata: ModelTypes["AnyObject"],
type: ModelTypes["PaymentMethodType"],
created: ModelTypes["Timestamp"],
livemode: boolean
livemode: boolean,
card?: ModelTypes["Card"] | undefined
};
["Card"]: {
brand: ModelTypes["Card"],
checks: ModelTypes["CardChecks"],
country: string,
exp_month: number,
exp_year: number,
fingerprint: string,
funding: string,
last4: string,
created: ModelTypes["Timestamp"],
networks: ModelTypes["CardNetworks"],
three_d_secure_usage: ModelTypes["CardThreeDSecureUsage"]
};
["CardThreeDSecureUsage"]: {
supported: boolean
};
["CardNetworks"]: {
preferred?: string | undefined,
available?: Array<string> | undefined
};
["CardChecks"]: {
address_line1_check: string,
address_postal_code_check: string,
cvc_check: string
};
["PaymentMethodType"]:PaymentMethodType;
["PaymentBillingDetails"]: {
Expand Down Expand Up @@ -2250,10 +2336,40 @@ export type GraphQLTypes = {
id: string,
billing_details: GraphQLTypes["PaymentBillingDetails"],
customer: string,
metadata?: GraphQLTypes["AnyObject"] | undefined,
metadata: GraphQLTypes["AnyObject"],
type: GraphQLTypes["PaymentMethodType"],
created: GraphQLTypes["Timestamp"],
livemode: boolean
livemode: boolean,
card?: GraphQLTypes["Card"] | undefined
};
["Card"]: {
__typename: "Card",
brand: GraphQLTypes["Card"],
checks: GraphQLTypes["CardChecks"],
country: string,
exp_month: number,
exp_year: number,
fingerprint: string,
funding: string,
last4: string,
created: GraphQLTypes["Timestamp"],
networks: GraphQLTypes["CardNetworks"],
three_d_secure_usage: GraphQLTypes["CardThreeDSecureUsage"]
};
["CardThreeDSecureUsage"]: {
__typename: "CardThreeDSecureUsage",
supported: boolean
};
["CardNetworks"]: {
__typename: "CardNetworks",
preferred?: string | undefined,
available?: Array<string> | undefined
};
["CardChecks"]: {
__typename: "CardChecks",
address_line1_check: string,
address_postal_code_check: string,
cvc_check: string
};
["PaymentMethodType"]: PaymentMethodType;
["PaymentBillingDetails"]: {
Expand Down
7 changes: 7 additions & 0 deletions packages/integrations/gei-stripe/stucco.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@
"resolve": {
"name": "Query.customer.handler"
}
},
"Customer.paymentMethods": {
"name": "paymentMethods",
"description": "Resolver for querying customer payment methods",
"resolve": {
"name": "Customer.paymentMethods.handler"
}
}
},
"azureOpts": {
Expand Down
10 changes: 10 additions & 0 deletions packages/sandboxes/gei-stripe-sandbox/stucco.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@
"resolve": {
"name": "gei-stripe@Product.prices"
}
},
"StripeCustomer.paymentMethods": {
"noCode": {
"package": "gei-stripe",
"version": "0.4.3",
"resolver": "paymentMethods"
},
"resolve": {
"name": "gei-stripe@Customer.paymentMethods"
}
}
},
"azureOpts": {
Expand Down

0 comments on commit e7594ca

Please sign in to comment.