Skip to content

Commit 42ca29b

Browse files
committed
addCreatePaymentSessionToStripe
1 parent 578be5f commit 42ca29b

File tree

8 files changed

+164
-51
lines changed

8 files changed

+164
-51
lines changed

packages/integrations/gei-stripe/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "gei-stripe",
3-
"version": "0.4.9",
3+
"version": "0.5.0",
44
"description": "Automatically generated by graphql-editor-cli",
55
"main": "lib/index.js",
66
"scripts": {
77
"start": "gecli dev",
88
"build": "tsc",
99
"watch": "tsc --watch",
10-
"update": "gecli codegen models && gecli schema && gecli codegen typings",
10+
"update": "gecli codegen models && gecli schema pull && gecli codegen typings",
1111
"integrate": "gecli gei integrate",
1212
"publish": "gecli gei publish",
1313
"integrate:env": "dotenv -e .env npm run integrate"

packages/integrations/gei-stripe/schema.graphql

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
2-
3-
4-
5-
61
type Query{
72
products(
83
filter: ProductFilter
94
): ProductsPage
10-
subscriptions(
5+
subscriptions(
116
filter: SubscriptionFilter
127
): [Subscription!]
138
paymentIntents(
@@ -18,10 +13,16 @@ type Query{
1813
): [Invoice!]
1914
customer(
2015
customerId: String!
21-
):Customer
16+
): Customer
2217
}
2318

2419
type Mutation{
20+
"""
21+
create session for simply payment
22+
"""
23+
createPaymentSession(
24+
payload: CreatePaymentSessionInput!
25+
): String!
2526
"""
2627
Creates stripe customer for further purchases, links with user "email" field in UserCollection
2728
"""
@@ -61,6 +62,9 @@ type Mutation{
6162
setDefaultPaymentMethod(
6263
payload: setDefaultPaymentMethodInput!
6364
): Boolean!
65+
"""
66+
Payment from stripe account to connected bank account
67+
"""
6468
createPayoutForConnectedAccount(
6569
payload: createPayoutForConnectedAccountInput!
6670
): Boolean!
@@ -70,13 +74,23 @@ type Mutation{
7074
webhook: String
7175
}
7276

73-
input createPayoutForConnectedAccountInput {
74-
accountId: String!
77+
input CreatePaymentSessionInput{
78+
amount: Int!
79+
currency: String!
80+
successUrl: String!
81+
cancelUrl: String!
82+
}
83+
84+
input createPayoutForConnectedAccountInput{
85+
"""
86+
If accountId is not specified, the default connected account is used.
87+
"""
88+
accountId: String
7589
amount: Int!
7690
currency: String!
7791
}
7892

79-
enum PaymentIntentStatus {
93+
enum PaymentIntentStatus{
8094
requires_payment_method
8195
requires_confirmation
8296
requires_action
@@ -86,7 +100,7 @@ enum PaymentIntentStatus {
86100
succeeded
87101
}
88102

89-
type Invoice {
103+
type Invoice{
90104
id: String!
91105
account_country: String!
92106
account_name: String!
@@ -123,23 +137,23 @@ type Invoice {
123137
total: Int!
124138
}
125139

126-
enum InvoiceStatus {
140+
enum InvoiceStatus{
127141
draft
128142
open
129143
paid
130144
uncollectible
131145
void
132146
}
133147

134-
enum InvoiceCollectionMethod {
148+
enum InvoiceCollectionMethod{
135149
charge_automatically
136150
"""
137151
Email payment instructions to the customer.
138152
"""
139153
send_invoice
140154
}
141155

142-
type PaymentIntent {
156+
type PaymentIntent{
143157
id: String!
144158
client_secret: String!
145159
"""
@@ -187,7 +201,7 @@ type PaymentIntent {
187201
on_behalf_of: String
188202
}
189203

190-
type PaymentIntentLastPaymentError {
204+
type PaymentIntentLastPaymentError{
191205
type: String!
192206
"""
193207
For card errors, the ID of the failed charge.
@@ -204,7 +218,7 @@ type PaymentIntentLastPaymentError {
204218
payment_method_type: String
205219
}
206220

207-
enum PaymentIntentSetupFutureUsage {
221+
enum PaymentIntentSetupFutureUsage{
208222
"""
209223
Use on_session if you intend to only reuse the payment method when your customer is present in your checkout flow.
210224
"""
@@ -215,12 +229,12 @@ enum PaymentIntentSetupFutureUsage {
215229
off_session
216230
}
217231

218-
input InvoiceFilter {
232+
input InvoiceFilter{
219233
customerId: String!
220234
status: InvoiceStatus
221235
}
222236

223-
input PaymentIntentFilter {
237+
input PaymentIntentFilter{
224238
customerId: String!
225239
status: PaymentIntentStatus
226240
}
@@ -230,12 +244,12 @@ input setDefaultPaymentMethodInput{
230244
customerId: String!
231245
}
232246

233-
input AttachPaymentMethodInput {
247+
input AttachPaymentMethodInput{
234248
paymentMethodId: String!
235249
customerId: String!
236250
}
237251

238-
input CreateConnectAccountInput {
252+
input CreateConnectAccountInput{
239253
type: ConnectAccountType!
240254
country: String!
241255
email: String!
@@ -250,13 +264,13 @@ enum ConnectAccountBusinessType{
250264
non_profit
251265
}
252266

253-
enum ConnectAccountType {
267+
enum ConnectAccountType{
254268
standard
255269
express
256270
custom
257271
}
258272

259-
input BankAccountInput {
273+
input BankAccountInput{
260274
country: String!
261275
"""
262276
Required supported currency for the country https://stripe.com/docs/payouts
@@ -273,12 +287,12 @@ input BankAccountInput {
273287
account_holder_type: BankAccountHolderType!
274288
}
275289

276-
enum BankAccountHolderType {
290+
enum BankAccountHolderType{
277291
individual
278292
company
279293
}
280294

281-
input SubscriptionFilter {
295+
input SubscriptionFilter{
282296
id: String
283297
cancel_at_period_end: Boolean
284298
current_period_end: TimestampFilter
@@ -290,7 +304,7 @@ input SubscriptionFilter {
290304
status: SubStatus
291305
}
292306

293-
type Subscription {
307+
type Subscription{
294308
id: String!
295309
cancel_at_period_end: Boolean!
296310
current_period_end: Timestamp!
@@ -312,15 +326,15 @@ enum SubStatus{
312326
unpaid
313327
}
314328

315-
type SubscriptionItems {
329+
type SubscriptionItems{
316330
data: [Item!]!
317331
has_more: Boolean!
318332
total_count: Int!
319333
url: String!
320334
object: String!
321335
}
322336

323-
type Item {
337+
type Item{
324338
id: String!
325339
created: Timestamp!
326340
metadata: AnyObject
@@ -368,7 +382,7 @@ input CreateCheckoutSessionInput{
368382
applicationFee: ApplicationFeeInput
369383
}
370384

371-
input ApplicationFeeInput {
385+
input ApplicationFeeInput{
372386
"""
373387
Value from 0-100
374388
"""
@@ -426,10 +440,11 @@ type Customer{
426440
invoicePrefix: String
427441
paymentMethods: [PaymentMethod!]
428442
}
443+
429444
"""
430445
https://stripe.com/docs/api/payment_methods/object
431446
"""
432-
type PaymentMethod {
447+
type PaymentMethod{
433448
id: String!
434449
billing_details: PaymentBillingDetails!
435450
customer: String!
@@ -440,7 +455,7 @@ type PaymentMethod {
440455
card: Card
441456
}
442457

443-
type Card {
458+
type Card{
444459
brand: Card!
445460
checks: CardChecks!
446461
country: String!
@@ -453,22 +468,22 @@ type Card {
453468
three_d_secure_usage: CardThreeDSecureUsage!
454469
}
455470

456-
type CardThreeDSecureUsage {
471+
type CardThreeDSecureUsage{
457472
supported: Boolean!
458473
}
459474

460-
type CardNetworks {
475+
type CardNetworks{
461476
preferred: String
462-
available : [String!]
477+
available: [String!]
463478
}
464479

465-
type CardChecks {
480+
type CardChecks{
466481
address_line1_check: String!
467482
address_postal_code_check: String!
468483
cvc_check: String!
469484
}
470485

471-
enum PaymentMethodType {
486+
enum PaymentMethodType{
472487
acss_debit
473488
affirm
474489
afterpay_clearpay
@@ -504,7 +519,7 @@ enum PaymentMethodType {
504519
zip
505520
}
506521

507-
type PaymentBillingDetails {
522+
type PaymentBillingDetails{
508523
address: Address
509524
email: String!
510525
name: String!
@@ -683,8 +698,7 @@ type ProductsPage{
683698
endingBefore: ID
684699
}
685700

686-
687701
schema{
688702
mutation: Mutation
689703
query: Query
690-
}
704+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
import { FieldResolveInput } from 'stucco-js';
3+
import { resolverFor } from '../zeus/index.js';
4+
import { newStripe } from '../utils/stripeInit.js';
5+
6+
export const createPaymentSession = async (input: FieldResolveInput) =>
7+
resolverFor('Mutation','createPaymentSession', async ({ payload: { successUrl,
8+
cancelUrl, amount, currency } }) => {
9+
try {
10+
const session = await newStripe().checkout.sessions.create({
11+
payment_method_types: ['card'],
12+
line_items: [
13+
{
14+
price_data: {
15+
currency,
16+
product_data: {
17+
name: 'Payment',
18+
},
19+
unit_amount: amount * 100,
20+
},
21+
quantity: 1,
22+
},
23+
],
24+
mode: 'payment',
25+
success_url: successUrl,
26+
cancel_url: cancelUrl,
27+
});
28+
return session.url
29+
30+
} catch (error) {
31+
throw new Error('Error creating payment intent: ' + JSON.stringify(error));
32+
}
33+
})(input.arguments);
34+
35+
export default createPaymentSession;

packages/integrations/gei-stripe/src/Mutation/createPayoutForConnectedAccount.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ export const createPayoutForConnectedAccount = async (input: FieldResolveInput)
1010
'createPayoutForConnectedAccount',
1111
async ({ payload: { accountId, amount, currency } }) => {
1212
try {
13-
const stripe_account = process.env.STRIPE_ACCOUNT_ID || accountId
14-
if (!stripe_account) throw new Error('missing accountId');
1513
const payout = await newStripe().payouts.create({
1614
amount,
1715
currency,
18-
destination: stripe_account,
16+
destination: accountId || undefined,
17+
source_type: 'bank_account',
1918
});
2019

2120
if (payout) {

packages/integrations/gei-stripe/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { NewIntegration } from 'graphql-editor-cli';
22
import initStripeCustomerHandler from './Mutation/initStripeCustomer.js';
33
import webhookHandler from './Mutation/webhook.js';
44
import createCustomerPortalHandler from './Mutation/createCustomerPortal.js';
5+
import createPaymentSessionHandler from './Mutation/createPaymentSession.js';
56
import createCheckoutSessionHandler from './Mutation/createCheckoutSession.js';
67
import createNewUserCheckoutSessionHandler from './Mutation/createNewUserCheckoutSession.js';
78
import createPayoutForConnectedAccountHandler from './Mutation/createPayoutForConnectedAccount.js';
@@ -82,6 +83,11 @@ export const integration = NewIntegration({
8283
description: 'Creates payout for one payment to connection account',
8384
handler: createPayoutForConnectedAccountHandler,
8485
},
86+
createPaymentSession: {
87+
name: 'createPaymentSession',
88+
description: 'Resolver to create a simply payment',
89+
handler: createPaymentSessionHandler,
90+
},
8591
setDefaultPaymentMethod: {
8692
name: 'setDefaultPaymentMethod',
8793
description: 'Sets default user payment method',

0 commit comments

Comments
 (0)