#cecilia-chen-_docs

1 messages ยท Page 1 of 1 (latest)

static vortexBOT
#

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

dull wyvern
#

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?

molten cairn
#

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)
}

`

dull wyvern
#

That isn't the object we show in our docs

#

You are doing something different

molten cairn
#

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

dull wyvern
#

No they are not. The object in our docs does not have a init function and requires no initial parameters

molten cairn
#

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

dull wyvern
#

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

molten cairn
#

later on in the step 6,

dull wyvern
#

Sorry I've only built this integration using UIKit

#

So I'm not sure if the SwiftUI docs are correct

molten cairn
#

are you able to find someone to help me with it? Im sad because I am not very familier with UIKit

cerulean flicker
#

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

molten cairn
#

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

cerulean flicker
#

What is the exact issue?

molten cairn
#

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

cerulean flicker
#

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

molten cairn
#

My current question is what CustomerSheet default value i should give it to

#

I need to give it a default value

cerulean flicker
#

I don't understand the words. Need a default value to what part?

molten cairn
#

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

cerulean flicker
#

Can you make it optional instead? Sorry I barely even understand your words unfortunately

molten cairn
#

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)

cerulean flicker
#

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)

molten cairn
#

if model.customerSheet is optional, I still need to give a default value

dull wyvern
#

@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
molten cairn
#

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

cerulean flicker
#

So you're saying it calls your server as soon as you initialize CustomerSheet and not later once you're ready to show it?

molten cairn
#

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

cerulean flicker
#

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

molten cairn
#

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.

cerulean flicker
#

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

molten cairn
#

if i don't have ephemeral key or setupintent secret, what value i should use for customerAdapter?

cerulean flicker
#

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

molten cairn
#

how to download it?

#

if i download it, will it running?

cerulean flicker
#

It's just an example app/code that you can use to understand what you are missing

molten cairn
#

ok, i will try to look at the code manually and trying to understand

#

thank you