vapor-community / stripe

Stripe library for Vapor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Concrete Routes Don't Allow Optional Values

JamesCoonce opened this issue · comments

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

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.

This compiles fine for me

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

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>

You sure you have the latest version of the provider?

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.

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

.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>
                ^

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