-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PIA-1824: Recover purchases sign in tvOS (#147)
* Integrate Sign up tvOS * PIA-1824: Add recover purchases Sign in on tvOS
- Loading branch information
1 parent
6108ab3
commit 395dd1b
Showing
18 changed files
with
625 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// PaymentProvider.swift | ||
// PIA VPN-tvOS | ||
// | ||
// Created by Said Rehouni on 20/5/24. | ||
// Copyright © 2024 Private Internet Access Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import PIALibrary | ||
|
||
class PaymentProvider: PaymentProviderType { | ||
private let store: InAppProvider | ||
|
||
init(store: InAppProvider) { | ||
self.store = store | ||
} | ||
|
||
func refreshPaymentReceipt(_ completion: @escaping (Result<Data, Error>) -> Void) { | ||
store.refreshPaymentReceipt { [weak self] error in | ||
if let error { | ||
completion(.failure(error)) | ||
return | ||
} | ||
|
||
guard let receipt = self?.store.paymentReceipt else { | ||
completion(.failure(ClientError.unexpectedReply)) | ||
return | ||
} | ||
|
||
completion(.success(receipt)) | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
PIA VPN-tvOS/LoginQR/Domain/Interfaces/PaymentProviderType.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// PaymentProviderType.swift | ||
// PIA VPN-tvOS | ||
// | ||
// Created by Said Rehouni on 21/5/24. | ||
// Copyright © 2024 Private Internet Access Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol PaymentProviderType { | ||
func refreshPaymentReceipt(_ completion: @escaping (Result<Data, Error>) -> Void) | ||
} |
54 changes: 54 additions & 0 deletions
54
PIA VPN-tvOS/LoginQR/Domain/Use cases/LoginWithReceiptUseCase.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// LoginWithReceiptUseCase.swift | ||
// PIA VPN-tvOS | ||
// | ||
// Created by Said Rehouni on 20/5/24. | ||
// Copyright © 2024 Private Internet Access Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol LoginWithReceiptUseCaseType { | ||
func callAsFunction() async throws -> UserAccount | ||
} | ||
|
||
class LoginWithReceiptUseCase: LoginWithReceiptUseCaseType { | ||
private let paymentProvider: PaymentProviderType | ||
private let loginProvider: LoginProviderType | ||
private let errorMapper: LoginDomainErrorMapperType | ||
|
||
init(paymentProvider: PaymentProviderType, loginProvider: LoginProviderType, errorMapper: LoginDomainErrorMapperType) { | ||
self.paymentProvider = paymentProvider | ||
self.loginProvider = loginProvider | ||
self.errorMapper = errorMapper | ||
} | ||
|
||
func callAsFunction() async throws -> UserAccount { | ||
return try await withCheckedThrowingContinuation { continuation in | ||
paymentProvider.refreshPaymentReceipt { [weak self] result in | ||
guard let self else { return } | ||
|
||
switch result { | ||
case .success(let receipt): | ||
login(with: receipt, continuation: continuation) | ||
|
||
case .failure(let error): | ||
continuation.resume(throwing: errorMapper.map(error: error)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private func login(with receipt: Data, continuation: CheckedContinuation<UserAccount, any Error>) { | ||
loginProvider.login(with: Data()) { [weak self] result in | ||
guard let self else { return } | ||
|
||
switch result { | ||
case .success(let userAccount): | ||
continuation.resume(returning: userAccount) | ||
case .failure(let error): | ||
continuation.resume(throwing: errorMapper.map(error: error)) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.