Skip to content

Commit

Permalink
Add missing fields to PI object (#665)
Browse files Browse the repository at this point in the history
* add missing fields to PI object.

* remove codes of debugging.
  • Loading branch information
ianlin-bbpos authored Apr 12, 2024
1 parent def5256 commit a4bfb64
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 23 deletions.
45 changes: 27 additions & 18 deletions android/src/main/java/com/stripeterminalreactnative/Mappers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ internal fun mapFromDeviceType(type: DeviceType): String {
DeviceType.WISEPAD_3S -> "wisePad3s"
DeviceType.WISEPOS_E -> "wisePosE"
DeviceType.WISEPOS_E_DEVKIT -> "wisePosEDevkit"

}
}

Expand All @@ -170,16 +169,12 @@ 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)
putString("id", paymentIntent.id)
putString("description", paymentIntent.description)
putString("status", mapFromPaymentIntentStatus(paymentIntent.status))
putInt("amount", paymentIntent.amount.toInt())
putString("captureMethod", paymentIntent.captureMethod)
putArray("charges", mapFromChargesList(paymentIntent.getCharges()))
putString("created", convertToUnixTimestamp(paymentIntent.created))
putString("sdkUuid", uuid)
putString("paymentMethodId", paymentIntent.paymentMethodId)
putMap("offlineDetails", mapFromOfflineDetails(paymentIntent?.offlineDetails))
putString("currency", paymentIntent.currency)
putMap(
"metadata",
nativeMapOf {
Expand All @@ -188,6 +183,15 @@ internal fun mapFromPaymentIntent(paymentIntent: PaymentIntent, uuid: String): R
}
}
)
putString("statementDescriptor", paymentIntent.statementDescriptor)
putString("status", mapFromPaymentIntentStatus(paymentIntent.status))
putMap("amountDetails", mapFromAmountDetails(paymentIntent.amountDetails))
putInt("amountTip", paymentIntent.amountTip?.toInt() ?: 0)
putString("statementDescriptorSuffix", paymentIntent.statementDescriptorSuffix)
putString("sdkUuid", uuid)
putString("paymentMethodId", paymentIntent.paymentMethodId)
putMap("paymentMethod", paymentIntent.paymentMethod?.let { mapFromPaymentMethod(it) })
putMap("offlineDetails", mapFromOfflineDetails(paymentIntent.offlineDetails))
}

internal fun mapFromSetupIntent(setupIntent: SetupIntent, uuid: String): ReadableMap = nativeMapOf {
Expand Down Expand Up @@ -548,22 +552,27 @@ private fun mapFromOfflineDetails(offlineDetails: OfflineDetails?): ReadableMap?
private fun mapFromAmountDetails(amountDetails: AmountDetails?): ReadableMap? =
amountDetails?.let {
nativeMapOf {
putMap("tip", nativeMapOf { putIntOrNull(this, "amount", amountDetails.tip?.amount?.toInt())})
putMap(
"tip",
nativeMapOf {
putIntOrNull(this, "amount", amountDetails.tip?.amount?.toInt())
}
)
}
}

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)
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)
mapFromReceiptDetails(offlineCardPresentDetails.receiptDetails)
)
}
}
Expand All @@ -576,7 +585,7 @@ internal fun mapFromWallet(wallet: Wallet?): ReadableMap =
private fun convertListToReadableArray(list: List<String>?): ReadableArray? {
return list?.let {
WritableNativeArray().apply { for (item in list) { pushString(item) } }
} ?: null
}
}

fun mapFromReceiptDetails(receiptDetails: ReceiptDetails?): ReadableMap =
Expand Down Expand Up @@ -647,7 +656,7 @@ fun mapFromReaderDisconnectReason(reason: DisconnectReason): String {

internal fun mapFromReaderSettings(settings: ReaderSettings): ReadableMap {
return nativeMapOf {
var ra = settings.readerAccessibility
val ra = settings.readerAccessibility
if (ra is ReaderAccessibility.Accessibility) {
val accessibility = nativeMapOf {
putString(
Expand Down
25 changes: 21 additions & 4 deletions ios/Mappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,14 @@ class Mappers {
return try BluetoothScanDiscoveryConfigurationBuilder().setSimulated(simulated).setTimeout(timeout).build()
}
}


class func mapFromCaptureMethod(_ captureMethod: CaptureMethod) -> String {
switch captureMethod {
case CaptureMethod.manual: return "manual"
case CaptureMethod.automatic: return "automatic"
default: return "unknown"
}
}

class func mapFromPaymentIntent(_ paymentIntent: PaymentIntent, uuid: String) -> NSDictionary {
var offlineDetailsMap: NSDictionary?
Expand All @@ -148,17 +155,27 @@ class Mappers {
if let paymentMetadata = paymentIntent.metadata {
metadataMap = NSDictionary(dictionary: paymentMetadata)
}
var paymentMethodMap: NSDictionary?
if let paymentMethod = paymentIntent.paymentMethod {
paymentMethodMap = mapFromPaymentMethod(paymentMethod)
}
let result: NSDictionary = [
"id": paymentIntent.stripeId ?? NSNull(),
"amount": paymentIntent.amount,
"captureMethod": mapFromCaptureMethod(paymentIntent.captureMethod),
"charges": mapFromCharges(paymentIntent.charges),
"created": convertDateToUnixTimestamp(date: paymentIntent.created) ?? NSNull(),
"currency": paymentIntent.currency,
"metadata": metadataMap ?? NSNull(),
"statementDescriptor": paymentIntent.statementDescriptor ?? NSNull(),
"status": mapFromPaymentIntentStatus(paymentIntent.status),
"id": paymentIntent.stripeId,
"amountDetails": mapFromAmountDetails(paymentIntent.amountDetails),
"amountTip": paymentIntent.amountTip ?? 0,
"statementDescriptorSuffix": paymentIntent.statementDescriptorSuffix ?? NSNull(),
"sdkUuid": uuid,
"paymentMethodId": paymentIntent.paymentMethodId,
"paymentMethodId": paymentIntent.paymentMethodId ?? NSNull(),
"paymentMethod": paymentMethodMap ?? NSNull(),
"offlineDetails": offlineDetailsMap ?? NSNull(),
"metadata": metadataMap ?? NSNull(),
]
return result
}
Expand Down
7 changes: 6 additions & 1 deletion src/types/PaymentIntent.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import type { Charge, OfflineDetails, PaymentMethod } from './';
import type { AmountDetails, Charge, OfflineDetails, PaymentMethod } from './';

export namespace PaymentIntent {
export interface Type {
id: string;
amount: number;
amountDetails: AmountDetails;
amountTip: number;
captureMethod: string;
charges: Charge[];
created: string;
currency: string;
statementDescriptor: string;
statementDescriptorSuffix: string;
status: Status;
sdkUuid: string;
paymentMethodId: string;
Expand Down

0 comments on commit a4bfb64

Please sign in to comment.