Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concrete Routes Don't Allow Optional Values #76

Closed
JamesCoonce opened this issue Oct 6, 2018 · 9 comments
Closed

Concrete Routes Don't Allow Optional Values #76

JamesCoonce opened this issue Oct 6, 2018 · 9 comments

Comments

@JamesCoonce
Copy link

I ran into the issue of trying to create a customer with only an email and description. Normally most parameters are optional. This is true in the Model and also in the protocol for CustomerRoutes.swift. The issue lies in the fact that the implementation StripeCustomerRoutes doesn't set the optional values to = nil like the extension of the protocol. This causes the parameter to be required or else you will receive an error to the one bellow.

error: missing argument for parameter 'accountBalance' in call
            let stripeCustomer = try client.customer.create(email: customer.email, description: customer.description)
                                                            ^
                                                            accountBalance: <#Int?#>,
Stripe.CustomerRoutes:2:17: note: 'create(accountBalance:businessVatId:coupon:defaultSource:description:email:metadata:shipping:source:)' declared here
@Andrewangeta
Copy link
Member

That shouldn’t be the case and works fine for me. Even in my test cases. If you look at Provider.swiftall of the route properties are using the protocol type rather than the concrete type. So those default implementations with nil being the default value should work fine.

@Andrewangeta
Copy link
Member

This compiles fine for me

let stripe = try req.make(StripeClient.self)
return try stripe.customer.create(email: registration.email).flatMap { customer in

@JamesCoonce
Copy link
Author

Hmmmm. That's strange

func create(_ req: Request) throws -> Future<Customer> {
        let stripe = try req.make(StripeClient.self)
        return try req.content.decode(Customer.self).flatMap(to: Customer.self) { customer in
            let stripeCustomer = try stripe.customer.create(email: customer.email, description: customer.description)
            customer.stripeId = stripeCustomer.id
            return customer.save(on: req)
        }
    }

/Users/jamescoonce/SwiftWeb/StripeCustomer/Sources/App/Controllers/CustomersController.swift:21:61: error: m
issing argument for parameter 'accountBalance' in call
            let stripeCustomer = try stripe.customer.create(email: customer.email, description: customer.des
cription)
                                                            ^
                                                            accountBalance: <#Int?#>,
Stripe.CustomerRoutes:2:17: note: 'create(accountBalance:businessVatId:coupon:defaultSource:description:email:metadata:shipping:source:)' declared here
    public func create(accountBalance: Int?, businessVatId: String?, coupon: String?, defaultSource: String?, description: String?, email: String?, metadata: [String : String]?, shipping: Stripe.ShippingLabel?, source: Any?) throws -> NIO.EventLoopFuture<Stripe.StripeCustomer>

@Andrewangeta
Copy link
Member

You sure you have the latest version of the provider?

@JamesCoonce
Copy link
Author

.package(url: "https://github.com/vapor-community/stripe-provider.git", from: "2.2.0"),

@Andrewangeta
Copy link
Member

That's interesting. I have no idea why you're getting a compile error. Get rid of the build folder, delete Package.resolved and try to do a package update. Maybe you have a really old version still.

@Andrewangeta
Copy link
Member

A new version of the provider was just released also. Although those changes were in previous release try the latest and see if that helps 2.2.1
https://github.com/vapor-community/stripe-provider/releases/tag/2.2.1

@JamesCoonce
Copy link
Author

.package(url: "https://github.com/vapor-community/stripe-provider.git", from: "2.2.1"),

In Package.resolved

{
        "package": "Stripe",
        "repositoryURL": "https://github.com/vapor-community/stripe-provider.git",
        "state": {
          "branch": null,
          "revision": "20c35dabd901c02bc7ad5fffd47f7a8e34595cbc",
          "version": "2.2.1"
        }
      },

.build was also delete

This is the output.


/Users/jamescoonce/SwiftWeb/StripeCustomer/Sources/App/Controllers/CustomersController.swift:21:61: error: missing argument for parameter 'accountBalance' in call
            let stripeCustomer = try stripe.customer.create(email: customer.email, description: customer.description)
                                                            ^
                                                            accountBalance: <#Int?#>,
Stripe.CustomerRoutes:2:17: note: 'create(accountBalance:businessVatId:coupon:defaultSource:description:email:metadata:shipping:source:)' declared here
    public func create(accountBalance: Int?, businessVatId: String?, coupon: String?, defaultSource: String?, description: String?, email: String?, metadata: [String : String]?, shipping: Stripe.ShippingLabel?, source: Any?) throws -> NIO.EventLoopFuture<Stripe.StripeCustomer>
                ^

@Andrewangeta
Copy link
Member

Where you able to figure this out? I don’t think anyone else has had this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants