Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not conform to protocol 'STPPaymentContextDelegate' #1048

Closed
alexgerrese opened this issue Nov 25, 2018 · 6 comments
Closed

Does not conform to protocol 'STPPaymentContextDelegate' #1048

alexgerrese opened this issue Nov 25, 2018 · 6 comments

Comments

@alexgerrese
Copy link

alexgerrese commented Nov 25, 2018

Summary

I have implemented the required protocols for STPPaymentContextDelegate but Xcode keeps asking me to add protocol stubs for "didFailToLoadWithError" and "didFinishWith" methods. When I let Xcode fill in the stubs, the error recursively reappears.

Code to reproduce

`// MARK: STPPaymentContextDelegate

func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error) {
    let alertController = UIAlertController(
        title: "Uh oh, an error occurred!",
        message: "Please try again.",
        preferredStyle: .alert
    )
    let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: { action in
        // Need to assign to _ because optional binding loses @discardableResult value
        // https://bugs.swift.org/browse/SR-1681
        _ = self.navigationController?.popViewController(animated: true)
    })
    let retry = UIAlertAction(title: "Retry", style: .default, handler: { action in
        self.paymentContext.retryLoading()
    })
    alertController.addAction(cancel)
    alertController.addAction(retry)
    self.present(alertController, animated: true, completion: nil)
}

func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?) {
    switch status {
    case .error:
        print("Error")
        return
    case .success:
        print("Success")
        placeOrder()
    case .userCancellation:
        return
    }
}

func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: @escaping STPErrorBlock) {
    MyAPIClient.sharedClient.completeCharge(paymentResult,
                                            amount: self.paymentContext.paymentAmount,
                                            completion: completion)
}

func paymentContextDidChange(_ paymentContext: STPPaymentContext) {
}`

iOS version

iOS 12.1

Installation method

Cocoapods

SDK version

14.0.0

@alexgerrese alexgerrese changed the title Does not conform to protocol 'STPPaymentContextDelegate' not working Does not conform to protocol 'STPPaymentContextDelegate' Nov 25, 2018
@danj-stripe
Copy link
Contributor

danj-stripe commented Nov 27, 2018

Hi @alexgerrese,

I'm having trouble reproducing your issue. I tried Xcode 10.1 (10B61) (since you mentioned you're using the iOS 12.1 SDK), and Xcode's fixit created stubs that caused the compile error to go away. I also tried in our cocoapod installation test project, and it's working correctly there too.

Any chance that cleaning the build folder in Xcode fixes the issue?

I also compared your method signatures to the ones in our sample code, and they're an exact match, so I'd expect it to be working for you.

Dan

PS: I think this is a different issue than #454

@alexgerrese
Copy link
Author

Cleaning doesn't fix the issue unfortunately.

I'm declaring the stubs in an extension of the ViewController so I thought that might have been the issue, but even when moving them to the original VC file the error persists. I'm importing Stripe in both files, I'm adhering to the STPPaymentContextDelegate, and my stubs are correctly typed, so I'm very confused as to what's going on.

I've even created a new Swift file that attempts to conform to the delegate, but even here it gives me the error so this must be a larger project issue.

`import Foundation
import Stripe

class StripeTest: UIViewController, STPPaymentContextDelegate {
func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error) {
<#code#>
}

func paymentContextDidChange(_ paymentContext: STPPaymentContext) {
    <#code#>
}

func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: @escaping STPErrorBlock) {
    <#code#>
}

func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?) {
    <#code#>
}

}`

I'm also on Stripe cocoapods version 14.0.0 so I should be up-to-date.

@danj-stripe
Copy link
Contributor

Hi @alexgerrese,

I don't think there's anything I can do to help.

You might try creating a brand new project and installing the Stripe pod via cocoapods. You should be able to verify that your StripeTest class is correct by putting it into that new project. (I did, and it works for me, other than the placeholders).

That'd also give you a point of reference for comparing if there are any differences between the working & non-working projects related to the cocoapods integration: the Pods project, the xcconfig files, etc.

We can't provide support for cocoapods or swiftc/Xcode, but if you run into other problems while integrating, feel free to reach out to our support at https://support.stripe.com/

Thanks,
Dan

@krzyzanowskim
Copy link

I run into the same issue today. Cannot conform to STPPaymentContextDelegate. Xcode 10.3 (10G8).

ScreenFlow

@krzyzanowskim
Copy link

In my case solution is to use explicit Swift.Error for imported interface.

@harrdy25
Copy link

Protocol 'CardSectionWithScannerViewDelegate' requires 'didScanCard(cardParams:)' to be available in iOS 12.0.0 and newer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants