SCPTerminal
Objective-C
@interface SCPTerminal : NSObject
Swift
class Terminal : NSObject
The SCPTerminal object that is made available by the Stripe Terminal SDK exposes
a generic interface for discovering readers, connecting to a reader, and
creating payments.
The SCPTerminal object is a singleton, and you cannot create multiple
SCPTerminal instances.
-
Sets the token provider for the shared (singleton)
SCPTerminalinstance.You must set a token provider before calling
sharedto initialize the Terminal singleton. We recommend callingsetTokenProvider:in your AppDelegate’sapplication:didFinishLaunchingWithOptions:method. Alternatively, you can wrap your call tosetTokenProvider:with adispatch_oncein Objective-C, or use a static constructor in Swift.Note that you may only set a token provider before requesting the shared Terminal instance for the first time. In order to switch accounts in your app, e.g. to switch between live and test Stripe API keys on your backend, refer to the documentation for the
clearCachedCredentialsmethod on the shared Terminal instance.Declaration
Objective-C
+ (void)setTokenProvider:(nonnull id<SCPConnectionTokenProvider>)tokenProvider; -
Returns true if a token provider has been set, through
setTokenProvider:Declaration
Objective-C
+ (BOOL)hasTokenProvider;Swift
class func hasTokenProvider() -> Bool -
Sets a block to listen for logs from the shared Terminal instance (optional).
You can use this optional method to listen for logs from the Stripe Terminal SDK and incorporate them into your own remote logs. Note that these logs are subject to change, and provided for informational and debugging purposes only. You should not depend on them for behavior in your app. Also note that the block you provide may be called from any thread.
To print internal logs from the SDK to the console, you can set
logLeveltoSCPLogLevelVerboseon the Terminal instance.Declaration
Objective-C
+ (void)setLogListener:(nonnull SCPLogListenerBlock)listener;Swift
class func setLogListener(_ listener: @escaping LogListenerBlock) -
Returns the shared (singleton) Terminal instance.
Before accessing the singleton for the first time, you must first call
setTokenProvider:andsetDelegate:.Declaration
Objective-C
@property (class, nonatomic, readonly) SCPTerminal *_Nonnull shared;Swift
class var shared: Terminal { get } -
The Terminal instance’s delegate (optional).
Set this to handle events from the Terminal instance.
Declaration
Objective-C
@property (nonatomic, nullable) id<SCPTerminalDelegate> delegate; -
The Terminal instance’s current connection status.
Declaration
Objective-C
@property (nonatomic, readonly) SCPConnectionStatus connectionStatus;Swift
var connectionStatus: ConnectionStatus { get } -
The log level for the SDK. The default value is
.none.Declaration
Objective-C
@property (nonatomic) SCPLogLevel logLevel;Swift
var logLevel: LogLevel { get set } -
The Terminal instance’s current payment status.
Declaration
Objective-C
@property (nonatomic, readonly) SCPPaymentStatus paymentStatus;Swift
var paymentStatus: PaymentStatus { get } -
Clears the current connection token, saved reader sessions, and any other cached credentials. You can use this method to switch accounts in your app, e.g. to switch between live and test Stripe API keys on your backend.
In order to switch accounts in your app:
- if a reader is connected, call
disconnectReader: - configure the
tokenProviderobject to return connection tokens for the new account. ThetokenProvideris implemented by your code, and you can do this however you want. - call
clearCachedCredentials - call
discoverReadersandconnectReaderto connect to a reader. Theconnectcall will request a new connection token from your backend server via the token provider.
An overview of the lifecycle of a connection token under the hood:
- When the Terminal singleton is initialized, the SDK attempts to proactively request a connection token from your backend server.
- When
connectis called, the SDK uses the connection token and reader information to create a reader session. - Subsequent calls to
connectwill re-use the reader session if the SDK has successfully connected to the reader already. Otherwise, it will require a new connection token when you callconnectagain.
Declaration
Objective-C
- (void)clearCachedCredentials;Swift
func clearCachedCredentials() - if a reader is connected, call
-
Begins discovering readers matching the given configuration.
When
discoverReadersis called, the terminal begins scanning for readers using the settings in the givenSCPDiscoveryConfiguration. You must implementSCPDiscoveryDelegateto handle displaying discovery results to your user and connecting to a selected reader.The discovery process will stop on its own when the terminal successfully connects to a reader, if the command is canceled, or if a discovery error occurs.
Note that if
discoverReadersis canceled, the completion block will be called withnil(rather than anSCPErrorCancelederror).Declaration
Objective-C
- (nullable SCPCancelable *) discoverReaders:(nonnull SCPDiscoveryConfiguration *)configuration delegate:(nonnull id<SCPDiscoveryDelegate>)delegate completion:(nonnull SCPErrorCompletionBlock)completion;Parameters
configurationThe configuration for reader discovery.
delegateYour delegate for reader discovery.
completionThe completion block called when the command completes.
-
Attempts to connect to the given reader with a given connection configuration.
If the connect succeeds, the completion block will be called with the connected reader, and
SCPTerminal.connectionStatuswill change to.connected.If the connect fails, the completion block will be called with an error.
The SDK must be actively discovering readers in order to connect to one. The discovery process will stop if this connection request succeeds, otherwise the SDK will continue discovering.
When this method is called, the SDK uses a connection token and the given reader information to create a reader session. If the SDK does not already have a connection token, it will call the `fetchConnectionToken method you defined to fetch one.
Currently the
connectionConfigis only utilized byverifoneP400and will be ignored if passed while attempting to connect to achipper2XorwisePad3. IfconnectionConfigis set tonil, the SDK will resort to default connection behavior; see theSCPConnectionConfigurationheader documentation for more details.Declaration
Objective-C
- (void)connectReader:(nonnull SCPReader *)reader connectionConfig:(nullable SCPConnectionConfiguration *)connectionConfig completion:(nonnull SCPReaderCompletionBlock)completion;Swift
func connectReader(_ reader: SCPReader, connectionConfig: SCPConnectionConfiguration?, completion: @escaping ReaderCompletionBlock)Parameters
readerThe reader to connect to. This should be a reader recently returned to the
didUpdateDiscoveredReaders:method.connectionConfigThe connection configuration for options while connecting to a reader. See
SCPConnectionConfigurationfor more details.completionThe completion block called when the command completes.
-
Convenience method for connecting to a reader without connection configuration. Please see above docs for functionality.
Declaration
Objective-C
- (void)connectReader:(nonnull SCPReader *)reader completion:(nonnull SCPReaderCompletionBlock)completion;Swift
func connectReader(_ reader: SCPReader, completion: @escaping ReaderCompletionBlock) -
Attempts to disconnect from the currently connected reader.
If the disconnect succeeds, the completion block is called with
nil. If the disconnect fails, the completion block is called with an error.Declaration
Objective-C
- (void)disconnectReader:(nonnull SCPErrorCompletionBlock)completion;Swift
func disconnectReader(_ completion: @escaping ErrorCompletionBlock)Parameters
completionThe completion block called when the command completes.
-
Creates a new
SCPPaymentIntentwith the given parameters.Note: If the information required to create a PaymentIntent isn’t readily available in your app, you can create the PaymentIntent on your server and use the
retrievePaymentIntentmethod to retrieve the PaymentIntent in your app.- - note: This cannot be used with the Verifone P400 reader. If used with the Verifone P400, the completion handler will be called with an SCPErrorFeatureNotAvailableWithConnectedReader error.Declaration
Objective-C
- (void)createPaymentIntent:(nonnull SCPPaymentIntentParameters *)parameters completion:(nonnull SCPPaymentIntentCompletionBlock)completion;Swift
func createPaymentIntent(_ parameters: SCPPaymentIntentParameters, completion: @escaping PaymentIntentCompletionBlock)Parameters
parametersThe parameters for the PaymentIntent to be created.
completionThe completion block called when the command completes.
-
Retrieves a
SCPPaymentIntentwith a client secret.If the information required to create a PaymentIntent isn’t readily available in your app, you can create the PaymentIntent on your server and use this method to retrieve the PaymentIntent in your app.
Declaration
Objective-C
- (void)retrievePaymentIntent:(nonnull NSString *)clientSecret completion: (nonnull SCPPaymentIntentCompletionBlock)completion;Swift
func retrievePaymentIntent(clientSecret: String, completion: @escaping PaymentIntentCompletionBlock)Parameters
clientSecretThe client secret of the PaymentIntent to be retrieved.
completionThe completion block called when the command completes.
-
Collects a payment method for the given
SCPPaymentIntent.Note:
collectPaymentMethoddoes not apply any changes to the PaymentIntent API object. Updates to the PaymentIntent are local to the SDK, and persisted in-memory.If collecting a payment method fails, the completion block will be called with an error. After resolving the error, you may call
collectPaymentMethodagain to either try the same card again, or try a different card.If collecting a payment method succeeds, the completion block will be called with a PaymentIntent with status
.requiresConfirmation, indicating that you should callprocessPayment:completion:to finish the payment.Note that if
collectPaymentMethodis canceled, the completion block will be called with aCancelederror.Declaration
Objective-C
- (nullable SCPCancelable *) collectPaymentMethod:(nonnull SCPPaymentIntent *)paymentIntent delegate:(nullable id<SCPReaderDisplayDelegate>)delegate completion:(nonnull SCPPaymentIntentCompletionBlock)completion;Swift
func collectPaymentMethod(_ paymentIntent: PaymentIntent, delegate: ReaderDisplayDelegate?, completion: @escaping PaymentIntentCompletionBlock) -> SCPCancelable?Parameters
paymentIntentThe PaymentIntent to collect a payment method for.
delegateYour delegate for handling reader input events. Providing an
SCPReaderDisplayDelegateis required when the connected reader doesn’t have a built-in display (e.g., the BBPOS Chipper 2X BT). These readers will request that your app display messages during thecollectPaymentMethodprocess (e.g., “Remove card”) via this delegate.completionThe completion block called when the command completes.
-
Processes a payment after collecting a payment method succeeds.
Synchronous capture
Stripe Terminal uses two-step card payments to prevent unintended and duplicate payments. When
processPaymentcompletes successfully, a charge has been authorized on the customer’s card, but not yet been “captured”. Your app must synchronously notify your backend to capture the PaymentIntent in order to settle the funds to your account.Handling failures
When
processPaymentfails, the SDK returns an error that includes the updatedSCPPaymentIntent. Your app should inspect the updated PaymentIntent to decide how to retry the payment.If the updated PaymentIntent is
nil, the request to Stripe’s servers timed out and the PaymentIntent’s status is unknown. We recommend that you retryprocessPaymentwith the original PaymentIntent. If you instead choose to abandon the original PaymentIntent and create a new one, do not capture the original PaymentIntent. If you do, you might charge your customer twice.If the updated PaymentIntent’s status is still
.requiresConfirmation(e.g., the request failed because your app is not connected to the internet), you can callprocessPaymentagain with the updated PaymentIntent to retry the request.If the updated PaymentIntent’s status changes to
.requiresPaymentMethod(e.g., the request failed because the card was declined), callcollectPaymentMethodwith the updated PaymentIntent to try charging another card.
Declaration
Objective-C
- (void)processPayment:(nonnull SCPPaymentIntent *)paymentIntent completion:(nonnull SCPProcessPaymentCompletionBlock)completion;Swift
func processPayment(_ paymentIntent: PaymentIntent, completion: @escaping ProcessPaymentCompletionBlock)Parameters
paymentIntentThe PaymentIntent to confirm.
completionThe completion block called when the confirm completes.
-
Cancels an
SCPPaymentIntent.If the cancel request succeeds, the completion block will be called with the updated PaymentIntent object with status Canceled. If the cancel request fails, the completion block will be called with an error.
Note
This cannot be used with the Verifone P400 reader. If used with the Verifone P400, the completion handler will be called with an SCPErrorFeatureNotAvailableWithConnectedReader error.
Declaration
Objective-C
- (void)cancelPaymentIntent:(nonnull SCPPaymentIntent *)paymentIntent completion:(nonnull SCPPaymentIntentCompletionBlock)completion;Swift
func cancelPaymentIntent(_ paymentIntent: PaymentIntent, completion: @escaping PaymentIntentCompletionBlock)Parameters
paymentIntentThe PaymentIntent to cancel.
completionThe completion block called when the cancel completes.
-
Reads a card with the given parameters and returns a PaymentMethod.
NOTE: Most integrations should not use
readReusableCard.You should create a
SCPPaymentIntentand use the associatedcollectPaymentMethodandprocessPaymentmethods if you are simply collecting a payment from a customer.You can use
readReusableCardto read payment details and defer payment for later. The PaymentMethod created by this method will have typecard, suitable for use with online payments.Note that if you use this method to defer a payment, the transaction will not receive the beneficial rates and liability shift associated with card present transactions.
If reading a card fails, the completion block will be called with an error containing details about the failure. If reading a card succeeds, the completion block will be called with a
PaymentMethod. You should send the ID of the payment method to your backend for further processing. For example, you can use the fingerprint to look up charges created using the same card.Note
This cannot be used with the Verifone P400 or WisePad 3 readers. This method will assert if called while the SDK is connected to a device of type
verifoneP400orwisePad3.Declaration
Objective-C
- (nullable SCPCancelable *) readReusableCard:(nonnull SCPReadReusableCardParameters *)parameters delegate:(nonnull id<SCPReaderDisplayDelegate>)delegate completion:(nonnull SCPPaymentMethodCompletionBlock)completion;Swift
func readReusableCard(_ parameters: SCPReadReusableCardParameters, delegate: ReaderDisplayDelegate, completion: @escaping PaymentMethodCompletionBlock) -> SCPCancelable?Parameters
parametersThe parameters for reading the card.
delegateYour delegate for handling reader input events.
completionThe completion block called when the command completes.
-
Initiates an in-person refund with a given set of
SCPRefundParametersby collecting the payment method that is to be refunded.Some payment methods, like Interac Debit payments, require that in-person payments also be refunded while the cardholder is present. The cardholder must present the Interac card to the card reader; these payments cannot be refunded via the dashboard or the API.
For payment methods that don’t require the cardholder be present, see https://stripe.com/docs/terminal/payments/refunds
This method, along with
processRefund, allow you to design an in-person refund flow into your app.If collecting a payment method fails, the completion block will be called with an error. After resolving the error, you may call
collectRefundPaymentMethodagain to either try the same card again, or try a different card.If collecting a payment method succeeds, the completion block will be called with an
nilerror. At that point, you can callprocessRefundto finish refunding the payment method.Calling any other SDK methods between
collectRefundPaymentMethodandprocessRefundwill result in undefined behavior.Note that if
collectRefundPaymentMethodis canceled, the completion block will be called with aCancelederror.Declaration
Objective-C
- (nullable SCPCancelable *) collectRefundPaymentMethod:(nonnull SCPRefundParameters *)refundParams completion:(nonnull SCPErrorCompletionBlock)completion;Swift
func collectRefundPaymentMethod(_ refundParams: RefundParameters, completion: @escaping ErrorCompletionBlock) -> SCPCancelable?Parameters
refundParamsThe SCPRefundParameters object that describes how the refund will be created.
completionThe completion block called when the command completes.
-
Processes an in-person refund after the refund payment method has been collected.
The completion block will either be called with the successful
SCPRefundor with anSCPProcessRefundError.When
processRefundfails, the SDK returns an error that either includes the failedSCPRefundor theSCPRefundParametersthat led to a failure. Your app should inspect theSCPProcessRefundErrorto decide how to proceed.If the refund property is
nil, the request to Stripe’s servers timed out and the refund’s status is unknown. We recommend that you retryprocessRefundwith the originalSCPRefundParameters.If the
SCPProcessRefundErrorhas afailure_reason, the refund was declined. We recommend that you take action based on the decline code you received.
Note
collectRefundPaymentMethod:completionandprocessRefundare only available for payment methods that require in-person refunds. For all other refunds, use the Stripe Dashboard or the Stripe API.Declaration
Objective-C
- (void)processRefund:(nonnull SCPProcessRefundCompletionBlock)completion;Swift
func processRefund(completion: @escaping ProcessRefundCompletionBlock)Parameters
completionThe completion block called when the command completes.
-
Checks for a reader software update, and returns an update object if an update is available.
If an update is available, the completion block will be called with an
SCPReaderSoftwareUpdateobject, indicating that a software update is available. The update object contains information about the update that you can display to the user, such as the estimated installation time.If an error occurs while checking for an update, the completion block will be called with an error. If there are no updates available and no errors occur, the completion block will be called with
(nil, nil).Note
This method will never return an update if it is called when the SDK is connected to the Verifone P400.
Declaration
Objective-C
- (nullable SCPCancelable *)checkForUpdate: (nonnull SCPReaderSoftwareUpdateCompletionBlock)completion;Swift
func checkForUpdate(_ completion: @escaping ReaderSoftwareUpdateCompletionBlock) -> SCPCancelable?Parameters
completionThe completion block called when checking for an update completes.
-
Clears the reader display and resets it to the splash screen.
Note
Only available for the Verifone P400
Declaration
Objective-C
- (void)clearReaderDisplay:(nonnull SCPErrorCompletionBlock)completion;Swift
func clearReaderDisplay(_ completion: @escaping ErrorCompletionBlock)Parameters
completionThe completion block called when the command completes.
-
Updates the reader display with cart information. This method is for display purposes only and has no correlation with what the customer is actually charged. Tax and total are also not automatically calculated and must be set in SCPCart.
Note
Only available for the Verifone P400
Declaration
Objective-C
- (void)setReaderDisplay:(nonnull SCPCart *)cart completion:(nonnull SCPErrorCompletionBlock)completion;Swift
func setReaderDisplay(_ cart: SCPCart, completion: @escaping ErrorCompletionBlock)Parameters
cartThe cart containing the information that will be displayed.
completionThe completion block called when the command completes.
-
Installs the provided update, and calls the completion block when the installation has completed.
If an error occurs while installing the update (e.g. because the update was interrupted), the completion block will be called with an error. If the update completed successfully, the completion block will be called with
nil. You must pass a delegate to handle events as the update proceeds. In your app, you should display the progress of the update to the user. You should also instruct the user to wait for the update to complete: “Do not leave this page, and keep the reader in range and powered on until the update is complete.”You must implement the ability to update your reader’s software in your app. Though we expect required software updates to be very rare, by using Stripe Terminal, you are obligated to include this functionality.
Note
It is an error to call this method when the SDK is connected to the Verifone P400 reader.
Declaration
Objective-C
- (nullable SCPCancelable *) installUpdate:(nonnull SCPReaderSoftwareUpdate *)update delegate:(nonnull id<SCPReaderSoftwareUpdateDelegate>)delegate completion:(nonnull SCPErrorCompletionBlock)completion;Parameters
updateThe reader update.
delegateYour delegate for handling update events.
completionThe completion block called when the update completes.
-
Returns an unlocalized string for the given reader input options, e.g. “Swipe / Insert”
Declaration
Objective-C
+ (nonnull NSString *)stringFromReaderInputOptions: (SCPReaderInputOptions)options;Swift
class func stringFromReaderInputOptions(_ options: ReaderInputOptions = []) -> String -
Returns an unlocalized string for the given reader display message, e.g. “Retry Card”
Declaration
Objective-C
+ (nonnull NSString *)stringFromReaderDisplayMessage: (SCPReaderDisplayMessage)message;Swift
class func stringFromReaderDisplayMessage(_ message: ReaderDisplayMessage) -> String -
Returns an unlocalized string for the given reader event, e.g. “Card Inserted”
Declaration
Objective-C
+ (nonnull NSString *)stringFromReaderEvent:(SCPReaderEvent)event;Swift
class func stringFromReaderEvent(_ event: ReaderEvent) -> String -
Returns an unlocalized string for the given connection status, e.g. “Connecting”
Declaration
Objective-C
+ (nonnull NSString *)stringFromConnectionStatus:(SCPConnectionStatus)status;Swift
class func stringFromConnectionStatus(_ status: ConnectionStatus) -> String -
Returns an unlocalized string for the given payment status, e.g. “Not Ready”
Declaration
Objective-C
+ (nonnull NSString *)stringFromPaymentStatus:(SCPPaymentStatus)status;Swift
class func stringFromPaymentStatus(_ status: PaymentStatus) -> String -
Returns an unlocalized string for the given device type.
Declaration
Objective-C
+ (nonnull NSString *)stringFromDeviceType:(SCPDeviceType)deviceType;Swift
class func stringFromDeviceType(_ deviceType: DeviceType) -> String -
Returns an unlocalized string for the given discovery method.
Declaration
Objective-C
+ (nonnull NSString *)stringFromDiscoveryMethod:(SCPDiscoveryMethod)method;Swift
class func stringFromDiscoveryMethod(_ method: DiscoveryMethod) -> String -
Unavailable
Use
initWithConfiguration:tokenProvider:delegate:Declaration
Objective-C
- (nonnull instancetype)init; -
Unavailable
Use
initWithConfiguration:tokenProvider:delegate:Declaration
Objective-C
+ (nonnull instancetype)new;
SCPTerminal Class Reference