#.lonestarx
1 messages · Page 1 of 1 (latest)
What do you mean by optional here?
Have you reviewed our docs for taking payment using payment sheet?
i may or may not have stripe payment available in this screen
That's up to your integration to choose when to use the payment sheet or not, right?
sorry to say but the paymentSheet documentation is horrendous
it doesn't even mention the existence of a viewModifier
all the docs i've seen offer the paymentsheet on a button
which is not useful every time
like in my case for example
Ok, well you can implement the app that uses the SDK any way you wish
i receive my payment methods from an API call, meaning i'll only know at runtime if it's stripe or something else
Ok, so then it sounds like you'd be implementing logic to initialize the payment sheet or not
like for example
in the docs
PaymentSheet.PaymentButton(
paymentSheet: paymentSheet,
onCompletion: model.onPaymentCompletion
) {
Text("Buy")
}```
this is pretty much all that's listed for swiftui
what if i don't wanna show the payment sheet from a button but optionally after an API call response?
Can you use the same paymentSheet?.present() used by the UIKit example? I'm not an iOS developer so not familiar with the nuances here, but you should be able to programmatically present this however you like
unfortunately i'm using swiftui, not UIkit, so no..
the only swiftui option is using a viewModifier
but that is very hard with an optional paymentSheet
cos paymentSheet is not optional... so you gotta work around it
paymentSheet is not optional
This is something our SDK is making difficult for you?
a lot lol
basically you NEED to know before your screen where you will have stripe payment that you will have stripe payment
you understand me?
I understand generally, but not the specific issues with the implementation in SwiftUI that get in your way here
Drawing analoy from the UIKit flow (even if you can't use that) we allow you to choose when to present the sheet
I would expect the same to be available by some mechanism in swiftui
it is but not really
the presentation of paymentsheet in swiftui allows conditioning based on a bool
but it also requires a paymentsheet (even if it's not presented)
which might not be available before a certain point
I'm not sure what you mean by that, can you share a short snippet showing what you expect to be able to do?
Have you looked at using the FlowController?
Though it does still describe;
Use PaymentSheet.FlowController.PaymentOptionsButton to wrap the button that presents the sheet to collect payment details.
So it sounds like this expects to be triggered by a button click at some point
yep
}.paymentSheet(isPresented: <#T##Binding<Bool>#>, paymentSheet: <#T##PaymentSheet#>, onCompletion: <#T##(PaymentSheetResult) -> Void#>)
right now this is the only way i could find in the sdk to present a sheet in swiftui other than with a button
problem is paymentSheet is not optional
and at compile time i don't have a paymentSheet
only at runtime (maybe)
the code above doesn't actually present the sheet, it's just a view modifier that ads the option to present a sheet from a view
my beef is with the fact that i need a paymentSheet object even just to be able to add the sheet presentation to my view, let alone actually use it
Ok thanks, seeing if I can find out more about this
To help me understand and narrow the issue, is the problem specific about tying presenting the sheet to a button press, or is it about the conditional existence of the sheet and referencing it somewhere in your code?
latter
I'm wondering if what you've done is what is needed based on what you're describing, looking again at our docs I noticed we describe PaymentButton as "a convenience wrapper for the .paymentSheet() ViewModifier."
And you've implemented your own view modifier instead of this, if i understood your earlier description correctly
i did not
i implemented that view modifier
but in a very hacky way
cos that's the only possible way with an optional paymentSheet
We've got an older example that had a similar implementation to what you did, maybe it can offer you some ideas on how to handle the payment sheet creation?
https://github.com/stripe/stripe-ios/blob/906114750f93347be43b4405f56d5f472802b39b/Example/PaymentSheet Example/PaymentSheet Example/PaymentSheetTestPlayground.swift#L138-L144
If you think there is a gap and opportunities for better patterns, I think it'd be great to file an issue with clear examples illustrating what you're doing and the necessary workaround and our mobile engineers can take a look
just a minute
My colleague also shared this sketch of a potential alternative as something to try, if you wanted:
Just like preparePaymentSheet() is being called from a Model file, I could add another function for presenting PaymentSheet like
func showPaySheet(someView: ContentView){
self.paymentSheet?.present(from: UIHostingController(rootView: someView), completion: { PaymentSheetResult in
})
}
and from the View file I can call it
.onAppear {
backendModel.showPaySheet(someView: self)
}
But if you have something that works for you, I'd probably say to stick with that
hmmm
doesn't this only show the paymentsheet upon the view appearing?
and no more later on?
this is the wrapper i made for all your stuff
and this is the only way i found it working
and it's not pretty at all
and for some stupid reason, that DispatchQueue.main.asyncAfter(deadline: .now() + 0.1, execute: {
is needed