-
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
sPOS offline mode support #649
Changes from 16 commits
3764f83
aab374b
e3a919c
a6b14c6
b410685
bef9149
58832b5
d226e96
4d79ea3
e5b2699
752f63e
8a42b28
798081c
585343d
04e3e8d
d55fd20
104e7c6
879f06c
fb30009
bc9a268
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,9 @@ import com.facebook.react.bridge.WritableArray | |
import com.facebook.react.bridge.WritableMap | ||
import com.facebook.react.bridge.WritableNativeArray | ||
import com.stripe.stripeterminal.external.CollectInputs | ||
import com.stripe.stripeterminal.external.OfflineMode | ||
import com.stripe.stripeterminal.external.models.Address | ||
import com.stripe.stripeterminal.external.models.AmountDetails | ||
import com.stripe.stripeterminal.external.models.CardDetails | ||
import com.stripe.stripeterminal.external.models.CardPresentDetails | ||
import com.stripe.stripeterminal.external.models.CartLineItem | ||
|
@@ -20,6 +22,8 @@ import com.stripe.stripeterminal.external.models.Location | |
import com.stripe.stripeterminal.external.models.LocationStatus | ||
import com.stripe.stripeterminal.external.models.NetworkStatus | ||
import com.stripe.stripeterminal.external.models.NumericResult | ||
import com.stripe.stripeterminal.external.models.OfflineCardPresentDetails | ||
import com.stripe.stripeterminal.external.models.OfflineDetails | ||
import com.stripe.stripeterminal.external.models.OfflineStatus | ||
import com.stripe.stripeterminal.external.models.PaymentIntent | ||
import com.stripe.stripeterminal.external.models.PaymentIntentStatus | ||
|
@@ -141,6 +145,8 @@ internal fun mapFromDeviceType(type: DeviceType): String { | |
DeviceType.WISEPAD_3S -> "wisePad3s" | ||
DeviceType.WISEPOS_E_DEVKIT -> "wisePosEDevkit" | ||
DeviceType.STRIPE_S700_DEVKIT -> "stripeS700Devkit" | ||
DeviceType.STRIPE_S700 -> "stripeS700" | ||
DeviceType.ETNA -> "etna" | ||
} | ||
} | ||
|
||
|
@@ -163,6 +169,7 @@ internal fun mapToDiscoveryMethod(method: String?): DiscoveryMethod? { | |
} | ||
} | ||
|
||
@OptIn(OfflineMode::class) | ||
internal fun mapFromPaymentIntent(paymentIntent: PaymentIntent, uuid: String): ReadableMap = nativeMapOf { | ||
putInt("amount", paymentIntent.amount.toInt()) | ||
putString("currency", paymentIntent.currency) | ||
|
@@ -173,6 +180,7 @@ internal fun mapFromPaymentIntent(paymentIntent: PaymentIntent, uuid: String): R | |
putString("created", convertToUnixTimestamp(paymentIntent.created)) | ||
putString("sdkUuid", uuid) | ||
putString("paymentMethodId", paymentIntent.paymentMethodId) | ||
putMap("offlineDetails", mapFromOfflineDetails(paymentIntent?.offlineDetails)) | ||
} | ||
|
||
internal fun mapFromSetupIntent(setupIntent: SetupIntent, uuid: String): ReadableMap = nativeMapOf { | ||
|
@@ -517,6 +525,42 @@ private fun mapFromCardPresentDetails(cardPresentDetails: CardPresentDetails?): | |
) | ||
} | ||
|
||
private fun mapFromOfflineDetails(offlineDetails: OfflineDetails?): ReadableMap? = | ||
offlineDetails?.let { | ||
nativeMapOf { | ||
putString("storedAt", offlineDetails.storedAt.toString()) | ||
putBoolean("requiresUpload", offlineDetails.requiresUpload) | ||
putMap( | ||
"cardPresentDetails", | ||
mapFromOfflineCardPresentDetails(offlineDetails.cardPresentDetails) | ||
) | ||
putMap("amountDetails", mapFromAmountDetails(offlineDetails.amountDetails)) | ||
} | ||
} | ||
|
||
private fun mapFromAmountDetails(amountDetails: AmountDetails?): ReadableMap? = | ||
amountDetails?.let { | ||
nativeMapOf { | ||
putMap("tip", nativeMapOf { putInt("amount", amountDetails.tip?.amount?.toInt() ?: 0) }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: we may want |
||
} | ||
} | ||
|
||
private fun mapFromOfflineCardPresentDetails(offlineCardPresentDetails: OfflineCardPresentDetails?): ReadableMap? = | ||
offlineCardPresentDetails?.let { | ||
nativeMapOf { | ||
putString("brand", offlineCardPresentDetails?.brand) | ||
putString("cardholderName", offlineCardPresentDetails?.cardholderName) | ||
putIntOrNull(this, "expMonth", offlineCardPresentDetails?.expMonth) | ||
putIntOrNull(this, "expYear", offlineCardPresentDetails?.expYear) | ||
putString("last4", offlineCardPresentDetails?.last4) | ||
putString("readMethod", offlineCardPresentDetails?.readMethod) | ||
putMap( | ||
"receiptDetails", | ||
mapFromReceiptDetails(offlineCardPresentDetails?.receiptDetails) | ||
) | ||
} | ||
} | ||
|
||
internal fun mapFromWallet(wallet: Wallet?): ReadableMap = | ||
nativeMapOf { | ||
putString("type", wallet?.type) | ||
|
@@ -537,8 +581,8 @@ fun mapFromReceiptDetails(receiptDetails: ReceiptDetails?): ReadableMap = | |
putString("authorizationResponseCode", receiptDetails?.authorizationResponseCode) | ||
putString("cvm", receiptDetails?.cvm) | ||
putString("dedicatedFileName", receiptDetails?.dedicatedFileName) | ||
putString("tsi", receiptDetails?.tsi) | ||
putString("tvr", receiptDetails?.tvr) | ||
putString("transactionStatusInformation", receiptDetails?.tsi) | ||
putString("terminalVerificationResult", receiptDetails?.tvr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder to add these name changes to a CHANGELOG. |
||
} | ||
|
||
internal fun mapFromNetworkStatus(status: NetworkStatus): String { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,43 @@ export default function DatabaseScreen() { | |
|
||
return ( | ||
<ScrollView style={styles.container}> | ||
<List bolded={false} topSpacing={false} title="PUBLIC INTERFACE SUMMARY"> | ||
<List bolded={false} topSpacing={false} title="READER SUMMARY"> | ||
{offlinePaymentStatus && | ||
offlinePaymentStatus.reader && | ||
offlinePaymentStatus.reader.offlinePaymentsCount > 0 ? ( | ||
Object.keys( | ||
offlinePaymentStatus.reader.offlinePaymentAmountsByCurrency | ||
).map((key) => ( | ||
<ListItem | ||
title={ | ||
getCurrencySymbols(key) + | ||
' ' + | ||
( | ||
Number( | ||
offlinePaymentStatus.reader! | ||
.offlinePaymentAmountsByCurrency[key] | ||
) / 100 | ||
).toFixed(2) | ||
} | ||
/> | ||
)) | ||
) : ( | ||
<></> | ||
)} | ||
</List> | ||
<Text style={styles.infoText}> | ||
{' '} | ||
{String( | ||
offlinePaymentStatus && | ||
offlinePaymentStatus.reader && | ||
offlinePaymentStatus.reader.offlinePaymentsCount | ||
? offlinePaymentStatus.reader.offlinePaymentsCount | ||
: 0 | ||
) + | ||
' payment intent(s) for ' + | ||
account?.settings?.dashboard.display_name}{' '} | ||
</Text> | ||
<List bolded={false} topSpacing={false} title="SDK SUMMARY"> | ||
{offlinePaymentStatus && | ||
offlinePaymentStatus.sdk.offlinePaymentsCount > 0 ? ( | ||
Object.keys( | ||
|
@@ -55,9 +91,8 @@ export default function DatabaseScreen() { | |
' ' + | ||
( | ||
Number( | ||
offlinePaymentStatus.sdk.offlinePaymentAmountsByCurrency[ | ||
key | ||
] | ||
offlinePaymentStatus.reader! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be |
||
.offlinePaymentAmountsByCurrency[key] | ||
) / 100 | ||
).toFixed(2) | ||
} | ||
|
@@ -70,7 +105,7 @@ export default function DatabaseScreen() { | |
<Text style={styles.infoText}> | ||
{' '} | ||
{String( | ||
offlinePaymentStatus | ||
offlinePaymentStatus && offlinePaymentStatus.sdk | ||
? offlinePaymentStatus.sdk.offlinePaymentsCount | ||
: 0 | ||
) + | ||
|
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.
This case is already covered. Suggest sorting this list alphabetically to make dupes easier to find.