Skip to content

Commit

Permalink
[QR] add support for QR fields (#827)
Browse files Browse the repository at this point in the history
* [QR] add support for QR fields

* update typescript types as well

* add payment intent status

* prevent android from crashing if invalid PMT is provided

* update dev app with QR support

* update example-app with dev-app changes

* address tim comments (remove flatlist, change how IPaymentMethodType is used)

* re-add enable_interac for tests + linter

* rename paymentMethods

* fix tests ......

* fix lint

* make collectPayment button static at the bottom of the screen (devapp)

* change test to not need scrolling to click collect payment

* disable flakey test and add todo
  • Loading branch information
henryx-stripe authored Oct 15, 2024
1 parent 093b45a commit 9f2527e
Show file tree
Hide file tree
Showing 15 changed files with 910 additions and 401 deletions.
22 changes: 22 additions & 0 deletions android/src/main/java/com/stripeterminalreactnative/Mappers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import com.stripe.stripeterminal.external.models.SimulateReaderUpdate
import com.stripe.stripeterminal.external.models.TextResult
import com.stripe.stripeterminal.external.models.ToggleResult
import com.stripe.stripeterminal.external.models.Wallet
import com.stripe.stripeterminal.external.models.WechatPayDetails
import com.stripe.stripeterminal.log.LogLevel

internal fun getInt(map: ReadableMap, key: String): Int? = if (map.hasKey(key)) map.getInt(key) else null
Expand Down Expand Up @@ -411,6 +412,7 @@ internal fun mapFromPaymentIntentStatus(status: PaymentIntentStatus?): String {
PaymentIntentStatus.REQUIRES_CONFIRMATION -> "requiresConfirmation"
PaymentIntentStatus.REQUIRES_PAYMENT_METHOD -> "requiresPaymentMethod"
PaymentIntentStatus.SUCCEEDED -> "succeeded"
PaymentIntentStatus.REQUIRES_ACTION -> "requiresAction"
else -> "unknown"
}
}
Expand Down Expand Up @@ -551,6 +553,10 @@ internal fun mapFromPaymentMethod(paymentMethod: PaymentMethod?): ReadableMap? =
"interacPresentDetails",
mapFromCardPresentDetails(it.interacPresentDetails)
)
putMap(
"wechatPayDetails",
mapFromWechatPayDetails(it.wechatPayDetails)
)
putString("customer", it.customer)
putString("id", it.id)
putString("type", mapFromPaymentMethodDetailsType(it.type))
Expand Down Expand Up @@ -580,6 +586,10 @@ private fun mapFromPaymentMethodDetails(paymentMethodDetails: PaymentMethodDetai
"interacPresentDetails",
mapFromCardPresentDetails(paymentMethodDetails?.interacPresentDetails)
)
putMap(
"wechatPayDetails",
mapFromWechatPayDetails(paymentMethodDetails?.wechatPayDetails)
)
putString("type", mapFromPaymentMethodDetailsType(paymentMethodDetails?.type))
}

Expand All @@ -588,6 +598,7 @@ internal fun mapFromPaymentMethodDetailsType(type: PaymentMethodType?): String {
PaymentMethodType.CARD -> "card"
PaymentMethodType.CARD_PRESENT -> "cardPresent"
PaymentMethodType.INTERAC_PRESENT -> "interacPresent"
PaymentMethodType.WECHAT_PAY -> "wechatPay"
else -> "unknown"
}
}
Expand Down Expand Up @@ -615,6 +626,17 @@ private fun mapFromCardPresentDetails(cardPresentDetails: CardPresentDetails?):
"preferredLocales",
convertListToReadableArray(it.preferredLocales)
)
putString("location", it.location)
putString("reader", it.reader)
}
}

private fun mapFromWechatPayDetails(wechatPayDetails: WechatPayDetails?): ReadableMap? =
wechatPayDetails?.let {
nativeMapOf {
putString("location", it.location)
putString("reader", it.reader)
putString("transactionId", it.transactionId)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,12 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :

val paymentMethodTypes = paymentMethods?.toArrayList()?.mapNotNull {
it as? String
}?.map{
PaymentMethodType.valueOf(it.uppercase())
}?.mapNotNull {
try {
PaymentMethodType.valueOf(it.uppercase())
} catch (e: IllegalArgumentException) {
null
}
}

val intentParams = paymentMethodTypes?.let {
Expand Down
14 changes: 14 additions & 0 deletions dev-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import DatabaseScreen from './screens/DatabaseScreen';
import ReaderSettingsScreen from './screens/ReaderSettingsScreen';
import CollectDataScreen from './screens/CollectDataScreen';
import CollectInputsScreen from './screens/CollectInputsScreen';
import PaymentMethodSelectScreen from './screens/PaymentMethodSelectScreen';
import {
Reader,
Location,
Expand Down Expand Up @@ -84,6 +85,11 @@ export type RouteParamList = {
event: Event;
log: Log;
};
PaymentMethodSelect: {
paymentMethodTypes: string[];
enabledPaymentMethodTypes: string[];
onChange: (paymentMethodTypes: string[]) => void;
};
};

LogBox.ignoreLogs([
Expand Down Expand Up @@ -280,6 +286,14 @@ export default function App() {
}}
component={CollectCardPaymentScreen}
/>
<Stack.Screen
name="PaymentMethodSelectScreen"
options={{
headerTitle: 'Select Payment Methods',
headerBackAccessibilityLabel: 'payment-back',
}}
component={PaymentMethodSelectScreen}
/>
<Stack.Screen
name="SetupIntentScreen"
options={{
Expand Down
Loading

0 comments on commit 9f2527e

Please sign in to comment.