SquareMobilePayment SDK for iOS. Payment not going through

I am using 2.2.3 version for iOS using swift and UIKit. My oauth is working fine. Reader is getting connected. But as soon as I put on card of square contactless reader. Popup appears Payment Failed. The payment could not be completed. Please try again.

Also delegate method for payment failed is not getting called.
Please help,
Payment Did Start: [“createdAt”: 2025-05-26 12:46:35 +0000, “totalMoney”: $1.00, “sourceType”: “UNKNOWN”, “amountMoney”: $1.00, “status”: INITIALIZED, “updatedAt”: 2025-05-26 12:46:35 +0000]
Here is my code

import UIKit
import CoreLocation
import SquareMobilePaymentsSDK
import CoreBluetooth
import SafariServices
import MockReaderUI

class ViewController: UIViewController {
    var availableCardInputMethods = MobilePaymentsSDK.shared.paymentManager.availableCardInputMethods
    private lazy var locationManager = CLLocationManager()
    private var centralManager: CBCentralManager?
    private var pairingHandle: PairingHandle?
    private var paymentHandle: PaymentHandle?
    
    private lazy var mockReaderUI: MockReaderUI? = {
        do {
            return try MockReaderUI(for: MobilePaymentsSDK.shared)
        } catch {
            assertionFailure("Could not instantiate a mock reader UI: \(error.localizedDescription)")
        }
        
        return nil
    }()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
//        try? mockReaderUI?.present()
    }
    
    func requestLocationPermission() {
        switch CLLocationManager.authorizationStatus() {
        case .notDetermined:
            locationManager.requestWhenInUseAuthorization()
        case .restricted, .denied:
            print("Show UI directing the user to the iOS Settings app")
        case .authorizedAlways, .authorizedWhenInUse:
            print("Location services have already been authorized.")
        @unknown default:
            print("unknown error in location")
        }
    }
    
    func requestBluetoothPermissions() {
        guard CBManager.authorization == .notDetermined else {
            return
        }
        
        centralManager = CBCentralManager(
            delegate: self,
            queue: .main,
            options: nil
        )
    }
    
    @IBAction private func settingTapped() {
        MobilePaymentsSDK.shared.settingsManager.presentSettings(with: self) { _ in }
    }
    
    @IBAction private func oauthTapped() {
        guard MobilePaymentsSDK.shared.authorizationManager.state == .notAuthorized else {
            print("Already authorized")
            return
        }
        MobilePaymentsSDK.shared.authorizationManager.authorize(withAccessToken: "EAAAliWKEztjcLXm6YnmyBWNd6vEDwzn8-6fzRT5FHe0viY3bNfctL4th_TYlevo", locationID: "L2XH7G705DRMJ") { error in
            if let authError = error {
                // Handle auth error
                print("error: \(authError.localizedDescription)")
                return
            }
            
            print("Square Mobile Payments SDK successfully authorized.")
        }
    }
    
    @IBAction private func readerTapped() {
        requestLocationPermission()
        requestBluetoothPermissions()
        MobilePaymentsSDK.shared.readerManager.add(self)
        pairingHandle = MobilePaymentsSDK.shared.readerManager.startPairing(with: self)
    }
    
    @IBAction private func paymentTapped() {
        paymentHandle = MobilePaymentsSDK.shared.paymentManager.startPayment(
            makePaymentParameters(),
            promptParameters: PromptParameters(
                mode: .default,
                additionalMethods: .all
            ),
            from: self,
            delegate: self
        )
    }
    
    func makePaymentParameters() -> PaymentParameters {
        PaymentParameters(
            idempotencyKey: UUID().uuidString,
            amountMoney: Money(amount: 100, currency: .USD),
            processingMode: .autoDetect
        )
    }
    
}

extension ViewController: PaymentManagerDelegate {
    public func paymentManager(
        _ paymentManager: PaymentManager,
        didFinish payment: Payment
    ) {
        print("Payment Did Finish: \(payment)")
    }
    
    func paymentManager(_ paymentManager: any PaymentManager, didStart payment: any Payment) {
        print("Payment Did Start: \(payment)")
    }

    public func paymentManager(
        _ paymentManager: PaymentManager,
        didFail payment: Payment,
        withError error: Error
    ) {
        // Handle Payment Failed
        if let paymentError = PaymentError(rawValue: (error as NSError).code) {
          print(paymentError.rawValue)
        }
        print("error: \(error.localizedDescription)")
    }

    public func paymentManager(
        _ paymentManager: PaymentManager,
        didCancel payment: Payment
    ) {
        // Handle Payment Canceled
        print("payment cancelled: \(payment)")
    }
    
    func paymentManager(_ paymentManager: any PaymentManager, willFinish payment: any Payment) {
        print("Payment will finish \(payment)")
    }
    
    func paymentManager(_ paymentManager: any PaymentManager, willCancel payment: any Payment) {
        print("Payment will cancel \(payment)")
    }
}

extension ViewController: AvailableCardInputMethodsObserver {
    func availableCardInputMethodsDidChange(_ cardInputMethods: CardInputMethods) {
        print("available input methods \(cardInputMethods.description)")
    }
}

extension ViewController: ReaderPairingDelegate {
    func readerPairingDidBegin() {
        print("reader pairing begin")
    }
    
    func readerPairingDidSucceed() {
        print("reader pairing success")
    }
    
    func readerPairingDidFail(with error: any Error) {
        print("reader pairing fail \(error.localizedDescription)")
    }
}

extension ViewController: CBCentralManagerDelegate {
    func centralManagerDidUpdateState(_ central: CBCentralManager) {
        print("bluetooth status \(central.state)")
    }
}

extension ViewController: ReaderObserver {
    func readerWasAdded(_ readerInfo: any ReaderInfo) {
        
    }
    
    func readerWasRemoved(_ readerInfo: any ReaderInfo) {
        
    }
    
    func readerDidChange(_ readerInfo: any ReaderInfo, change: ReaderChange) {
        
    }
}

:waving_hand: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Enable Apple Pay
Take a Credit Card Payment
Enable Secure Remote Commerce - iOS

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

Nope this is not working for me. If someone from your dev team can help it will be better.

If you try something like this do you still get the error?:

func makePaymentParameters() -> PaymentParameters {
    let params = PaymentParameters(
        idempotencyKey: UUID().uuidString,
        amountMoney: Money(amount: 100, currency: .USD),
        processingMode: .cardPresent // Change from autoDetect to cardPresent
    )
    params.note = "Test Payment" // Add a note for tracking
    params.referenceID = "REF_\(UUID().uuidString)" // Add a reference ID
    return params
}

:slight_smile:

Still Not working.

Type ‘ProcessingMode’ has no member ‘cardPresent’

I am using Authorize the Mobile Payments SDK
This sdk for iOS. Please suggest accordingly

It has only 3 option

What’s your application ID and the location_id your trying to take a payment with? :slight_smile:

Application id - sq0idp-zA-e5d8W3Sb7k19qCMV-eg
Location id - “L2XH7G705DRMJ”

Any update on this? we are stuck

Any update on this? We have been waiting for a long time. And our app is not working. I would request you to provide a solution here.

Are you connected to the integration with OAuth? :slight_smile:

Yes Oauth connected. Square sdk authorized. Reader connected. Payment screen presented but payment failed