-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: check for existence of pass on paired watch (#1219)
- Loading branch information
1 parent
9a1a163
commit de9727e
Showing
9 changed files
with
149 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// PKPaymentPassFinder.swift | ||
// stripe-react-native | ||
// | ||
// Created by Charles Cruzan on 10/6/22. | ||
// | ||
|
||
import Foundation | ||
|
||
internal class PaymentPassFinder: NSObject { | ||
enum PassLocation: String { | ||
case CURRENT_DEVICE | ||
case PAIRED_DEVICE | ||
} | ||
|
||
class func findPassWithLast4(last4: String, hasPairedAppleWatch: Bool, completion: @escaping ((Bool, [PassLocation]) -> Void)) { | ||
let existingPassOnDevice: PKPass? = { | ||
if #available(iOS 13.4, *) { | ||
return PKPassLibrary().passes(of: PKPassType.secureElement) | ||
.first(where: { $0.secureElementPass?.primaryAccountNumberSuffix == last4 && $0.secureElementPass?.passActivationState != .deactivated && !$0.isRemotePass }) | ||
} else { | ||
return PKPassLibrary().passes(of: PKPassType.payment) | ||
.first(where: { $0.paymentPass?.primaryAccountNumberSuffix == last4 && $0.paymentPass?.passActivationState != .deactivated && !$0.isRemotePass }) | ||
} | ||
}() | ||
|
||
var passLocations: [PassLocation] = [] | ||
if (existingPassOnDevice != nil) { | ||
passLocations.append(.CURRENT_DEVICE) | ||
} | ||
|
||
// We're done here if the user does not have a paired Apple Watch | ||
if (!hasPairedAppleWatch) { | ||
completion( | ||
passLocations.count < 1, | ||
passLocations | ||
) | ||
return | ||
} | ||
|
||
let existingPassOnPairedDevices: PKPass? = { | ||
if #available(iOS 13.4, *) { | ||
return PKPassLibrary().remoteSecureElementPasses | ||
.first(where: { $0.secureElementPass?.primaryAccountNumberSuffix == last4 && $0.secureElementPass?.passActivationState != .deactivated }) | ||
} else { | ||
return PKPassLibrary().remotePaymentPasses() | ||
.first(where: { $0.paymentPass?.primaryAccountNumberSuffix == last4 && $0.paymentPass?.passActivationState != .deactivated }) | ||
} | ||
}() | ||
|
||
|
||
if (existingPassOnPairedDevices != nil) { | ||
passLocations.append(.PAIRED_DEVICE) | ||
} | ||
|
||
completion( | ||
passLocations.count < 2, | ||
passLocations | ||
) | ||
} | ||
} |
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
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