#cecilia-chen-_docs
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can 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/1254926097351704729
๐ Have more to share? Add details, code, screenshots, videos, etc. below.
Hi ๐
I think this is intended to be a placeholder for whatever your application would implement as a ViewModel
It's not Stripe specific
Wait.. NVM You mean this model
class YourAccountViewModel: ObservableObject {
var customerSheet: CustomerSheet
}
Did you create this observable object yet?
yes, i have:
`class YourStripeAccountViewModel: ObservableObject {
var customerSheet: CustomerSheet
@Published var customerSheetResult: CustomerSheet.CustomerSheetResult?
init(customerSheet: CustomerSheet) {
self.customerSheet = customerSheet
}
func onCompletion(result: CustomerSheet.CustomerSheetResult) {
self.customerSheetResult = result
}
}
and then in my swiftui Profile View, I decalred it as @ObservedObject private var stripeAccountVM: YourStripeAccountViewModel`
but I need to give it some values to initialize it
I am wondering should i place those 3 functions inside my ProfileView? or should i placed them in the parent view of ProfileView?
` private func createCustomerAdapter() {
Task {
do {
let ephemeralKey = try await getCustomerEphemeralKey()
let setupIntentClientSecret = try await getSetupIntentForCustomer()
let customerAdapter = StripeCustomerAdapter(
customerEphemeralKeyProvider: {
return ephemeralKey
},
setupIntentClientSecretProvider: {
return setupIntentClientSecret
}
)
var configuration = CustomerSheet.Configuration()
configuration.headerTextForSelectionScreen = "Manage your payment method"
} catch {
print("there is an error creating customer adapter: \(error.localizedDescription)")
}
}
}
private func getCustomerEphemeralKey() async throws -> CustomerEphemeralKey {
let data = [
"customerId": userProfileViewModel.dbUser?.stripeId,
"stripeVersion": "2024-04-10"
]
let result = try await Functions.functions().httpsCallable("createEphemeralKey").call(data)
guard let data = result.data as? [String: Any],
let ephemeralKeySecret = data["secret"] as? String else {
throw NSError(domain: "Invalid secret data", code: -1, userInfo: nil)
}
return CustomerEphemeralKey(customerId: userProfileViewModel.dbUser?.stripeId ?? "",
ephemeralKeySecret: ephemeralKeySecret)
}
`
private func getSetupIntentForCustomer() async throws -> String { let result = try await Functions.functions().httpsCallable("createSetupIntent").call(["customer_id": userProfileViewModel.dbUser?.stripeId]) guard let data = result.data as? [String: Any], let setupIntentClientSecret = data["setupIntent"] as? String else { throw NSError(domain: "Invalid setupIntent data", code: -1, userInfo: nil) } return setupIntentClientSecret }
they are the same, I just named YourAccountViewModel as YourStripeAccountViewModel
No they are not. The object in our docs does not have a init function and requires no initial parameters
since customerSheet variable in the class does not have a default value, we need to give the class a default value, or we need to pass a value as parameter when init the class
if i comment the init out, I still need to give customerSheet some value
The only declaration we have in our docs definition is the first line, var customerSheet: CustomerSheet
Oh sorry no, we add to is throughout the doc
later on in the step 6,
Sorry I've only built this integration using UIKit
So I'm not sure if the SwiftUI docs are correct
are you able to find someone to help me with it? Im sad because I am not very familier with UIKit
๐ Sorry none of us know much about iOS right now on shift. I would recommend to ignore our examples for a bit. Assuming you are an experienced iOS developer, you should be able to have your own models/views work properly and then pipe in the Stripe-specific code right?
and I had trouble when following the SwiftUI doc for the step 4 , but I figured it out. but now i have problem with step 6
What is the exact issue?
the white background is my current code, it worked because it can receive the setupIntentClientSecret. From the step 4 from the doc, it tells me to use json["setupIntentClientSecret", but actuaclly the returned key is 'setupIntent', there is no key called 'setupIntentClientSecret'. The black background is my node js code, I am using firebase cloud functions
yeah sorry those are pictures of code.
Remember, we said the docs might just be plain incorrect, it's sad but it's unfortunately common. I'm happy to try and help with the little I know about iOS.
What is your exact question? Right now you seemed to say "I looked at one variable, it's fine, but your docs say to use another word" I'd just use whatever works
My current question is what CustomerSheet default value i should give it to
I need to give it a default value
I don't understand the words. Need a default value to what part?
before a user taps a button and retreive his/her saved payments methods. I need to give customerSheet variable a default value in the YourAccountViewModel class
Can you make it optional instead? Sorry I barely even understand your words unfortunately
I can't, because if I make it optional, then there is another part of the code won't work, this code is also provided by the doc:
.customerSheet(
isPresented: $showingCustomerSheet,
customerSheet: model.customerSheet,
onCompletion: model.onCompletion)
I don't even get what your picture means (and I tried to avoid pictures of code whatsoever but you share a lot of those)
if model.customerSheet is optional, I still need to give a default value
@molten cairn I think you can try passing in the variable defined in Step 5?
var configuration = CustomerSheet.Configuration()
// Configure settings for the CustomerSheet here. For example:
configuration.headerTextForSelectionScreen = "Manage your payment method"
let customerSheet = CustomerSheet(configuration: configuration, customer: customerAdapter). // <- Pass customerSheet to you ViewModel
it is easy to pass in CustomerSheet.Configuration() to the configuration parameter, but for customerAdapter, it will get EphemeralKey and etSetupIntentForCustomer result first, and then construct the StripeCustomerAdapter, which mean this step will be async
So you're saying it calls your server as soon as you initialize CustomerSheet and not later once you're ready to show it?
CustomerSheet(configuration: CustomerSheet.Configuration(), customer: <#T##any CustomerAdapter#>), i need to fill in the CustomerAdapter part
I don't want to call server, thats why i need to give it a default value, but I dont know what value i should give it to
I don't understand what "give it a default value" could mean sadly
sorry it's tough to understand each other. You shared a picture without much details. I still don't get if you are trying to give a default value to customerSheet or customerAdapter or something else
getting ephemetal key required server call. I don't know what value i should give to customerAdapter, because I only know getting CustomerAdapter by getting ephemeral key and setupintent secret.
You are supposed to define a CustomerAdapter that will call your server to get all this data. There's no "default value" to pass, you need to write the Adapter
if i don't have ephemeral key or setupintent secret, what value i should use for customerAdapter?
You create an adapter to call your server and you pass that adapter to CustomerSheet. Later, when CustomerSheet needs it, it will call your server to get the info it needs
Someone on my team recommended looking at https://github.com/stripe/stripe-ios/blob/master/Example/PaymentSheet Example/PaymentSheet Example/ExampleSwiftUICustomerSheet.swift which is a running demo
It's just an example app/code that you can use to understand what you are missing