I have an apple pay button and I wanted to know how I would segue to another view controller. The apple pay button is added programmatically. I already tried adding a performSegue and that did not work. This is the code for it once it is tapped:
@objc private func applePayButtonTapped(sender: UIButton) {
// Cards that should be accepted
let paymentNetworks:[PKPaymentNetwork] = [.discover, .amex, .masterCard, .visa]
if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: paymentNetworks) {
let request = PKPaymentRequest()
request.merchantIdentifier = "merchant.com.shiningdevelopers"
request.countryCode = "CA"
request.currencyCode = "CAD"
request.supportedNetworks = paymentNetworks
request.requiredShippingContactFields = [.name, .postalAddress]
// This is based on using Stripe
request.merchantCapabilities = .capability3DS
let drive = PKPaymentSummaryItem(label: "Drive", amount: NSDecimalNumber(decimal: 1.00), type: .final)
let tax = PKPaymentSummaryItem(label: "Tax", amount: NSDecimalNumber(decimal:1.00), type: .final)
let total = PKPaymentSummaryItem(label: "Total", amount: NSDecimalNumber(decimal:3.00), type: .final)
request.paymentSummaryItems = [drive, tax, total]
let authorizationViewController = PKPaymentAuthorizationViewController(paymentRequest: request)
if let viewController = authorizationViewController {
viewController.delegate = self
present(viewController, animated: true, completion: nil)
}
}
}