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

QR code on purchases #338

Merged
merged 7 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Sources/TripKit/helpers/TKJSONCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,29 @@ public class TKJSONCache: TKFileCache {
}
}

public class TKCodableCache<Content>: TKFileCache where Content: Codable {
public static func read(_ id: String, directory: TKFileCacheDirectory, subdirectory: String? = nil) -> Content? {

guard let data = TKFileCache.read(id, directory: directory, subdirectory: subdirectory) else { return nil }

do {
return try PropertyListDecoder().decode(Content.self, from: data)
} catch {
assertionFailure("Error while reading: \(error)")
return nil
}
}

public static func save(_ id: String, content: Codable, directory: TKFileCacheDirectory, subdirectory: String? = nil) {
do {
let data = try PropertyListEncoder().encode(content)
TKFileCache.save(id, data: data, directory: directory, subdirectory: subdirectory)
} catch {
assertionFailure("Error while saving: \(error)")
}
}
}

public class TKFileCache: NSObject {

public static func read(_ id: String, directory: TKFileCacheDirectory, subdirectory: String? = nil) -> Data? {
Expand Down
10 changes: 7 additions & 3 deletions Sources/TripKit/model/TKBookingTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ extension TKBooking {
public let details: String

/// Price in cents
public let price: Int
public let price: Int?

public let currencyCode: String
public let currencyCode: String?

/// Number of tickets to pre-select, can also be used to define how many tickets to purchase for this fare
public var amount: Int?
Expand Down Expand Up @@ -402,6 +402,8 @@ extension TKBooking {

/// URL to fetch ticket details, provided if `status == .activated`
public let ticketURL: URL?

public let qrCode: String?

@DefaultEmptyArray public var actions: [Action]

Expand All @@ -420,6 +422,7 @@ extension TKBooking {
case status
case ticketURL
case actions
case qrCode

case ticketExpiration = "ticketExpirationTimestamp"
case purchased = "purchasedTimestamp"
Expand Down Expand Up @@ -498,7 +501,8 @@ extension TKBooking.BookingInput.ReturnTripDateValue {

extension TKBooking.Fare {

public func priceValue(locale: Locale = .current) -> String {
public func priceValue(locale: Locale = .current) -> String? {
guard let price, let currencyCode else { return nil }
return NSNumber(value: Float(price) / 100).toMoneyString(currencyCode: currencyCode, locale: locale)
}

Expand Down
Loading