import UIKit
import PassKit
class WalletViewController: BaseViewController {
private var paymentRequset: PKPaymentRequest = {
let request = PKPaymentRequest()
request.merchantIdentifier = "merchant.你的appBundleID"
request.supportedNetworks = [.visa]
request.supportedCountries = ["TW"]
request.merchantCapabilities = .capability3DS
request.currencyCode = "TWD"
request.countryCode = "TW"
request.paymentSummaryItems = [PKPaymentSummaryItem(label: "iphone", amount: 31500)]
return request
}()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .black
print("you enter WalletViewController!")
}
@IBAction func pat(_ sender: Any) {
applePay()
}
func applePay() {
let controller = PKPaymentAuthorizationViewController(paymentRequest: paymentRequset)
if controller != nil {
controller!.delegate = self
present(controller!, animated: true) {
print("success")
}
}
}
}
extension WalletViewController: PKPaymentAuthorizationViewControllerDelegate {
func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
controller.dismiss(animated: true)
}
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
completion(PKPaymentAuthorizationResult(status: .success, errors: nil))
}
}