Skip to content

Instantly share code, notes, and snippets.

@rcaos
Created August 15, 2022 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcaos/41dc725abbfe8ab2dfc76157c43a76da to your computer and use it in GitHub Desktop.
Save rcaos/41dc725abbfe8ab2dfc76157c43a76da to your computer and use it in GitHub Desktop.
StoreKit
func foo(_ a: SKProductsResponse) {
_ = a.invalidProductIdentifiers
_ = a.products
}
// APi
protocol ApiStoreKitProtocol {
func fetchProducts(_ productsIdentifiers: Set<String>) -> SFProductsResponse
}
struct SFProductsResponse {
let invalidProductIdentifiers: [String]
let products: [SFProduct]
}
// Domain
struct SFPaymentTransaction {
/// An object describing the error that occurred while processing the transaction.
let error: NSError?
let rawValue: SKPaymentTransaction?
/// The payment for the transaction.
/// Each payment transaction is created in response to a payment that your application added to the payment queue.
let payment: SFPayment
/// The date the transaction was added to the App Store’s payment queue.
let transactionDate: Date
/// A string that uniquely identifies a successful payment transaction.
let transactionIdentifier: String
/// The current state of the transaction.
/// case purchasing //A transaction that is being processed by the App Store.
/// case purchased; /// A successfully processed transaction.
/// case failed /// A failed transaction.
/// case restored /// A transaction that restores content previously purchased by the user.
/// case deferred /// A transaction that is in the queue, but its final status is pending external action such as Ask to Buy.
let transactionState: SKPaymentTransactionState
}
struct SFPayment {
/// A string used to identify a product that can be purchased from within your app.
let productIdentifier: String
/// The number of items the user wants to purchase. Max 10
let quantity: Int
/// A string that associates the payment transaction with a user on your service.
let applicationUsername: String?
/// A Boolean value that produces an "ask to buy" flow for this payment in the sandbox.
let simulatesAskToBuyInSandbox: Bool
}
struct SFProduct {
/// The string that identifies the product to the Apple App Store.
let productIdentifier: String
/// The title's language is determined by the storefront that the user's device is connected to,
/// not the preferred language set on the device.
let localizedTitle: String
/// The description's language is determined by the storefront that the user's device is connected to,
/// not the preferred language set on the device.
let localizedDescription: String
/// The cost of the product in the local currency.
/// let numberFormatter = NumberFormatter()
/// numberFormatter.numberStyle = .currency
/// numberFormatter.locale = product.priceLocale
/// let formattedString = numberFormatter.string(from: product.price)
let price: NSDecimalNumber
/// The locale used to format the price of the product.
let priceLocale: Locale
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment