#brunowilliang_code

1 messages ¡ Page 1 of 1 (latest)

celest daggerBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1220657793854341170

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

hasty dockBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

kind kraken
#

Hi, let me help you with this.

#

Could you please share the PaymentIntent ID pi_xxx?

cursive pumice
#
const createPayment = useCallback(async () => {
    const { error: createError, paymentIntent } = await createPaymentIntent({
        amount: amount * 100,
        currency: __DEV__ ? 'gbp' : 'eur',
        offlineBehavior: 'prefer_online',
        captureMethod: 'automatic',
        paymentMethodTypes: ['card_present'],
        metadata: {
            name: IDonate Tap - pag?.id,
            UUID: deviceUUID,
            'Device Type': deviceType,
        },
    })

    if (createError) {
        throw new Error(createError.message)
    }

    if (!paymentIntent) {
        const message = 'Failed to create payment intent.'
        throw new Error(message)
    } else {
        console.log(
            'Payment intent created successfully:',
            JSON.stringify(paymentIntent, null, 2),
        )
    }

    return paymentIntent
}, [...deps])
LOG  Payment intent created successfully: {
  "charges": [],
  "currency": "gbp",
  "paymentMethodId": null,
  "created": "1711097746000",
  "status": "requiresPaymentMethod",
  "id": "pi_3Ox3t8JbWeNjTcRL0BJ1Xiju",
  "sdkUuid": "D095ACBC-B048-48C0-9BD8-1E9AF3269486",
  "amount": 1000
}
#
const collectPayment = useCallback(
    async (paymentIntent: PaymentIntent.Type) => {
        const { error: collectError, paymentIntent: collectPayment } =
            await collectPaymentMethod({
                paymentIntent: paymentIntent,
                enableCustomerCancellation: false,
                skipTipping: true,
            })

        if (collectError) {
            throw new Error(collectError.message)
        } else {
            console.log(
                'Payment method collected successfully:',
                JSON.stringify(collectPayment, null, 2),
            )
        }
    },
    [...deps],
)
LOG  Payment method collected successfully: {
  "charges": [],
  "currency": "gbp",
  "paymentMethodId": null,
  "created": "1711097746000",
  "status": "requiresConfirmation",
  "id": "pi_3Ox3t8JbWeNjTcRL0BJ1Xiju",
  "sdkUuid": "D095ACBC-B048-48C0-9BD8-1E9AF3269486",
  "amount": 1000
}
#
const confirmPayment = useCallback(
    async (paymentIntent: PaymentIntent.Type) => {
        try {
            const { error: confirmError, paymentIntent: confirmedPaymentIntent } =
                await confirmPaymentIntent(paymentIntent)

            if (confirmError) {
                console.error('Payment failed', JSON.stringify(confirmError, null, 2))
            } else {
                Alert.alert('Payment', 'Payment succeeded')
                console.log(
                    'Payment succeeded',
                    JSON.stringify(confirmedPaymentIntent, null, 2),
                )
            }
        } catch (error: any) {
            console.error('Payment failed', error?.response)
        }
    },
    [...deps],
)
 LOG  Payment succeeded {
  "charges": [
    {
      "amount": 1000,
      "id": "ch_3Ox3t8JbWeNjTcRL02oeIiJi",
      "description": null,
      "currency": "gbp",
      "status": "succeeded"
    }
  ],
  "currency": "gbp",
  "paymentMethodId": "pm_1Ox3tFJbWeNjTcRLOoVvLBQi",
  "created": "1711097746000",
  "status": "succeeded",
  "id": "pi_3Ox3t8JbWeNjTcRL0BJ1Xiju",
  "sdkUuid": "FC372140-D417-4E0E-ACD6-33A084205B94",
  "amount": 1000
}
#

@kind kraken I am developing an application using React Native and testing payment flows with Stripe on the iOS simulator. I am facing challenges with confirming and capturing PaymentIntents as expected, particularly regarding the PaymentIntent status remaining as 'requiresPaymentMethod' after confirmation attempts.

kind kraken
#

What are you trying to achieve exactly?
Do you need to capture the funds separately?

cursive pumice
#

I need to capture it to my database...

#

but when I pass my capturePayment:

const confirmPayment = useCallback(
    async (paymentIntent: PaymentIntent.Type) => {
        try {
            const { error: confirmError, paymentIntent: confirmedPaymentIntent } =
                await confirmPaymentIntent(paymentIntent)

            if (confirmError) {
                console.error('Payment failed', JSON.stringify(confirmError, null, 2))
            } else {
                capturePayment({
                    intent: paymentIntent.id,
                    pageId: page?.id,
                    amount: amount * 100,
                    orgAmt: amount,
                    log: 'Confirm Payment',
                    stat: 'succeeded',
                    currency: __DEV__ ? 'gbp' : 'eur',
                    mode: __DEV__ ? 'test' : 'live',
                    device: deviceType,
                })
                Alert.alert('Payment', 'Payment succeeded')
                console.log(
                    'Payment succeeded',
                    JSON.stringify(confirmedPaymentIntent, null, 2),
                )
            }
        } catch (error: any) {
            console.error('Payment failed', error?.response)
        }
    },
    [...deps],
)
#

it gives this error:

 LOG  Payment succeeded {
  "charges": [
    {
      "amount": 1000,
      "id": "ch_3Ox4A2JbWeNjTcRL1RlmOvko",
      "description": null,
      "currency": "gbp",
      "status": "succeeded"
    }
  ],
  "currency": "gbp",
  "paymentMethodId": "pm_1Ox4A7JbWeNjTcRL70WvzrgN",
  "created": "1711098794000",
  "status": "succeeded",
  "id": "pi_3Ox4A2JbWeNjTcRL1YmEUmwZ",
  "sdkUuid": "B36E3523-8E67-4033-830F-6234AAA92CFD",
  "amount": 1000
}
 ERROR  log {
  "name": "Capture Payment Error",
  "type": "Failed",
  "endpoint": "/terminal/capture",
  "message": "Request failed with status code 400",
  "metadata": {
    "code": 400,
    "data": "This PaymentIntent could not be captured because it has already been captured."
  },
  "createdAt": "2024-03-22T09:13:21.346Z"
}
kind kraken
kind kraken
cursive pumice
#

capturePayment takes the stripe payment and sends it to my database

#
const capturePayment = async (
    data: ICaptureData,
): Promise<ICaptureResponse> => {
    const response = await api.post<ICaptureResponse>('/terminal/capture', data)
    return response.data
}

It's nothing more than a call to my API to send the payment

#

@kind kraken this application was in kotlin and we are moving to react native, so the endpoint is the same, and in kotlin it works

kind kraken
#

Could you please share the backend endpoint code?

#

I would also recommend avoid using the term "capture" if you're not actually intending to capture the payment. This leads to confusion and issue like this one.

kind kraken
cursive pumice
#

I don't have access to the api endpoints, but I have the working code of the application made in Kotlin

kind kraken
cursive pumice
#

I will try permission to show the code of this endpoint