Search code examples
ruby-on-railsswiftstripe-paymentsstripe-connect

Cannot Return JSON from login_link api Stripe Ruby on Rails Server


I have a functioning Ruby on Rails server which is being used to handle Stripe account creation, payments, and express (connect) account management. The api says the the login_links.create api should return a JSON, however I receive the error "responseValidationFailed(Alamofire.AFError.ResponseValidationFailureReason.unacceptableStatusCode(500))" when trying to receive any response from my own api client. The API for login_links (https://stripe.com/docs/api#create_login_link) is somewhat vague, but I am a ROR beginner so any help is appreciated.

My ROR Server /CreateBalanceLink function:

post '/createBalanceLink' do
    accountID = params[:account]
    begin
        account = Stripe::Account.retrieve(accountID)
        account.login_links.create

    rescue Stripe::StripeError => e
        status 402
        return "Error creating link: #{e.message}"

    end

    status 200
    return "Link successfully created"
end

My API Client:

    func generateBalanceAccessLink(stripeAccount: String, completion: @escaping (_ result: Bool) -> ()) {
    let url = "https://swaprevive.herokuapp.com/createBalanceLinkTest"
    let params: [String: Any] = [
        "account": stripeAccount
        ]
    Alamofire.request(url, method: .post, parameters: params)
        .validate(statusCode: 200..<300)
        .responseJSON { responseJSON in
            switch responseJSON.result {
            case .success(let json):
                let data:[String:AnyObject] = json as! [String : AnyObject]
                print(data)
                //print("Created Link:",data["url"] as! String)
                //appDelegate.balanceLink = data["url"] as! String
                completion(true)
            case .failure(let error):
                print(error)
            }
        }

}

Solution

  • The 500 response from your server means there's a server error. You'll want to check your logs and figure out what error that is and go from there.