-
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
Add captureMethod to createPaymentIntent on iOS #443
Conversation
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 is great, thanks. If you're feeling ambitious, we'd appreciate support for adding an automatic/manual picker to our example and dev apps. It'd mean adding a new Picker
like we have for currency
[0] to allow users to select between manual and automatic when starting the payment collection process. We'd pass the selected value to the existing calls to createPaymentIntent
[1].
[0]
stripe-terminal-react-native/dev-app/src/screens/CollectCardPaymentScreen.tsx
Lines 436 to 455 in 29bcc57
<List bolded={false} topSpacing={false} title="CURRENCY"> | |
<Picker | |
selectedValue={inputValues?.currency} | |
style={styles.picker} | |
itemStyle={styles.pickerItem} | |
testID="select-currency-picker" | |
onValueChange={(value) => | |
setInputValues((state) => ({ ...state, currency: value })) | |
} | |
> | |
{CURRENCIES.map((a) => ( | |
<Picker.Item | |
key={a.value} | |
label={a.label} | |
testID={a.value} | |
value={a.value} | |
/> | |
))} | |
</Picker> | |
</List> |
[1]
const response = await createPaymentIntent({ |
stripe-terminal-react-native/example-app/src/screens/CollectCardPaymentScreen.tsx
Line 137 in 29bcc57
const response = await createPaymentIntent({ |
src/types/index.ts
Outdated
@@ -161,6 +161,7 @@ export type CreatePaymentIntentParams = CreatePaymentIntentIOSParams & { | |||
transferGroup?: string; | |||
metadata?: Record<string, string>; | |||
paymentMethodOptions?: PaymentMethodOptions; | |||
captureMethod?: string; |
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.
Can you update this to be 'automatic' | 'manual'
?
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.
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.
As a side note, maybe it would be nicer if you update in a future version the type for paymentMethodTypes as well. I see you only allow 'cardPresent' | 'interacPresent' | 'card'
for paymentMethodType
but on the backend the list is bigger https://stripe.com/docs/api/payment_intents/create#create_payment_intent-payment_method_types
I'm also confused why it's camel case for the SDK, I tested with snake case and it worked fine!
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.
As a side note, maybe it would be nicer if you update in a future version the type for paymentMethodTypes as well. I see you only allow
'cardPresent' | 'interacPresent' | 'card'
forpaymentMethodType
but on the backend the list is bigger https://stripe.com/docs/api/payment_intents/create#create_payment_intent-payment_method_types
Terminal really only supports card_present
and interac_present
(we may even want to remove "card"). Terminal is meant to support in-person (aka, card-present) payments. Type card
is used for card-not-present payments (e.g., for e-commerce).
I'm also confused why it's camel case for the SDK, I tested with snake case and it worked fine!
Yeah, that's a good point. It looks like for Stripe API responses, we translate to the camel-case versions [0] (only for Setup Attempts and Refunds -- not Payment Intents), but when setting the params, we expect and use snake case [1]. They are being passed through directly to the native iOS SDK, and they should be snake case (since that's also what the native SDK and backend expect).
Agree this could use some cleaning up. Thanks for pointing it out.
[0]
stripe-terminal-react-native/ios/Mappers.swift
Lines 377 to 384 in 0bca5f0
class func mapFromPaymentMethodDetailsType(_ type: PaymentMethodType) -> String { | |
switch type { | |
case PaymentMethodType.card: return "card" | |
case PaymentMethodType.cardPresent: return "cardPresent" | |
case PaymentMethodType.interacPresent: return "interacPresent" | |
default: return "unknown" | |
} | |
} |
[1]
stripe-terminal-react-native/dev-app/src/screens/CollectCardPaymentScreen.tsx
Lines 113 to 116 in 29bcc57
const paymentMethods = ['card_present']; | |
if (enableInterac) { | |
paymentMethods.push('interac_present'); | |
} |
ios/StripeTerminalReactNative.swift
Outdated
|
||
|
||
let paymentIntentParams = PaymentIntentParameters(amount: UInt(truncating: amount), currency: currency, paymentMethodTypes: paymentMethodTypes) | ||
let paymentIntentParams = PaymentIntentParameters(amount: UInt(truncating: amount), currency: currency, paymentMethodTypes: paymentMethodTypes, captureMethod: captureMethod == "automatic" ? .automatic : .manual) |
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.
Nit: this line is pretty long. Can you add newlines between each parameter like we do here?
stripe-terminal-react-native/ios/StripeTerminalReactNative.swift
Lines 302 to 306 in 29bcc57
let connectionConfig = LocalMobileConnectionConfiguration( | |
locationId: locationId ?? selectedReader.locationId ?? "", | |
merchantDisplayName: nil, // use the location name, | |
onBehalfOf: onBehalfOf ?? nil | |
) |
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.
I added for dev-app here d760bf1, for example-app you need to publish a new package version. I didn't get a chance to test yet, so if you can that would be great! |
Closing this PR, now that #447 has landed. |
Summary
We can now call
createPaymentIntent({ captureMethod: 'automatic', ... })
from RNMotivation
Related to the discussion here #439 (comment)
Testing
I called
createPaymentIntent({ captureMethod: 'automatic', ... })
in RN and saw the API request being made in stripe dashboard withcapture_method
set toautomatic
Documentation
Select one: