stripe-ios
stripe-ios copied to clipboard
[BUG] paymentSheet.present is unavailable in application extensions for iOS
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
Hi @harishjangid154,
Is your View Controller part of an app extension?
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.
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:

Hi @ramont-stripe
I have checked the membership for this view controller
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.
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
?
Closing due to inactivity