Stripe-ios: does not conform to protocol 'STPPaymentContextDelegate' xcode 8

Created on 16 Sep 2016  Â·  8Comments  Â·  Source: stripe/stripe-ios

Summary

Since we upgraded to swift 3 and xcode 8 we are seeing this error. We added all functions but we still see compile error.

Code to reproduce

iOS version

9.3

Installation method

cocoapods

Most helpful comment

Hey @meandkareem – in Swift 3, you'll need to mark your completion blocks as @escaping.

We've filed a Swift bug report to make the error message clearer, and we're also adding a note to our documentation in #453 .

All 8 comments

Hey @meandkareem – in Swift 3, you'll need to mark your completion blocks as @escaping.

We've filed a Swift bug report to make the error message clearer, and we're also adding a note to our documentation in #453 .

I still have same error and I added escaping. I did this even before I submitted.

These are functions I have

 func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: @escaping (STPErrorBlock)) {
       ... 
    }

 func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?) {

    }

 func paymentContextDidChange(_ paymentContext: STPPaymentContext) {
       ... 
    }

func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error) {
        ...
    }

Those look correct and work for me. I would try doing a clean build if you are still seeing errors.

image

This is exaclty what I see .. tried all . cleaned ,reseted pods .. everything.

If you pull latest master, the Swift example app in it has been updated to Swift 3. Maybe you could try comparing its integration with STPPaymentContextDelegate to your implementation.

I did and I noticed that dynamic farmework is diffirent . This is how my delegate looks

public protocol STPPaymentContextDelegate : NSObjectProtocol {


    /**
     *  Called when the payment context encounters an error when fetching its initial set of data. A few ways to handle this are:
     - If you're showing the user a checkout page, dismiss the checkout page when this is called and present the error to the user.
     - Present the error to the user using a `UIAlertController` with two buttons: Retry and Cancel. If they cancel, dismiss your UI. If they Retry, call `retryLoading` on the payment context.

     To make it harder to get your UI into a bad state, this won't be called until the context's `hostViewController` has finished appearing.
     *
     *  @param paymentContext the payment context that encountered the error
     *  @param error          the error that was encountered
     */
    public func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error)


    /**
     *  This is called every time the contents of the payment context change. When this is called, you should update your app's UI to reflect the current state of the payment context. For example, if you have a checkout page with a "selected payment method" row, you should update its payment method with `paymentContext.selectedPaymentMethod.label`. If that checkout page has a "buy" button, you should enable/disable it depending on the result of `[paymentContext isReadyForPayment]`.
     *
     *  @param paymentContext the payment context that changed
     */
    public func paymentContextDidChange(_ paymentContext: STPPaymentContext)


    /**
     *  Inside this method, you should make a call to your backend API to make a charge with that Customer + source, and invoke the `completion` block when that is done.
     *
     *  @param paymentContext The context that succeeded
     *  @param paymentResult  Information associated with the payment that you can pass to your server. You should go to your backend API with this payment result and make a charge to complete the payment, passing `paymentResult.source.stripeID` as the `source` parameter to the create charge method and your customer's ID as the `customer` parameter (see stripe.com/docs/api#charge_create for more info). Once that's done call the `completion` block with any error that occurred (or none, if the charge succeeded). @see STPPaymentResult.h
     *  @param completion     Call this block when you're done creating a charge (or subscription, etc) on your backend. If it succeeded, call `completion(nil)`. If it failed with an error, call `completion(error)`.
     */
    public func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: Stripe.STPErrorBlock)


    /**
     *  This is invoked by an `STPPaymentContext` when it is finished. This will be called after the payment is done and all necessary UI has been dismissed. You should inspect the returned `status` and behave appropriately. For example: if it's `STPPaymentStatusSuccess`, show the user a receipt. If it's `STPPaymentStatusError`, inform the user of the error. If it's `STPPaymentStatusUserCanceled`, do nothing.
     *
     *  @param paymentContext The payment context that finished
     *  @param status         The status of the payment - `STPPaymentStatusSuccess` if it succeeded, `STPPaymentStatusError` if it failed with an error (in which case the `error` parameter will be non-nil), `STPPaymentStatusUserCanceled` if the user canceled the payment.
     *  @param error          An error that occurred, if any.
     */
    public func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?)
}

So I assume that "Stripe.STPErrorBlock" property is issue. But i cant change or find solution how to fix this.

func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: @escaping STPErrorBlock) {

Fixed the issue

I'm still seeing this error, on the "didFailToLoadWithError" and "didFinishWith" methods. Xcode keeps asking if I want to add the protocol stubs even though I've implemented the methods, and even if I delete them and let Xcode add the protocol stubs for me it still throws the error and asks me again.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

billinghamj picture billinghamj  Â·  6Comments

chrismanderson picture chrismanderson  Â·  4Comments

olegdanu-newstore picture olegdanu-newstore  Â·  7Comments

Andrewangeta picture Andrewangeta  Â·  6Comments

imhugofonseca picture imhugofonseca  Â·  7Comments