Collect payments
Note
For BBPOS WisePOS E readers, we recommend the server-driven integration, which uses the Stripe API instead of a Terminal SDK to collect payments.
Collecting payments with Stripe Terminal requires writing a payment flow in your application. Use the Stripe Terminal SDK to create and update a PaymentIntent, an object representing a single payment session.
Designed to be robust to failures, the Terminal integration splits the payment process into several steps, each of which can be retried safely:
In Step 1, you can define whether to automatically or manually capture your payments. Authorization on the customer’s card takes place in Step 3, when the SDK processes the payment.
Create a PaymentIntentClient-sideServer-side
The first step when collecting payments is to start the payment flow. When a customer begins checking out, your application must create a PaymentIntent
object. This represents a new payment session on Stripe.
You can create a PaymentIntent on the client or server.
Use test amounts to try producing different results. An amount ending in 00
results in an approved payment.
Client-side
Create a PaymentIntent from your client:
Warning
If your app is connected to the Verifone P400, you can’t create a PaymentIntent from the iOS SDK. Instead, you must create the PaymentIntent server-side and retrieve it in your app using the Terminal.retrievePaymentIntent
method in the SDK.
Server-side
You can create the PaymentIntent
on your server if the information required to start a payment isn’t readily available in your app.
The following example shows how to create a PaymentIntent
on your server:
For Terminal payments, the payment_method_types
parameter must include card_present
.
You can control the payment flow as follows:
- To fully control the payment flow for
card_present
payments, set thecapture_method
tomanual
. This allows you to add a reconciliation step before finalizing the payment. - To authorize and capture payments in one step, set the
capture_method
toautomatic
.
Note
To accept Interac payments in Canada, you must also include interac_present
in payment_method_types
. For more details, visit our Canada documentation.
The PaymentIntent contains a client secret, a key that is unique to the individual PaymentIntent. To use the client secret, you must obtain it from the PaymentIntent on your server and pass it to the client side.
First use the client secret to call retrievePaymentIntent
, and then use the retrieved PaymentIntent to call collectPaymentMethod
.
Collect a payment method Client-side
After you’ve created a PaymentIntent, the next step is to collect a payment method with the SDK.
In order to collect a payment method, your app needs to be connected to a reader. The connected reader will wait for a card to be presented after your app calls collectPaymentMethod
.
This method collects encrypted payment method data using the connected card reader, and associates the encrypted data with the local PaymentIntent.
Caution
Collecting a payment method happens locally and requires no authorization or updates to the Payment Intents API object until the next step, process the payment.
Optionally inspect payment method details Beta
For advanced use cases, you may optionally examine the payment method details of the presented card and perform your own business logic prior to authorization.
Use the initWithUpdatePaymentIntent
parameter in CollectionConfiguration
to attach a PaymentMethod to the server-side PaymentIntent. This data is returned in the collectPaymentMethod
response.
Note
This method attaches the collected encrypted payment method data with an update to the PaymentIntent object. It requires no authorization until the next step, process the payment.
This advanced use case isn’t supported on the Verifone P400 or with simulated Terminal readers.
You can cancel collecting a payment method using the Cancelable
object returned by the iOS SDK.
Handle events
When collecting a payment method using a reader like the BBPOS Chipper 2X BT, without a built-in display, your app must be able to display events from the payment method collection process to users. These events help users successfully collect payments (for example, retrying a card, trying a different card, or using a different read method).
When a transaction begins, the SDK passes a ReaderInputOptions
value to your app’s reader display handler, denoting the acceptable types of input (for example, Swipe, Insert, Tap). In your app’s checkout UI, prompt the user to present a card using one of these options.
During the transaction, the SDK might request your app to display additional prompts (for example, Retry Card) to your user by passing a ReaderDisplayMessage
value to your app’s reader display handler. Make sure your checkout UI displays these messages to the user.
Note
Your application doesn’t need to display events from the payment method collection process to users because the reader displays them. To clear the payment method on a transaction, you can cancel the request.
Collect payments with Tap to Pay on iPhone
When your application is ready to collect a payment, the Stripe iOS SDK takes over the display to handle the collection process. After calling the collect payment method, your application remains running, but the iPhone displays a full-screen prompt to the cardholder, instructing them to present their card or NFC-based mobile wallet. If there’s an error reading the card, a prompt for retry displays. A successful presentation returns a success indication, and then control returns to your application to process the payment.
Process the paymentClient-side
After successfully collecting a payment method from the customer, the next step is to process the payment with the SDK. When you’re ready to proceed with the payment, call processPayment
with the updated PaymentIntent
from Step 2.
- For manual capture of payments, a successful
processPayment
call results in aPaymentIntent
with a status ofrequires_capture
. - For automatic capture of payments, the
PaymentIntent
transitions to asucceeded
state.
Warning
You must manually capture PaymentIntents
within two days or the authorization expires and funds are released to the customer.
Handle processing failures
When processing a payment fails, the SDK returns an error that includes the updated PaymentIntent
. Your application needs to inspect the PaymentIntent
to decide how to deal with the error.
PaymentIntent Status | Meaning | Resolution |
---|---|---|
requires_payment_method | Payment method declined | Try collecting a different payment method by calling collectPaymentMethod again with the same PaymentIntent. |
requires_confirmation | Temporary connectivity problem | Call processPayment again with the same PaymentIntent to retry the request. |
PaymentIntent is nil | Request to Stripe timed out, unknown PaymentIntent status | Retry processing the original PaymentIntent. Don’t create a new one, as that could result in multiple authorizations for the cardholder. |
If you encounter multiple, consecutive timeouts, there might be a problem with your connectivity. Make sure that your app can communicate with the internet.
Capture the paymentServer-side
If you defined capture_method
as manual
during PaymentIntent
creation in Step 1, the SDK returns an authorized but not captured PaymentIntent
to your application. Learn more about the difference between authorization and capture.
When your app receives a confirmed PaymentIntent
from the SDK, make sure it notifies your backend to capture the payment. Create an endpoint on your backend that accepts a PaymentIntent
ID and sends a request to the Stripe API to capture it:
A successful capture
call results in a PaymentIntent
with a status of succeeded
.
Note
To ensure the application fee captured is correct for connected accounts, inspect each PaymentIntent
and modify the application fee, if needed, prior to manually capturing the payment.
Reconcile payments
To monitor the payments activity of your business, you may want to reconcile PaymentIntents with your internal orders system on your server at the end of a day’s activity.
A PaymentIntent that retains a requires_capture
status may represent two things:
Unnecessary authorization on your customer’s card statement
- Cause: User abandons your app’s checkout flow in the middle of a transaction
- Solution: If the uncaptured PaymentIntent isn’t associated with a completed order on your server, you can cancel it. A canceled PaymentIntent can no longer be used to perform charges.
Incomplete collection of funds from a customer
- Cause: Failure of the request from your app notifying your backend to capture the payment
- Solution: If the uncaptured PaymentIntent is associated with a completed order on your server, and no other payment has been taken for the order (for example, a cash payment), you can capture it.
Collect tips US only
In the US, eligible users can collect tips when capturing payments.