If I only have one product item in Apple Pay, how would I detect a total? My app is a donation platform, so I don't need to actually ship anything, but would like contact info. I have a number of errors that I have tried to figure out to debug to no avail. Any help is appreciated.
Also I keep getting this error (this was the same as the sample code given from WWDC).
This is in my BuyTicketViewController.swift file.
if PKPaymentAuthorizationViewController.canMakePaymentsUsingNetworks(BuyTicketViewController.paymentNetworks) {
let button = PKPaymentButton(type: .Buy, style,: .Black)
button.addTarget(self, action: "applePayButtonPressed", forControlEvents: .TouchUpInside)
button.center = applePayView.center
button.autoresizingMask = [.FlexibleLeftMargin, .FlexibleRightMarin]
applePayView.addSubview(button)
}
}The error says 'expected declaration.'
The sample says to use else (for traditional checkout). When I put that it, it breaks the rest of my code and I get lots of errors.
line 8 - eror on MerchantID
line 9 - error on supportedPaymentNetworks
line 52 - use of unresolved identifier 'self'
line 68 - use of unresolved identifier 'self'
line 69 - use of unresolved identifer present view controller
line 76 - Anonymous closure argument not contained in a closure
I also have a number of other errors shooting up that didn't come up before with regard to 'self' and I am unsure how to fix them.
Yes, I am aware this is incomplete code as it is still a work in progress. Some of these errors I'm not sure have to do with Apple Pay itself. The 'basic' syntax I know I can have errors. Example, I used a Ray Wenderlich tutorial on Apple Pay and know that a traditional check-out method can be use for the 'else' in the if-else statement, however I'm still puzzled as to why the if PKPaymentAuthorizationViewController.canMakePaymentsUsingNetworks(BuyTicketViewController.paymentNetworks) {
statement is not working within XCode 7 Beta 6 either, so I don't think it's just a plain syntax issue of an if-else statement.
This was the tutorial: http://www.raywenderlich.com/87300/apple-pay-tutorial
/
/
/
/
/
/
/
import UIKit
import PassKit
import Contacts
class BuyTicketViewController: UIViewController {
/
@IBOutlet weak var applePayButton: UIButton!
/
/
/
let paymentNetworks = [
PKPaymentNetworkAmex,
PKPaymentNetworkDiscover,
PKPaymentNetworkMasterCard,
PKPaymentNetworkVisa]
if PKPaymentAuthorizationViewController.canMakePaymentsUsingNetworks(BuyTicketViewController.paymentNetworks) {
let button = PKPaymentButton(type: .Buy, style,: .Black)
button.addTarget(self, action: "applePayButtonPressed", forControlEvents: .TouchUpInside)
button.center = applePayView.center
button.autoresizingMask = [.FlexibleLeftMargin, .FlexibleRightMarin]
applePayView.addSubview(button)
}
}
/
/
/
/
/
func applePayButtonPressed(){
let request = PKPaymentRequest()
let applePayController = PKPaymentAuthorizationViewController(paymentRequest: request)
self.presentViewController(applePayController, animated: true, completion: nil)
/
request.merchantIdentifier = MerchantID
request.supportedNetworks = SupportedPaymentNetworks
request.merchantCapabilities = PKMerchantCapability.Capability3DS
request.countryCode = "US"
request.currencyCode = "USD"
/
paymentRequest.requiredShippingAddressFields = .PostalAddress
/
let vc = PKPaymentAuthorizationViewController(paymentRequest: request)
vc.delegate = self
presentViewController(vc, animated: true, completion: nil)
/ Display an Apple Pay button if a payment card is available.*/
request.paymentSummaryItems = [
PKPaymentSummaryItem(label: title, amount: $2700)
]
let hfaMerchantID = "com.erinjerri.hfa-iphone" /
}
/
var items = [PKPaymentSummaryItem]()
let total = PKPaymentSummaryItem(label: "Hillary for America",
amount: NSDecimalNumber(string: "2700.00"))
request.paymentSummaryItems = [total]
/
/
/
/