I have an app similar to Uber. The problem I am having is that I want it so that when you click on the apple pay button and pay for the ride the order is saved on my orders view controller. Just let me know what code you need and I will provide it.
So, you can use a delegate.
Define a protocol:
- in Orders, before class declaration
protocol PayRequestDelegate {
func sendRequest(items: [PKPaymentSummaryItem])
}
- in Orders, declare that the class conforms to protocol
class Orders: UIViewController, PayRequestDelegate {
}
- in Orders, in the class, implement the protocol
func sendRequest(items: [PKPaymentSummaryItem]) {
// Display the elements you get in the appropriate labels or var
}
- in Orders, in the prepare to go to priceView, set the delegate that you will declare in PriceView
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? PriceView {
destination.delegate = self
}
}
- in PriceView, declare a delegate
var delegate : PayRequestDelegate?
- in PriceView, when request is completed, use the delegate to send to Orders
let tshirt = PKPaymentSummaryItem(label: "T-shirt", amount: NSDecimalNumber(decimal:1.00), type: .final)
let shipping = PKPaymentSummaryItem(label: "Shipping", 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 = [tshirt, shipping, tax, total]
delegate?.sendRequest(items: request.paymentSummaryItems])