Skip to content

Commit 27b1619

Browse files
authored
Merge branch 'develop' into fix/with-deleted-detection
2 parents bf9ca7d + b116f75 commit 27b1619

31 files changed

Lines changed: 517 additions & 911 deletions

File tree

.github/teams.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
- "@thetutlage"
1212
- "@christiananese"
1313
- "@peterlgh7"
14+
- "@juanzgc"

packages/core/types/src/payment/provider.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ export interface UpdateAccountHolderInput extends PaymentProviderInput {
190190
/**
191191
* The data to delete an account holder.
192192
*/
193-
export interface DeleteAccountHolderInput extends Omit<PaymentProviderInput, "context"> {
193+
export interface DeleteAccountHolderInput
194+
extends Omit<PaymentProviderInput, "context"> {
194195
/**
195196
* The context of deleting the account holder.
196197
*/
@@ -237,6 +238,10 @@ export interface InitiatePaymentOutput extends PaymentProviderOutput {
237238
* The ID of the payment session in the payment provider.
238239
*/
239240
id: string
241+
/**
242+
* The status of the payment session, which will be stored in the payment session's `status` field.
243+
*/
244+
status?: PaymentSessionStatus
240245
}
241246

242247
/**
@@ -305,12 +310,15 @@ export interface DeleteAccountHolderOutput extends PaymentProviderOutput {}
305310
/**
306311
* The result of listing payment methods for an account holder in the third-party payment provider.
307312
*/
308-
export interface ListPaymentMethodsOutput extends Array<PaymentProviderOutput & {
309-
/**
310-
* The ID of the payment method in the payment provider.
311-
*/
312-
id: string
313-
}> {}
313+
export interface ListPaymentMethodsOutput
314+
extends Array<
315+
PaymentProviderOutput & {
316+
/**
317+
* The ID of the payment method in the payment provider.
318+
*/
319+
id: string
320+
}
321+
> {}
314322

315323
/**
316324
* The result of saving a payment method.

packages/modules/payment/src/services/payment-module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ export default class PaymentModuleService
363363
{
364364
id: paymentSession!.id,
365365
data: { ...input.data, ...providerPaymentSession.data },
366+
status: providerPaymentSession.status ?? PaymentSessionStatus.PENDING,
366367
},
367368
sharedContext
368369
)

packages/modules/providers/payment-stripe/src/core/stripe-base.ts

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ abstract class StripeBase extends AbstractPaymentProvider<StripeOptions> {
215215
}
216216
}
217217

218-
async getPaymentStatus({
219-
data,
220-
}: GetPaymentStatusInput): Promise<GetPaymentStatusOutput> {
221-
const id = data?.id as string
218+
async getPaymentStatus(
219+
input: GetPaymentStatusInput
220+
): Promise<GetPaymentStatusOutput> {
221+
const id = input?.data?.id as string
222222
if (!id) {
223223
throw this.buildError(
224224
"No payment intent ID provided while getting payment status",
@@ -227,30 +227,11 @@ abstract class StripeBase extends AbstractPaymentProvider<StripeOptions> {
227227
}
228228

229229
const paymentIntent = await this.stripe_.paymentIntents.retrieve(id)
230-
const dataResponse = paymentIntent as unknown as Record<string, unknown>
230+
const statusResponse = this.getStatus(paymentIntent)
231231

232-
switch (paymentIntent.status) {
233-
case "requires_payment_method":
234-
if (paymentIntent.last_payment_error) {
235-
return { status: PaymentSessionStatus.ERROR, data: dataResponse }
236-
}
237-
return { status: PaymentSessionStatus.PENDING, data: dataResponse }
238-
case "requires_confirmation":
239-
case "processing":
240-
return { status: PaymentSessionStatus.PENDING, data: dataResponse }
241-
case "requires_action":
242-
return {
243-
status: PaymentSessionStatus.REQUIRES_MORE,
244-
data: dataResponse,
245-
}
246-
case "canceled":
247-
return { status: PaymentSessionStatus.CANCELED, data: dataResponse }
248-
case "requires_capture":
249-
return { status: PaymentSessionStatus.AUTHORIZED, data: dataResponse }
250-
case "succeeded":
251-
return { status: PaymentSessionStatus.CAPTURED, data: dataResponse }
252-
default:
253-
return { status: PaymentSessionStatus.PENDING, data: dataResponse }
232+
return {
233+
status: statusResponse.status,
234+
data: statusResponse.data as unknown as Record<string, unknown>,
254235
}
255236
}
256237

@@ -281,15 +262,15 @@ abstract class StripeBase extends AbstractPaymentProvider<StripeOptions> {
281262
const isPaymentIntent = "id" in sessionData
282263
return {
283264
id: isPaymentIntent ? sessionData.id : (data?.session_id as string),
265+
status: isPaymentIntent ? this.getStatus(sessionData).status : undefined,
284266
data: sessionData as unknown as Record<string, unknown>,
285267
}
286268
}
287269

288270
async authorizePayment(
289271
input: AuthorizePaymentInput
290272
): Promise<AuthorizePaymentOutput> {
291-
const statusResponse = await this.getPaymentStatus(input)
292-
return statusResponse
273+
return this.getPaymentStatus(input)
293274
}
294275

295276
async cancelPayment({
@@ -605,6 +586,34 @@ abstract class StripeBase extends AbstractPaymentProvider<StripeOptions> {
605586
return { id: resp.id, data: resp as unknown as Record<string, unknown> }
606587
}
607588

589+
private getStatus(
590+
paymentIntent: Stripe.PaymentIntent
591+
): Omit<GetPaymentStatusOutput, "data"> & { data: Stripe.PaymentIntent } {
592+
switch (paymentIntent.status) {
593+
case "requires_payment_method":
594+
if (paymentIntent.last_payment_error) {
595+
return { status: PaymentSessionStatus.ERROR, data: paymentIntent }
596+
}
597+
return { status: PaymentSessionStatus.PENDING, data: paymentIntent }
598+
case "requires_confirmation":
599+
case "processing":
600+
return { status: PaymentSessionStatus.PENDING, data: paymentIntent }
601+
case "requires_action":
602+
return {
603+
status: PaymentSessionStatus.REQUIRES_MORE,
604+
data: paymentIntent,
605+
}
606+
case "canceled":
607+
return { status: PaymentSessionStatus.CANCELED, data: paymentIntent }
608+
case "requires_capture":
609+
return { status: PaymentSessionStatus.AUTHORIZED, data: paymentIntent }
610+
case "succeeded":
611+
return { status: PaymentSessionStatus.CAPTURED, data: paymentIntent }
612+
default:
613+
return { status: PaymentSessionStatus.PENDING, data: paymentIntent }
614+
}
615+
}
616+
608617
async getWebhookActionAndData(
609618
webhookData: ProviderWebhookPayload["payload"]
610619
): Promise<WebhookActionResult> {

www/apps/api-reference/.env.sample

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@ NEXT_PUBLIC_DOCS_V1_URL=
1515
NEXT_PUBLIC_API_V1_URL=
1616
ALGOLIA_WRITE_API_KEY=
1717
ANALYZE_BUNDLE=
18-
NEXT_PUBLIC_AI_ASSISTANT_URL=
19-
NEXT_PUBLIC_AI_WEBSITE_ID=
20-
NEXT_PUBLIC_AI_API_ASSISTANT_RECAPTCHA_SITE_KEY=
18+
NEXT_PUBLIC_INTEGRATION_ID=
2119
NEXT_PUBLIC_GA_ID=

www/apps/api-reference/providers/index.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@ const Providers = ({ children }: ProvidersProps) => {
2424
<MainNavProvider>
2525
<SearchProvider>
2626
<AiAssistantProvider
27-
apiUrl={process.env.NEXT_PUBLIC_AI_ASSISTANT_URL || "temp"}
28-
websiteId={process.env.NEXT_PUBLIC_AI_WEBSITE_ID || "temp"}
29-
recaptchaSiteKey={
30-
process.env
31-
.NEXT_PUBLIC_AI_API_ASSISTANT_RECAPTCHA_SITE_KEY ||
32-
"temp"
27+
integrationId={
28+
process.env.NEXT_PUBLIC_INTEGRATION_ID || "temp"
3329
}
3430
chatType="popover"
3531
>

www/apps/book/.env.sample

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ NEXT_PUBLIC_API_URL=
1313
NEXT_PUBLIC_DOCS_V1_URL=
1414
ALGOLIA_WRITE_API_KEY=
1515
ANALYZE_BUNDLE=
16-
NEXT_PUBLIC_AI_ASSISTANT_URL=
17-
NEXT_PUBLIC_AI_WEBSITE_ID=
18-
NEXT_PUBLIC_AI_API_ASSISTANT_RECAPTCHA_SITE_KEY=
1916
CLOUDINARY_CLOUD_NAME=
2017
NEXT_PUBLIC_BASE_PATH=
2118
NEXT_PUBLIC_GA_ID=
22-
NEXT_PUBLIC_PROD_BASE_URL=
19+
NEXT_PUBLIC_PROD_BASE_URL=
20+
NEXT_PUBLIC_INTEGRATION_ID=

www/apps/book/providers/index.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,8 @@ const Providers = ({ children, aiAssistantProps = {} }: ProvidersProps) => {
3434
<SearchProvider>
3535
<AiAssistantProvider
3636
{...aiAssistantProps}
37-
apiUrl={
38-
process.env.NEXT_PUBLIC_AI_ASSISTANT_URL || "temp"
39-
}
40-
websiteId={
41-
process.env.NEXT_PUBLIC_AI_WEBSITE_ID || "temp"
42-
}
43-
recaptchaSiteKey={
44-
process.env
45-
.NEXT_PUBLIC_AI_API_ASSISTANT_RECAPTCHA_SITE_KEY ||
46-
"temp"
37+
integrationId={
38+
process.env.NEXT_PUBLIC_INTEGRATION_ID || "temp"
4739
}
4840
>
4941
<HooksLoader

www/apps/cloud/.env.example

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ NEXT_PUBLIC_API_URL=
1313
NEXT_PUBLIC_USER_GUIDE_URL=
1414
ALGOLIA_WRITE_API_KEY=
1515
ANALYZE_BUNDLE=
16-
NEXT_PUBLIC_AI_ASSISTANT_URL=
17-
NEXT_PUBLIC_AI_WEBSITE_ID=
18-
NEXT_PUBLIC_AI_API_ASSISTANT_RECAPTCHA_SITE_KEY=
1916
CLOUDINARY_CLOUD_NAME=
20-
NEXT_PUBLIC_GA_ID=
17+
NEXT_PUBLIC_GA_ID=
18+
NEXT_PUBLIC_INTEGRATION_ID=

www/apps/cloud/providers/index.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,8 @@ const Providers = ({ children }: ProvidersProps) => {
3737
<MainNavProvider>
3838
<SearchProvider>
3939
<AiAssistantProvider
40-
apiUrl={
41-
process.env.NEXT_PUBLIC_AI_ASSISTANT_URL ||
42-
"temp"
43-
}
44-
websiteId={
45-
process.env.NEXT_PUBLIC_AI_WEBSITE_ID || "temp"
46-
}
47-
recaptchaSiteKey={
48-
// eslint-disable-next-line prettier/prettier, max-len
49-
process.env.NEXT_PUBLIC_AI_API_ASSISTANT_RECAPTCHA_SITE_KEY ||
50-
"temp"
40+
integrationId={
41+
process.env.NEXT_PUBLIC_INTEGRATION_ID || "temp"
5142
}
5243
>
5344
<HooksLoader

0 commit comments

Comments
 (0)