saltedge / saltedge-ios-swift

MIT License
10 stars 13 forks source link

CreateConnectSession Params, Invalid customer id. #60

Closed yh2015 closed 3 years ago

yh2015 commented 3 years ago

let connectSessionsParams = SEConnectSessionsParams( attempt: SEAttempt(returnTo: "https://www.google.com"), javascriptCallbackType: "iframe", consent: SEConsent(scopes: ["account_details", "transactions_details"]) )

    SERequestManager.shared.createConnectSession(params: connectSessionsParams) { response in
        switch response {
        case .success(let value):
            if let url = URL(string: value.data.connectUrl) {
                self.webView.load(URLRequest(url: url))
            }
        case .failure(let error):
            // Handle error
        }
    }

After successfully creating a customer, trying to connect to a session is failing because of an invalid customer id. I cannot find a param for sending the customer id. How should I add it to the API call?

ConstantinKV commented 3 years ago

Hello @yh2015 . Thank you for your contribution. Please pay attention to next code snippet:

let params = SECustomerParams(identifier: "your-customer-unique-id")
SERequestManager.shared.createCustomer(with: params) { response in
    switch response {
    case .success(let value):
        // Save customer secret to your storage
                UserDefaultsHelper.customerSecret = value.data.secret

        SERequestManager.shared.set(customerSecret: value.data.secret)
    case .failure(let error):
        // Handle error
    }
}

After receiving of customer secret for future rest calls you should save it (e.g. in UserDefault), otherwise you may receive invalid customer id.

Hope advice was helpful.

yh2015 commented 3 years ago

Thank for answering @ConstantinKV, I am saving the customer secret. That's not the issue, my problem is: how can I use the incoming data (secret) in the next call when I try to create a session. No place for customer Id in the SEConnectSessionsParams. Should the secret be saved in a specific location where it can be sent automatically when I use createConnectSession(params: connectSessionsParams), because even after saving the secret customer Id is still empty.

baller784 commented 3 years ago

@yh2015 After you receive the customer secret, you should link it with the SERequestManager, like this:

SERequestManager.shared.set(customerSecret: "received-customer-secret-here")

Check this method here.

By doing this you will set the Customer-secret HTTP header and all outgoing requests will have the proper customer-related HTTP headers set by default.

yh2015 commented 3 years ago

Thanks for replying @baller784, actually I am working with a client that provides the customer Id, in case I received this error Customer with identifier: '****' already exists. how can I connect to a session while not being able to save theshared secret since the creation wasn't successful and I didn't save the secret.

baller784 commented 3 years ago

@yh2015 There is no way to create a connection without a customer secret. Before creating a connection, you should check whether you have the customer secret and linked it to SERequestManager, which you can use for future requests.

You can do one of the following:

  1. Try to create a customer secret with a new specific customer id and then use the new received customer secret.
  2. Or, if you want to create a customer secret with already existing customer id, you may try to remove this customer in your Salt Edge Dashboard and then recreate customer in your app.

But, make sure to check every time, whether you have the customer secret and you have linked it to SERequestManager.

Please, check the docs:

https://docs.saltedge.com/account_information/v5/#customers

yh2015 commented 3 years ago

Thank you for the clear answer @baller784.