stripe-ios icon indicating copy to clipboard operation
stripe-ios copied to clipboard

[BUG] paymentSheet.present is unavailable in application extensions for iOS

Open harishjangid154 opened this issue 3 years ago • 5 comments

Summary

I am using Stripe SDK to charge for a product from my application, but when I try to use paymentSheet.present(from: self), XCode shows that it is not available on this object

Code to reproduce

@objc func handleCardPayment(){

    // MARK: Start the checkout process
      paymentSheet?.present(from: self) { paymentResult in
        // MARK: Handle the payment result
        switch paymentResult {
        case .completed:
          print("Your order is confirmed")
        case .canceled:
          print("Canceled!")
        case .failed(let error):
          print("Payment failed: \(error)")
        }
      }

}

iOS version

IOS 12.0 and XCode 12

Installation method

I have installed SDK throw COCOAPods

SDK version

Other information

harishjangid154 avatar Feb 08 '22 06:02 harishjangid154

Hi @harishjangid154,

Is your View Controller part of an app extension?

ramont-stripe avatar Feb 08 '22 23:02 ramont-stripe

Hi @ramont-stripe No, I am running all this code on a button tap. As this view controller loads, I am running a request to my server to get the customer_id, ephemeral_key, publishable_key and payment_intent of a certain amount, when request returns a response I am running this code

       STPAPIClient.shared.publishableKey = publishableKey
       // MARK: Create a PaymentSheet instance
       var configuration = PaymentSheet.Configuration()
       configuration.merchantDisplayName = "Example, Inc."
       configuration.customer = .init(id: customerId, ephemeralKeySecret: customerEphemeralKeySecret)
       // Set `allowsDelayedPaymentMethods` to true if your business can handle payment
       // methods that complete payment after a delay, like SEPA Debit and Sofort.
      configuration.allowsDelayedPaymentMethods = true
      self.paymentSheet = PaymentSheet(paymentIntentClientSecret: paymentIntentClientSecret, configuration:configuration);

and enabling the payment button to tap, on that button tap, I wanted to present the paymentSheet to process further, but not getting error from xcode.

harishjangid154 avatar Feb 09 '22 08:02 harishjangid154

Got it!

paymentSheet.present is unavailable in application extensions for iOS

This type of error commonly happens when you try to use Payment Sheet in an app extension, which is currently not supported.

You can try checking the target membership of your view controller (Option+Command+1). Only the app target must be checked:

ramont-stripe avatar Feb 09 '22 23:02 ramont-stripe

Hi @ramont-stripe I have checked the membership for this view controller image

and I am running this code in @objc func,

and @racheltan-stripe, one other issue I am facing, which is little bit different, that the class STPPaymentHandler, doc says that it is in the SDK, but when i use it, Xcode is not recognising it.

harishjangid154 avatar Feb 10 '22 04:02 harishjangid154

Hi @harishjangid154! Would you mind providing some more detail here on what you mean by "Xcode is not recognising it"? Are you getting a compiler error when trying to use either STPPaymentHandler or PaymentSheet?

csabol-stripe avatar May 24 '22 23:05 csabol-stripe

Closing due to inactivity

sfriedman-stripe avatar Dec 24 '23 06:12 sfriedman-stripe