Skip to content

Commit cf38b15

Browse files
authored
Fix #14 (#144)
* Fix #14 * update readmes, fix typo
1 parent 7ecec5f commit cf38b15

File tree

3 files changed

+121
-30
lines changed

3 files changed

+121
-30
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ Future<void> onGooglePayResult(paymentResult) async {
172172

173173
## Known issues
174174

175-
- The Card field on Android has focus issues - it's being tracked in [#14](https://github.com/flutter-stripe/flutter_stripe/issues/14) and related to issues in the Flutter framework. If this is a
176-
blocker for your project consider using the PaymentSheet alternative
175+
- The Card field on Android has focus issues on older Flutter versions - it has been fixed by the Flutter framework in
176+
the master branch. The issue is being tracked in [#14](https://github.com/flutter-stripe/flutter_stripe/issues/14).
177177

178178
## Contributing
179179

packages/stripe/README.md

+96-23
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
12
<img src="https://user-images.githubusercontent.com/19904063/116995247-20519e80-acda-11eb-8e1b-7d0efbd193ad.png" height="36" />
23

34

45
# Flutter Stripe
6+
57
[![pub package](https://img.shields.io/pub/v/flutter_stripe.svg)](https://pub.dev/packages/flutter_stripe) ![build](https://img.shields.io/github/workflow/status/flutter-stripe/flutter_stripe/all_plugins?logo=github)
68

79
> 🚨 flutter_stripe is in beta - please provide feedback (and/or contribute) if you find issues 💙️
810
11+
912
The Stripe Flutter SDK allows you to build delightful payment experiences in your native Android and iOS apps using Flutter. We provide powerful and customizable UI screens and elements that can be used out-of-the-box to collect your users' payment details.
1013

11-
![payment_sheet](https://user-images.githubusercontent.com/19904063/119301240-6d35ee80-bc62-11eb-98ea-f71d2d1949bb.png)
14+
15+
![stripe-flutter_cover](https://user-images.githubusercontent.com/19904063/121511757-48bf6d80-c9e9-11eb-9674-0fec35e26ef5.png)
16+
1217

1318

1419
## Features
@@ -17,13 +22,19 @@ The Stripe Flutter SDK allows you to build delightful payment experiences in you
1722

1823
**Apple Pay**: We provide a [seamless integration with Apple Pay](https://stripe.com/docs/apple-pay).
1924

25+
**Google Pay**: The plugin can easily act as payment provider for the [Pay plugin](#Pay-Plugin-support) that enables you to seamlessly integrate Google Pay or Apple Pay. All you need to do is add your stripe publishable key to the payment profile.
26+
2027
**Payment methods**: Accepting more [payment methods](https://stripe.com/docs/payments/payment-methods/overview) helps your business expand its global reach and improve checkout conversion.
2128

2229
**SCA-Ready**: The SDK automatically performs native [3D Secure authentication](https://stripe.com/docs/payments/3d-secure) if needed to comply with [Strong Customer Authentication](https://stripe.com/docs/strong-customer-authentication) regulation in Europe.
2330

2431
**Native UI**: We provide native screens and elements to securely collect payment details on Android and iOS.
2532

26-
**Pre-built payments UI**: Learn how to integrate Payment Sheet, the new pre-built payments UI for mobile apps. This pre-built UI lets you accept cards, Apple Pay, and Google Pay out of the box, and includes support for saving & reusing cards.
33+
**Pre-built payments UI**: Learn how to integrate Payment Sheet, the new pre-built payments UI for mobile apps. This pre-built UI lets you accept cards, Apple Pay, and Google Pay out of the box, and includes support for saving & reusing cards.
34+
35+
#### Recommended usage
36+
37+
If you're selling digital products or services within your app, (e.g. subscriptions, in-game currencies, game levels, access to premium content, or unlocking a full version), you must use the app store's in-app purchase APIs. See [Apple's](https://developer.apple.com/app-store/review/guidelines/#payments) and [Google's](https://support.google.com/googleplay/android-developer/answer/9858738?hl=en&ref_topic=9857752) guidelines for more information. For all other scenarios you can use this SDK to process payments via Stripe.
2738

2839
## Installation
2940

@@ -35,7 +46,12 @@ dart pub add flutter_stripe
3546

3647
#### Android
3748

38-
Android 5.0 (API level 21) and above
49+
- Android 5.0 (API level 21) and above
50+
- Kotlin version 1.5.0 and above: [example](https://github.com/flutter-stripe/flutter_stripe/blob/79b201a2e9b827196d6a97bb41e1d0e526632a5a/example/android/build.gradle#L2)
51+
- Using a descendant of `Theme.AppCompact` for your activity: [example](https://github.com/flutter-stripe/flutter_stripe/blob/384d390c8a90d19dc62c73faa5226fa931fd6d44/example/android/app/src/main/res/values/styles.xml#L15)
52+
- Using `FlutterFragmentActivity` instead of `FlutterActivity` in `MainActivity.kt`: [example](https://github.com/flutter-stripe/flutter_stripe/blob/79b201a2e9b827196d6a97bb41e1d0e526632a5a/example/android/app/src/main/kotlin/com/flutter/stripe/example/MainActivity.kt#L6)
53+
54+
This is caused by the Stripe SDK requires the use of the AppCompact theme for their UI components and the Support Fragment Manager for the Payment Sheets
3955

4056
#### iOS
4157

@@ -49,27 +65,35 @@ import 'package:flutter_stripe/flutter_stripe.dart';
4965
5066
void main() async {
5167
WidgetsFlutterBinding.ensureInitialized();
52-
68+
5369
// set the publishable key for Stripe - this is mandatory
5470
Stripe.publishableKey = stripePublishableKey;
55-
runApp(App());
71+
runApp(PaymentScreen());
5672
}
5773
5874
// payment_screen.dart
5975
class PaymentScreen extends StatelessWidget {
60-
76+
6177
@override
6278
Widget build(BuildContext context) {
6379
return Scaffold(
6480
appBar: AppBar(),
65-
body: Container(
66-
alignment: Alignment.center,
67-
padding: EdgeInsets.all(16),
68-
child: CardField(
69-
onCardChanged: (card) {
70-
print(card);
71-
},
72-
),
81+
body: Column(
82+
children: [
83+
CardField(
84+
onCardChanged: (card) {
85+
print(card);
86+
},
87+
),
88+
TextButton(
89+
onPressed: () async {
90+
// create payment method
91+
final paymentMethod =
92+
await Stripe.instance.createPaymentMethod(PaymentMethodParams.card());
93+
},
94+
child: Text('pay'),
95+
)
96+
],
7397
),
7498
);
7599
}
@@ -83,7 +107,9 @@ To initialize Stripe in your Flutter app, use the `Stripe` base class.
83107
`Stripe` offers `publishableKey`, `stripeAccountId`, `threeDSecureParams` and `merchantIdentifier`. Only `publishableKey` is required.
84108

85109
## Dart API
110+
86111
The library offers several methods to handle stripe related actions:
112+
87113
```dart
88114
Future<PaymentMethod> createPaymentMethod(...);
89115
Future<PaymentIntent> handleCardAction(...);
@@ -100,19 +126,44 @@ Future<void> initPaymentSheet(...);
100126
Future<void> presentPaymentSheet(...);
101127
Future<void> confirmPaymentSheetPayment()
102128
```
129+
103130
The example app offers examples on how to use these methods.
104131

132+
## Pay Plugin support
133+
134+
flutter_stripe fully supports the [Pay plugin](https://pub.dev/packages/pay) from the Google Pay team. By including a few lines you can integrate Stripe as a payment processor for Google / Apple Pay:
135+
136+
```dart
137+
Future<void> onGooglePayResult(paymentResult) async {
138+
final response = await fetchPaymentIntentClientSecret();
139+
final clientSecret = response['clientSecret'];
140+
final token = paymentResult['paymentMethodData']['tokenizationData']['token'];
141+
final tokenJson = Map.castFrom(json.decode(token));
142+
143+
final params = PaymentMethodParams.cardFromToken(
144+
token: tokenJson['id'],
145+
);
146+
// Confirm Google pay payment method
147+
await Stripe.instance.confirmPaymentMethod(
148+
clientSecret,
149+
params,
150+
);
151+
}
152+
```
153+
105154
## Run the example app
106155

156+
- Navigate to the example folder `cd example`
107157
- Install the dependencies
108-
- `flutter pub get`
109-
- Set up env vars for the flutter app and a local backend.
110-
- [Get your test Stripe API keys](https://stripe.com/docs/keys)
111-
- `cp lib/.env.dart lib/.env.dart` and set your Stripe publishable key.
112-
- `cp server/.env.example server/.env` and set the variable values in your newly created `.env` file.
158+
- `flutter pub get`
159+
- Set up env vars for the flutter app and a local backend.
160+
- [Get your test Stripe API keys](https://stripe.com/docs/keys)
161+
- `cp lib/.env.example.dart lib/.env.dart` and set your Stripe publishable key.
162+
- `cp server/.env.example server/.env` and set the variable values in your newly created `.env` file.
163+
- Install the server dependencies: `yarn --cwd "server"`
113164
- Start the example
114-
- Terminal 1: `cd server && yarn example start:server`
115-
- Terminal 2: `flutter run`
165+
- Terminal 1: `yarn --cwd "server" start`
166+
- Terminal 2: `flutter run`
116167

117168
##### Additional steps for webhook forwarding
118169

@@ -121,5 +172,27 @@ The example app offers examples on how to use these methods.
121172

122173
## Known issues
123174

124-
- the Card field on Android has focus issues - it's being tracked in [#14](https://github.com/flutter-stripe/flutter_stripe/issues/14) and related to issues in the Flutter framework. If this is a
125-
blocker for your project consider using the PaymentSheet alternative
175+
- The Card field on Android has focus issues on older Flutter versions - it has been fixed by the Flutter framework in
176+
the master branch. The issue is being tracked in [#14](https://github.com/flutter-stripe/flutter_stripe/issues/14).
177+
178+
## Contributing
179+
180+
You can help us make this project better, feel free to open an new issue or a pull request.
181+
182+
##### Setup
183+
184+
This project uses [melos](https://github.com/invertase/melos) to manage all the packages inside this repo.
185+
186+
- Install melos: `dart pub global activate melos`
187+
- Setup melos in your local folder: `melos bootstrap`
188+
189+
##### Useful commands
190+
191+
- Format `melos run format`
192+
- Analyze `melos run analyze`
193+
- Test `melos run test`
194+
- Pub get `melos run get`
195+
196+
##### Publishing
197+
198+
- Use `melos version` and `melos publish` to keep all the repositories in sync

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

+23-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.flutter.stripe
22

33
import android.content.Context
44
import android.text.InputType
5+
import android.util.Log
56
import android.view.View
67
import android.view.inputmethod.InputMethodManager
78
import androidx.annotation.NonNull
@@ -40,11 +41,28 @@ class StripeSdkCardPlatformView(
4041
if (creationParams?.containsKey("postalCodeEnabled") == true) {
4142
stripeSdkCardViewManager.setPostalCodeEnabled(cardView, creationParams["postalCodeEnabled"] as Boolean)
4243
}
43-
// Temporal fix to https://github.com/flutter/flutter/issues/81029
44-
val binding = CardInputWidgetBinding.bind(cardView.mCardWidget)
45-
binding.cardNumberEditText.inputType = InputType.TYPE_CLASS_TEXT
46-
binding.cvcEditText.inputType = InputType.TYPE_CLASS_TEXT
47-
binding.expiryDateEditText.inputType = InputType.TYPE_CLASS_TEXT
44+
applyFocusFix()
45+
}
46+
47+
/**
48+
* https://github.com/flutter-stripe/flutter_stripe/issues/14
49+
* https://github.com/flutter/engine/pull/26602 HC_PLATFORM_VIEW was introduced in
50+
* that PR - we're checking for its availability and apply the old fix accordingly
51+
*/
52+
private fun applyFocusFix() {
53+
try {
54+
val enumConstants = Class.forName("io.flutter.plugin.editing.TextInputPlugin\$InputTarget\$Type").enumConstants as Array<Enum<*>>
55+
val shouldApplyFix = enumConstants.none { it.name == "HC_PLATFORM_VIEW" }
56+
if (shouldApplyFix) {
57+
// Temporal fix to https://github.com/flutter/flutter/issues/81029
58+
val binding = CardInputWidgetBinding.bind(cardView.mCardWidget)
59+
binding.cardNumberEditText.inputType = InputType.TYPE_CLASS_TEXT
60+
binding.cvcEditText.inputType = InputType.TYPE_CLASS_TEXT
61+
binding.expiryDateEditText.inputType = InputType.TYPE_CLASS_TEXT
62+
}
63+
} catch (e: Exception) {
64+
Log.e("Stripe Plugin", "Error", e)
65+
}
4866
}
4967

5068
override fun getView(): View {

0 commit comments

Comments
 (0)