#saif-mustafa_code
1 messages ยท Page 1 of 1 (latest)
๐ 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.
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
Hi there, do you see any errors after calling cancelPaymentIntent ?
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.
Discord is a public place and anyone can see the content posted on it.
even on this support chat?
Yes
no errors at all! ๐ฆ The xcode network logs dont show anything
ok thanks
I will just send snippets
thank you for making me aware of this and apologies!
No worries, do you have the PaymentIntent ID?
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?
Can you share with me the existing PaymentIntent ID which you cancelled by using Terminal.shared.cancelPaymentIntent(paymentIntent) ?
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
https://dashboard.stripe.com/test/logs/req_FmIgFPggNrX7Ni I saw a request to cancel this PaymentIntent, but it's from your Python backend,
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
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
Just to clarify, are you using the server-driven integration?
my method has both, should this not be the case?
What do you mean by "my method has both" ?
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 ๐ฆ
What reader are you using?
Xcode 15, iOS 17.1.2, iPad Pro 2nd Generation
developer machine: MacBook Pro m2 Pro
So you are not using server-driven integration , and you want to create, collect and cancel payments from your iOS app?
You misunderstand
So I am following this:
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
Which one did you choose?
If you follow the iOS integration alone, are you able to complete what you want to achieve?
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?
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.
So you mean you are able to create, collect and cancel payments from your iOS app?
what do you think the issue is?
I am able to create and collect from my iOS app
yes
not cancel
for some reason
https://docs.stripe.com/terminal/payments/collect-payment?terminal-sdk-platform=ios#collect-cancel-collection are you following this guide to cancel payment collection?
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.
Ok, so you don't want your customer to cancel it.
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
No, you should still be able to cancel the payment even if setEnableCustomerCancellation is set to false
this is the screen the user sees when the reader calls collectPaymentMethod
ah. I thought so!!! But it's not working ๐ฆ
I've really tried everything. so you guys are my last hope
I must be missing some small configuration or step
https://github.com/stripe/stripe-terminal-ios/blob/master/Example/Example/PaymentViewController.swift#L187 Can you run the Example project and see if the payment intent cancellation work for your reader?
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
Can you share with me the PaymentIntent ID?
Copy and past it here
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
I'm not an expert in iOS, can you use the example code in your project and see if it works for you?