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

Add new parameters for PaymentIntent #574

Merged
merged 4 commits into from
Nov 27, 2023
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 @@ -156,7 +156,8 @@ internal fun mapFromPaymentIntent(paymentIntent: PaymentIntent, uuid: String): R
putString("status", mapFromPaymentIntentStatus(paymentIntent.status))
putArray("charges", mapFromChargesList(paymentIntent.getCharges()))
putString("created", convertToUnixTimestamp(paymentIntent.created))
putString("sdk_uuid", uuid)
putString("sdkUuid", uuid)
putString("paymentMethodId", paymentIntent.paymentMethodId)
}

internal fun mapFromSetupIntent(setupIntent: SetupIntent, uuid: String): ReadableMap = nativeMapOf {
Expand All @@ -172,7 +173,7 @@ internal fun mapFromSetupIntent(setupIntent: SetupIntent, uuid: String): Readabl
putString("onBehalfOfId", setupIntent.onBehalfOfId)
putString("paymentMethodId", setupIntent.paymentMethodId)
putString("singleUseMandateId", setupIntent.singleUseMandateId)
putString("sdk_uuid", uuid)
putString("sdkUuid", uuid)
}

internal fun mapFromSetupAttempt(attempt: SetupAttempt?): ReadableMap? = attempt?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :
val applicationFeeAmount = getInt(params, "applicationFeeAmount")
val stripeDescription = params.getString("stripeDescription")
val statementDescriptor = params.getString("statementDescriptor")
val statementDescriptorSuffix = params.getString("statementDescriptorSuffix")
val receiptEmail = params.getString("receiptEmail")
val customer = params.getString("customer")
val transferGroup = params.getString("transferGroup")
Expand Down Expand Up @@ -349,6 +350,9 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :
statementDescriptor?.let {
intentParams.setStatementDescriptor(it)
}
statementDescriptorSuffix?.let {
intentParams.setStatementDescriptorSuffix(it)
}
receiptEmail?.let {
intentParams.setReceiptEmail(it)
}
Expand Down Expand Up @@ -427,11 +431,11 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :
val paymentIntentJson = requireParam(params.getMap("paymentIntent")) {
"You must provide a paymentIntent"
}
val uuid = requireParam(paymentIntentJson.getString("sdk_uuid")) {
"The PaymentIntent is missing sdk_uuid field. This method requires you to use the PaymentIntent that was returned from either createPaymentIntent or retrievePaymentIntent."
val uuid = requireParam(paymentIntentJson.getString("sdkUuid")) {
"The PaymentIntent is missing sdkUuid field. This method requires you to use the PaymentIntent that was returned from either createPaymentIntent or retrievePaymentIntent."
}
val paymentIntent = requireParam(paymentIntents[uuid]) {
"No PaymentIntent was found with the sdk_uuid $uuid. The PaymentIntent provided must be re-retrieved with retrievePaymentIntent or a new PaymentIntent must be created with createPaymentIntent."
"No PaymentIntent was found with the sdkUuid $uuid. The PaymentIntent provided must be re-retrieved with retrievePaymentIntent or a new PaymentIntent must be created with createPaymentIntent."
}

val configBuilder = CollectConfiguration.Builder()
Expand Down Expand Up @@ -476,11 +480,11 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :
@ReactMethod
@Suppress("unused")
fun confirmPaymentIntent(paymentIntent: ReadableMap, promise: Promise) = withExceptionResolver(promise) {
val uuid = requireParam(paymentIntent.getString("sdk_uuid")) {
"The PaymentIntent is missing sdk_uuid field. This method requires you to use the PaymentIntent that was returned from either createPaymentIntent or retrievePaymentIntent."
val uuid = requireParam(paymentIntent.getString("sdkUuid")) {
"The PaymentIntent is missing sdkUuid field. This method requires you to use the PaymentIntent that was returned from either createPaymentIntent or retrievePaymentIntent."
}
val paymentIntent = requireParam(paymentIntents[uuid]) {
"No PaymentIntent was found with the sdk_uuid $uuid. The PaymentIntent provided must be re-retrieved with retrievePaymentIntent or a new PaymentIntent must be created with createPaymentIntent."
"No PaymentIntent was found with the sdkUuid $uuid. The PaymentIntent provided must be re-retrieved with retrievePaymentIntent or a new PaymentIntent must be created with createPaymentIntent."
}

terminal.confirmPaymentIntent(paymentIntent, RNPaymentIntentCallback(promise, uuid) {
Expand Down Expand Up @@ -526,11 +530,11 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :
@Suppress("unused")
fun cancelPaymentIntent(paymentIntent: ReadableMap, promise: Promise) =
withExceptionResolver(promise) {
val uuid = requireParam(paymentIntent.getString("sdk_uuid")) {
"The PaymentIntent is missing sdk_uuid field. This method requires you to use the PaymentIntent that was returned from either createPaymentIntent or retrievePaymentIntent."
val uuid = requireParam(paymentIntent.getString("sdkUuid")) {
"The PaymentIntent is missing sdkUuid field. This method requires you to use the PaymentIntent that was returned from either createPaymentIntent or retrievePaymentIntent."
}
val paymentIntent = requireParam(paymentIntents[uuid]) {
"No PaymentIntent was found with the sdk_uuid $uuid. The PaymentIntent provided must be re-retrieved with retrievePaymentIntent or a new PaymentIntent must be created with createPaymentIntent."
"No PaymentIntent was found with the sdkUuid $uuid. The PaymentIntent provided must be re-retrieved with retrievePaymentIntent or a new PaymentIntent must be created with createPaymentIntent."
}

terminal.cancelPaymentIntent(paymentIntent, RNPaymentIntentCallback(promise, uuid) {
Expand All @@ -545,11 +549,11 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :
val setupIntentJson = requireParam(params.getMap("setupIntent")) {
"You must provide a setupIntent"
}
val uuid = requireParam(setupIntentJson.getString("sdk_uuid")) {
"The SetupIntent is missing sdk_uuid field. This method requires you to use the SetupIntent that was returned from either createPaymentIntent or retrievePaymentIntent."
val uuid = requireParam(setupIntentJson.getString("sdkUuid")) {
"The SetupIntent is missing sdkUuid field. This method requires you to use the SetupIntent that was returned from either createPaymentIntent or retrievePaymentIntent."
}
val setupIntent = requireParam(setupIntents[uuid]) {
"No SetupIntent was found with the sdk_uuid $uuid. The SetupIntent provided must be re-retrieved with retrieveSetupIntent or a new SetupIntent must be created with createSetupIntent."
"No SetupIntent was found with the sdkUuid $uuid. The SetupIntent provided must be re-retrieved with retrieveSetupIntent or a new SetupIntent must be created with createSetupIntent."
}

val customerConsentCollected = getBoolean(params, "customerConsentCollected")
Expand Down Expand Up @@ -608,11 +612,11 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :
@Suppress("unused")
fun cancelSetupIntent(setupIntent: ReadableMap, promise: Promise) =
withExceptionResolver(promise) {
val uuid = requireParam(setupIntent.getString("sdk_uuid")) {
"The SetupIntent is missing sdk_uuid field. This method requires you to use the SetupIntent that was returned from either createPaymentIntent or retrievePaymentIntent."
val uuid = requireParam(setupIntent.getString("sdkUuid")) {
"The SetupIntent is missing sdkUuid field. This method requires you to use the SetupIntent that was returned from either createPaymentIntent or retrievePaymentIntent."
}
val setupIntent = requireParam(setupIntents[uuid]) {
"No SetupIntent was found with the sdk_uuid $uuid. The SetupIntent provided must be re-retrieved with retrieveSetupIntent or a new SetupIntent must be created with createSetupIntent."
"No SetupIntent was found with the sdkUuid $uuid. The SetupIntent provided must be re-retrieved with retrieveSetupIntent or a new SetupIntent must be created with createSetupIntent."
}

val params = SetupIntentCancellationParameters.Builder().build()
Expand All @@ -626,11 +630,11 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :
@Suppress("unused")
fun confirmSetupIntent(setupIntent: ReadableMap, promise: Promise) =
withExceptionResolver(promise) {
val uuid = requireParam(setupIntent.getString("sdk_uuid")) {
"The SetupIntent is missing sdk_uuid field. This method requires you to use the SetupIntent that was returned from either createPaymentIntent or retrievePaymentIntent."
val uuid = requireParam(setupIntent.getString("sdkUuid")) {
"The SetupIntent is missing sdkUuid field. This method requires you to use the SetupIntent that was returned from either createPaymentIntent or retrievePaymentIntent."
}
val setupIntent = requireParam(setupIntents[uuid]) {
"No SetupIntent was found with the sdk_uuid $uuid. The SetupIntent provided must be re-retrieved with retrieveSetupIntent or a new SetupIntent must be created with createSetupIntent."
"No SetupIntent was found with the sdkUuid $uuid. The SetupIntent provided must be re-retrieved with retrieveSetupIntent or a new SetupIntent must be created with createSetupIntent."
}

terminal.confirmSetupIntent(setupIntent, RNSetupIntentCallback(promise, uuid) {
Expand Down
7 changes: 4 additions & 3 deletions ios/Mappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,16 @@ class Mappers {
"currency": paymentIntent.currency,
"status": mapFromPaymentIntentStatus(paymentIntent.status),
"id": paymentIntent.stripeId,
"sdk_uuid": uuid,
"sdkUuid": uuid,
"paymentMethodId": paymentIntent.paymentMethodId,
]
return result
}

class func mapFromSetupIntent(_ setupIntent: SetupIntent, uuid: String) -> NSDictionary {
let result: NSDictionary = [
"id": setupIntent.stripeId,
"sdk_uuid": uuid,
"sdkUuid": uuid,
"created": convertDateToUnixTimestamp(date: setupIntent.created) ?? NSNull(),
"status": mapFromSetupIntentStatus(setupIntent.status),
"latestAttempt": mapFromSetupAttempt(setupIntent.latestAttempt) ?? NSNull(),
Expand Down Expand Up @@ -515,7 +516,7 @@ class Mappers {
default: return "unknown"
}
}

class func mapFromOfflineStatus(_ offlineStatus: OfflineStatus) -> NSDictionary {
let result: NSDictionary = [
"networkStatus": mapFromNetworkStatus(offlineStatus.sdk.networkStatus)
Expand Down
Loading