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

CreatePaymentIntent improvements #724

Merged
merged 1 commit into from
Jun 7, 2024
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 @@ -372,12 +372,10 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :
val captureMethod = params.getString("captureMethod")
val offlineBehavior = params.getString("offlineBehavior")

val paymentMethodTypes = paymentMethods?.toArrayList()?.mapNotNull {
if (it is String) {
PaymentMethodType.valueOf(it.uppercase())
} else {
null
}
val paymentMethodTypes = paymentMethods?.toArrayList()?.mapNotNull {
it as? String
}?.map{
PaymentMethodType.valueOf(it.uppercase())
}

val intentParams = paymentMethodTypes?.let {
Expand Down Expand Up @@ -451,14 +449,14 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :
}
}

val offlineBehaviorParam = offlineBehavior.let {
val offlineBehaviorParam = offlineBehavior?.let {
when (it) {
"prefer_online" -> OfflineBehavior.PREFER_ONLINE
"require_online" -> OfflineBehavior.REQUIRE_ONLINE
"force_offline" -> OfflineBehavior.FORCE_OFFLINE
else -> OfflineBehavior.PREFER_ONLINE
}
}
} ?: OfflineBehavior.PREFER_ONLINE

val uuid = UUID.randomUUID().toString()

Expand Down
5 changes: 4 additions & 1 deletion ios/StripeTerminalReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ class StripeTerminalReactNative: RCTEventEmitter, DiscoveryDelegate, BluetoothRe
let captureMethod = params["captureMethod"] as? String

let paymentParamsBuilder = PaymentIntentParametersBuilder(amount: UInt(truncating: amount),currency: currency)
.setPaymentMethodTypes(paymentMethodTypes)
.setCaptureMethod(captureMethod == "automatic" ? .automatic : .manual)
.setSetupFutureUsage(setupFutureUsage)
.setOnBehalfOf(onBehalfOf)
Expand All @@ -410,6 +409,10 @@ class StripeTerminalReactNative: RCTEventEmitter, DiscoveryDelegate, BluetoothRe
.setCustomer(customer)
.setTransferGroup(transferGroup)
.setMetadata(metadata)

if !paymentMethodTypes.isEmpty {
paymentParamsBuilder.setPaymentMethodTypes(paymentMethodTypes)
}

let cardPresentParamsBuilder = CardPresentParametersBuilder()
.setRequestExtendedAuthorization(extendedAuth)
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export type CreatePaymentIntentParams = CreatePaymentIntentIOSParams & {
metadata?: Record<string, string>;
paymentMethodOptions?: PaymentMethodOptions;
captureMethod?: 'automatic' | 'manual';
offlineBehavior: 'prefer_online' | 'require_online' | 'force_offline';
offlineBehavior?: 'prefer_online' | 'require_online' | 'force_offline';
};

export type CreatePaymentIntentIOSParams = {
Expand Down