Skip to content

Commit 2648f80

Browse files
committed
v3.8.0
1 parent ea33eb9 commit 2648f80

File tree

6 files changed

+97
-11
lines changed

6 files changed

+97
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [3.8.0] - 2023-07-12
2+
3+
* Encrypted for app info response.
4+
* New Firebase config fields added to `WooSignalApp` class.
5+
* Pubspec.yaml dependency updates.
6+
17
## [3.7.1] - 2023-07-03
28

39
* Update parameters for creating orders.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ In your flutter project add the dependency:
1515
``` dart
1616
dependencies:
1717
...
18-
woosignal: ^3.7.1
18+
woosignal: ^3.8.0
1919
```
2020

2121
### Usage example #

lib/models/response/woosignal_app.dart

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class WooSignalApp {
5050
Map<String, dynamic>? socialLinks;
5151
List<MenuLink> menuLinks = [];
5252
Map<String, dynamic>? themeColors;
53+
Map<String, dynamic>? firebaseOptionsIos = {};
54+
Map<String, dynamic>? firebaseOptionsAndroid = {};
55+
bool? firebaseFcmIsEnabled;
5356

5457
WooSignalApp(
5558
{this.appName,
@@ -82,7 +85,9 @@ class WooSignalApp {
8285
this.themeFont,
8386
this.socialLinks,
8487
this.menuLinks = const [],
85-
this.themeColors});
88+
this.themeColors,
89+
this.firebaseOptionsIos = const {},
90+
this.firebaseOptionsAndroid = const {}});
8691

8792
WooSignalApp.fromJson(Map<String, dynamic> json) {
8893
appName = json['app_name'];
@@ -151,6 +156,26 @@ class WooSignalApp {
151156
json['theme_colors'] is Map<String, dynamic>?) {
152157
themeColors = json['theme_colors'];
153158
}
159+
160+
if (json.containsKey('firebase_config') &&
161+
json['firebase_config'] is Map<String, dynamic>?) {
162+
Map<String, dynamic> firebaseConfig = json['firebase_config'];
163+
if (firebaseConfig.containsKey('firebase_options_ios') &&
164+
firebaseConfig['firebase_options_ios'] != null) {
165+
firebaseOptionsIos = firebaseConfig['firebase_options_ios'];
166+
}
167+
168+
if (firebaseConfig.containsKey('firebase_options_android') &&
169+
firebaseConfig['firebase_options_android'] != null) {
170+
firebaseOptionsAndroid = firebaseConfig['firebase_options_android'];
171+
}
172+
}
173+
174+
if (json['firebase_fcm_enabled'] != null) {
175+
firebaseFcmIsEnabled =
176+
json['firebase_fcm_enabled'].toString() == "1" ? true : false;
177+
}
178+
154179
if (json.containsKey('menu_links')) {
155180
menuLinks = List.from(json['menu_links'])
156181
.map((bet) => MenuLink.fromJson(bet))
@@ -191,6 +216,14 @@ class WooSignalApp {
191216
data['theme_font'] = themeFont;
192217
data['social_links'] = socialLinks;
193218
data['theme_colors'] = themeColors;
219+
if (firebaseOptionsIos != null) {
220+
data['firebase_config']['firebase_options_ios'] = firebaseOptionsIos;
221+
}
222+
if (firebaseOptionsAndroid != null) {
223+
data['firebase_config']['firebase_options_android'] =
224+
firebaseOptionsAndroid;
225+
}
226+
data['fcm_enabled'] = firebaseFcmIsEnabled;
194227
return data;
195228
}
196229
}

lib/networking/api_provider.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ class ApiProvider {
122122
}
123123

124124
/// HTTP GET request using a [url]
125-
Future<dynamic> get(url) async {
125+
Future<dynamic> get(url, {dynamic data}) async {
126126
try {
127-
Response response = await _dio.get(url);
127+
Response response = await _dio.get(url, data: data);
128128
return response.data;
129129
} catch (error, stacktrace) {
130130
_printLog("$error stackTrace: $stacktrace");

lib/woosignal.dart

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ library woosignal;
1515
// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1616
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1717

18+
import 'dart:convert';
19+
1820
import 'package:woosignal/models/response/api_data.dart';
1921
import 'package:woosignal/models/response/continent.dart';
2022
import 'package:woosignal/models/response/currencies.dart';
@@ -51,24 +53,37 @@ import 'package:woosignal/models/response/system_status.dart';
5153
import 'package:woosignal/models/response/setting_option.dart';
5254
import 'package:woosignal/models/response/setting_option_batch.dart';
5355
import 'package:woosignal/models/response/product_batch.dart';
56+
import 'package:encrypt/encrypt.dart' as enc;
57+
import 'package:encrypt/encrypt.dart';
5458

5559
/// WooSignal Package version
56-
const String wooSignalVersion = "3.7.1";
60+
const String wooSignalVersion = "3.8.0";
5761

5862
class WooSignal {
5963
WooSignal._privateConstructor();
6064
static final WooSignal instance = WooSignal._privateConstructor();
6165

6266
late ApiProvider _apiProvider;
6367
bool? _debugMode;
68+
String? _encryptKey, _encryptSecret;
6469

6570
/// Initialize the class
66-
Future<void> init({required String? appKey, bool debugMode = false}) async {
71+
Future<void> init(
72+
{required String? appKey,
73+
bool debugMode = false,
74+
String? encryptKey,
75+
String? encryptSecret}) async {
6776
assert(appKey != null && appKey != "",
6877
"Provide a valid app key. Visit https://woosignal.com");
6978
_apiProvider = ApiProvider(
7079
appKey: appKey!, debugMode: debugMode, version: wooSignalVersion);
7180
setDebugMode(debugMode);
81+
if (encryptKey != null) {
82+
_encryptKey = encryptKey;
83+
}
84+
if (encryptSecret != null) {
85+
_encryptSecret = encryptSecret;
86+
}
7287
await _apiProvider.init();
7388
}
7489

@@ -121,14 +136,45 @@ class WooSignal {
121136
return model;
122137
}
123138

139+
String encrypt(String text) {
140+
if (_encryptKey == null) {
141+
return "";
142+
}
143+
if (_encryptSecret == null) {
144+
return "";
145+
}
146+
final key = enc.Key.fromUtf8(_encryptKey!);
147+
final iv = IV.fromUtf8(_encryptSecret!);
148+
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
149+
final encrypted = encrypter.encrypt(text, iv: iv);
150+
return encrypted.base64;
151+
}
152+
153+
String decrypt(String text) {
154+
if (_encryptKey == null) {
155+
return "";
156+
}
157+
if (_encryptSecret == null) {
158+
return "";
159+
}
160+
final key = enc.Key.fromUtf8(_encryptKey!);
161+
final iv = IV.fromUtf8(_encryptSecret!);
162+
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
163+
final decrypted = encrypter.decrypt(Encrypted.fromBase64(text), iv: iv);
164+
return decrypted;
165+
}
166+
124167
/// Get app information from WooSignal
125-
Future<WooSignalApp?> getApp() async {
126-
dynamic response = await _apiProvider.get("/app");
168+
Future<WooSignalApp?> getApp({bool encrypted = false}) async {
169+
dynamic response =
170+
await _apiProvider.get("/app", data: {"encrypted": encrypted});
127171
if (response == null) {
128172
return null;
129173
}
174+
if (encrypted == true) {
175+
response = jsonDecode(decrypt(response));
176+
}
130177
WooSignalApp wooSignalApp = WooSignalApp.fromJson(response);
131-
132178
_printLog(wooSignalApp.toString());
133179
return wooSignalApp;
134180
}

pubspec.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
name: woosignal
22
description: WooCommerce REST API for dart, connect a WooCommerce store and start developing with our interface for their API endpoints.
3-
version: 3.7.1
3+
version: 3.8.0
44
homepage: https://woosignal.com
55
repository: https://github.com/woosignal/flutter-woocommerce-api
66
issue_tracker: https://github.com/woosignal/flutter-woocommerce-api/issues
77
documentation: https://woosignal.com/docs/api/1.0/overview
88

99
environment:
10-
sdk: '>=2.19.0 <4.0.0'
10+
sdk: '>=3.0.0 <4.0.0'
1111

1212
dependencies:
1313
dio: ^5.2.1+1
1414
device_info_plus: ^9.0.2
1515
shared_preferences: ^2.2.0
16+
encrypt: ^5.0.1
1617
uuid: ^3.0.6
1718

1819
flutter:

0 commit comments

Comments
 (0)