Skip to content

Commit 18a8c4f

Browse files
Brian SchardtBrian Schardt
authored andcommitted
added configuration options
1 parent b058834 commit 18a8c4f

6 files changed

Lines changed: 96 additions & 109 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## 0.1.1.
1+
## 0.0.1
22

33
* TODO: Describe initial release.

LICENSE

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
Copyright 2019 Leonid Veremchuk
1+
MIT License
22

3-
Licensed under the Apache License, Version 2.0 (the "License");
4-
you may not use this file except in compliance with the License.
5-
You may obtain a copy of the License at
3+
Copyright (c) 2019 Brian Schardt
64

7-
http://www.apache.org/licenses/LICENSE-2.0
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
811

9-
Unless required by applicable law or agreed to in writing, software
10-
distributed under the License is distributed on an "AS IS" BASIS,
11-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
See the License for the specific language governing permissions and
13-
limitations under the License.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Flutter for Plaid Link
22

3+
based off of: https://pub.dev/packages/flutter_plaid
4+
But provides additional necessary functionality
35
[![pub](https://img.shields.io/pub/v/flutter_plaid.svg)](https://pub.dev/packages/flutter_plaid)
46

57
## Usage
Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@ import 'package:http/http.dart';
88
import 'package:webview_flutter/webview_flutter.dart';
99

1010
class FlutterPlaidApi {
11-
Configuration _configuration;
12-
1311
FlutterPlaidApi(Configuration configuration) {
14-
this._configuration = configuration;
12+
_configuration = configuration;
1513
}
14+
Configuration _configuration;
1615

1716
/// stripeToken = false use for get plaid token and accountId
1817
/// stripeToken = true: use for add the new payment method, returns stripe_token
1918
launch(BuildContext context, success(Result result),
2019
{bool stripeToken = false}) {
21-
_WebViewPage _webViewPage = new _WebViewPage();
22-
_webViewPage._init(this._configuration, success, stripeToken, context);
20+
final _WebViewPage _webViewPage = _WebViewPage();
21+
_webViewPage._init(_configuration, success, stripeToken, context);
2322

2423
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) {
2524
return _webViewPage.build(context);
@@ -36,30 +35,30 @@ class _WebViewPage {
3635

3736
_init(Configuration config, success(Result result), bool stripeToken,
3837
BuildContext context) {
39-
this._success = success;
40-
this._config = config;
41-
this._stripeToken = stripeToken;
42-
this._context = context;
38+
_success = success;
39+
_config = config;
40+
_stripeToken = stripeToken;
41+
_context = context;
4342
_url = config.plaidBaseUrl +
4443
'?key=' +
4544
config.plaidPublicKey +
46-
'&isWebview=true' +
47-
'&product=auth' +
48-
'&isMobile=true' +
49-
'&apiVersion=v2' +
50-
'&selectAccount=true' +
51-
'&webhook=https://requestb.in' +
45+
'&isWebview=' + config.isWebview +
46+
'&product=' + config.products +
47+
'&isMobile=' + config.isMobile +
48+
'&apiVersion=' + config.apiVersion +
49+
'&selectAccount=' + config.selectAccount +
50+
'&webhook=' + config.webhook +
5251
'&env=' +
5352
config.plaidEnvironment;
5453
debugPrint('init plaid: ' + _url);
5554
}
5655

5756
_parseUrl(String url) {
5857
if (url?.isNotEmpty != null) {
59-
Uri uri = Uri.parse(url);
58+
final Uri uri = Uri.parse(url);
6059
debugPrint('PLAID uri: ' + uri.toString());
61-
Map<String, String> queryParams = uri.queryParameters;
62-
List<String> segments = uri.pathSegments;
60+
final Map<String, String> queryParams = uri.queryParameters;
61+
final List<String> segments = uri.pathSegments;
6362
debugPrint('queryParams: ' + queryParams?.toString());
6463
debugPrint('segments: ' + segments?.toString());
6564
_processParams(queryParams, url);
@@ -68,52 +67,52 @@ class _WebViewPage {
6867

6968
_processParams(Map<String, String> queryParams, String url) async {
7069
if (queryParams != null) {
71-
String eventName = queryParams['event_name'] ?? 'unknow';
72-
debugPrint("PLAID Event name: " + eventName);
70+
final String eventName = queryParams['event_name'] ?? 'unknow';
71+
debugPrint('PLAID Event name: $eventName');
7372

7473
if (eventName == 'EXIT' || (url?.contains('/exit?') ?? false)) {
75-
this._closeWebView();
74+
_closeWebView();
7675
} else if (eventName == 'HANDOFF') {
77-
this._closeWebView();
76+
_closeWebView();
7877
}
79-
dynamic token = queryParams['public_token'];
80-
dynamic accountId = queryParams['account_id'];
78+
final dynamic token = queryParams['public_token'];
79+
final dynamic accountId = queryParams['account_id'];
8180
if (token != null && accountId != null) {
8281
if (!_stripeToken) {
8382
this._success(Result(token, accountId, queryParams));
8483
} else {
85-
await this._fetchStripeToken(token, accountId);
84+
await _fetchStripeToken(token, accountId);
8685
}
8786
}
8887
}
8988
}
9089

9190
_fetchStripeToken(String token, String accountId) async {
92-
var headers = {'Content-Type': 'application/json'};
91+
final headers = {'Content-Type': 'application/json'};
9392

94-
Response responseAccessToken =
93+
final Response responseAccessToken =
9594
await post(_config.environmentPlaidPathAccessToken,
9695
body: json.encode({
9796
'public_token': token,
98-
'client_id': this._config.plaidClientId,
99-
'secret': this._config.secret
97+
'client_id': _config.plaidClientId,
98+
'secret': _config.secret
10099
}),
101100
headers: headers);
102-
var accessTokenData =
101+
final accessTokenData =
103102
json.decode(utf8.decode(responseAccessToken.bodyBytes));
104-
String accessToken = accessTokenData['access_token'];
103+
final String accessToken = accessTokenData['access_token'];
105104

106-
Response responseStripeToken =
105+
final Response responseStripeToken =
107106
await post(_config.environmentPlaidPathStripeToken,
108107
body: json.encode({
109-
'client_id': this._config.plaidClientId,
110-
'secret': this._config.secret,
108+
'client_id': _config.plaidClientId,
109+
'secret': _config.secret,
111110
'access_token': accessToken,
112111
'account_id': accountId
113112
}),
114113
headers: headers);
115114

116-
var stripeTokenData =
115+
final stripeTokenData =
117116
json.decode(utf8.decode(responseStripeToken.bodyBytes));
118117
_success(Result(
119118
stripeTokenData['stripe_bank_account_token'], null, stripeTokenData));
@@ -126,12 +125,12 @@ class _WebViewPage {
126125
}
127126

128127
Widget build(BuildContext context) {
129-
var webView = new WebView(
128+
final webView = WebView(
130129
initialUrl: _url,
131130
javascriptMode: JavascriptMode.unrestricted,
132131
navigationDelegate: (NavigationRequest navigation) {
133132
if (navigation.url.contains('plaidlink://')) {
134-
this._parseUrl(navigation.url);
133+
_parseUrl(navigation.url);
135134
return NavigationDecision.prevent;
136135
}
137136
return NavigationDecision.navigate;
@@ -142,28 +141,41 @@ class _WebViewPage {
142141
}
143142

144143
class Configuration {
144+
Configuration(
145+
{
146+
@required this.plaidPublicKey,
147+
@required this.plaidBaseUrl,
148+
@required this.plaidEnvironment,
149+
@required this.environmentPlaidPathAccessToken,
150+
@required this.environmentPlaidPathStripeToken,
151+
@required this.plaidClientId,
152+
@required this.secret,
153+
this.webhook = 'https://requestb.in',
154+
this.products = 'auth,income',//e.g. auth or auth,income
155+
this.selectAccount = 'true',//e.g. auth or auth,income
156+
this.isMobile = 'true',
157+
this.apiVersion = 'v2',
158+
this.isWebview = 'true',
159+
});
145160
String plaidPublicKey;
146161
String plaidBaseUrl;
147162
String plaidEnvironment;
148163
String environmentPlaidPathAccessToken;
149164
String environmentPlaidPathStripeToken;
150165
String plaidClientId;
151166
String secret;
152-
153-
Configuration(
154-
{@required this.plaidPublicKey,
155-
@required this.plaidBaseUrl,
156-
@required this.plaidEnvironment,
157-
@required this.environmentPlaidPathAccessToken,
158-
@required this.environmentPlaidPathStripeToken,
159-
@required this.plaidClientId,
160-
@required this.secret});
167+
String webhook;
168+
String products;
169+
String selectAccount;
170+
String apiVersion;
171+
String isMobile;
172+
String isWebview;
161173
}
162174

163175
class Result {
176+
Result(this.token, this.accountId, this.response);
177+
164178
String token;
165179
String accountId;
166180
dynamic response;
167-
168-
Result(this.token, this.accountId, this.response);
169181
}

pubspec.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# Generated by pub
2-
# See https://www.dartlang.org/tools/pub/glossary#lockfile
2+
# See https://dart.dev/tools/pub/glossary#lockfile
33
packages:
44
async:
55
dependency: transitive
66
description:
77
name: async
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "2.1.0"
10+
version: "2.3.0"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
1414
name: boolean_selector
1515
url: "https://pub.dartlang.org"
1616
source: hosted
17-
version: "1.0.4"
17+
version: "1.0.5"
1818
charcode:
1919
dependency: transitive
2020
description:
@@ -66,28 +66,28 @@ packages:
6666
name: meta
6767
url: "https://pub.dartlang.org"
6868
source: hosted
69-
version: "1.1.6"
69+
version: "1.1.7"
7070
path:
7171
dependency: transitive
7272
description:
7373
name: path
7474
url: "https://pub.dartlang.org"
7575
source: hosted
76-
version: "1.6.2"
76+
version: "1.6.4"
7777
pedantic:
7878
dependency: transitive
7979
description:
8080
name: pedantic
8181
url: "https://pub.dartlang.org"
8282
source: hosted
83-
version: "1.5.0"
83+
version: "1.8.0+1"
8484
quiver:
8585
dependency: transitive
8686
description:
8787
name: quiver
8888
url: "https://pub.dartlang.org"
8989
source: hosted
90-
version: "2.0.2"
90+
version: "2.0.5"
9191
sky_engine:
9292
dependency: transitive
9393
description: flutter
@@ -120,7 +120,7 @@ packages:
120120
name: string_scanner
121121
url: "https://pub.dartlang.org"
122122
source: hosted
123-
version: "1.0.4"
123+
version: "1.0.5"
124124
term_glyph:
125125
dependency: transitive
126126
description:
@@ -134,7 +134,7 @@ packages:
134134
name: test_api
135135
url: "https://pub.dartlang.org"
136136
source: hosted
137-
version: "0.2.4"
137+
version: "0.2.5"
138138
typed_data:
139139
dependency: transitive
140140
description:
@@ -157,5 +157,5 @@ packages:
157157
source: hosted
158158
version: "0.3.7+1"
159159
sdks:
160-
dart: ">=2.2.0 <3.0.0"
160+
dart: ">=2.2.2 <3.0.0"
161161
flutter: ">=0.11.9 <2.0.0"

pubspec.yaml

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name: flutter_plaid
1+
name: plaid
22
description: Porting of Plaid Api (https://plaid.com/docs/) to Flutter.
3-
version: 0.1.1
4-
author: Leonid Veremchuk<leonid.veremchuk@gmail.com>
5-
homepage: https://github.com/LeonidVeremchuk
3+
version: 0.0.1
4+
author: Brian Schardt<brian.ja.schardt@gmail.com>
5+
homepage: https://github.com/prototype-two/flutter_plaid
66

77
environment:
88
sdk: ">=2.1.0 <3.0.0"
@@ -16,40 +16,5 @@ dependencies:
1616
dev_dependencies:
1717
flutter_test:
1818
sdk: flutter
19-
20-
# For information on the generic Dart part of this file, see the
21-
# following page: https://www.dartlang.org/tools/pub/pubspec
22-
23-
# The following section is specific to Flutter.
19+
2420
flutter:
25-
26-
# To add assets to your package, add an assets section, like this:
27-
# assets:
28-
# - images/a_dot_burr.jpeg
29-
# - images/a_dot_ham.jpeg
30-
#
31-
# For details regarding assets in packages, see
32-
# https://flutter.dev/assets-and-images/#from-packages
33-
#
34-
# An image asset can refer to one or more resolution-specific "variants", see
35-
# https://flutter.dev/assets-and-images/#resolution-aware.
36-
37-
# To add custom fonts to your package, add a fonts section here,
38-
# in this "flutter" section. Each entry in this list should have a
39-
# "family" key with the font family name, and a "fonts" key with a
40-
# list giving the asset and other descriptors for the font. For
41-
# example:
42-
# fonts:
43-
# - family: Schyler
44-
# fonts:
45-
# - asset: fonts/Schyler-Regular.ttf
46-
# - asset: fonts/Schyler-Italic.ttf
47-
# style: italic
48-
# - family: Trajan Pro
49-
# fonts:
50-
# - asset: fonts/TrajanPro.ttf
51-
# - asset: fonts/TrajanPro_Bold.ttf
52-
# weight: 700
53-
#
54-
# For details regarding fonts in packages, see
55-
# https://flutter.dev/custom-fonts/#from-packages

0 commit comments

Comments
 (0)