Skip to content

Commit e91a9c0

Browse files
authored
Merge pull request #425 from markhermano/feat/terminal-app-on-device-connection
feat(terminal): Implemented handoff connection type
2 parents 390ec57 + dd8e9eb commit e91a9c0

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

packages/terminal/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ And add next block to `android/app/build.gradle`.
8383
+ apply plugin: 'kotlin-android'
8484
```
8585

86+
If you are developing apps for Stripe Android devices (e.g. Stripe Reader S700), follow the Stripe's documentation for the client-side setup.
87+
- [Stripe - Android configure your app](https://docs.stripe.com/terminal/features/apps-on-devices/build?terminal-sdk-platform=android&lang-android=java#setup-app)
88+
89+
8690
## Usage
8791

8892
### Simple collect payment
@@ -1048,6 +1052,7 @@ addListener(eventName: TerminalEventsEnum.ReaderReconnectFailed, listenerFunc: (
10481052
| **`Bluetooth`** | <code>'bluetooth'</code> |
10491053
| **`Usb`** | <code>'usb'</code> |
10501054
| **`TapToPay`** | <code>'tap-to-pay'</code> |
1055+
| **`HandOff`** | <code>'hand-off'</code> |
10511056
10521057
10531058
#### SimulateReaderUpdate

packages/terminal/android/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ext {
88
volleyVersion = project.hasProperty('volleyVersion') ? rootProject.ext.volleyVersion : '1.2.1'
99
stripeterminalTapToPayVersion = project.hasProperty('stripeterminalTapToPayVersion') ? rootProject.ext.stripeterminalTapToPayVersion : '4.1.0'
1010
stripeterminalCoreVersion = project.hasProperty('stripeterminalCoreVersion') ? rootProject.ext.stripeterminalCoreVersion : '4.1.0'
11+
stripeterminalHandoffClientVersion = project.hasProperty('stripeterminalHandoffClientVersion') ? rootProject.ext.stripeterminalHandoffClientVersion : '4.1.0'
1112
}
1213

1314
buildscript {
@@ -71,6 +72,7 @@ dependencies {
7172

7273
implementation "com.stripe:stripeterminal-core:$stripeterminalCoreVersion"
7374
implementation "com.stripe:stripeterminal-taptopay:$stripeterminalTapToPayVersion"
75+
implementation "com.stripe:stripeterminal-handoffclient:$stripeterminalHandoffClientVersion"
7476
implementation "com.android.volley:volley:$volleyVersion"
7577
implementation "com.google.android.gms:play-services-wallet:$playServicesWalletVersion"
7678
}

packages/terminal/android/src/main/java/com/getcapacitor/community/stripe/terminal/StripeTerminal.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import com.stripe.stripeterminal.external.callable.PaymentIntentCallback
2929
import com.stripe.stripeterminal.external.callable.ReaderCallback
3030
import com.stripe.stripeterminal.external.callable.TapToPayReaderListener
3131
import com.stripe.stripeterminal.external.callable.TerminalListener
32+
import com.stripe.stripeterminal.external.callable.HandoffReaderListener
3233
import com.stripe.stripeterminal.external.models.BatteryStatus
3334
import com.stripe.stripeterminal.external.models.CardPresentDetails
3435
import com.stripe.stripeterminal.external.models.Cart
@@ -194,6 +195,9 @@ class StripeTerminal(
194195
) {
195196
config = DiscoveryConfiguration.BluetoothDiscoveryConfiguration(0, this.isTest!!)
196197
this.terminalConnectType = TerminalConnectTypes.Bluetooth
198+
} else if (call.getString("type") == TerminalConnectTypes.HandOff.webEventName) {
199+
config = DiscoveryConfiguration.HandoffDiscoveryConfiguration()
200+
this.terminalConnectType = TerminalConnectTypes.HandOff
197201
} else {
198202
call.unimplemented(call.getString("type") + " is not support now")
199203
return
@@ -240,6 +244,8 @@ class StripeTerminal(
240244
this.connectUsbReader(call)
241245
} else if (this.terminalConnectType == TerminalConnectTypes.Bluetooth) {
242246
this.connectBluetoothReader(call)
247+
} else if (this.terminalConnectType == TerminalConnectTypes.HandOff) {
248+
this.connectHandOffReader(call)
243249
} else {
244250
call.reject("type is not defined.")
245251
}
@@ -440,6 +446,39 @@ class StripeTerminal(
440446
Terminal.getInstance().connectReader(foundReader, config, this.readerCallback(call))
441447
}
442448

449+
private fun connectHandOffReader(call: PluginCall) {
450+
val reader = call.getObject("reader")
451+
val serialNumber = reader.getString("serialNumber")
452+
val foundReader = this.discoveredReadersList.firstOrNull()
453+
454+
if (serialNumber == null || foundReader == null) {
455+
call.reject("The reader value is not set correctly.")
456+
return
457+
}
458+
459+
val config: ConnectionConfiguration.HandoffConnectionConfiguration = ConnectionConfiguration.HandoffConnectionConfiguration(
460+
this.handoffReaderListener
461+
)
462+
463+
Terminal.getInstance().connectReader(foundReader, config, this.readerCallback(call))
464+
}
465+
466+
var handoffReaderListener: HandoffReaderListener = object : HandoffReaderListener {
467+
override fun onDisconnect(reason: DisconnectReason) {
468+
notifyListeners(
469+
TerminalEnumEvent.DisconnectedReader.webEventName,
470+
JSObject().put("reason", reason.toString())
471+
)
472+
}
473+
474+
override fun onReportReaderEvent(event: ReaderEvent) {
475+
notifyListeners(
476+
TerminalEnumEvent.ReaderEvent.webEventName,
477+
JSObject().put("event", event.toString())
478+
)
479+
}
480+
}
481+
443482
fun cancelDiscoverReaders(call: PluginCall) {
444483
if (discoveryCancelable == null || discoveryCancelable!!.isCompleted) {
445484
call.resolve()

packages/terminal/android/src/main/java/com/getcapacitor/community/stripe/terminal/TerminalConnectTypes.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ enum class TerminalConnectTypes(val webEventName: String) {
66
Bluetooth("bluetooth"),
77
Usb("usb"),
88
TapToPay("tap-to-pay"),
9+
HandOff("hand-off"),
910
}

packages/terminal/src/stripe.enum.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export enum TerminalConnectTypes {
44
Bluetooth = 'bluetooth',
55
Usb = 'usb',
66
TapToPay = 'tap-to-pay',
7+
HandOff = 'hand-off',
78
}
89

910
/**

0 commit comments

Comments
 (0)