diff --git a/android/src/main/java/com/stripeterminalreactnative/Mappers.kt b/android/src/main/java/com/stripeterminalreactnative/Mappers.kt index 7b555abd..1fd42a30 100644 --- a/android/src/main/java/com/stripeterminalreactnative/Mappers.kt +++ b/android/src/main/java/com/stripeterminalreactnative/Mappers.kt @@ -823,10 +823,10 @@ fun mapFromCollectInputsResults(results: List): ReadableArr @OptIn(CollectInputs::class) fun mapFromToggleResult(toggleResult: ToggleResult): String { return when (toggleResult) { - ToggleResult.ENABLED -> "ENABLED" - ToggleResult.DISABLED -> "DISABLED" - ToggleResult.SKIPPED -> "SKIPPED" - else -> { "UNKNOWN" } + ToggleResult.ENABLED -> "enable" + ToggleResult.DISABLED -> "disable" + ToggleResult.SKIPPED -> "skipped" + else -> { "unknown" } } } diff --git a/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt b/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt index 1af1628a..cbe6d6dc 100644 --- a/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt +++ b/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt @@ -859,14 +859,14 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : @ReactMethod @Suppress("unused") fun collectInputs(params: ReadableMap, promise: Promise) = withExceptionResolver(promise) { - val collectInputs = requireParam(params.getArray("collectInputs")) { - "You must provide a collectInputs" + val collectInputs = requireParam(params.getArray("inputs")) { + "You must provide an inputs value" } val listInput = ArrayList() for (i in 0 until collectInputs.size()) { val collectInput = collectInputs.getMap(i) - when (collectInput.getString("inputType")) { - "TEXT" -> { + when (collectInput.getString("formType")) { + "text" -> { collectInput.let { var toggles = ArrayList() it.getArray("toggles") @@ -882,7 +882,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : ) } } - "NUMERIC" -> { + "numeric" -> { collectInput.let { var toggles = ArrayList() it.getArray("toggles") @@ -898,7 +898,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : ) } } - "EMAIL" -> { + "email" -> { collectInput.let { var toggles = ArrayList() it.getArray("toggles") @@ -914,7 +914,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : ) } } - "PHONE" -> { + "phone" -> { collectInput.let { var toggles = ArrayList() it.getArray("toggles") @@ -930,7 +930,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : ) } } - "SIGNATURE" -> { + "signature" -> { collectInput.let { var toggles = ArrayList() it.getArray("toggles") @@ -946,7 +946,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : ) } } - "SELECTION" -> { + "selection" -> { collectInput.let { var toggles = ArrayList() it.getArray("toggles") @@ -958,7 +958,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : val button = array.getMap(i) listSelectionButtons.add( SelectionButton( - if (button.getString("style") == "PRIMARY") { + if (button.getString("style") == "primary") { SelectionButtonStyle.PRIMARY } else { SelectionButtonStyle.SECONDARY diff --git a/dev-app/src/screens/CollectInputsScreen.tsx b/dev-app/src/screens/CollectInputsScreen.tsx index 129cb32b..2e81f16e 100644 --- a/dev-app/src/screens/CollectInputsScreen.tsx +++ b/dev-app/src/screens/CollectInputsScreen.tsx @@ -3,7 +3,8 @@ import { ScrollView, StyleSheet } from 'react-native'; import List from '../components/List'; import ListItem from '../components/ListItem'; import { - CollectInputsParameters, + FormType, + ICollectInputsParameters, SelectionButtonStyle, ToggleValue, useStripeTerminal, @@ -17,7 +18,7 @@ export default function CollectInputsScreen() { const { addLogs, clearLogs, setCancel } = useContext(LogContext); const navigation = useNavigation(); - const _collectInputs = async (params: CollectInputsParameters) => { + const _collectInputs = async (params: ICollectInputsParameters) => { clearLogs(); setCancel({ label: 'Cancel CollectInput', @@ -81,9 +82,9 @@ export default function CollectInputsScreen() { color={colors.blue} onPress={async () => { _collectInputs({ - collectInputs: [ + inputs: [ { - inputType: 'SIGNATURE', + formType: FormType.SIGNATURE, title: 'Please sign', required: false, description: @@ -98,7 +99,7 @@ export default function CollectInputsScreen() { ], }, { - inputType: 'SELECTION', + formType: FormType.SELECTION, title: 'Choose an option', required: false, description: 'Were you happy with customer service?', @@ -117,23 +118,23 @@ export default function CollectInputsScreen() { color={colors.blue} onPress={async () => { _collectInputs({ - collectInputs: [ + inputs: [ { - inputType: 'TEXT', + formType: FormType.TEXT, title: 'Enter your name', required: false, description: "We'll need your name to look up your account", submitButtonText: 'Done', }, { - inputType: 'NUMERIC', + formType: FormType.NUMERIC, title: 'Enter your zip code', required: false, description: '', submitButtonText: 'Done', }, { - inputType: 'EMAIL', + formType: FormType.EMAIL, title: 'Enter your email address', required: false, description: @@ -148,7 +149,7 @@ export default function CollectInputsScreen() { ], }, { - inputType: 'PHONE', + formType: FormType.PHONE, title: 'Enter your phone number', required: false, description: "We'll text you when your order is ready", diff --git a/ios/Mappers.swift b/ios/Mappers.swift index 586922be..5ab27103 100644 --- a/ios/Mappers.swift +++ b/ios/Mappers.swift @@ -783,10 +783,10 @@ class Mappers { class func mapFromToggleResult(_ toggleResult: NSNumber) -> String { switch toggleResult { - case 0: return "ENABLED" - case 1: return "DISABLED" - case 2: return "SKIPPED" - default: return "UNKNOWN" + case 0: return "enabled" + case 1: return "disabled" + case 2: return "skipped" + default: return "unknown" } } diff --git a/ios/StripeTerminalReactNative.swift b/ios/StripeTerminalReactNative.swift index 60589eb3..4bd919bf 100644 --- a/ios/StripeTerminalReactNative.swift +++ b/ios/StripeTerminalReactNative.swift @@ -1007,12 +1007,12 @@ class StripeTerminalReactNative: RCTEventEmitter, DiscoveryDelegate, BluetoothRe let collectInputsParameters: CollectInputsParameters var inputs: [Input] = [] - let collectInputs = params["collectInputs"] as? [NSDictionary] + let collectInputs = params["inputs"] as? [NSDictionary] if let collectInputs = collectInputs { for collectInput in collectInputs { - let inputType = collectInput["inputType"] as? String ?? "" + let inputType = collectInput["formType"] as? String ?? "" switch (inputType) { - case "EMAIL": + case "email": var toggles: [Toggle] = [] let toggleList = collectInput["toggles"] as? [NSDictionary] if let toggleList = toggleList { @@ -1043,7 +1043,7 @@ class StripeTerminalReactNative: RCTEventEmitter, DiscoveryDelegate, BluetoothRe return } break - case "NUMERIC": + case "numeric": var toggles: [Toggle] = [] let toggleList = collectInput["toggles"] as? [NSDictionary] if let toggleList = toggleList { @@ -1074,7 +1074,7 @@ class StripeTerminalReactNative: RCTEventEmitter, DiscoveryDelegate, BluetoothRe return } break - case "PHONE": + case "phone": var toggles: [Toggle] = [] let toggleList = collectInput["toggles"] as? [NSDictionary] if let toggleList = toggleList { @@ -1105,7 +1105,7 @@ class StripeTerminalReactNative: RCTEventEmitter, DiscoveryDelegate, BluetoothRe return } break - case "TEXT": + case "text": var toggles: [Toggle] = [] let toggleList = collectInput["toggles"] as? [NSDictionary] if let toggleList = toggleList { @@ -1136,7 +1136,7 @@ class StripeTerminalReactNative: RCTEventEmitter, DiscoveryDelegate, BluetoothRe return } break - case "SELECTION": + case "selection": var toggles: [Toggle] = [] let toggleList = collectInput["toggles"] as? [NSDictionary] if let toggleList = toggleList { @@ -1183,7 +1183,7 @@ class StripeTerminalReactNative: RCTEventEmitter, DiscoveryDelegate, BluetoothRe return } break - case "SIGNATURE": + case "signature": var toggles: [Toggle] = [] let toggleList = collectInput["toggles"] as? [NSDictionary] if let toggleList = toggleList { diff --git a/src/StripeTerminalSdk.tsx b/src/StripeTerminalSdk.tsx index 99ef9636..e40a1c63 100644 --- a/src/StripeTerminalSdk.tsx +++ b/src/StripeTerminalSdk.tsx @@ -31,8 +31,8 @@ import type { PaymentIntent, SetupIntent, OfflineStatus, - CollectInputsParameters, - CollectInputsResults, + ICollectInputsParameters, + ICollectInputsResults, PaymentStatus, ConnectionStatus, } from './types'; @@ -154,7 +154,9 @@ export interface StripeTerminalSdkType { setReaderSettings( params: Reader.ReaderSettingsParameters ): Promise; - collectInputs(params: CollectInputsParameters): Promise; + collectInputs( + params: ICollectInputsParameters + ): Promise; cancelCollectInputs(): Promise<{ error?: StripeError; }>; diff --git a/src/__tests__/__snapshots__/index.test.tsx.snap b/src/__tests__/__snapshots__/index.test.tsx.snap index 9d12eb87..793e6d54 100644 --- a/src/__tests__/__snapshots__/index.test.tsx.snap +++ b/src/__tests__/__snapshots__/index.test.tsx.snap @@ -14,6 +14,14 @@ Object { "FINISH_DISCOVERING_READERS": "FINISH_DISCOVERING_READERS", "FINISH_INSTALLING_UPDATE": "FINISH_INSTALLING_UPDATE", "FORWARD_PAYMENT_INTENT": undefined, + "FormType": Object { + "EMAIL": "email", + "NUMERIC": "numeric", + "PHONE": "phone", + "SELECTION": "selection", + "SIGNATURE": "signature", + "TEXT": "text", + }, "PaymentIntent": Object {}, "PaymentMethod": Object {}, "READER_RECONNECT_FAIL": undefined, @@ -35,8 +43,8 @@ Object { "START_INSTALLING_UPDATE": "START_INSTALLING_UPDATE", "START_READER_RECONNECT": undefined, "SelectionButtonStyle": Object { - "PRIMARY": "PRIMARY", - "SECONDARY": "SECONDARY", + "PRIMARY": "primary", + "SECONDARY": "secondary", }, "SetupIntent": Object { "Android": Object {}, @@ -45,13 +53,13 @@ Object { "StripeTerminalProvider": [Function], "StripeTerminalProviderProps": undefined, "ToggleResult": Object { - "DISABLED": "DISABLED", - "ENABLED": "ENABLED", - "SKIPPED": "SKIPPED", + "DISABLED": "disabled", + "ENABLED": "enabled", + "SKIPPED": "skipped", }, "ToggleValue": Object { - "DISABLED": "DISABLED", - "ENABLED": "ENABLED", + "DISABLED": "disabled", + "ENABLED": "enabled", }, "UPDATE_DISCOVERED_READERS": "UPDATE_DISCOVERED_READERS", "UseStripeTerminalProps": undefined, diff --git a/src/functions.ts b/src/functions.ts index 3f75665d..0515e92c 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -32,8 +32,8 @@ import type { PaymentIntent, SetupIntent, OfflineStatus, - CollectInputsParameters, - CollectInputsResults, + ICollectInputsParameters, + ICollectInputsResults, PaymentStatus, ConnectionStatus, } from './types'; @@ -862,8 +862,8 @@ export async function setReaderSettings( } export async function collectInputs( - params: CollectInputsParameters -): Promise { + params: ICollectInputsParameters +): Promise { return Logger.traceSdkMethod(async () => { try { const response = await StripeTerminalSdk.collectInputs(params); diff --git a/src/hooks/useStripeTerminal.tsx b/src/hooks/useStripeTerminal.tsx index 6038e951..3fa599b9 100644 --- a/src/hooks/useStripeTerminal.tsx +++ b/src/hooks/useStripeTerminal.tsx @@ -21,7 +21,7 @@ import type { PaymentIntent, SetupIntent, OfflineStatus, - CollectInputsParameters, + ICollectInputsParameters, ReaderEvent, } from '../types'; import { @@ -960,7 +960,7 @@ export function useStripeTerminal(props?: Props) { ); const _collectInputs = useCallback( - async (params: CollectInputsParameters) => { + async (params: ICollectInputsParameters) => { if (!_isInitialized()) { console.error(NOT_INITIALIZED_ERROR_MESSAGE); throw Error(NOT_INITIALIZED_ERROR_MESSAGE); diff --git a/src/types/index.ts b/src/types/index.ts index bb4b2dcc..d2840936 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -381,27 +381,36 @@ export type PaymentMethodResultType = error: StripeError; }; -export type CollectInputsParameters = { - collectInputs: Input[]; -}; +export interface ICollectInputsParameters { + inputs: Array; +} -export type CollectInputsResults = { - collectInputResults?: CollectInputResult[]; - error: StripeError; -}; +export enum FormType { + SELECTION = 'selection', + SIGNATURE = 'signature', + PHONE = 'phone', + EMAIL = 'email', + NUMERIC = 'numeric', + TEXT = 'text', +} -export type Input = { - inputType: 'EMAIL' | 'NUMERIC' | 'PHONE' | 'TEXT' | 'SELECTION' | 'SIGNATURE'; - description?: string; - required: boolean; - skipButtonText?: string; - submitButtonText?: string; +export interface IInput { + formType: FormType; + required?: boolean | null; title: string; - selectionButtons?: SelectionButton[]; - toggles?: Toggle[]; -}; + description?: string | null; + toggles?: IToggle[] | null; + skipButtonText?: string | null; + submitButtonText?: string | null; + selectionButtons?: ISelectionButton[]; +} + +export interface ICollectInputsResults { + collectInputResults?: ICollectInputsResult[]; + error: StripeError; +} -export type CollectInputResult = { +export interface ICollectInputsResult { skipped: boolean; email?: string; numericString?: string; @@ -409,34 +418,34 @@ export type CollectInputResult = { selection?: string; signatureSvg?: string; text?: string; - toggles?: ToggleResult[]; -}; + toggles: ToggleResult[]; +} -export type SelectionButton = { +export interface ISelectionButton { style: SelectionButtonStyle; text: string; -}; +} export enum SelectionButtonStyle { - PRIMARY = 'PRIMARY', - SECONDARY = 'SECONDARY', + PRIMARY = 'primary', + SECONDARY = 'secondary', } -export type Toggle = { - title: string; - description: string; +export interface IToggle { + title?: string | null; + description?: string | null; defaultValue: ToggleValue; -}; +} export enum ToggleValue { - ENABLED = 'ENABLED', - DISABLED = 'DISABLED', + ENABLED = 'enabled', + DISABLED = 'disabled', } export enum ToggleResult { - ENABLED = 'ENABLED', - DISABLED = 'DISABLED', - SKIPPED = 'SKIPPED', + ENABLED = 'enabled', + DISABLED = 'disabled', + SKIPPED = 'skipped', } export type OfflineDetails = {