簡體   English   中英

類型MyViewController不符合協議'STPPaymentContextDelegate'

[英]Type MyViewController does not conform to protocol 'STPPaymentContextDelegate'

我正在我的類上創建一個擴展,以符合協議'STPPaymentContextDelegate'。 由於某種原因,編譯器抱怨,即使我在擴展中的所有方法都如此正確地聲明。

extension PaymentPopupViewController: STPPaymentContextDelegate {

func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error) {
    self.delegate?.paymentPopupViewController(controller: self, didFinishPerhapsWithError: error as NSError?)
}

func paymentContextDidChange(_ paymentContext: STPPaymentContext) {
    if paymentContext.loading {
        self.indicatorView.startAnimating()
    } else {
        self.indicatorView.stopAnimating()
        if paymentContext.selectedPaymentMethod == nil {
            self.presentPaymentMehtodsViewController()
        }
    }
    self.indicatorView.isHidden = !paymentContext.loading
    self.paymentMethodLabel.isHidden = paymentContext.loading
    self.changePaymentMethodButton.isEnabled = !paymentContext.loading
    self.payButton.isEnabled = !paymentContext.loading && paymentContext.selectedPaymentMethod != nil
    self.paymentMethodLabel.text = paymentContext.selectedPaymentMethod?.label
}

func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: STPErrorBlock) {
    fatalError("Method isn't implemented because our backend makes a charge, not the app.")

}

func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?) {
    if status == .userCancellation {
        return
    }
    self.delegate?.paymentPopupViewController(controller: self, didFinishPerhapsWithError: error as NSError?)
}

以下是協議規定的委托方法:

@protocol STPPaymentContextDelegate <NSObject>

- (void)paymentContext:(STPPaymentContext *)paymentContext didFailToLoadWithError:(NSError *)error;
- (void)paymentContextDidChange:(STPPaymentContext *)paymentContext;
- (void)paymentContext:(STPPaymentContext *)paymentContext
didCreatePaymentResult:(STPPaymentResult *)paymentResult
        completion:(STPErrorBlock)completion;
- (void)paymentContext:(STPPaymentContext *)paymentContext
didFinishWithStatus:(STPPaymentStatus)status
             error:(nullable NSError *)error;

我該如何解決這個問題?

您的實施中存在一些錯誤。

替換它

func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error)

func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: NSError)

並取而代之

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

func paymentContext(_ paymentContext: STPPaymentContext, didFinishWithStatus status: STPPaymentStatus, error: NSError?)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM