vapor-community / stripe

Stripe library for Vapor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nullable Source "creation" Date

lukenewman opened this issue · comments

I ran into this decoding error when trying to make a charge: Value required for key 'source.created'.

The code that got me there was the following:

let stripe = try req.make(StripeClient.self)

return try stripe.charge.create(amount: 1234, currency: .usd, description: "TESTING", customer: "cus_DSt0Pqu1iiiQDt").map() { charge in
    ...
}

I can fix it by changing the created var in Source.swift to an optional and its decoding line to decodeIfPresent. I'd open a PR for it but I don't have write access. Let me know how you'd like to progress. Thanks!

Thanks I’ll go ahead and get this merged in! At first all stripe model properties were optional but that was a little annoying having to unwrap everything first so we made certain assumptions that some properties would never be null/nil from the api like livemode id object etc. thought this would be one of them.

Gotcha. Thanks Andrew!

@Andrewangeta FYI -- flow, livemode, status, usage, and type also need to be Optionals. I've attached my patched Source.swift.

Source.swift.zip

@lukenewman Is there ever a time when livemode will be null?

@Andrewangeta Not sure. Thanks for fixing them all!