Apple Pay
ApplePay is enabled via the Braintree DropIn UI.
It is advised that you use the frameworks provided in our demo app to enable this feature or use Cocoapods or Carthage to download the 4.23.0
of the Braintree iOS SDK.
Apple Pay Merchant Identifier and Payment Processing Certificate
To enable Apple Pay, you must first inquire with VenueNext to provide a Certificate Signing Request which can be used to generate an Apple Pay Payment Processing Certificate. Use the provided CSR and follow these steps to generate an Apple Pay Merchant Identifier and Payment Processing Certificate: Apple Pay Programming Guide: Configuring Your Environment. Once this is completed, provide the Merchant Identifier and Payment Processing Certificate back to VenueNext for registration.
Xcode
Enable Apple Pay in your Project Settings under Capabilities. You will need to enter the Apple Pay Merchant ID that was created above.
The PaymentAdapter.swift file will enable the bulk of the ApplePay functionality and should be used exactly as provided. There are only two lines that you need to update.
You will need to explicitly set the paymentRequest.merchantIdentifier
with your Apple Pay Merchant ID as shown below.
func setupPaymentRequest(for productType: ProductType, completion: @escaping (PKPaymentRequest?, Error?) -> Void) {
guard let braintreeApiClient = braintreeApiClient else {
let error = NSError(source: self, code: 404, userInfo: [NSLocalizedDescriptionKey: "Could not setup Apple Pay payments because BTAPIClient is nil"])
completion(nil, error)
return
}
let applePayClient = BTApplePayClient(apiClient: braintreeApiClient)
// You can use the following helper method to create a PKPaymentRequest which will set the `countryCode`,
// `currencyCode`, `merchantIdentifier`, and `supportedNetworks` properties.
// You can also create the PKPaymentRequest manually. Be aware that you'll need to keep these in
// sync with the gateway settings if you go this route.
applePayClient.paymentRequest { (paymentRequest, error) in
guard let paymentRequest = paymentRequest else {
completion(nil, error)
return
}
paymentRequest.merchantIdentifier = "ADD YOUR MERCHANT ID HERE"
// We recommend collecting billing address information, at minimum
// billing postal code, and passing that billing postal code with all
// Apple Pay transactions as a best practice.
paymentRequest.requiredBillingContactFields = [.postalAddress]
let paymentSummaryItems = VNOrderData.shared.cart.paymentSummaryItems(for: productType)
// Set other PKPaymentRequest properties here
paymentRequest.merchantCapabilities = .capability3DS
paymentRequest.paymentSummaryItems = paymentSummaryItems
completion(paymentRequest, nil)
}
Ensure that Apple is not disabled on the BTDropInRequest
. This is enabled by default, but make sure that request.applePayDisabled
is not set to true
func processPayment(from viewController: UIViewController?, productType: ProductType, completion: @escaping (PaymentMethodRepresentable?, NSError?) -> Void) {
VNPayment.shared.getPaymentToken() { (result) in
switch result {
case .success(let token):
DispatchQueue.main.async {
let request = BTDropInRequest()
request.paypalDisabled = true
request.vaultManager = true
let dropIn = BTDropInController(authorization: token, request: request) { [weak self] (controller, result, error) in
...
}
}
For custom support outside of the supported Braintree Drop-In UI, please contact us.