2.1.0 • Published 1 year ago

capacitor-stripe-terminal v2.1.0

Weekly downloads
36
License
MIT
Repository
github
Last release
1 year ago

npm GitHub Issues GitHub Pull Requests GitHub license Slack


Current project status

WARNING: Until this project reaches 1.0, the API is subject to breaking changes.

📝 Table of Contents

🏁 Getting Started

iOS Setup

First, follow all Stripe instructions under "Configure your app". Then run the following in your Capacitor project:

# install the bridge
npm install capacitor-stripe-terminal

# sync the iOS project
npx cap sync ios

Android Setup

(not supported yet)

🎈 Usage

import {
  StripeTerminalPlugin,
  DeviceType,
  DiscoveryMethod
} from 'capacitor-stripe-terminal'

// First, initialize the SDK
const terminal = new StripeTerminal({
  fetchConnectionToken: async () => {
    const resp = await fetch('https://your-backend.dev/token', {
      method: 'POST'
    })
    const data = await resp.json()

    return data.secret
  }
})

// Start scanning for readers
// capacitor-stripe-terminal uses Observables for any data streams
// To stop scanning, unsubscribe from the Observable.
// You must connect to a reader while scanning
terminal
  .discoverReaders({
    simulated: false,
    deviceType: DeviceType.Chipper2X,
    discoveryMethod: DiscoveryMethod.BluetoothProximity
  })
  .subscribe(readers => {
    if (readers.length) {
      terminal
        .connectReader({ serialNumber: readers[0].serialNumber })
        .then(connectedReader => {
          // the reader is now connected and usable
        })
    }
  })

// Once the reader is connected, collect a payment intent!
;(async () => {
  // subscribe to user instructions - these should be displayed to the user
  const waitingSubscription = terminal
    .readerDisplayMessage()
    .subscribe(message => {
      console.log('readerDisplayMessage', message.text)
    })
  const inputSubscription = terminal.readerInput().subscribe(message => {
    console.log('readerInput', message.text)
  })

  // retrieve the payment intent
  const pi = await terminal.retrievePaymentIntent(
    'your client secret created server side'
  )

  // collect the payment method
  await terminal.collectPaymentMethod()

  // and finally, process the payment
  await terminal.processPayment()

  // once you are done, make sure to unsubscribe (e.g. in ngOnDestroy)
  waitingSubscription.unsubscribe()
  inputSubscription.unsubscribe()
})()

See the full docs here.

✍️ Authors

See also the list of contributors who participated in this project.

🎉 Acknowledgements

3.0.0-beta.5

1 year ago

3.0.0-beta.4

1 year ago

3.0.0-beta.7

1 year ago

3.0.0-beta.6

1 year ago

3.0.0-beta.8

1 year ago

3.0.0-beta.3

1 year ago

3.0.0-beta.2

2 years ago

3.0.0-beta.1

2 years ago

2.1.0

2 years ago

2.1.1-beta.1

2 years ago

2.1.0-beta.5

2 years ago

2.1.0-beta.6

2 years ago

2.1.0-beta.4

2 years ago

2.0.0-beta.7

2 years ago

2.0.1-beta.1

2 years ago

2.0.0-beta.6

2 years ago

2.0.0

2 years ago

2.1.0-beta.1

2 years ago

2.1.0-beta.3

2 years ago

2.1.0-beta.2

2 years ago

2.0.0-beta.5

3 years ago

2.0.0-beta.4

3 years ago

2.0.0-beta.3

3 years ago

2.0.0-beta.2

3 years ago

2.0.0-beta.1

3 years ago

1.1.0

3 years ago

1.1.0-beta.2

3 years ago

1.1.0-beta.1

3 years ago

1.0.1-beta.1

3 years ago

1.0.0-beta.11

3 years ago

1.0.0

3 years ago

1.0.0-beta.10

3 years ago

1.0.0-beta.9

3 years ago

1.0.0-beta.8

4 years ago

1.0.0-beta.6

4 years ago

1.0.0-beta.7

4 years ago

1.0.0-beta.5

4 years ago

1.0.0-beta.4

4 years ago

1.0.0-beta.3

4 years ago

1.0.0-beta.2

4 years ago

1.0.0-beta.1

5 years ago