#saif-mustafa_code

1 messages ยท Page 1 of 1 (latest)

fickle bayBOT
#

๐Ÿ‘‹ 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/1224519218209230980

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

timber bluffBOT
frosty lagoon
#

Hi, I'm Saif! I'm a software engineer for Lloyds Banking Group in the United Kingdom (my full-time role), but I am currently also doing a client side-project building a professional iOS application for Carter & George Physiotherapy Clinics in the United Kingdom. This will be a bespoke iOS SwiftUI point of sale application!

I am currently trying to integrate my client's payment terminal hardware with the iOS app I am also developing, and I am at the final piece of the puzzle (or so I thought!), whereby I am trying to execute the cancelPaymentIntent method from the Stripe Terminal iOS SDK and for some reason, the paymentIntent I can see is fed into it as an argument is simply not letting the async method execute to perform the necessary SDK action. And also this means my reader display does not show any proper cancel display state. This is now a blocker for us as I have tried debugging this heavily, going to the extend of also fully integrating webhooks

raw minnow
#

Hi there, do you see any errors after calling cancelPaymentIntent ?

frosty lagoon
#

attached is my frontend iOS SwiftUI code I am developing. I trust this code will not be shared outside of this chat as it is client confidential but for the sake of debugging we think it is necessary to share.

raw minnow
#

Discord is a public place and anyone can see the content posted on it.

frosty lagoon
#

even on this support chat?

raw minnow
#

Yes

frosty lagoon
#

ok thanks

#

I will just send snippets

#

thank you for making me aware of this and apologies!

raw minnow
#

No worries, do you have the PaymentIntent ID?

frosty lagoon
#

