0

I am trying to make a payment via Apple pay using world pay and their SDK HERE https://github.com/Worldpay/worldpay-lib-ios. Within my app this payment is done via a notification, the user clicks on the notification, my app opens and the apple pay view is presented.

When I try to make my payment request (follow code below) with this line

let request = wp.createPaymentRequest(withMerchantIdentifier: ApplePaySwagMerchantID)

However my app crashes with:

2017-03-30 20:38:20.026378 CarGo[757:79619] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Worldpay createPaymentRequestWithMerchantIdentifier:]: unrecognized selector sent to instance 0x1740fea00'

I'm not really sure what could be causing this or how to go about debugging it?

my complete method which runs in the app delegate:

func makePayment(locationString: String){

        let defaults = UserDefaults.standard

        let topWindow: UIWindow = UIWindow(frame: UIScreen.main.bounds)
        topWindow.rootViewController = UIViewController()
        topWindow.windowLevel = UIWindowLevelAlert + 1
        topWindow.makeKeyAndVisible()

        let wp: Worldpay = Worldpay.sharedInstance();
        wp.clientKey = "xxxxxxx";
        wp.reusable = true;


        let request = wp.createPaymentRequest(withMerchantIdentifier: ApplePaySwagMerchantID)
        request?.supportedNetworks = SupportedPaymentNetworks
        request?.countryCode = "GB"
        request?.currencyCode = "GBP"
        request?.merchantCapabilities = PKMerchantCapability.capability3DS

        var decimalValue = NSDecimalNumber(string: defaults.string(forKey: locationString))

        decimalValue = decimalValue.multiplying(by: 100)

        self.transactionsDescription = "Toll Payment: " + locationString
        self.transactionCost = decimalValue.intValue

        request?.paymentSummaryItems = [
            PKPaymentSummaryItem(label: "Toll Payment: " + locationString, amount:NSDecimalNumber(string: defaults.string(forKey: locationString)))
        ]

        let applePayController = PKPaymentAuthorizationViewController(paymentRequest: request!)
        applePayController.delegate = self

        topWindow.rootViewController?.present(applePayController, animated: true, completion: nil)

    }

My bridge header file:

#import "Worldpay.h"
#import "APMController.h"
#import "WorldpayAPMViewController.h"
#import "ThreeDSController.h"
#import "WorldpayCardViewController.h"
#import "Worldpay+ApplePay.h"
DevWithZachary
  • 3,545
  • 11
  • 49
  • 101
  • Which version of the WorldPay SDK are you using? I'm having trouble finding the WorldPay class you're using in the documentation here: https://worldpayus.github.io/ipc_sdk_ios/ – Mark Mar 30 '17 at 20:26
  • @mark https://github.com/Worldpay/worldpay-lib-ios – DevWithZachary Mar 30 '17 at 20:30
  • Where did you find the signature for `wp.createPaymentRequest(withMerchantIdentifier: ApplePaySwagMerchantID)`? Was it autocompleted by Xcode? The guide to working with ObjC classes suggests `wp.createPaymentRequestWithMerchantIdentifier(ApplePaySwagMerchantID)`. Reference, Working With Methods: https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html#//apple_ref/doc/uid/TP40014216-CH4-ID35 – Mark Mar 30 '17 at 20:41
  • 'createPaymentRequestWithMerchantIdentifier' has been renamed to 'createPaymentRequest(withMerchantIdentifier:)' – DevWithZachary Mar 30 '17 at 20:46
  • @ZacPowell out of interest how did you test Apple Pay payments on your WorldPay testing environment? I can't add the WorldPay test card details to my wallet on my phone :/ – simonthumper May 17 '17 at 13:38

1 Answers1

0

I think I might have found the issue. Have you included the following import in your Objective-C Bridging Header?

import "Worldpay+ApplePay.h"

This is a category that extends the WorldPay class with methods related to Apple Pay, and likely contains the method in question.

EDIT:

Make sure to include the -ObjC linker flag in your project's Other Linker Flags property in the Build Settings.

Mark
  • 7,167
  • 4
  • 44
  • 68