From 1cc8bfaa0294aeb765e49338648b714e5365e51b Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Thu, 9 Aug 2018 18:22:43 -0400 Subject: [PATCH] Fix for nullable client secret. Although stripes documentation suggests that this value will always be apart of the request there's a scenario where it's not. --- Sources/Stripe/Models/Sources/Source.swift | 4 ++-- Tests/StripeTests/SourceTests.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Stripe/Models/Sources/Source.swift b/Sources/Stripe/Models/Sources/Source.swift index d389330..2507723 100644 --- a/Sources/Stripe/Models/Sources/Source.swift +++ b/Sources/Stripe/Models/Sources/Source.swift @@ -20,7 +20,7 @@ public struct StripeSource: StripeModel { public var id: String public var object: String public var amount: Int? - public var clientSecret: String + public var clientSecret: String? public var codeVerification: CodeVerification? public var created: Date public var currency: StripeCurrency? @@ -50,7 +50,7 @@ public struct StripeSource: StripeModel { id = try container.decode(String.self, forKey: .id) object = try container.decode(String.self, forKey: .object) amount = try container.decodeIfPresent(Int.self, forKey: .amount) - clientSecret = try container.decode(String.self, forKey: .clientSecret) + clientSecret = try container.decodeIfPresent(String.self, forKey: .clientSecret) codeVerification = try container.decodeIfPresent(CodeVerification.self, forKey: .codeVerification) created = try container.decode(Date.self, forKey: .created) currency = try container.decodeIfPresent(StripeCurrency.self, forKey: .currency) diff --git a/Tests/StripeTests/SourceTests.swift b/Tests/StripeTests/SourceTests.swift index d33686f..c4f7342 100644 --- a/Tests/StripeTests/SourceTests.swift +++ b/Tests/StripeTests/SourceTests.swift @@ -22,7 +22,7 @@ class SourceTests: XCTestCase { "id": "src_1AhIN74iJb0CbkEwmbRYPsd4", "object": "source", "amount": 20, - "client_secret": "src_client_secret_sSPHZ17iQG6j9uKFdAYqPErO", + "client_secret": null, "created": 1500471469, "currency": "usd", "flow": "redirect", @@ -102,7 +102,7 @@ class SourceTests: XCTestCase { XCTAssertEqual(source.id, "src_1AhIN74iJb0CbkEwmbRYPsd4") XCTAssertEqual(source.object, "source") XCTAssertEqual(source.amount, 20) - XCTAssertEqual(source.clientSecret, "src_client_secret_sSPHZ17iQG6j9uKFdAYqPErO") + XCTAssertEqual(source.clientSecret, nil) XCTAssertEqual(source.created, Date(timeIntervalSince1970: 1500471469)) XCTAssertEqual(source.currency, .usd) XCTAssertEqual(source.flow, Flow.redirect)