yes it's being passed in from this code:

    Task {
                        guard let currentPaymentIntent = paymentTerminalManager.currentPaymentIntent else {
                            print("No current payment intent available")
                            onDismiss()
                            return
                        }
                        do {
                            try await paymentTerminalManager.cancelPaymentIntent(paymentIntentId: currentPaymentIntent.stripeId ?? "")
                            print("Payment intent cancelled successfully.")
                        } catch {
                            print("Failed to cancel payment intent: \(error)")
                        }
                        onDismiss()
#

did you want me to build the app and run the payments flow we have and generate a PaymentIntendID?

raw minnow
#

Can you share with me the existing PaymentIntent ID which you cancelled by using Terminal.shared.cancelPaymentIntent(paymentIntent) ?

frosty lagoon
#

yes one second

#

Hi

#

sorry my reader rebooted

#

getting it now

#

Printing description of paymentIntent:
<SCPPaymentIntent: 0x283e85740; amount = 10000; amount_details = <SCPAmountDetails: 0x280be4600; tip = <SCPTip: 0x280be45e0; amount = (null)>>; amount_tip = (null); capture_method = manual; currency = gbp; created = 2024-04-02 01:03:46 +0000; charges = (
); metadata = {
}; offline_details = (null); payment_method = (null); payment_method_id = (null); statement_descriptor = (null); statement_descriptor_suffix = (null); status = requires_payment_method; stripeId = pi_3P0vlOCl1DmNbO6G1PTCEvet>

#

so this SDK call refuses to execute for some reason, despite having a payment intent with a status of requires_payment_method

#

and I know it's not triggering as I have a boolean flag in place that dismisses my payment cancellation modal when the SDK call succeeds, but it doesn't seem to be wanting to and I am not sure at this point if this is a bug in the SDK

#

do {
let canceledIntent = try await Terminal.shared.cancelPaymentIntent(paymentIntent)
print("Payment intent canceled successfully: (canceledIntent)")
} catch {
print("Failed to cancel PaymentIntent: (error.localizedDescription)")
// Consider more detailed error handling here
}

        self.isPaymentIntentCancelled = true
raw minnow
frosty lagoon
#

yes correct

#

as in line with Stripe recommendations

#

the cancel payment intent is server-driven

#

but I have a question here actually too

#

should the server-driven request occur first and then the SDK call for a cancel payment intent?

#

I tried coding it both ways i.e. SDK call first, then cancelPaymentIntent endpoint call on my backend, but no luck, the cancelPaymentIntent does not seem to execute as expected

raw minnow
#

Just to clarify, are you using the server-driven integration?

frosty lagoon
#

my method has both, should this not be the case?

raw minnow
#

What do you mean by "my method has both" ?

frosty lagoon
#

so my frontend code calls the server to cancel the payment intent

#

and if this returns a 200, it then calls the SDK method

#

I tried it the other way around too fyi, as in try the SDK call for cancelPaymentIntent first

#

but this doesn't execute

#

my concern is the instance of the payment intent look identical. I even cross-referenced them using chatGPT haha

#

(not sending it the client secret ofc haha)

#

My main issue is why isn't the cancelPaymentIntent SDK call working

#

I simplified the problem as I thought it might be a state instance issue by simply calling the 3 SDK methods in order in the same code block:

createPaymentIntent
collectPaymentMethod
cancelPaymentIntent

but the cancelPaymentIntent does not execute in even the simplest SDK code scenarios!

#

I am wondering if anything needs to be assigned from the server-side cancellation response to the payment intent object before it can be allowed to be cancelled by the SDK?

#

if it helps, I thought updating to Stripe Terminal v3.4.0 would help if there was a bug fix... I having been stuck on this issue for 3 days now ๐Ÿ˜ฆ

raw minnow
#

What reader are you using?

frosty lagoon
#

Xcode 15, iOS 17.1.2, iPad Pro 2nd Generation

#

developer machine: MacBook Pro m2 Pro

raw minnow
#

So you are not using server-driven integration , and you want to create, collect and cancel payments from your iOS app?

frosty lagoon
#

You misunderstand

#

And

#

Programmatic cancellation
SDK REFERENCE

  • Cancelable (iOS)
    You can cancel collecting a payment method using the Cancelable object returned by the iOS SDK.
#

I can see this in the documentation now reading it as I speak to you

#

is this cancelable object the same as the cancelPaymentIntent?

#

this might be where my confusion lies

raw minnow
#

Which one did you choose?

frosty lagoon
#

iOS

#

but followed the Server-side implementation part of it

#

as well ๐Ÿ™‚

raw minnow
#

If you follow the iOS integration alone, are you able to complete what you want to achieve?

frosty lagoon
#

Are you suggesting the confusion might lie with a mixture of server and ios integration I have done?

#

If the server cancels a payment integration can the SDK not do this?

#

I thought the Stripe Terminal SDK forces us to firstly make a backend call to cancel the payment intent and then only we should make the SDK call? or vice versa?

#

are you saying ONLY* the iOS SDK call should be made?

#

Is it ok to have a mixture of server-driven frontend code and SDK code for the terminal?

#

e.g. createPaymentIntent server-driven returning the PaymentIntent object and then other calls being SDK calls directly on the frontend interacting with Stripe APIs?

raw minnow
#

You can cancel a PaymentIntent either from backend or frontend, that doesn't' matter. But I'd suggest you follow the iOS integration guide to complete the frontend integration first.

frosty lagoon
#

I have done all of it

#

but are you saying to go over it again?

#

to be sure?

raw minnow
#

So you mean you are able to create, collect and cancel payments from your iOS app?

frosty lagoon
#

what do you think the issue is?

#

I am able to create and collect from my iOS app

#

yes

#

not cancel

#

for some reason

raw minnow
frosty lagoon
#

I am indeed. But** in my iOS code as per my client designs, we are setting:

setEnableCustomerCancellation(false)

#

to allow cancellation via our iOS UI cancel button directly

#

if we enable setEnableCustomerCancellation(true)

#

the cancellation works as expected.

#

but this is only when we tap "X" on the reader

#

we do not want this.

raw minnow
#

Ok, so you don't want your customer to cancel it.

frosty lagoon
#

hold up

#

yes we do, but only via the UI

#

hence setEnableCustomerCancellation(false)

#

but you're saying

#

maybe I misunderstand the purpose of this

#

if we set this to true, then only can we cancel the payment intent?

#

via the iOS app UI even I mean

#

not** the reader itself

#

This might help for context

raw minnow
#

No, you should still be able to cancel the payment even if setEnableCustomerCancellation is set to false

frosty lagoon
#

this is the screen the user sees when the reader calls collectPaymentMethod

frosty lagoon
#

I've really tried everything. so you guys are my last hope

#

I must be missing some small configuration or step

raw minnow
frosty lagoon
#

sure, let me try now, thank you ๐Ÿ™‚

#

I need to install a module called Static?

#

ignore me, opened the workspace now

#

hopefully will build...

#

need to run the backend code for it, one sec...

#

just connected to the test app

#

where do I go?

#

the cancel is not happening

#

ok when I tap cancel it does

raw minnow
#

Can you share with me the PaymentIntent ID?

frosty lagoon
raw minnow
#

Copy and past it here

frosty lagoon
#

I can see from the stripe dashboard it was cancelled

#

this indicates the SDK is working as expected

#

the issue lies with the payment intent state in my code

#

it must do right?

#

I am curious to know if it is because in the SDK example the SDK call to cancelPaymentIntent is done via a closure

#

and in my code I am using Apple's more recent try await async pattern

raw minnow
#

I'm not an expert in iOS, can you use the example code in your project and see if it works for you?

frosty lagoon
#

yeah doing that now

#

no worries, you've been great help so far

#

just want to confirm

#

for the iOS integration

#

we only need to call the SDK call

#

not the server-side cancellation?

#

unless as a failsafe in the case the SDK fails maybe? But otherwise no?

raw minnow
#

Yes, you don't need to call server-side cancellation.

#

But you still do so if your business requires it.