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

Source.type missing crash #41

Closed
foscomputerservices opened this issue May 12, 2018 · 4 comments
Closed

Source.type missing crash #41

foscomputerservices opened this issue May 12, 2018 · 4 comments

Comments

@foscomputerservices
Copy link

Quite possibly I've misunderstood something as I'm very new to Stripe. I've followed the docs on Checkout and then the docs on Creating Charges and successfully retrieved my 'Strip token. I then make the following call to stripe-provider:

 return try stripeClient.charge.create(
                amount: Int(amount * 100.0),
                currency: .usd,
                source: stripeToken,
                statementDescriptor: "EFL 1 Year"
            )

According to Stripe's website the charge is successful. However, StripeSource.init crashes in the following code as type is nil.

        type = try container.decodeIfPresent(SourceType.self, forKey: .type)
        
        switch type! {
        case .card:

I've locally made the following changes and all works as expected:

        type = try container.decodeIfPresent(SourceType.self, forKey: .type)
        
        switch type {
        case .some(.card):
            card = try container.decodeIfPresent(StripeCard.self, forKey: .card)
...
            
        default: break
        }

Am I missing something in my call to cause type to be set in the response?

@Andrewangeta
Copy link
Member

@foscomputerservices So I think I know the problem.
When you make a charge the response returned has a source attached to it BUT that source doesn't have a type property but Sources themselves have a type property. I'll reach out to Stripe to see if they can add a type property to the response when completing charges. But for now I think I'll just check the object property to see if I can parse the source.

@anthonycastelli
Copy link
Member

#43 should fix this, right?

@Andrewangeta
Copy link
Member

@foscomputerservices For now when a source is returned with no type it won't populate until we find a better way to represent a source as anything other than the Any type.

@foscomputerservices
Copy link
Author

Thanks for the fix!!

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

3 participants