API Reference

Terminal Simulation - Stripe

Not all developers and QA testers need or can have a physical terminal to test payments. However, you might still need for them to be able to submit terminal request. You can emulate a Stripe terminal in you application for testing Stripe CP payments.

Overview

Simulated terminals when testing Stripe are not managed by Quilt. This is because everything is handled in the JavaScript SDK. So you will need to follow Stripes documentation.

Here is an overview of the process in Stripes documentation:
https://docs.stripe.com/terminal/references/testing?terminal-sdk-platform=react-native#see-also

You can then create a simulated configuration for the simulated terminal:
https://docs.stripe.com/terminal/references/api/js-sdk#stripeterminal-setsimulatorconfig

You will need to discover a simulated reader so that is it returned.
https://docs.stripe.com/terminal/references/api/js-sdk#discover-readers

At that point you would process the request in the JavaScript like normal.

An example:

Below is the basic outline for getting a simulated terminal and processing a payment. However, it is not a working example. You will need to handle the flow below in your application. The critical parts to using a test terminal are setting the terminal id to simulated and creating the config with simulated to true and the testCardNumber to one of the many test cards. The rest is then the same as processing a terminal request with real hardware.

Get your terminal

let terminalId = 'simulated';
let cardNumber = '4242424242424242';

let terminal = StripeTerminal.create({
  onFetchConnectionToken: this.fetchConnectionToken,
  onUnexpectedReaderDisconnect: this.unexpectedDisconnect,
 });
 
let config = {};
if (this.terminal === 'simulated') {
  config = {
    simulated: true,
    testCardNumber: cardNumber,
  };
  terminal.setSimulatorConfiguration(config);
}

Connect to the reader

let readers = await terminal.discoverReaders(config);
let reader = readers[0];
await terminal.connectReader(reader);

Get an intent

// POST https://<your portal domain>/v2/payment/intent
{
  "amount": 32.99,
  "external_account_id": "account_12345",
  "external_payment_id": "external_12345",
  "payment_method_types": "card_present",
  "capture_method": "automatic"
}

Collect and process the payment

let paymentResult = await terminal.collectPaymentMethod(intent.token);
let processResult = await terminal.processPayment(paymentResult.paymentIntent);