Skip to content
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
56 changes: 29 additions & 27 deletions example/lib/screens/card_payments/no_webhook_payment_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
CardField(
preferredNetworks: [CardBrand.Amex],
controller: controller,
numberHintText: '34556689232',
),
SizedBox(height: 20),
LoadingButton(
Expand Down Expand Up @@ -75,9 +76,7 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
),
Divider(),
SizedBox(height: 20),
ResponseCard(
response: controller.details.toJson().toPrettyString(),
)
ResponseCard(response: controller.details.toJson().toPrettyString()),
],
);
}
Expand Down Expand Up @@ -106,11 +105,10 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {

// 2. Create payment method
final paymentMethod = await Stripe.instance.createPaymentMethod(
params: PaymentMethodParams.card(
paymentMethodData: PaymentMethodData(
billingDetails: billingDetails,
params: PaymentMethodParams.card(
paymentMethodData: PaymentMethodData(billingDetails: billingDetails),
),
));
);

// 3. call API to create PaymentIntent
final paymentIntentResult = await callNoWebhookPayEndpointMethodId(
Expand All @@ -123,8 +121,9 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
if (paymentIntentResult['error'] != null) {
// Error during creating or confirming Intent
if (context.mounted) {
scaffoldMessenger.showSnackBar(SnackBar(
content: Text('Error: ${paymentIntentResult['error']}')));
scaffoldMessenger.showSnackBar(
SnackBar(content: Text('Error: ${paymentIntentResult['error']}')),
);
}
return;
}
Expand All @@ -134,9 +133,11 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
context.mounted) {
// Payment succedeed

scaffoldMessenger.showSnackBar(SnackBar(
content:
Text('Success!: The payment was confirmed successfully!')));
scaffoldMessenger.showSnackBar(
SnackBar(
content: Text('Success!: The payment was confirmed successfully!'),
),
);
return;
}

Expand All @@ -154,8 +155,9 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
} else {
// Payment succedeed
if (context.mounted) {
scaffoldMessenger.showSnackBar(SnackBar(
content: Text('Error: ${paymentIntentResult['error']}')));
scaffoldMessenger.showSnackBar(
SnackBar(content: Text('Error: ${paymentIntentResult['error']}')),
);
}
}
}
Expand All @@ -170,15 +172,19 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
Future<void> confirmIntent(String paymentIntentId) async {
final scaffoldMessenger = ScaffoldMessenger.of(context);
final result = await callNoWebhookPayEndpointIntentId(
paymentIntentId: paymentIntentId);
paymentIntentId: paymentIntentId,
);
if (result['error'] != null && context.mounted) {
scaffoldMessenger
.showSnackBar(SnackBar(content: Text('Error: ${result['error']}')));
scaffoldMessenger.showSnackBar(
SnackBar(content: Text('Error: ${result['error']}')),
);
} else {
if (context.mounted) {
scaffoldMessenger.showSnackBar(SnackBar(
content:
Text('Success!: The payment was confirmed successfully!')));
scaffoldMessenger.showSnackBar(
SnackBar(
content: Text('Success!: The payment was confirmed successfully!'),
),
);
}
}
}
Expand All @@ -189,9 +195,7 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
final url = Uri.parse('$kApiUrl/charge-card-off-session');
final response = await http.post(
url,
headers: {
'Content-Type': 'application/json',
},
headers: {'Content-Type': 'application/json'},
body: json.encode({'paymentIntentId': paymentIntentId}),
);
return json.decode(response.body);
Expand All @@ -206,14 +210,12 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
final url = Uri.parse('$kApiUrl/pay-without-webhooks');
final response = await http.post(
url,
headers: {
'Content-Type': 'application/json',
},
headers: {'Content-Type': 'application/json'},
body: json.encode({
'useStripeSdk': useStripeSdk,
'paymentMethodId': paymentMethodId,
'currency': currency,
'items': items
'items': items,
}),
);
return json.decode(response.body);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.flutter.stripe

import android.content.Context
import android.util.Log
import android.view.View
import android.view.inputmethod.InputMethodManager
import androidx.annotation.NonNull
Expand All @@ -17,12 +18,12 @@


class StripeSdkCardPlatformView(
private val context: Context,
channel: MethodChannel,
id: Int,
creationParams: Map<String?, Any?>?,
private val stripeSdkCardViewManager: CardFieldViewManager,
sdkAccessor: () -> StripeSdkModule
private val context: Context,
channel: MethodChannel,
id: Int,
creationParams: Map<String?, Any?>?,
private val stripeSdkCardViewManager: CardFieldViewManager,
sdkAccessor: () -> StripeSdkModule
) : PlatformView, MethodChannel.MethodCallHandler {

private val themedContext = ThemedReactContext(sdkAccessor().reactContext, channel, sdkAccessor)
Expand All @@ -40,7 +41,16 @@
entry.value,
)
}
// workaround to fix inconsistent naming between iOS and Android
if (creationParams?.containsKey("placeholder") == true) {
stripeSdkCardViewManager.getDelegate().setProperty(
cardView,
"placeholders",
creationParams["placeholder"]?.convertToReadable()
)
}
if (creationParams?.containsKey("cardDetails") == true) {

val value = ReadableMap(creationParams["cardDetails"] as Map<String, Any>)
stripeSdkCardViewManager.setCardDetails(value, themedContext)

Expand Down Expand Up @@ -82,19 +92,37 @@
"requestFocus" -> {
val binding = StripeCardInputWidgetBinding.bind(cardView.mCardWidget)
binding.cardNumberEditText.requestFocus()
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
val imm =

Check warning on line 95 in packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardPlatformView.kt

View workflow job for this annotation

GitHub Actions / Typo CI

imm

"imm" is a typo. Did you mean "mim"?
context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.toggleSoftInput(

Check warning on line 97 in packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardPlatformView.kt

View workflow job for this annotation

GitHub Actions / Typo CI

imm

"imm" is a typo. Did you mean "mim"?
InputMethodManager.SHOW_FORCED,
InputMethodManager.HIDE_IMPLICIT_ONLY
);
result.success(null)
}

"clearFocus" -> {
// Hide keyboard
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
val imm =

Check warning on line 106 in packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardPlatformView.kt

View workflow job for this annotation

GitHub Actions / Typo CI

imm

"imm" is a typo. Did you mean "mim"?
context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(cardView.windowToken, 0)
// Clear focus
cardView.clearFocus()
result.success(null)
}
"focus", "blur", "clear" -> stripeSdkCardViewManager.receiveCommand(cardView, call.method, null)
"onPlaceholderChanged" -> {
stripeSdkCardViewManager.delegate.setProperty(
cardView,
"placeholders",
call.arguments.convertToReadable()
)
}
"focus", "blur", "clear" -> stripeSdkCardViewManager.receiveCommand(
cardView,
call.method,
null
)

else -> {
stripeSdkCardViewManager.delegate.setProperty(
cardView,
Expand Down
Loading