Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Commit b587910

Browse files
authored
fix: handle string timestamp in DiscountOfferInputIOS (#26)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Enhanced timestamp parsing to accept both Double and string numeric formats. * **Chores** * Updated gql dependency to version 1.2.2. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 24d8545 commit b587910

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

Sources/Models/Types.swift

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -567,30 +567,54 @@ public struct DeepLinkOptions: Codable {
567567
}
568568

569569
public struct DiscountOfferInputIOS: Codable {
570-
/// Discount identifier
571570
public var identifier: String
572-
/// Key identifier for validation
573571
public var keyIdentifier: String
574-
/// Cryptographic nonce
575572
public var nonce: String
576-
/// Signature for validation
577573
public var signature: String
578-
/// Timestamp of discount offer
579574
public var timestamp: Double
580575

581-
public init(
582-
identifier: String,
583-
keyIdentifier: String,
584-
nonce: String,
585-
signature: String,
586-
timestamp: Double
587-
) {
576+
public init(identifier: String, keyIdentifier: String, nonce: String, signature: String, timestamp: Double) {
588577
self.identifier = identifier
589578
self.keyIdentifier = keyIdentifier
590579
self.nonce = nonce
591580
self.signature = signature
592581
self.timestamp = timestamp
593582
}
583+
584+
private enum CodingKeys: String, CodingKey {
585+
case identifier, keyIdentifier, nonce, signature, timestamp
586+
}
587+
588+
public init(from decoder: Decoder) throws {
589+
let container = try decoder.container(keyedBy: CodingKeys.self)
590+
identifier = try container.decode(String.self, forKey: .identifier)
591+
keyIdentifier = try container.decode(String.self, forKey: .keyIdentifier)
592+
nonce = try container.decode(String.self, forKey: .nonce)
593+
signature = try container.decode(String.self, forKey: .signature)
594+
595+
// Flexible timestamp decoding: accept Double or String
596+
if let timestampDouble = try? container.decode(Double.self, forKey: .timestamp) {
597+
timestamp = timestampDouble
598+
} else if let timestampString = try? container.decode(String.self, forKey: .timestamp),
599+
let timestampDouble = Double(timestampString) {
600+
timestamp = timestampDouble
601+
} else {
602+
throw DecodingError.dataCorruptedError(
603+
forKey: .timestamp,
604+
in: container,
605+
debugDescription: "timestamp must be a number or numeric string"
606+
)
607+
}
608+
}
609+
610+
public func encode(to encoder: Encoder) throws {
611+
var container = encoder.container(keyedBy: CodingKeys.self)
612+
try container.encode(identifier, forKey: .identifier)
613+
try container.encode(keyIdentifier, forKey: .keyIdentifier)
614+
try container.encode(nonce, forKey: .nonce)
615+
try container.encode(signature, forKey: .signature)
616+
try container.encode(timestamp, forKey: .timestamp)
617+
}
594618
}
595619

596620
/// Connection initialization configuration

openiap-versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"apple": "1.2.22",
3-
"gql": "1.2.1"
3+
"gql": "1.2.2"
44
}

0 commit comments

Comments
 (0)