Skip to content

Commit

Permalink
Merge pull request #62 from vapor-community/fixes
Browse files Browse the repository at this point in the history
Optional properties
  • Loading branch information
Andrewangeta authored Sep 3, 2018
2 parents 877e4ca + b86c5aa commit fa6bc4b
Showing 1 changed file with 36 additions and 35 deletions.
71 changes: 36 additions & 35 deletions Sources/Stripe/Models/Sources/Source.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public struct StripeSource: StripeModel {
public var created: Date?
public var currency: StripeCurrency?
public var flow: Flow?
public var livemode: Bool
public var livemode: Bool?
public var metadata: [String: String]
public var owner: StripeOwner?
public var receiver: StripeReceiver?
public var redirect: SourceRedirect?
public var statementDescriptor: String?
public var status: StripeStatus?
public var type: SourceType
public var type: SourceType?
public var usage: String?
public var card: StripeBasicCard?
public var threeDSecure: ThreeDSecure?
Expand All @@ -55,46 +55,47 @@ public struct StripeSource: StripeModel {
created = try container.decodeIfPresent(Date.self, forKey: .created)
currency = try container.decodeIfPresent(StripeCurrency.self, forKey: .currency)
flow = try container.decodeIfPresent(Flow.self, forKey: .flow)
livemode = try container.decode(Bool.self, forKey: .livemode)
livemode = try container.decodeIfPresent(Bool.self, forKey: .livemode)
metadata = try container.decode([String: String].self, forKey: .metadata)
owner = try container.decodeIfPresent(StripeOwner.self, forKey: .owner)
receiver = try container.decodeIfPresent(StripeReceiver.self, forKey: .receiver)
redirect = try container.decodeIfPresent(SourceRedirect.self, forKey: .redirect)
statementDescriptor = try container.decodeIfPresent(String.self, forKey: .statementDescriptor)
status = try container.decodeIfPresent(StripeStatus.self, forKey: .status)
usage = try container.decodeIfPresent(String.self, forKey: .usage)
type = try container.decode(SourceType.self, forKey: .type)

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

case .threeDSecure:
threeDSecure = try container.decodeIfPresent(ThreeDSecure.self, forKey: .threeDSecure)

case .giropay:
giropay = try container.decodeIfPresent(Giropay.self, forKey: .giropay)

case .sepaDebit:
sepaDebit = try container.decodeIfPresent(SepaDebit.self, forKey: .sepaDebit)

case .ideal:
ideal = try container.decodeIfPresent(iDEAL.self, forKey: .ideal)

case .sofort:
sofort = try container.decodeIfPresent(SOFORT.self, forKey: .sofort)

case .bancontact:
bancontact = try container.decodeIfPresent(Bancontact.self, forKey: .bancontact)

case .alipay:
alipay = try container.decodeIfPresent(Alipay.self, forKey: .alipay)

case .p24:
p24 = try container.decodeIfPresent(P24.self, forKey: .p24)

case .achCreditTransfer:
achCreditTransfer = try container.decodeIfPresent(ACHCreditTransfer.self, forKey: .achCreditTransfer)
type = try container.decodeIfPresent(SourceType.self, forKey: .type)
if let sourceType = type {
switch sourceType {
case .card:
card = try container.decodeIfPresent(StripeBasicCard.self, forKey: .card)

case .threeDSecure:
threeDSecure = try container.decodeIfPresent(ThreeDSecure.self, forKey: .threeDSecure)

case .giropay:
giropay = try container.decodeIfPresent(Giropay.self, forKey: .giropay)

case .sepaDebit:
sepaDebit = try container.decodeIfPresent(SepaDebit.self, forKey: .sepaDebit)

case .ideal:
ideal = try container.decodeIfPresent(iDEAL.self, forKey: .ideal)

case .sofort:
sofort = try container.decodeIfPresent(SOFORT.self, forKey: .sofort)

case .bancontact:
bancontact = try container.decodeIfPresent(Bancontact.self, forKey: .bancontact)

case .alipay:
alipay = try container.decodeIfPresent(Alipay.self, forKey: .alipay)

case .p24:
p24 = try container.decodeIfPresent(P24.self, forKey: .p24)

case .achCreditTransfer:
achCreditTransfer = try container.decodeIfPresent(ACHCreditTransfer.self, forKey: .achCreditTransfer)
}
}
}

Expand Down

0 comments on commit fa6bc4b

Please sign in to comment.