├── README.md ├── Consumable ├── Supporting Files │ ├── Assets.xcassets │ │ ├── Contents.json │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ └── LaunchScreen.storyboard │ └── Info.plist ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json ├── AppDelegate.swift ├── Payment │ ├── PaymentError.swift │ ├── PaymentState.swift │ ├── PaymentQueue.swift │ ├── PaymentTransactionObserver.swift │ └── PaymentService.swift ├── API │ └── APIClient.swift ├── Persistence │ └── PersistenceService.swift ├── SceneDelegateProxy.swift ├── Models │ └── ConsumableItem.swift ├── Environment.swift ├── Views │ ├── ConsumableBindingModel.swift │ ├── ConsumableView.swift │ └── ConsumableViewModel.swift └── SceneDelegate.swift ├── Consumable.xcodeproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── project.pbxproj └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | # Consumable 2 | 3 | - Consumable In-App Purchase 4 | - Combine 5 | - SwiftUI 6 | -------------------------------------------------------------------------------- /Consumable/Supporting Files/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Consumable/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Consumable.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Consumable/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | @UIApplicationMain 4 | class AppDelegate: UIResponder, UIApplicationDelegate { 5 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool { 6 | return true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Consumable/Payment/PaymentError.swift: -------------------------------------------------------------------------------- 1 | enum PaymentError: String, Error { 2 | case notFoundItem 3 | case sendReceipt 4 | case receiveResponse 5 | case hasUnfinishedTransaction 6 | case unknown 7 | 8 | var localizedDescription: String { 9 | return "PaymentError(\(self.rawValue))" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Consumable.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Consumable/Payment/PaymentState.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | enum PaymentState { 4 | case initial 5 | case started 6 | case purchased 7 | case failed(Error) 8 | 9 | var localizedDescription: String { 10 | switch self { 11 | case .initial: 12 | return "initial" 13 | 14 | case .started: 15 | return "started" 16 | 17 | case .purchased: 18 | return "purchased" 19 | 20 | case let .failed(error): 21 | return (error as? PaymentError)?.localizedDescription ?? error.localizedDescription 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Consumable/API/APIClient.swift: -------------------------------------------------------------------------------- 1 | import Combine 2 | 3 | protocol APIClientType { 4 | func send() -> AnyPublisher, Never> 5 | } 6 | 7 | struct APIClient: APIClientType { 8 | private let environment: EnvironmentType 9 | 10 | init(environment: EnvironmentType = Environment.shared) { 11 | self.environment = environment 12 | } 13 | 14 | func send() -> AnyPublisher, Never> { 15 | guard environment.isResponseReceivabled else { 16 | return Just(.failure(PaymentError.receiveResponse)).eraseToAnyPublisher() 17 | } 18 | 19 | return Just(.success(())).eraseToAnyPublisher() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Consumable/Payment/PaymentQueue.swift: -------------------------------------------------------------------------------- 1 | import StoreKit 2 | 3 | protocol PaymentQueue { 4 | var transactions: [SKPaymentTransaction] { get } 5 | 6 | func canMakePayments() -> Bool 7 | func add(_ observer: SKPaymentTransactionObserver) 8 | func remove(_ observer: SKPaymentTransactionObserver) 9 | func add(_ payment: SKPayment) 10 | func finishTransaction(_ transaction: SKPaymentTransaction) 11 | func restoreCompletedTransactions() 12 | func restoreCompletedTransactions(withApplicationUsername username: String?) 13 | } 14 | 15 | extension SKPaymentQueue: PaymentQueue { 16 | func canMakePayments() -> Bool { 17 | return SKPaymentQueue.canMakePayments() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Consumable/Persistence/PersistenceService.swift: -------------------------------------------------------------------------------- 1 | import Combine 2 | import Foundation 3 | 4 | protocol PersistenceServiceType { 5 | func refreshAmount(with amount: Int) 6 | func fetchAmount() -> Int 7 | } 8 | 9 | class PersistenceService: PersistenceServiceType { 10 | private let userDefaults: UserDefaults 11 | private let key: String = "amount" 12 | 13 | init(userDefaults: UserDefaults = .standard) { 14 | self.userDefaults = userDefaults 15 | } 16 | 17 | func refreshAmount(with amount: Int) { 18 | return userDefaults.set(amount, forKey: key) 19 | } 20 | 21 | func fetchAmount() -> Int { 22 | return userDefaults.integer(forKey: key) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Consumable/SceneDelegateProxy.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import SwiftUI 3 | 4 | class SceneDelegateProxy: UIResponder, UIWindowSceneDelegate { 5 | let sceneDelegate = SceneDelegate() 6 | 7 | var window: UIWindow? { 8 | get { sceneDelegate.window } 9 | set { assertionFailure("Unexpected window settter call: \(newValue as UIWindow?)")} 10 | } 11 | 12 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 13 | sceneDelegate.scene(scene, willConnectTo: session, options: connectionOptions) 14 | } 15 | 16 | func sceneWillEnterForeground(_ scene: UIScene) { 17 | sceneDelegate.sceneWillEnterForeground(scene) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Consumable/Models/ConsumableItem.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import StoreKit 3 | import SwiftUI 4 | 5 | struct ConsumableItem { 6 | let id: Id 7 | let title: String 8 | let price: String 9 | 10 | struct Id: Hashable { 11 | let row: String 12 | } 13 | } 14 | 15 | extension ConsumableItem { 16 | init(product: SKProduct) { 17 | self.id = Id(row: product.productIdentifier) 18 | self.title = product.localizedTitle 19 | 20 | let formatter = NumberFormatter() 21 | formatter.formatterBehavior = .behavior10_4 22 | formatter.numberStyle = .currency 23 | formatter.locale = product.priceLocale 24 | self.price = formatter.string(from: product.price) ?? "" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Consumable/Environment.swift: -------------------------------------------------------------------------------- 1 | protocol EnvironmentType { 2 | var isNetworkEnabled: Bool { get } 3 | var isResponseReceivabled: Bool { get } 4 | 5 | func setIsNetworkEnabled(with isNetworkEnabled: Bool) 6 | func setIsResponseReceivabled(with isResponseReceivabled: Bool) 7 | } 8 | 9 | class Environment: EnvironmentType { 10 | static let shared = Environment() 11 | 12 | private(set) var isNetworkEnabled: Bool = true 13 | private(set) var isResponseReceivabled: Bool = true 14 | 15 | func setIsNetworkEnabled(with isNetworkEnabled: Bool) { 16 | self.isNetworkEnabled = isNetworkEnabled 17 | } 18 | 19 | func setIsResponseReceivabled(with isResponseReceivabled: Bool) { 20 | self.isResponseReceivabled = isResponseReceivabled 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Consumable/Payment/PaymentTransactionObserver.swift: -------------------------------------------------------------------------------- 1 | import Combine 2 | import StoreKit 3 | 4 | protocol PaymentTransactionObserverType: SKPaymentTransactionObserver { 5 | var updatedTransactions: AnyPublisher<[SKPaymentTransaction], Never> { get } 6 | } 7 | 8 | class PaymentTransactionObserver: NSObject, PaymentTransactionObserverType { 9 | let updatedTransactions: AnyPublisher<[SKPaymentTransaction], Never> 10 | private let _updatedTransactions = PassthroughSubject<[SKPaymentTransaction], Never>() 11 | 12 | override init() { 13 | self.updatedTransactions = _updatedTransactions.eraseToAnyPublisher() 14 | super.init() 15 | } 16 | 17 | func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { 18 | _updatedTransactions.send(transactions) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Consumable/Views/ConsumableBindingModel.swift: -------------------------------------------------------------------------------- 1 | import Combine 2 | import Foundation 3 | import SwiftUI 4 | 5 | protocol ConsumableBindingModelType: AnyObject { 6 | var items: [ConsumableItem] { get set } 7 | var state: PaymentState { get set } 8 | var amount: Int { get set } 9 | } 10 | 11 | class ConsumableBindingModel: ObservableObject, ConsumableBindingModelType { 12 | let objectWillChange: AnyPublisher 13 | private let _objectWillChange = PassthroughSubject() 14 | 15 | var items: [ConsumableItem] = [] { 16 | didSet { 17 | _objectWillChange.send(()) 18 | } 19 | } 20 | 21 | var state: PaymentState = .initial { 22 | didSet { 23 | _objectWillChange.send(()) 24 | } 25 | } 26 | 27 | var amount: Int = 0 { 28 | didSet { 29 | _objectWillChange.send(()) 30 | } 31 | } 32 | 33 | init() { 34 | self.objectWillChange = _objectWillChange.eraseToAnyPublisher() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Consumable/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import SwiftUI 3 | 4 | protocol SceneDelegateType { 5 | var window: UIWindow? { get } 6 | 7 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) 8 | func sceneWillEnterForeground(_ scene: UIScene) 9 | } 10 | 11 | class SceneDelegate: SceneDelegateType { 12 | private(set) var window: UIWindow? 13 | private let paymentService: PaymentServiceType 14 | 15 | init(paymentService: PaymentServiceType = PaymentService.shared) { 16 | self.paymentService = paymentService 17 | } 18 | 19 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 20 | guard let windowScene = scene as? UIWindowScene else { 21 | return 22 | } 23 | 24 | let window = UIWindow(windowScene: windowScene) 25 | window.rootViewController = UIHostingController(rootView: ConsumableView()) 26 | self.window = window 27 | window.makeKeyAndVisible() 28 | } 29 | 30 | func sceneWillEnterForeground(_ scene: UIScene) { 31 | _ = paymentService.recoveryPendingTransactions() 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Consumable/Supporting Files/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Consumable/Views/ConsumableView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct ConsumableView: View { 4 | private let viewModel: ConsumableViewModelType 5 | private let environment: EnvironmentType 6 | 7 | @ObservedObject 8 | private var bindingModel: ConsumableBindingModel 9 | 10 | @State 11 | private var network = true 12 | 13 | @State 14 | private var response = true 15 | 16 | var body: some View { 17 | environment.setIsNetworkEnabled(with: _network.wrappedValue) 18 | environment.setIsResponseReceivabled(with: _response.wrappedValue) 19 | 20 | return VStack(spacing: 35) { 21 | ForEach(bindingModel.items, id: \.id) { item in 22 | Button("Purchase \(item.title) (\(item.price))") { 23 | // 1. 購入リクエスト 24 | self.viewModel.purchase(by: item.id) 25 | } 26 | } 27 | 28 | Toggle(isOn: $network) { 29 | Text("Enable Network") 30 | }.padding() 31 | 32 | Toggle(isOn: $response) { 33 | Text("Receive Response") 34 | }.padding() 35 | 36 | Button("Fetch Consumable Items") { 37 | self.viewModel.fetch() 38 | } 39 | 40 | Button("Recovery Pending Transactions") { 41 | self.viewModel.recovery() 42 | } 43 | 44 | Button("Print Receipt") { 45 | self.viewModel.printReceipt() 46 | } 47 | 48 | Text("Amount: \(bindingModel.amount)") 49 | Text("State: \(bindingModel.state.localizedDescription)") 50 | } 51 | } 52 | 53 | init(viewModel: ConsumableViewModelType = ConsumableViewModel(mainScheduler: DispatchQueue.main), 54 | environment: EnvironmentType = Environment.shared) { 55 | self.viewModel = viewModel 56 | self.bindingModel = viewModel.bindingModel as! ConsumableBindingModel 57 | self.environment = environment 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Consumable/Supporting Files/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /Consumable/Supporting Files/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UILaunchStoryboardName 33 | LaunchScreen 34 | UISceneConfigurationName 35 | Default Configuration 36 | UISceneDelegateClassName 37 | $(PRODUCT_MODULE_NAME).SceneDelegateProxy 38 | 39 | 40 | 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIRequiredDeviceCapabilities 45 | 46 | armv7 47 | 48 | UISupportedInterfaceOrientations 49 | 50 | UIInterfaceOrientationPortrait 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | 54 | UISupportedInterfaceOrientations~ipad 55 | 56 | UIInterfaceOrientationPortrait 57 | UIInterfaceOrientationPortraitUpsideDown 58 | UIInterfaceOrientationLandscapeLeft 59 | UIInterfaceOrientationLandscapeRight 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac 2 | .DS_Store 3 | 4 | # Git 5 | .gitattributes 6 | 7 | # Created by https://www.gitignore.io/api/swift,osx 8 | 9 | ### Swift ### 10 | # Xcode 11 | # 12 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 13 | 14 | ## Build generated 15 | build/ 16 | DerivedData/ 17 | 18 | ## Various settings 19 | *.pbxuser 20 | !default.pbxuser 21 | *.mode1v3 22 | !default.mode1v3 23 | *.mode2v3 24 | !default.mode2v3 25 | *.perspectivev3 26 | !default.perspectivev3 27 | xcuserdata/ 28 | 29 | ## Other 30 | *.moved-aside 31 | *.xcuserstate 32 | *.mobileprovision 33 | 34 | ## Obj-C/Swift specific 35 | *.hmap 36 | *.ipa 37 | *.dSYM.zip 38 | 39 | ## Playgrounds 40 | timeline.xctimeline 41 | playground.xcworkspace 42 | 43 | # Swift Package Manager 44 | # 45 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 46 | # Packages/ 47 | # .build/ 48 | 49 | # CocoaPods 50 | # 51 | # We recommend against adding the Pods directory to your .gitignore. However 52 | # you should judge for yourself, the pros and cons are mentioned at: 53 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 54 | # 55 | Pods/ 56 | 57 | # Carthage 58 | # 59 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 60 | Carthage/Checkouts 61 | Carthage/Build 62 | 63 | # fastlane 64 | # 65 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 66 | # screenshots whenever they are needed. 67 | # For more information about the recommended setup visit: 68 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 69 | 70 | fastlane/report.xml 71 | fastlane/Preview.html 72 | fastlane/test_output 73 | fastlane/.env 74 | 75 | ### OSX ### 76 | .DS_Store 77 | .AppleDouble 78 | .LSOverride 79 | 80 | # Icon must end with two \r 81 | Icon 82 | 83 | # Thumbnails 84 | ._* 85 | 86 | # Files that might appear in the root of a volume 87 | .DocumentRevisions-V100 88 | .fseventsd 89 | .Spotlight-V100 90 | .TemporaryItems 91 | .Trashes 92 | .VolumeIcon.icns 93 | 94 | # Directories potentially created on remote AFP share 95 | .AppleDB 96 | .AppleDesktop 97 | Network Trash Folder 98 | Temporary Items 99 | .apdisk 100 | 101 | ### Ruby ### 102 | 103 | ## Environment normalization: 104 | .bundle/ 105 | vendor/bundle 106 | 107 | # IntelliJ 108 | .idea/* 109 | 110 | # VSCode 111 | *vscode/* 112 | -------------------------------------------------------------------------------- /Consumable/Views/ConsumableViewModel.swift: -------------------------------------------------------------------------------- 1 | import Combine 2 | import Foundation 3 | 4 | protocol ConsumableViewModelType { 5 | var bindingModel: ConsumableBindingModelType { get } 6 | 7 | func fetch() 8 | func purchase(by id: ConsumableItem.Id) 9 | func recovery() 10 | func printReceipt() 11 | } 12 | 13 | class ConsumableViewModel: ConsumableViewModelType { 14 | private(set) var bindingModel: ConsumableBindingModelType 15 | private let paymentService: PaymentServiceType 16 | private let persistenceService: PersistenceServiceType 17 | private let bundle: Bundle 18 | 19 | private let _fetch = PassthroughSubject() 20 | private let _purchase = PassthroughSubject() 21 | private let _recovery = PassthroughSubject() 22 | private let _printReceipt = PassthroughSubject() 23 | 24 | init(bindingModel: ConsumableBindingModelType = ConsumableBindingModel(), 25 | paymentService: PaymentServiceType = PaymentService.shared, 26 | persistenceService: PersistenceServiceType = PersistenceService(), 27 | bundle: Bundle = .main, 28 | mainScheduler: S) { 29 | self.bindingModel = bindingModel 30 | self.paymentService = paymentService 31 | self.persistenceService = persistenceService 32 | self.bundle = bundle 33 | 34 | self.bindingModel.amount = persistenceService.fetchAmount() 35 | 36 | _fetch 37 | .flatMap { paymentService.fetch() } 38 | .receive(on: mainScheduler) 39 | .handleEvents(receiveOutput: { [weak self] _ in 40 | self?.bindingModel.amount = persistenceService.fetchAmount() 41 | }) 42 | .receive(subscriber: Subscribers.Assign(object: bindingModel, keyPath: \.items)) 43 | 44 | _purchase 45 | .flatMap { paymentService.purchase(by: $0) } 46 | .receive(on: mainScheduler) 47 | .handleEvents(receiveOutput: { [weak self] _ in 48 | self?.bindingModel.amount = persistenceService.fetchAmount() 49 | }) 50 | .receive(subscriber: Subscribers.Assign(object: bindingModel, keyPath: \.state)) 51 | 52 | _recovery 53 | .flatMap { paymentService.recoveryPendingTransactions() } 54 | .receive(on: mainScheduler) 55 | .receive(subscriber: Subscribers.Sink( 56 | receiveCompletion: { _ in }, 57 | receiveValue: { [weak self] _ in 58 | self?.bindingModel.amount = persistenceService.fetchAmount() 59 | } 60 | )) 61 | 62 | _printReceipt 63 | .receive(subscriber: Subscribers.Sink( 64 | receiveCompletion: { _ in }, 65 | receiveValue: { _ in 66 | let base64EncodedString = bundle.appStoreReceiptURL 67 | .flatMap { try? Data(contentsOf: $0) } 68 | .map { $0.base64EncodedString(options: .init(rawValue: 0)) } 69 | print(base64EncodedString ?? "Not Found Receipt") 70 | } 71 | )) 72 | } 73 | 74 | func fetch() { 75 | _fetch.send(()) 76 | } 77 | 78 | func purchase(by id: ConsumableItem.Id) { 79 | _purchase.send(id) 80 | } 81 | 82 | func recovery() { 83 | _recovery.send(()) 84 | } 85 | 86 | func printReceipt() { 87 | _printReceipt.send(()) 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Consumable/Payment/PaymentService.swift: -------------------------------------------------------------------------------- 1 | import Combine 2 | import StoreKit 3 | 4 | protocol PaymentServiceType { 5 | func fetch() -> AnyPublisher<[ConsumableItem], Never> 6 | func purchase(by id: ConsumableItem.Id) -> AnyPublisher 7 | func recoveryPendingTransactions() -> AnyPublisher 8 | } 9 | 10 | class PaymentService: NSObject, PaymentServiceType { 11 | static let shared = PaymentService() 12 | 13 | private let paymentQueue: PaymentQueue 14 | private let transationObserver: PaymentTransactionObserverType 15 | private let apiClient: APIClientType 16 | private let persitenceService: PersistenceServiceType 17 | private let environment: EnvironmentType 18 | 19 | private let _fetch = CurrentValueSubject<[SKProduct], Never>([]) 20 | private let _purchase = PassthroughSubject() 21 | private var _paymentState = PassthroughSubject() 22 | 23 | init(paymentQueue: PaymentQueue = SKPaymentQueue.default(), 24 | transationObserver: PaymentTransactionObserverType = PaymentTransactionObserver(), 25 | apiClient: APIClientType = APIClient(), 26 | persitenceService: PersistenceServiceType = PersistenceService(), 27 | environment: EnvironmentType = Environment.shared) { 28 | self.paymentQueue = paymentQueue 29 | self.transationObserver = transationObserver 30 | self.apiClient = apiClient 31 | self.persitenceService = persitenceService 32 | self.environment = environment 33 | super.init() 34 | paymentQueue.add(transationObserver) 35 | 36 | transationObserver.updatedTransactions 37 | .combineLatest(_purchase.eraseToAnyPublisher()) 38 | .receive(subscriber: Subscribers.Sink( 39 | receiveCompletion: { _ in }, 40 | receiveValue: { [weak self] (transactions, id) in 41 | guard let transaction = transactions.filter({ $0.payment.productIdentifier == id.row }).first else { 42 | self?._paymentState.send(.failed(PaymentError.notFoundItem)) 43 | return 44 | } 45 | 46 | switch transaction.transactionState { 47 | case .purchasing: 48 | self?._paymentState.send(.started) 49 | 50 | case .purchased: 51 | // 2. 購入完了 52 | self?.finishPurchaseConsumable(transaction: transaction) 53 | 54 | case .failed: 55 | self?.paymentQueue.finishTransaction(transaction) 56 | self?._paymentState.send(.failed(transaction.error ?? PaymentError.unknown)) 57 | 58 | default: 59 | break 60 | } 61 | } 62 | )) 63 | 64 | _purchase 65 | .tryMap { [weak self] id -> Result in 66 | guard let product = self?._fetch.value.filter({ $0.productIdentifier == id.row }).first else { 67 | return .failure(PaymentError.notFoundItem) 68 | } 69 | 70 | return .success(SKMutablePayment(product: product)) 71 | } 72 | .receive(subscriber: Subscribers.Sink( 73 | receiveCompletion: { _ in }, 74 | receiveValue: { [weak self] result in 75 | switch result { 76 | case let .success(payment): 77 | self?.paymentQueue.add(payment) 78 | case let .failure(error): 79 | self?._paymentState.send(.failed(error)) 80 | } 81 | } 82 | )) 83 | } 84 | 85 | deinit { 86 | paymentQueue.remove(transationObserver) 87 | } 88 | 89 | func fetch() -> AnyPublisher<[ConsumableItem], Never> { 90 | return fetchProducts() 91 | .map { $0.map(ConsumableItem.init(product:)) } 92 | .eraseToAnyPublisher() 93 | } 94 | 95 | func purchase(by id: ConsumableItem.Id) -> AnyPublisher { 96 | if hasQueueingTransactions { 97 | // 未完了トランザクションが存在するとき 98 | return Just(.failed(PaymentError.hasUnfinishedTransaction)).eraseToAnyPublisher() 99 | } 100 | 101 | _purchase.send(id) 102 | return _paymentState.eraseToAnyPublisher() 103 | } 104 | 105 | func recoveryPendingTransactions() -> AnyPublisher { 106 | // 未完了トランザクションのリトライ 107 | let transactions = paymentQueue.transactions 108 | .filter { $0.transactionState != .purchasing } 109 | 110 | for transaction in transactions { 111 | finishPurchaseConsumable(transaction: transaction) 112 | } 113 | 114 | return Just(()).eraseToAnyPublisher() 115 | } 116 | 117 | private var hasQueueingTransactions: Bool { 118 | return !paymentQueue.transactions.isEmpty 119 | } 120 | 121 | private func fetchProducts() -> AnyPublisher<[SKProduct], Never> { 122 | let productIdentifiers: Set = [ 123 | "com.nonchalant.consumable1", 124 | "com.nonchalant.consumable2" 125 | ] 126 | 127 | let request = SKProductsRequest(productIdentifiers: productIdentifiers) 128 | request.delegate = self 129 | request.start() 130 | 131 | return _fetch.eraseToAnyPublisher() 132 | } 133 | 134 | private func finishPurchaseConsumable(transaction: SKPaymentTransaction) { 135 | guard environment.isNetworkEnabled else { 136 | // レシート送信に失敗するケース 137 | _paymentState.send(.failed(PaymentError.sendReceipt)) 138 | return 139 | } 140 | 141 | // 3. レシート送信 (4~6) 142 | apiClient.send() 143 | .receive(subscriber: Subscribers.Sink( 144 | receiveCompletion: { _ in }, 145 | receiveValue: { [weak self] result in 146 | // 7. 完了レスポンス(201) 147 | guard let me = self else { 148 | self?._paymentState.send(.failed(PaymentError.unknown)) 149 | return 150 | } 151 | 152 | switch result { 153 | case .success: 154 | // 8. トランザクションの終了 155 | me.paymentQueue.finishTransaction(transaction) 156 | 157 | let price = me._fetch.value 158 | .filter { $0.productIdentifier == transaction.payment.productIdentifier } 159 | .first? 160 | .price ?? 0 161 | 162 | me.persitenceService.refreshAmount(with: Int(truncating: price) + me.persitenceService.fetchAmount()) 163 | me._paymentState.send(.purchased) 164 | 165 | case let .failure(error): 166 | // 完了レスポンスの受け取りに失敗するケース 167 | self?._paymentState.send(.failed(error)) 168 | } 169 | } 170 | )) 171 | } 172 | } 173 | 174 | extension PaymentService: SKProductsRequestDelegate { 175 | func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) { 176 | _fetch.send(response.products) 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /Consumable.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 244044B22300721C008B3D1E /* SceneDelegateProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 244044B12300721C008B3D1E /* SceneDelegateProxy.swift */; }; 11 | 247EA34122EC2F1B0006F9A0 /* PaymentQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 247EA34022EC2F1B0006F9A0 /* PaymentQueue.swift */; }; 12 | 247EA34322EC2F510006F9A0 /* PaymentTransactionObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 247EA34222EC2F510006F9A0 /* PaymentTransactionObserver.swift */; }; 13 | 24A8B8B322EC62E100AB12C4 /* Environment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24A8B8B222EC62E100AB12C4 /* Environment.swift */; }; 14 | 24ACD27322EC56BE009C5D5C /* PaymentError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24ACD27222EC56BE009C5D5C /* PaymentError.swift */; }; 15 | 24ACD27622EC602E009C5D5C /* APIClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24ACD27522EC602E009C5D5C /* APIClient.swift */; }; 16 | 24ACD27822EC61D7009C5D5C /* PaymentState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24ACD27722EC61D7009C5D5C /* PaymentState.swift */; }; 17 | 24B83400230018340012AA1B /* PersistenceService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24B833FF230018340012AA1B /* PersistenceService.swift */; }; 18 | 5F5301C722E8DE270006B924 /* ConsumableViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F5301C622E8DE270006B924 /* ConsumableViewModel.swift */; }; 19 | 5F5301CA22E8DF990006B924 /* ConsumableBindingModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F5301C922E8DF990006B924 /* ConsumableBindingModel.swift */; }; 20 | 5F5301CC22E8E63B0006B924 /* PaymentService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F5301CB22E8E63B0006B924 /* PaymentService.swift */; }; 21 | 5F90470C22E840210097CF2A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F90470B22E840210097CF2A /* AppDelegate.swift */; }; 22 | 5F90470E22E840210097CF2A /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F90470D22E840210097CF2A /* SceneDelegate.swift */; }; 23 | 5F90471022E840210097CF2A /* ConsumableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F90470F22E840210097CF2A /* ConsumableView.swift */; }; 24 | 5F90471222E840220097CF2A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5F90471122E840220097CF2A /* Assets.xcassets */; }; 25 | 5F90471522E840220097CF2A /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5F90471422E840220097CF2A /* Preview Assets.xcassets */; }; 26 | 5F90471822E840220097CF2A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5F90471622E840220097CF2A /* LaunchScreen.storyboard */; }; 27 | 5F90472E22E841BE0097CF2A /* ConsumableItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F90472D22E841BE0097CF2A /* ConsumableItem.swift */; }; 28 | /* End PBXBuildFile section */ 29 | 30 | /* Begin PBXFileReference section */ 31 | 244044B12300721C008B3D1E /* SceneDelegateProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegateProxy.swift; sourceTree = ""; }; 32 | 247EA34022EC2F1B0006F9A0 /* PaymentQueue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentQueue.swift; sourceTree = ""; }; 33 | 247EA34222EC2F510006F9A0 /* PaymentTransactionObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentTransactionObserver.swift; sourceTree = ""; }; 34 | 247EA34522EC390E0006F9A0 /* SwiftUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftUI.framework; path = System/Library/Frameworks/SwiftUI.framework; sourceTree = SDKROOT; }; 35 | 247EA34722EC395B0006F9A0 /* Combine.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Combine.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Combine.framework; sourceTree = DEVELOPER_DIR; }; 36 | 24A8B8B222EC62E100AB12C4 /* Environment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Environment.swift; sourceTree = ""; }; 37 | 24ACD27222EC56BE009C5D5C /* PaymentError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentError.swift; sourceTree = ""; }; 38 | 24ACD27522EC602E009C5D5C /* APIClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIClient.swift; sourceTree = ""; }; 39 | 24ACD27722EC61D7009C5D5C /* PaymentState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentState.swift; sourceTree = ""; }; 40 | 24B833FF230018340012AA1B /* PersistenceService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersistenceService.swift; sourceTree = ""; }; 41 | 5F5301C622E8DE270006B924 /* ConsumableViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsumableViewModel.swift; sourceTree = ""; }; 42 | 5F5301C922E8DF990006B924 /* ConsumableBindingModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConsumableBindingModel.swift; sourceTree = ""; }; 43 | 5F5301CB22E8E63B0006B924 /* PaymentService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentService.swift; sourceTree = ""; }; 44 | 5F90470822E840210097CF2A /* Consumable.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Consumable.app; sourceTree = BUILT_PRODUCTS_DIR; }; 45 | 5F90470B22E840210097CF2A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 46 | 5F90470D22E840210097CF2A /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 47 | 5F90470F22E840210097CF2A /* ConsumableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsumableView.swift; sourceTree = ""; }; 48 | 5F90471122E840220097CF2A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 49 | 5F90471422E840220097CF2A /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 50 | 5F90471722E840220097CF2A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 51 | 5F90471922E840220097CF2A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 52 | 5F90472D22E841BE0097CF2A /* ConsumableItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsumableItem.swift; sourceTree = ""; }; 53 | /* End PBXFileReference section */ 54 | 55 | /* Begin PBXFrameworksBuildPhase section */ 56 | 5F90470522E840210097CF2A /* Frameworks */ = { 57 | isa = PBXFrameworksBuildPhase; 58 | buildActionMask = 2147483647; 59 | files = ( 60 | ); 61 | runOnlyForDeploymentPostprocessing = 0; 62 | }; 63 | /* End PBXFrameworksBuildPhase section */ 64 | 65 | /* Begin PBXGroup section */ 66 | 247EA34422EC390D0006F9A0 /* Frameworks */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 247EA34722EC395B0006F9A0 /* Combine.framework */, 70 | 247EA34522EC390E0006F9A0 /* SwiftUI.framework */, 71 | ); 72 | name = Frameworks; 73 | sourceTree = ""; 74 | }; 75 | 24ACD27422EC601F009C5D5C /* API */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | 24ACD27522EC602E009C5D5C /* APIClient.swift */, 79 | ); 80 | path = API; 81 | sourceTree = ""; 82 | }; 83 | 24B833FE230018250012AA1B /* Persistence */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | 24B833FF230018340012AA1B /* PersistenceService.swift */, 87 | ); 88 | path = Persistence; 89 | sourceTree = ""; 90 | }; 91 | 5F5301C822E8DF5F0006B924 /* Supporting Files */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 5F90471122E840220097CF2A /* Assets.xcassets */, 95 | 5F90471622E840220097CF2A /* LaunchScreen.storyboard */, 96 | 5F90471922E840220097CF2A /* Info.plist */, 97 | ); 98 | path = "Supporting Files"; 99 | sourceTree = ""; 100 | }; 101 | 5F5301CD22E8E6410006B924 /* Payment */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 24ACD27222EC56BE009C5D5C /* PaymentError.swift */, 105 | 5F5301CB22E8E63B0006B924 /* PaymentService.swift */, 106 | 24ACD27722EC61D7009C5D5C /* PaymentState.swift */, 107 | 247EA34222EC2F510006F9A0 /* PaymentTransactionObserver.swift */, 108 | 247EA34022EC2F1B0006F9A0 /* PaymentQueue.swift */, 109 | ); 110 | path = Payment; 111 | sourceTree = ""; 112 | }; 113 | 5F9046FF22E840200097CF2A = { 114 | isa = PBXGroup; 115 | children = ( 116 | 5F90470A22E840210097CF2A /* Consumable */, 117 | 5F90470922E840210097CF2A /* Products */, 118 | 247EA34422EC390D0006F9A0 /* Frameworks */, 119 | ); 120 | sourceTree = ""; 121 | }; 122 | 5F90470922E840210097CF2A /* Products */ = { 123 | isa = PBXGroup; 124 | children = ( 125 | 5F90470822E840210097CF2A /* Consumable.app */, 126 | ); 127 | name = Products; 128 | sourceTree = ""; 129 | }; 130 | 5F90470A22E840210097CF2A /* Consumable */ = { 131 | isa = PBXGroup; 132 | children = ( 133 | 5F90470B22E840210097CF2A /* AppDelegate.swift */, 134 | 24A8B8B222EC62E100AB12C4 /* Environment.swift */, 135 | 5F90470D22E840210097CF2A /* SceneDelegate.swift */, 136 | 244044B12300721C008B3D1E /* SceneDelegateProxy.swift */, 137 | 5F90473122E843A30097CF2A /* Views */, 138 | 5F90473422E880860097CF2A /* Models */, 139 | 5F5301CD22E8E6410006B924 /* Payment */, 140 | 24B833FE230018250012AA1B /* Persistence */, 141 | 24ACD27422EC601F009C5D5C /* API */, 142 | 5F5301C822E8DF5F0006B924 /* Supporting Files */, 143 | 5F90471322E840220097CF2A /* Preview Content */, 144 | ); 145 | path = Consumable; 146 | sourceTree = ""; 147 | }; 148 | 5F90471322E840220097CF2A /* Preview Content */ = { 149 | isa = PBXGroup; 150 | children = ( 151 | 5F90471422E840220097CF2A /* Preview Assets.xcassets */, 152 | ); 153 | path = "Preview Content"; 154 | sourceTree = ""; 155 | }; 156 | 5F90473122E843A30097CF2A /* Views */ = { 157 | isa = PBXGroup; 158 | children = ( 159 | 5F5301C922E8DF990006B924 /* ConsumableBindingModel.swift */, 160 | 5F90470F22E840210097CF2A /* ConsumableView.swift */, 161 | 5F5301C622E8DE270006B924 /* ConsumableViewModel.swift */, 162 | ); 163 | path = Views; 164 | sourceTree = ""; 165 | }; 166 | 5F90473422E880860097CF2A /* Models */ = { 167 | isa = PBXGroup; 168 | children = ( 169 | 5F90472D22E841BE0097CF2A /* ConsumableItem.swift */, 170 | ); 171 | path = Models; 172 | sourceTree = ""; 173 | }; 174 | /* End PBXGroup section */ 175 | 176 | /* Begin PBXNativeTarget section */ 177 | 5F90470722E840210097CF2A /* Consumable */ = { 178 | isa = PBXNativeTarget; 179 | buildConfigurationList = 5F90472722E840220097CF2A /* Build configuration list for PBXNativeTarget "Consumable" */; 180 | buildPhases = ( 181 | 5F90470422E840210097CF2A /* Sources */, 182 | 5F90470522E840210097CF2A /* Frameworks */, 183 | 5F90470622E840210097CF2A /* Resources */, 184 | ); 185 | buildRules = ( 186 | ); 187 | dependencies = ( 188 | ); 189 | name = Consumable; 190 | productName = Consumable; 191 | productReference = 5F90470822E840210097CF2A /* Consumable.app */; 192 | productType = "com.apple.product-type.application"; 193 | }; 194 | /* End PBXNativeTarget section */ 195 | 196 | /* Begin PBXProject section */ 197 | 5F90470022E840200097CF2A /* Project object */ = { 198 | isa = PBXProject; 199 | attributes = { 200 | LastSwiftUpdateCheck = 1100; 201 | LastUpgradeCheck = 1100; 202 | ORGANIZATIONNAME = "Takeshi Ihara"; 203 | TargetAttributes = { 204 | 5F90470722E840210097CF2A = { 205 | CreatedOnToolsVersion = 11.0; 206 | }; 207 | }; 208 | }; 209 | buildConfigurationList = 5F90470322E840210097CF2A /* Build configuration list for PBXProject "Consumable" */; 210 | compatibilityVersion = "Xcode 9.3"; 211 | developmentRegion = en; 212 | hasScannedForEncodings = 0; 213 | knownRegions = ( 214 | en, 215 | Base, 216 | ); 217 | mainGroup = 5F9046FF22E840200097CF2A; 218 | productRefGroup = 5F90470922E840210097CF2A /* Products */; 219 | projectDirPath = ""; 220 | projectRoot = ""; 221 | targets = ( 222 | 5F90470722E840210097CF2A /* Consumable */, 223 | ); 224 | }; 225 | /* End PBXProject section */ 226 | 227 | /* Begin PBXResourcesBuildPhase section */ 228 | 5F90470622E840210097CF2A /* Resources */ = { 229 | isa = PBXResourcesBuildPhase; 230 | buildActionMask = 2147483647; 231 | files = ( 232 | 5F90471822E840220097CF2A /* LaunchScreen.storyboard in Resources */, 233 | 5F90471522E840220097CF2A /* Preview Assets.xcassets in Resources */, 234 | 5F90471222E840220097CF2A /* Assets.xcassets in Resources */, 235 | ); 236 | runOnlyForDeploymentPostprocessing = 0; 237 | }; 238 | /* End PBXResourcesBuildPhase section */ 239 | 240 | /* Begin PBXSourcesBuildPhase section */ 241 | 5F90470422E840210097CF2A /* Sources */ = { 242 | isa = PBXSourcesBuildPhase; 243 | buildActionMask = 2147483647; 244 | files = ( 245 | 24ACD27822EC61D7009C5D5C /* PaymentState.swift in Sources */, 246 | 5F5301C722E8DE270006B924 /* ConsumableViewModel.swift in Sources */, 247 | 5F90470C22E840210097CF2A /* AppDelegate.swift in Sources */, 248 | 5F90470E22E840210097CF2A /* SceneDelegate.swift in Sources */, 249 | 5F5301CA22E8DF990006B924 /* ConsumableBindingModel.swift in Sources */, 250 | 247EA34122EC2F1B0006F9A0 /* PaymentQueue.swift in Sources */, 251 | 244044B22300721C008B3D1E /* SceneDelegateProxy.swift in Sources */, 252 | 24ACD27622EC602E009C5D5C /* APIClient.swift in Sources */, 253 | 24ACD27322EC56BE009C5D5C /* PaymentError.swift in Sources */, 254 | 24B83400230018340012AA1B /* PersistenceService.swift in Sources */, 255 | 24A8B8B322EC62E100AB12C4 /* Environment.swift in Sources */, 256 | 247EA34322EC2F510006F9A0 /* PaymentTransactionObserver.swift in Sources */, 257 | 5F90471022E840210097CF2A /* ConsumableView.swift in Sources */, 258 | 5F5301CC22E8E63B0006B924 /* PaymentService.swift in Sources */, 259 | 5F90472E22E841BE0097CF2A /* ConsumableItem.swift in Sources */, 260 | ); 261 | runOnlyForDeploymentPostprocessing = 0; 262 | }; 263 | /* End PBXSourcesBuildPhase section */ 264 | 265 | /* Begin PBXVariantGroup section */ 266 | 5F90471622E840220097CF2A /* LaunchScreen.storyboard */ = { 267 | isa = PBXVariantGroup; 268 | children = ( 269 | 5F90471722E840220097CF2A /* Base */, 270 | ); 271 | name = LaunchScreen.storyboard; 272 | sourceTree = ""; 273 | }; 274 | /* End PBXVariantGroup section */ 275 | 276 | /* Begin XCBuildConfiguration section */ 277 | 5F90472522E840220097CF2A /* Debug */ = { 278 | isa = XCBuildConfiguration; 279 | buildSettings = { 280 | ALWAYS_SEARCH_USER_PATHS = NO; 281 | CLANG_ANALYZER_NONNULL = YES; 282 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 283 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 284 | CLANG_CXX_LIBRARY = "libc++"; 285 | CLANG_ENABLE_MODULES = YES; 286 | CLANG_ENABLE_OBJC_ARC = YES; 287 | CLANG_ENABLE_OBJC_WEAK = YES; 288 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 289 | CLANG_WARN_BOOL_CONVERSION = YES; 290 | CLANG_WARN_COMMA = YES; 291 | CLANG_WARN_CONSTANT_CONVERSION = YES; 292 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 293 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 294 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 295 | CLANG_WARN_EMPTY_BODY = YES; 296 | CLANG_WARN_ENUM_CONVERSION = YES; 297 | CLANG_WARN_INFINITE_RECURSION = YES; 298 | CLANG_WARN_INT_CONVERSION = YES; 299 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 300 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 301 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 302 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 303 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 304 | CLANG_WARN_STRICT_PROTOTYPES = YES; 305 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 306 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 307 | CLANG_WARN_UNREACHABLE_CODE = YES; 308 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 309 | COPY_PHASE_STRIP = NO; 310 | DEBUG_INFORMATION_FORMAT = dwarf; 311 | ENABLE_STRICT_OBJC_MSGSEND = YES; 312 | ENABLE_TESTABILITY = YES; 313 | GCC_C_LANGUAGE_STANDARD = gnu11; 314 | GCC_DYNAMIC_NO_PIC = NO; 315 | GCC_NO_COMMON_BLOCKS = YES; 316 | GCC_OPTIMIZATION_LEVEL = 0; 317 | GCC_PREPROCESSOR_DEFINITIONS = ( 318 | "DEBUG=1", 319 | "$(inherited)", 320 | ); 321 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 322 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 323 | GCC_WARN_UNDECLARED_SELECTOR = YES; 324 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 325 | GCC_WARN_UNUSED_FUNCTION = YES; 326 | GCC_WARN_UNUSED_VARIABLE = YES; 327 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 328 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 329 | MTL_FAST_MATH = YES; 330 | ONLY_ACTIVE_ARCH = YES; 331 | SDKROOT = iphoneos; 332 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 333 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 334 | }; 335 | name = Debug; 336 | }; 337 | 5F90472622E840220097CF2A /* Release */ = { 338 | isa = XCBuildConfiguration; 339 | buildSettings = { 340 | ALWAYS_SEARCH_USER_PATHS = NO; 341 | CLANG_ANALYZER_NONNULL = YES; 342 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 343 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 344 | CLANG_CXX_LIBRARY = "libc++"; 345 | CLANG_ENABLE_MODULES = YES; 346 | CLANG_ENABLE_OBJC_ARC = YES; 347 | CLANG_ENABLE_OBJC_WEAK = YES; 348 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 349 | CLANG_WARN_BOOL_CONVERSION = YES; 350 | CLANG_WARN_COMMA = YES; 351 | CLANG_WARN_CONSTANT_CONVERSION = YES; 352 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 353 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 354 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 355 | CLANG_WARN_EMPTY_BODY = YES; 356 | CLANG_WARN_ENUM_CONVERSION = YES; 357 | CLANG_WARN_INFINITE_RECURSION = YES; 358 | CLANG_WARN_INT_CONVERSION = YES; 359 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 360 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 361 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 362 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 363 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 364 | CLANG_WARN_STRICT_PROTOTYPES = YES; 365 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 366 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 367 | CLANG_WARN_UNREACHABLE_CODE = YES; 368 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 369 | COPY_PHASE_STRIP = NO; 370 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 371 | ENABLE_NS_ASSERTIONS = NO; 372 | ENABLE_STRICT_OBJC_MSGSEND = YES; 373 | GCC_C_LANGUAGE_STANDARD = gnu11; 374 | GCC_NO_COMMON_BLOCKS = YES; 375 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 376 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 377 | GCC_WARN_UNDECLARED_SELECTOR = YES; 378 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 379 | GCC_WARN_UNUSED_FUNCTION = YES; 380 | GCC_WARN_UNUSED_VARIABLE = YES; 381 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 382 | MTL_ENABLE_DEBUG_INFO = NO; 383 | MTL_FAST_MATH = YES; 384 | SDKROOT = iphoneos; 385 | SWIFT_COMPILATION_MODE = wholemodule; 386 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 387 | VALIDATE_PRODUCT = YES; 388 | }; 389 | name = Release; 390 | }; 391 | 5F90472822E840220097CF2A /* Debug */ = { 392 | isa = XCBuildConfiguration; 393 | buildSettings = { 394 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 395 | CODE_SIGN_STYLE = Automatic; 396 | DEVELOPMENT_ASSET_PATHS = "Consumable/Preview\\ Content"; 397 | DEVELOPMENT_TEAM = HKDHURHY83; 398 | ENABLE_PREVIEWS = YES; 399 | INFOPLIST_FILE = "Consumable/Supporting Files/Info.plist"; 400 | LD_RUNPATH_SEARCH_PATHS = ( 401 | "$(inherited)", 402 | "@executable_path/Frameworks", 403 | ); 404 | PRODUCT_BUNDLE_IDENTIFIER = com.nonchalant.Consumable; 405 | PRODUCT_NAME = "$(TARGET_NAME)"; 406 | SWIFT_VERSION = 5.0; 407 | TARGETED_DEVICE_FAMILY = "1,2"; 408 | }; 409 | name = Debug; 410 | }; 411 | 5F90472922E840220097CF2A /* Release */ = { 412 | isa = XCBuildConfiguration; 413 | buildSettings = { 414 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 415 | CODE_SIGN_STYLE = Automatic; 416 | DEVELOPMENT_ASSET_PATHS = "Consumable/Preview\\ Content"; 417 | DEVELOPMENT_TEAM = HKDHURHY83; 418 | ENABLE_PREVIEWS = YES; 419 | INFOPLIST_FILE = "Consumable/Supporting Files/Info.plist"; 420 | LD_RUNPATH_SEARCH_PATHS = ( 421 | "$(inherited)", 422 | "@executable_path/Frameworks", 423 | ); 424 | PRODUCT_BUNDLE_IDENTIFIER = com.nonchalant.Consumable; 425 | PRODUCT_NAME = "$(TARGET_NAME)"; 426 | SWIFT_VERSION = 5.0; 427 | TARGETED_DEVICE_FAMILY = "1,2"; 428 | }; 429 | name = Release; 430 | }; 431 | /* End XCBuildConfiguration section */ 432 | 433 | /* Begin XCConfigurationList section */ 434 | 5F90470322E840210097CF2A /* Build configuration list for PBXProject "Consumable" */ = { 435 | isa = XCConfigurationList; 436 | buildConfigurations = ( 437 | 5F90472522E840220097CF2A /* Debug */, 438 | 5F90472622E840220097CF2A /* Release */, 439 | ); 440 | defaultConfigurationIsVisible = 0; 441 | defaultConfigurationName = Release; 442 | }; 443 | 5F90472722E840220097CF2A /* Build configuration list for PBXNativeTarget "Consumable" */ = { 444 | isa = XCConfigurationList; 445 | buildConfigurations = ( 446 | 5F90472822E840220097CF2A /* Debug */, 447 | 5F90472922E840220097CF2A /* Release */, 448 | ); 449 | defaultConfigurationIsVisible = 0; 450 | defaultConfigurationName = Release; 451 | }; 452 | /* End XCConfigurationList section */ 453 | }; 454 | rootObject = 5F90470022E840200097CF2A /* Project object */; 455 | } 456 | --------------------------------------------------------------------------------