Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename collect input types. #721

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -823,10 +823,10 @@ fun mapFromCollectInputsResults(results: List<CollectInputsResult>): 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" }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Input>()
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<Toggle>()
it.getArray("toggles")
Expand All @@ -882,7 +882,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :
)
}
}
"NUMERIC" -> {
"numeric" -> {
collectInput.let {
var toggles = ArrayList<Toggle>()
it.getArray("toggles")
Expand All @@ -898,7 +898,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :
)
}
}
"EMAIL" -> {
"email" -> {
collectInput.let {
var toggles = ArrayList<Toggle>()
it.getArray("toggles")
Expand All @@ -914,7 +914,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :
)
}
}
"PHONE" -> {
"phone" -> {
collectInput.let {
var toggles = ArrayList<Toggle>()
it.getArray("toggles")
Expand All @@ -930,7 +930,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :
)
}
}
"SIGNATURE" -> {
"signature" -> {
collectInput.let {
var toggles = ArrayList<Toggle>()
it.getArray("toggles")
Expand All @@ -946,7 +946,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :
)
}
}
"SELECTION" -> {
"selection" -> {
collectInput.let {
var toggles = ArrayList<Toggle>()
it.getArray("toggles")
Expand All @@ -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
Expand Down
21 changes: 11 additions & 10 deletions dev-app/src/screens/CollectInputsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand Down Expand Up @@ -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:
Expand All @@ -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?',
Expand All @@ -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:
Expand All @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions ios/Mappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down
16 changes: 8 additions & 8 deletions ios/StripeTerminalReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions src/StripeTerminalSdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import type {
PaymentIntent,
SetupIntent,
OfflineStatus,
CollectInputsParameters,
CollectInputsResults,
ICollectInputsParameters,
ICollectInputsResults,
PaymentStatus,
ConnectionStatus,
} from './types';
Expand Down Expand Up @@ -154,7 +154,9 @@ export interface StripeTerminalSdkType {
setReaderSettings(
params: Reader.ReaderSettingsParameters
): Promise<Reader.ReaderSettings>;
collectInputs(params: CollectInputsParameters): Promise<CollectInputsResults>;
collectInputs(
params: ICollectInputsParameters
): Promise<ICollectInputsResults>;
cancelCollectInputs(): Promise<{
error?: StripeError;
}>;
Expand Down
22 changes: 15 additions & 7 deletions src/__tests__/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {},
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import type {
PaymentIntent,
SetupIntent,
OfflineStatus,
CollectInputsParameters,
CollectInputsResults,
ICollectInputsParameters,
ICollectInputsResults,
PaymentStatus,
ConnectionStatus,
} from './types';
Expand Down Expand Up @@ -862,8 +862,8 @@ export async function setReaderSettings(
}

export async function collectInputs(
params: CollectInputsParameters
): Promise<CollectInputsResults> {
params: ICollectInputsParameters
): Promise<ICollectInputsResults> {
return Logger.traceSdkMethod(async () => {
try {
const response = await StripeTerminalSdk.collectInputs(params);
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useStripeTerminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type {
PaymentIntent,
SetupIntent,
OfflineStatus,
CollectInputsParameters,
ICollectInputsParameters,
ReaderEvent,
} from '../types';
import {
Expand Down Expand Up @@ -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);
Expand Down
Loading