Tax

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)
            }
        }
    }

Replies

You would have to build the tax table (array) yourself. Or look for it on web site (they certainly exist).


Take care that in some countries, tax (VAT) may depend on type of product.

So your tax table could be a dictionary:

[state: String : (ProductCategory: CatEnum, percent: Float)]


enum CatEnum {
  case garment
  case food
// and so on
  case generic
}

Take care that in some countries, tax (VAT) may depend on type of product.

Also, in the US it’s not uncommon for sales tax to vary by county.

@Joel14, Putting this logic in your app is unlikely to end well. I strongly recommend that you connect up with a payment processing provider than can help you with this and many other issues.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"