I'm creating an extension on my class to conform to the protocol 'STPPaymentContextDelegate'. For some reason, the compiler complains, even though I have all the methods within the extension all declared properly like so.
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?)
}
Here are the delegate methods as stated by the protocol:
@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;
How do I go about resolving this issue?
You have some mistakes in your implementations.
Replace this
func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error)
With
func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: NSError)
And replace this
func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?)
With
func paymentContext(_ paymentContext: STPPaymentContext, didFinishWithStatus status: STPPaymentStatus, error: NSError?)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.