-
Notifications
You must be signed in to change notification settings - Fork 50
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
Support CollectData feature #765
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good on the Android and TS side of things. @bric-stripe could you check the iOS changes? 🙇
ios/Mappers.swift
Outdated
switch type { | ||
case "unknown": return CollectDataType.unknown | ||
case "magstripe": return CollectDataType.magstripe | ||
default: return CollectDataType.unknown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preference for unknown default so we get warnings/errors when new enum values are added in the native SDK
and I think we should return nil for the default case since this is marked nullable and null is handled in the caller
default: return CollectDataType.unknown | |
@unknown default: return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emm..it seems that @unknown cannot be used here because it can only be utilized in switch statements within enumeration types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, that makes sense I didn't think about that since this is going back from strings. ignore that bit then 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its still worth returning nil though so we get a RN side error when the input is validated
ios/StripeTerminalReactNative.swift
Outdated
} else { | ||
resolve(collectedData != nil ? Mappers.mapFromCollectedData(collectedData!) : [:]) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit but I think this reads a little better and avoids the force unwrap
} else { | |
resolve(collectedData != nil ? Mappers.mapFromCollectedData(collectedData!) : [:]) | |
} | |
} else if let collectedData { | |
resolve(Mappers.mapFromCollectedData(collectedData)) | |
} else { | |
// Unexpected | |
resolve([:]) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requesting changes for minor formatting and typos
|
||
fun mapFromCollectedData(collectData: CollectedData): ReadableMap { | ||
return nativeMapOf { | ||
putString("stripeId",collectData.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting nit:
putString("stripeId",collectData.id) | |
putString("stripeId", collectData.id) |
} | ||
|
||
fun mapFromCollectDataType(type: String): CollectDataType? { | ||
return when(type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting nit:
return when(type) { | |
return when (type) { |
val collectDataType = requireParam(mapFromCollectDataType(collectDataTypeParam)) { | ||
"Unknown collectDataType: $collectDataTypeParam" | ||
} | ||
val enableCustomerCancellation = getBoolean(params,"enableCustomerCancellation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting nit:
val enableCustomerCancellation = getBoolean(params,"enableCustomerCancellation") | |
val enableCustomerCancellation = getBoolean(params, "enableCustomerCancellation") |
ios/StripeTerminalReactNative.swift
Outdated
|
||
let collectDataType = Mappers.mapToCollectDataType(collectDataTypeParam) | ||
guard let collectDataType else { | ||
resolve(Errors.createError(code: CommonErrorType.InvalidRequiredParameter, message: "You must provide correct collectDataType parameter.")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would recommend keeping this the same as android
resolve(Errors.createError(code: CommonErrorType.InvalidRequiredParameter, message: "You must provide correct collectDataType parameter.")) | |
resolve(Errors.createError(code: CommonErrorType.InvalidRequiredParameter, message: "You must provide a collectDataType")) |
|
||
let collectDataConfig: CollectDataConfiguration | ||
do { | ||
collectDataConfig = try CollectDataConfigurationBuilder().setCollectDataType(collectDataType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enableCustomerCancellation
is missing here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enableCustomerCancellation
seem have not support in IOS SDK yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh! thanks for pointing that out 👍
src/types/index.ts
Outdated
|
||
export enum CollectDataType { | ||
MAGSTRIPE = 'magstripe', | ||
UNKNOW = 'unknown', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo:
UNKNOW = 'unknown', | |
UNKNOWN = 'unknown', |
src/types/index.ts
Outdated
@@ -490,3 +490,29 @@ export type AmountDetails = { | |||
export type Amount = { | |||
amount: number; | |||
}; | |||
|
|||
export type CollectData = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo - this should match the iOS and Android types:
export type CollectData = { | |
export type CollectedData = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for addressing feedback!
Summary
Add collectData feature in sdk
Motivation
Support new collectData feature
Testing
Documentation
Select one: