-
Notifications
You must be signed in to change notification settings - Fork 138
/
README.md
193 lines (136 loc) · 5.79 KB
/
README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
[![pub package](https://img.shields.io/pub/v/stripe_sdk.svg)](https://pub.dev/packages/stripe_sdk)
# Flutter Stripe SDK
A native dart package for Stripe. There are various other flutter plugins that wrap existing Stripe libraries,
but this package uses a different approach.
It does not wrap existing Stripe libraries, but instead accesses the Stripe API directly.
Flutter support:
* [x] iOS
* [x] Android
* [x] Web
See *example/main.dart* for additional short examples.
See <https://github.com/ezet/stripe-sdk/tree/master/example> for a complete demo application,
with a working example backend.
Demo backend: <https://github.com/ezet/stripe-sdk-demo-api>
## Features
* Supports all types of SCA, including 3DS, 3DS2, BankID and others.
* Handle payments with complete SCA support.
* Add, remove and update payment methods, sources and cards, optionally with SCA.
* Manage customer information.
* Create all types of Stripe tokens.
### Supported APIs
- PaymentIntent, with SCA
- SetupIntent, with SCA
- PaymentMethod
- Customer
- Cards
- Sources
- Tokens
## Demo application
There is a complete demo application available at <https://github.com/ezet/stripe-sdk/tree/master/example/app>.
<img src="https://raw.githubusercontent.com/ezet/stripe-sdk/master/doc/demo.png" width="300">
## Overview
- The return type for each function is `Future<Map<String, dynamic>>`, where the value depends on the stripe API version.
The library has three classes to access the Stripe API:
- `Stripe` for generic, non-customer specific APIs, using publishable keys.
- `CustomerSession` for customer-specific APIs, using stripe ephemeral keys.
- `StripeApi` enables raw REST calls against the Stripe API.
### Stripe
- <https://stripe.dev/stripe-android/index.html?com/stripe/android/Stripe.html>
Aims to provide high-level functionality similar to the official mobile Stripe SDKs.
### CustomerSession
_Requires a Stripe ephemeral key._
- <https://stripe.com/docs/mobile/android/customer-information#customer-session-no-ui>
- <https://stripe.com/docs/mobile/android/standard#creating-ephemeral-keys>
Provides functionality similar to CustomerSession in the Stripe Android SDK.
### StripeApi
- <https://stripe.com/docs/api>
Provides basic low-level methods to access the Stripe REST API.
- Limited to the APIs that can be used with a public key or ephemeral key.
- Library methods map to a Stripe API call with the same name.
- Additional parameters can be provided as an optional argument.
_`Stripe` and `CustomerSession` use this internally._
## Initialization
All classes offer a singleton instance that can be initiated by calling the `init(...)` methods and then accessed through `.instance`.
Regular instances can also be created using the constructor, which allows them to be managed by e.g. dependency injection instead.
### Stripe
```dart
Stripe.init('pk_xxx');
// or, to manage your own instance, or multiple instances
final stripe = Stripe('pk_xxx');
```
### CustomerSession
The function that retrieves the ephemeral key must return the JSON response as a plain string.
```dart
CustomerSession.init((apiVersion) => server.getEphemeralKeyFromServer(apiVersion));
// or, to manage your own instances
final session = CustomerSession((apiVersion) => server.getEphemeralKeyFromServer(apiVersion));
```
### StripeApi
```dart
StripeApi.init('pk_xxx');
// or, to manage your own instances
final stripeApi = StripeApi('pk_xxx');
```
## SCA/PSD2
The library offers complete support for SCA on iOS and Android.
It handles all types of SCA, including 3DS, 3DS2, BankID and others.
It handles SCA by launching the authentication flow in a web browser, and returns the result to the app.
The `returnUrlForSca` parameter must match the configuration of your `AndroidManifest.xml` and `Info.plist` as shown in the next steps.
```dart
Stripe.init('pk_xxx', returnUrlForSca: 'stripesdk://3ds.stripesdk.io');
final clientSecret = await server.createPaymentIntent(Stripe.instance.getReturnUrlForSca());
final paymentIntent = await Stripe.instance.confirmPayment(clientSecret, paymentMethodId: 'pm_card_visa');
```
### Android
You need to declare the following intent filter in `android/app/src/main/AndroidManifest.xml`.
This example is for the url `stripesdk://3ds.stripesdk.io`:
```xml
<manifest ...>
<!-- ... other tags -->
<application ...>
<activity ...>
<!-- The launchMode should be singleTop or singleTask,
to avoid launching a new instance of the app when SCA has been completed. -->
android:launchMode="singleTop"
<!-- ... other tags -->
<!-- Deep Links -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="stripesdk"
android:host="3ds.stripesdk.io" />
</intent-filter>
</activity>
</application>
</manifest>
```
### IOS
For iOS you need to declare the scheme in `ios/Runner/Info.plist` (or through Xcode's Target Info editor,
under URL Types). This example is for the url `stripesdk://3ds.stripesdk.io`:
```xml
<!-- ... other tags -->
<plist>
<dict>
<!-- ... other tags -->
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>3ds.stripesdk.io</string>
<key>CFBundleURLSchemes</key>
<array>
<string>stripesdk</string>
</array>
</dict>
</array>
<!-- ... other tags -->
</dict>
</plist>
```
## Experimental
Experimental features are marked as `deprecated` and the API is subject to change until it is deemed stable.
Feel free to use these features but be aware that breaking changes might be introduced in minor updates.