I have an app and I wanted to know how would I make it so that when the user purchases something from the app it know the tax for each state and add it automatically for each state. Here is some of my code:
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 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)
let authorizationViewController = PKPaymentAuthorizationViewController(paymentRequest: request)
if let viewController = authorizationViewController {
viewController.delegate = self
present(viewController, animated: true, completion: nil)
}
}
}