StripeAPI
public class StripeAPI : NSObject
A top-level class that imports the rest of the Stripe SDK.
-
Set this to your Stripe publishable API key, obtained from https://dashboard.stripe.com/apikeys. Set this as early as possible in your application’s lifecycle, preferably in your AppDelegate or SceneDelegate. New instances of STPAPIClient will be initialized with this value. @warning Make sure not to ship your test API keys to the App Store! This will log a warning if you use your test key in a release build.
Declaration
Swift
@objc public static var defaultPublishableKey: String?
-
Set this to your Stripe publishable API key, obtained from https://dashboard.stripe.com/apikeys. Set this as early as possible in your application’s lifecycle, preferably in your AppDelegate or SceneDelegate. New instances of STPAPIClient will be initialized with this value. @warning Make sure not to ship your test API keys to the App Store! This will log a warning if you use your test key in a release build.
Declaration
Swift
public func setDefaultPublishableKey(_ publishableKey: String)
-
A Boolean value that determines whether additional device data is sent to Stripe for fraud prevention. If YES, additional device signals will be sent to Stripe. For more details on the information we collect, visit https://stripe.com/docs/disputes/prevention/advanced-fraud-detection Disabling this setting will reduce Stripe’s ability to protect your business from fraudulent payments. The default value is YES.
Declaration
Swift
@objc public static var advancedFraudSignalsEnabled: Bool
-
Japanese users can enable JCB for Apple Pay by setting this to
YES
, after they have been approved by JCB. The default value is NO. @note JCB is only supported on iOS 10.1+Declaration
Swift
@objc public class var jcbPaymentNetworkSupported: Bool { get set }
-
The SDK accepts Amex, Mastercard, Visa, and Discover for Apple Pay. Set this property to enable other card networks in addition to these. For example,
additionalEnabledApplePayNetworks = [.JCB]
enables JCB (note this requires onboarding from JCB and Stripe).Declaration
Swift
@objc public static var additionalEnabledApplePayNetworks: [PKPaymentNetwork]
-
Whether or not this device is capable of using Apple Pay. This checks both whether the device supports Apple Pay, as well as whether or not they have stored Apple Pay cards on their device.
Declaration
Swift
@objc public class func canSubmitPaymentRequest(_ paymentRequest: PKPaymentRequest) -> Bool
Parameters
paymentRequest
The return value of this method depends on the
supportedNetworks
property of this payment request, which by default should be[.amex, .masterCard, .visa, .discover]
.Return Value
whether or not the user is currently able to pay with Apple Pay.
-
Whether or not this can make Apple Pay payments via a card network supported by Stripe. The Stripe supported Apple Pay card networks are: American Express, Visa, Mastercard, Discover, Maestro. Japanese users can enable JCB by setting
JCBPaymentNetworkSupported
to YES, after they have been approved by JCB.Declaration
Swift
@objc dynamic public class func deviceSupportsApplePay() -> Bool
Return Value
YES if the device is currently able to make Apple Pay payments via one of the supported networks. NO if the user does not have a saved card of a supported type, or other restrictions prevent payment (such as parental controls).
-
A convenience method to build a
PKPaymentRequest
with sane default values. You will still need to configure thepaymentSummaryItems
property to indicate what the user is purchasing, as well as the optionalrequiredShippingAddressFields
,requiredBillingAddressFields
, andshippingMethods
properties to indicate what contact information your application requires. Note that this method sets the payment request’s countryCode to “US” and its currencyCode to “USD”.Declaration
Swift
@available(*, deprecated, message: "Use `paymentRequestWithMerchantIdentifier:country:currency:` instead.") @objc public class func paymentRequest(withMerchantIdentifier merchantIdentifier: String) -> PKPaymentRequest
Parameters
merchantIdentifier
Your Apple Merchant ID.
Return Value
a
PKPaymentRequest
with proper default values. Returns nil if running on < iOS8. @deprecated UsepaymentRequestWithMerchantIdentifier:country:currency:
instead. Apple Pay is available in many countries and currencies, and you should use the appropriate values for your business. -
A convenience method to build a
PKPaymentRequest
with sane default values. You will still need to configure thepaymentSummaryItems
property to indicate what the user is purchasing, as well as the optionalrequiredShippingContactFields
,requiredBillingContactFields
, andshippingMethods
properties to indicate what additional contact information your application requires.Declaration
Swift
@objc public class func paymentRequest( withMerchantIdentifier merchantIdentifier: String, country countryCode: String, currency currencyCode: String ) -> PKPaymentRequest
Parameters
merchantIdentifier
Your Apple Merchant ID.
countryCode
The two-letter code for the country where the payment will be processed. This should be the country of your Stripe account.
currencyCode
The three-letter code for the currency used by this payment request. Apple Pay interprets the amounts provided by the summary items attached to this request as amounts in this currency.
Return Value
a
PKPaymentRequest
with proper default values.
-
Call this method in your app delegate whenever you receive an URL in your app delegate for a Stripe callback. For convenience, you can pass all URL’s you receive in your app delegate to this method first, and check the return value to easily determine whether it is a callback URL that Stripe will handle or if your app should process it normally. If you are using a universal link URL, you will receive the callback in
application:continueUserActivity:restorationHandler:
To learn more about universal links, see https://developer.apple.com/library/content/documentation/General/Conceptual/AppSearch/UniversalLinks.html If you are using a native scheme URL, you will receive the callback inapplication:openURL:options:
To learn more about native url schemes, see https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html#//apple_ref/doc/uid/TP40007072-CH6-SW10Declaration
Swift
@discardableResult @objc(handleStripeURLCallbackWithURL:) public static func handleURLCallback(with url: URL) -> Bool
Parameters
url
The URL that you received in your app delegate
Return Value
YES if the URL is expected and will be handled by Stripe. NO otherwise.