tf-checkout-react 1.7.7-beta.9 → 1.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,3 @@
1
- import { PaymentType } from '../../components/paymentContainer'
2
- import { PaymentStatuses } from '../../components/process-redirect-container'
3
-
4
1
  interface IPaymentCartData {
5
2
  cartName: string;
6
3
  options: {
@@ -34,15 +31,6 @@ interface IPaymentOrderDetails {
34
31
  }
35
32
 
36
33
  interface IPaymentMethodData {
37
- type?: string;
38
- }
39
-
40
- interface IMercadoPagoProPaymentMethodData extends IPaymentMethodData {
41
- public_key?: string
42
- preference_id?: string
43
- }
44
-
45
- interface IStripePaymentMethodData {
46
34
  id: string;
47
35
  name: string;
48
36
  stripe_client_secret: string;
@@ -75,7 +63,7 @@ interface IPaymentData {
75
63
  expires_at: number;
76
64
  cart: IPaymentCartData[];
77
65
  order_details: IPaymentOrderDetails;
78
- payment_method: IPaymentMethodData | IMercadoPagoProPaymentMethodData | IStripePaymentMethodData;
66
+ payment_method: IPaymentMethodData;
79
67
  shipping_info: IShippingBillingInfoData;
80
68
  billing_info: IShippingBillingInfoData;
81
69
  event_details: IEventDetails;
@@ -190,22 +178,3 @@ interface ICheckoutCompleteDataResponse extends IAxiosResponseData {
190
178
  type: string;
191
179
  };
192
180
  }
193
-
194
- interface ICheckoutMercadoPagoProPaymentData {
195
- publicKey?: string;
196
- paymentId?: string
197
- preferenceId?: string
198
- }
199
-
200
- interface ICheckoutProcessPaymentData {
201
- returnUrl: string
202
- status: PaymentStatuses
203
- paymentType: PaymentType
204
- mercadoPagoInformation?: ICheckoutMercadoPagoProPaymentData
205
- }
206
-
207
- interface ICheckoutProcessPaymentResponse extends IAxiosResponseData {
208
- data: {
209
- attributes: ICheckoutProcessPaymentData;
210
- };
211
- }
@@ -1,18 +0,0 @@
1
- import { AxiosError } from 'axios';
2
- import React from 'react';
3
- import { ICheckoutProcessPaymentData } from '../../types/api/payment';
4
- export declare enum PaymentStatuses {
5
- INCOMPLETE = "incomplete",
6
- COMPLETE = "complete",
7
- PENDING = "pending",
8
- CANCELLED = "cancelled"
9
- }
10
- export interface IProcessRedirectContainer {
11
- orderHash?: string;
12
- onPaymentProcessed: (status: string, paymentData: ICheckoutProcessPaymentData, orderHash: string) => void;
13
- onProcessError?: (error: AxiosError) => void;
14
- loadingMessage?: string;
15
- renderProcessing?: () => React.ReactNode;
16
- renderCompleted?: (status: string, paymentData: ICheckoutProcessPaymentData, orderHash: string) => React.ReactNode | void;
17
- }
18
- export declare const ProcessRedirectContainer: ({ orderHash: orderHashProp, onPaymentProcessed, onProcessError, loadingMessage, renderProcessing, renderCompleted, }: IProcessRedirectContainer) => JSX.Element | null;
@@ -1,180 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import CircularProgress from '@mui/material/CircularProgress'
3
- import { initMercadoPago, StatusScreen } from '@mercadopago/sdk-react'
4
- import { AxiosError } from 'axios'
5
- import _identity from 'lodash/identity'
6
- import React, { useEffect, useState } from 'react'
7
-
8
- import { processPayment } from '../../api/payment'
9
- import { PaymentType } from '../../components/paymentContainer'
10
- import { isBrowser } from '../../utils'
11
- import { ICheckoutProcessPaymentData } from '../../types/api/payment'
12
-
13
- export enum PaymentStatuses {
14
- INCOMPLETE = 'incomplete',
15
- COMPLETE = 'complete',
16
- PENDING = 'pending',
17
- CANCELLED = 'cancelled',
18
- }
19
-
20
- export interface IProcessRedirectContainer {
21
- orderHash?: string;
22
- onPaymentProcessed: (
23
- status: string,
24
- paymentData: ICheckoutProcessPaymentData,
25
- orderHash: string
26
- ) => void;
27
- onProcessError?: (error: AxiosError) => void;
28
- loadingMessage?: string;
29
- renderProcessing?: () => React.ReactNode;
30
- renderCompleted?: (
31
- status: string,
32
- paymentData: ICheckoutProcessPaymentData,
33
- orderHash: string
34
- ) => React.ReactNode | void;
35
- }
36
-
37
- export const ProcessRedirectContainer = ({
38
- orderHash: orderHashProp = undefined,
39
- onPaymentProcessed = _identity,
40
- onProcessError = _identity,
41
- loadingMessage = 'Processing your payment...',
42
- renderProcessing,
43
- renderCompleted,
44
- }: IProcessRedirectContainer) => {
45
- const [isProcessing, setIsProcessing] = useState(true)
46
- const [error, setError] = useState<string | null>(null)
47
- const [completedData, setCompletedData] = useState<{
48
- status: string;
49
- paymentData: ICheckoutProcessPaymentData;
50
- orderHash: string;
51
- } | null>(null)
52
-
53
- useEffect(() => {
54
- const processRedirect = async () => {
55
- if (!isBrowser) return
56
-
57
- try {
58
- // Extract order hash from URL path if not provided as prop
59
- // Expected URL format: /processing-payment/:order_hash
60
- let orderHash = orderHashProp
61
- if (!orderHash) {
62
- const pathParts = window.location.pathname.split('/')
63
- const orderHashIndex = pathParts.indexOf('processing-payment')
64
- if (orderHashIndex !== -1 && pathParts[orderHashIndex + 1]) {
65
- orderHash = pathParts[orderHashIndex + 1]
66
- }
67
- }
68
-
69
- if (!orderHash) {
70
- throw new Error('Order hash not found in URL or props')
71
- }
72
-
73
- // Extract all query parameters from the URL
74
- const urlParams = new URLSearchParams(window.location.search)
75
- const params: Record<string, string> = {}
76
-
77
- urlParams.forEach((value, key) => {
78
- params[key] = value
79
- })
80
-
81
- // Call the processPayment API with orderHash and query params
82
- const paymentData = await processPayment(orderHash, params)
83
-
84
- // Store completed data for rendering
85
- setCompletedData({
86
- status: paymentData.status,
87
- paymentData,
88
- orderHash,
89
- })
90
-
91
- // Trigger the callback with payment status, data, and orderHash
92
- onPaymentProcessed(paymentData.status, paymentData, orderHash)
93
- } catch (err) {
94
- const axiosError = err as AxiosError
95
- setError(axiosError.message || 'Failed to process payment')
96
- onProcessError(axiosError)
97
- } finally {
98
- setIsProcessing(false)
99
- }
100
- }
101
-
102
- processRedirect()
103
- }, [orderHashProp, onPaymentProcessed, onProcessError])
104
-
105
- if (error) {
106
- return (
107
- <div style={{ padding: '20px', textAlign: 'center' }}>
108
- <p style={{ color: 'red' }}>Error: {error}</p>
109
- </div>
110
- )
111
- }
112
-
113
- if (isProcessing) {
114
- // Use custom processing render if provided
115
- if (renderProcessing) {
116
- return <>{renderProcessing()}</>
117
- }
118
-
119
- // Default processing UI
120
- return (
121
- <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', padding: '40px' }}>
122
- <CircularProgress />
123
- {loadingMessage && (
124
- <p style={{ marginTop: '20px', fontSize: '16px' }}>{loadingMessage}</p>
125
- )}
126
- </div>
127
- )
128
- }
129
-
130
- // Payment processing completed
131
- if (completedData) {
132
- const { status, paymentData, orderHash } = completedData
133
-
134
- // Use custom completed render if provided
135
- if (renderCompleted) {
136
- const customContent = renderCompleted(status, paymentData, orderHash)
137
- if (customContent) {
138
- return <>{customContent}</>
139
- }
140
- }
141
-
142
- // Check if it's a Mercado Pago payment
143
- const isMercadoPago = paymentData.paymentType === PaymentType.MERCADO_PAGO_PRO
144
-
145
- if (
146
- isMercadoPago &&
147
- paymentData.mercadoPagoInformation?.paymentId &&
148
- paymentData.mercadoPagoInformation?.publicKey
149
- ) {
150
- // Show StatusScreen for Mercado Pago payments
151
- initMercadoPago(paymentData.mercadoPagoInformation?.publicKey)
152
- return (
153
- <StatusScreen
154
- initialization={{ paymentId: paymentData.mercadoPagoInformation.paymentId }}
155
- />
156
- )
157
- }
158
-
159
- // Default: Show simple text with payment status
160
- const statusMessages = {
161
- [PaymentStatuses.COMPLETE]: 'Your payment has been completed successfully!',
162
- [PaymentStatuses.PENDING]: 'Your payment is being processed.',
163
- [PaymentStatuses.INCOMPLETE]: 'Your payment is incomplete. Please try again.',
164
- [PaymentStatuses.CANCELLED]: 'Your payment has been cancelled.',
165
- }
166
-
167
- const message = statusMessages[status as PaymentStatuses] || `Payment status: ${status}`
168
-
169
- return (
170
- <div style={{ padding: '40px', textAlign: 'center' }}>
171
- <h2>{message}</h2>
172
- <p style={{ marginTop: '20px', fontSize: '14px', color: '#666' }}>
173
- Order: {orderHash}
174
- </p>
175
- </div>
176
- )
177
- }
178
-
179
- return null
180
- }