Skip to content

Commit 132ae36

Browse files
authored
fix: hinttext android (#2215)
1 parent 7e0f368 commit 132ae36

File tree

2 files changed

+67
-37
lines changed

2 files changed

+67
-37
lines changed

example/lib/screens/card_payments/no_webhook_payment_screen.dart

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
4343
CardField(
4444
preferredNetworks: [CardBrand.Amex],
4545
controller: controller,
46+
numberHintText: '34556689232',
4647
),
4748
SizedBox(height: 20),
4849
LoadingButton(
@@ -75,9 +76,7 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
7576
),
7677
Divider(),
7778
SizedBox(height: 20),
78-
ResponseCard(
79-
response: controller.details.toJson().toPrettyString(),
80-
)
79+
ResponseCard(response: controller.details.toJson().toPrettyString()),
8180
],
8281
);
8382
}
@@ -106,11 +105,10 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
106105

107106
// 2. Create payment method
108107
final paymentMethod = await Stripe.instance.createPaymentMethod(
109-
params: PaymentMethodParams.card(
110-
paymentMethodData: PaymentMethodData(
111-
billingDetails: billingDetails,
108+
params: PaymentMethodParams.card(
109+
paymentMethodData: PaymentMethodData(billingDetails: billingDetails),
112110
),
113-
));
111+
);
114112

115113
// 3. call API to create PaymentIntent
116114
final paymentIntentResult = await callNoWebhookPayEndpointMethodId(
@@ -123,8 +121,9 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
123121
if (paymentIntentResult['error'] != null) {
124122
// Error during creating or confirming Intent
125123
if (context.mounted) {
126-
scaffoldMessenger.showSnackBar(SnackBar(
127-
content: Text('Error: ${paymentIntentResult['error']}')));
124+
scaffoldMessenger.showSnackBar(
125+
SnackBar(content: Text('Error: ${paymentIntentResult['error']}')),
126+
);
128127
}
129128
return;
130129
}
@@ -134,9 +133,11 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
134133
context.mounted) {
135134
// Payment succedeed
136135

137-
scaffoldMessenger.showSnackBar(SnackBar(
138-
content:
139-
Text('Success!: The payment was confirmed successfully!')));
136+
scaffoldMessenger.showSnackBar(
137+
SnackBar(
138+
content: Text('Success!: The payment was confirmed successfully!'),
139+
),
140+
);
140141
return;
141142
}
142143

@@ -154,8 +155,9 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
154155
} else {
155156
// Payment succedeed
156157
if (context.mounted) {
157-
scaffoldMessenger.showSnackBar(SnackBar(
158-
content: Text('Error: ${paymentIntentResult['error']}')));
158+
scaffoldMessenger.showSnackBar(
159+
SnackBar(content: Text('Error: ${paymentIntentResult['error']}')),
160+
);
159161
}
160162
}
161163
}
@@ -170,15 +172,19 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
170172
Future<void> confirmIntent(String paymentIntentId) async {
171173
final scaffoldMessenger = ScaffoldMessenger.of(context);
172174
final result = await callNoWebhookPayEndpointIntentId(
173-
paymentIntentId: paymentIntentId);
175+
paymentIntentId: paymentIntentId,
176+
);
174177
if (result['error'] != null && context.mounted) {
175-
scaffoldMessenger
176-
.showSnackBar(SnackBar(content: Text('Error: ${result['error']}')));
178+
scaffoldMessenger.showSnackBar(
179+
SnackBar(content: Text('Error: ${result['error']}')),
180+
);
177181
} else {
178182
if (context.mounted) {
179-
scaffoldMessenger.showSnackBar(SnackBar(
180-
content:
181-
Text('Success!: The payment was confirmed successfully!')));
183+
scaffoldMessenger.showSnackBar(
184+
SnackBar(
185+
content: Text('Success!: The payment was confirmed successfully!'),
186+
),
187+
);
182188
}
183189
}
184190
}
@@ -189,9 +195,7 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
189195
final url = Uri.parse('$kApiUrl/charge-card-off-session');
190196
final response = await http.post(
191197
url,
192-
headers: {
193-
'Content-Type': 'application/json',
194-
},
198+
headers: {'Content-Type': 'application/json'},
195199
body: json.encode({'paymentIntentId': paymentIntentId}),
196200
);
197201
return json.decode(response.body);
@@ -206,14 +210,12 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
206210
final url = Uri.parse('$kApiUrl/pay-without-webhooks');
207211
final response = await http.post(
208212
url,
209-
headers: {
210-
'Content-Type': 'application/json',
211-
},
213+
headers: {'Content-Type': 'application/json'},
212214
body: json.encode({
213215
'useStripeSdk': useStripeSdk,
214216
'paymentMethodId': paymentMethodId,
215217
'currency': currency,
216-
'items': items
218+
'items': items,
217219
}),
218220
);
219221
return json.decode(response.body);

packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardPlatformView.kt

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.flutter.stripe
22

33
import android.content.Context
4+
import android.util.Log
45
import android.view.View
56
import android.view.inputmethod.InputMethodManager
67
import androidx.annotation.NonNull
@@ -17,12 +18,12 @@ import io.flutter.plugin.platform.PlatformView
1718

1819

1920
class StripeSdkCardPlatformView(
20-
private val context: Context,
21-
channel: MethodChannel,
22-
id: Int,
23-
creationParams: Map<String?, Any?>?,
24-
private val stripeSdkCardViewManager: CardFieldViewManager,
25-
sdkAccessor: () -> StripeSdkModule
21+
private val context: Context,
22+
channel: MethodChannel,
23+
id: Int,
24+
creationParams: Map<String?, Any?>?,
25+
private val stripeSdkCardViewManager: CardFieldViewManager,
26+
sdkAccessor: () -> StripeSdkModule
2627
) : PlatformView, MethodChannel.MethodCallHandler {
2728

2829
private val themedContext = ThemedReactContext(sdkAccessor().reactContext, channel, sdkAccessor)
@@ -40,7 +41,16 @@ class StripeSdkCardPlatformView(
4041
entry.value,
4142
)
4243
}
44+
// workaround to fix inconsistent naming between iOS and Android
45+
if (creationParams?.containsKey("placeholder") == true) {
46+
stripeSdkCardViewManager.getDelegate().setProperty(
47+
cardView,
48+
"placeholders",
49+
creationParams["placeholder"]?.convertToReadable()
50+
)
51+
}
4352
if (creationParams?.containsKey("cardDetails") == true) {
53+
4454
val value = ReadableMap(creationParams["cardDetails"] as Map<String, Any>)
4555
stripeSdkCardViewManager.setCardDetails(value, themedContext)
4656

@@ -82,19 +92,37 @@ class StripeSdkCardPlatformView(
8292
"requestFocus" -> {
8393
val binding = StripeCardInputWidgetBinding.bind(cardView.mCardWidget)
8494
binding.cardNumberEditText.requestFocus()
85-
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
86-
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
95+
val imm =
96+
context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
97+
imm.toggleSoftInput(
98+
InputMethodManager.SHOW_FORCED,
99+
InputMethodManager.HIDE_IMPLICIT_ONLY
100+
);
87101
result.success(null)
88102
}
103+
89104
"clearFocus" -> {
90105
// Hide keyboard
91-
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
106+
val imm =
107+
context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
92108
imm.hideSoftInputFromWindow(cardView.windowToken, 0)
93109
// Clear focus
94110
cardView.clearFocus()
95111
result.success(null)
96112
}
97-
"focus", "blur", "clear" -> stripeSdkCardViewManager.receiveCommand(cardView, call.method, null)
113+
"onPlaceholderChanged" -> {
114+
stripeSdkCardViewManager.delegate.setProperty(
115+
cardView,
116+
"placeholders",
117+
call.arguments.convertToReadable()
118+
)
119+
}
120+
"focus", "blur", "clear" -> stripeSdkCardViewManager.receiveCommand(
121+
cardView,
122+
call.method,
123+
null
124+
)
125+
98126
else -> {
99127
stripeSdkCardViewManager.delegate.setProperty(
100128
cardView,

0 commit comments

Comments
 (0)