From 72a92d1fcce7fcddbc342839e54e68ed643ecc32 Mon Sep 17 00:00:00 2001 From: saroar Date: Thu, 27 Oct 2022 15:11:47 +0300 Subject: [PATCH] update store kit model --- .../VerifyReceiptInput.swift | 6 +- .../AppleVerifyReceiptResponse.swift | 63 ++++++++++++++++--- .../NWSharedModels/Route/AppStoreRoute.swift | 7 ++- 3 files changed, 60 insertions(+), 16 deletions(-) diff --git a/Sources/NWSharedModels/AppStoreVerifyReceipt/VerifyReceiptInput.swift b/Sources/NWSharedModels/AppStoreVerifyReceipt/VerifyReceiptInput.swift index 21305c8..854a6ab 100644 --- a/Sources/NWSharedModels/AppStoreVerifyReceipt/VerifyReceiptInput.swift +++ b/Sources/NWSharedModels/AppStoreVerifyReceipt/VerifyReceiptInput.swift @@ -4,21 +4,17 @@ public struct VerifyReceiptInput: Equatable, Codable { public init( receiptData: Data, - excludeOldTransactions: Bool? = nil, - password: String + excludeOldTransactions: Bool? = nil ) { self.receiptData = receiptData self.excludeOldTransactions = excludeOldTransactions - self.password = password } public let receiptData: Data public let excludeOldTransactions: Bool? - public let password: String enum CodingKeys: String, CodingKey { case receiptData = "receipt-data" case excludeOldTransactions = "exclude-old-transactions" - case password } } diff --git a/Sources/NWSharedModels/ComposableStoreKit/AppleVerifyReceiptResponse.swift b/Sources/NWSharedModels/ComposableStoreKit/AppleVerifyReceiptResponse.swift index b665ad2..f46a1d8 100644 --- a/Sources/NWSharedModels/ComposableStoreKit/AppleVerifyReceiptResponse.swift +++ b/Sources/NWSharedModels/ComposableStoreKit/AppleVerifyReceiptResponse.swift @@ -6,12 +6,25 @@ public struct AppleVerifyReceiptResponse: Equatable, Sendable { public var receipt: Receipt public var status: Int + public init( + environment: AppleVerifyReceiptResponse.Environment? = nil, + isRetryable: Bool, + receipt: AppleVerifyReceiptResponse.Receipt, + status: Int + ) { + self.environment = environment + self.isRetryable = isRetryable + self.receipt = receipt + self.status = status + } + public enum Environment: String, Codable, Equatable, Sendable { case sandbox = "Sandbox" case production = "Production" } - public struct Receipt: Equatable, Sendable { + public struct Receipt: Equatable, Sendable { + public var appItemId: Int public var applicationVersion: String public var bundleId: String @@ -20,13 +33,47 @@ public struct AppleVerifyReceiptResponse: Equatable, Sendable { public var receiptCreationDate: Date public var requestDate: Date - public struct InApp: Equatable, Sendable { - public var originalPurchaseDate: Date - public var originalTransactionId: String - public var productId: String - public var purchaseDate: Date - public var quantity: Int - public var transactionId: String + public init( + appItemId: Int, + applicationVersion: String, + bundleId: String, + inApp: [AppleVerifyReceiptResponse.Receipt.InApp], + originalPurchaseDate: Date, + receiptCreationDate: Date, + requestDate: Date + ) { + self.appItemId = appItemId + self.applicationVersion = applicationVersion + self.bundleId = bundleId + self.inApp = inApp + self.originalPurchaseDate = originalPurchaseDate + self.receiptCreationDate = receiptCreationDate + self.requestDate = requestDate + } + + public struct InApp: Equatable, Sendable { + public var originalPurchaseDate: Date + public var originalTransactionId: String + public var productId: String + public var purchaseDate: Date + public var quantity: Int + public var transactionId: String + + public init( + originalPurchaseDate: Date, + originalTransactionId: String, + productId: String, + purchaseDate: Date, + quantity: Int, + transactionId: String + ) { + self.originalPurchaseDate = originalPurchaseDate + self.originalTransactionId = originalTransactionId + self.productId = productId + self.purchaseDate = purchaseDate + self.quantity = quantity + self.transactionId = transactionId + } } } } diff --git a/Sources/NWSharedModels/Route/AppStoreRoute.swift b/Sources/NWSharedModels/Route/AppStoreRoute.swift index af0c33f..b465db2 100644 --- a/Sources/NWSharedModels/Route/AppStoreRoute.swift +++ b/Sources/NWSharedModels/Route/AppStoreRoute.swift @@ -1,13 +1,14 @@ import URLRouting +import Foundation public enum AppStoreRoute: Equatable { - case verifyReceipt(input: VerifyReceiptInput) + case verifyReceipt(Data) } public let appStoreRouter = OneOf { Route(.case(AppStoreRoute.verifyReceipt)) { - Path { "verify_receipt" } Method.post - Body(.json(VerifyReceiptInput.self)) + Path { "verify-receipt" } + Body() } }