Skip to content

Commit 1d27018

Browse files
committed
Coupons Apis are done. If have error kindly tell me.
1 parent d89c58c commit 1d27018

File tree

4 files changed

+301
-131
lines changed

4 files changed

+301
-131
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_info","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\device_info-0.4.2+10\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.12+4\\\\","dependencies":[]}],"android":[{"name":"device_info","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\device_info-0.4.2+10\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.12+4\\\\","dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-0.0.1+6\\\\","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-0.0.1+2\\\\","dependencies":[]},{"name":"shared_preferences_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_linux-0.0.2+4\\\\","dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-0.0.4+3\\\\","dependencies":[]},{"name":"shared_preferences_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_windows-0.0.1+3\\\\","dependencies":["path_provider_windows"]}],"web":[{"name":"shared_preferences_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-0.1.2+4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"device_info","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2020-11-04 16:45:17.345850","version":"1.22.2"}
1+
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_info","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\device_info-0.4.2+10\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.12+4\\\\","dependencies":[]}],"android":[{"name":"device_info","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\device_info-0.4.2+10\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.12+4\\\\","dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-0.0.1+6\\\\","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-0.0.1+2\\\\","dependencies":[]},{"name":"shared_preferences_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_linux-0.0.2+4\\\\","dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-0.0.4+3\\\\","dependencies":[]},{"name":"shared_preferences_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_windows-0.0.1+3\\\\","dependencies":["path_provider_windows"]}],"web":[{"name":"shared_preferences_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-0.1.2+4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"device_info","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2020-11-07 00:03:36.058707","version":"1.22.2"}

example/lib/main.dart

Lines changed: 23 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,8 @@
1-
// import 'package:flutter/material.dart';
2-
// import 'package:flutter/services.dart';
3-
// import 'package:provider/provider.dart';
4-
// import 'package:haider_app/screens/business_overview_screen.dart';
5-
// import 'package:haider_app/screens/splash_screen.dart';
6-
7-
// import './screens/login_screen.dart';
8-
9-
// import './providers/auth.dart';
10-
11-
// Future main() async {
12-
// WidgetsFlutterBinding.ensureInitialized();
13-
// await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
14-
// runApp(MyApp());
15-
// }
16-
17-
// class MyApp extends StatelessWidget {
18-
// @override
19-
// Widget build(BuildContext context) {
20-
// return MultiProvider(
21-
// providers: [
22-
// ChangeNotifierProvider(
23-
// create: (context) => Auth(),
24-
// ),
25-
// ],
26-
// child: Consumer<Auth>(builder: (ctx, auth, _) {
27-
// // print(auth.isAuth);
28-
// return MaterialApp(
29-
// debugShowCheckedModeBanner: false,
30-
// title: '''Haider's App''',
31-
// theme: ThemeData(
32-
// scaffoldBackgroundColor: Colors.white,
33-
// primaryColor: Color.fromRGBO(124, 116, 146, 1),
34-
// buttonTheme: ButtonThemeData(textTheme: ButtonTextTheme.primary),
35-
// appBarTheme: AppBarTheme(
36-
// color: Colors.white,
37-
// elevation: 0.0,
38-
// iconTheme:
39-
// IconThemeData(color: Color.fromRGBO(124, 116, 146, 1))),
40-
// ),
41-
// home: auth.isAuth
42-
// ? BusinessOverViewScreen()
43-
// : FutureBuilder(
44-
// builder: (context, authResultSnapshot) {
45-
// print(auth.isAuth);
46-
// return authResultSnapshot.connectionState ==
47-
// ConnectionState.waiting
48-
// ? SplashScreen()
49-
// : LoginScreen();
50-
// },
51-
// future: auth.tryAutoLogin(),
52-
// ),
53-
// routes: {
54-
// LoginScreen.routeName: (ctx) => LoginScreen(),
55-
// // RegisterScreen.routeName: (ctx) => RegisterScreen(),
56-
// BusinessOverViewScreen.routeName: (ctx) =>
57-
// BusinessOverViewScreen()
58-
// },
59-
// );
60-
// }));
61-
// }
62-
// }
63-
// import 'package:flutter/material.dart';
64-
// import 'package:flutter/services.dart';
65-
// import 'package:sms_maintained/sms.dart';
66-
67-
// Future main() async {
68-
// WidgetsFlutterBinding.ensureInitialized();
69-
// await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
70-
// runApp(
71-
// MaterialApp(
72-
// home: SendSmsScreen(),
73-
// ),
74-
// );
75-
// }
76-
77-
// class SendSmsScreen extends StatelessWidget {
78-
// final SmsSender sender = SmsSender();
79-
// final SmsMessage message = SmsMessage('03009640742', '_body');
80-
// final List<SmsMessage> smsList = [
81-
// SmsMessage('03009750742', 'Random'),
82-
// SmsMessage('03008750742', 'Kaleem'),
83-
// SmsMessage('03056750742', 'Shahryar'),
84-
// SmsMessage('03127750742', 'Shahryar Zong')
85-
// ];
86-
// @override
87-
// Widget build(BuildContext context) {
88-
// return Scaffold(
89-
// appBar: AppBar(),
90-
// body: ListView.builder(
91-
// itemCount: smsList.length,
92-
// itemBuilder: (context, index) {
93-
// return SingleChildScrollView(
94-
// child: Column(
95-
// children: [
96-
// IconButton(
97-
// icon: Icon(Icons.send),
98-
// onPressed: () {
99-
// sender.sendSms(smsList[index]);
100-
// },
101-
// ),
102-
// StreamBuilder<SmsMessageState>(
103-
// key: GlobalKey(debugLabel: 'String $index'),
104-
// // initialData: SmsMessageState.None,
105-
// builder: (context, snapshot) {
106-
// if (snapshot.data == SmsMessageState.Sent) {
107-
// return Text('Message Sent');
108-
// }
109-
// if (snapshot.data == SmsMessageState.Delivered) {
110-
// return Text('Message Delivered');
111-
// }
112-
// if (snapshot.data == SmsMessageState.Sending) {
113-
// return Text('Sending');
114-
// }
115-
// if (snapshot.data == SmsMessageState.Fail)
116-
// return Text('Sending Failed');
117-
// return Text('Error');
118-
// },
119-
// stream: smsList[index].onStateChanged,
120-
// ),
121-
// ],
122-
// ),
123-
// );
124-
// },
125-
// ));
126-
// }
127-
// }
1281
import 'package:flutter/material.dart';
1292
import 'package:woosignal/models/response/products.dart';
1303
import 'package:woosignal/models/response/coupon.dart';
1314
import 'package:woosignal/woosignal.dart';
5+
import 'package:woosignal/models/response/coupon_batch.dart';
1326

1337
void main() => runApp(MyApp());
1348

@@ -167,11 +41,30 @@ class _MyHomePageState extends State<MyHomePage> {
16741
// CREATING AN INSTANCE
16842
WooSignal wooSignal = await WooSignal.getInstance(config: wsConfig);
16943

170-
Coupon coupons = await wooSignal.retrieveCoupons(id: 511);
171-
print(coupons.id);
44+
// Coupon coupons = await wooSignal.batchCoupon(data: {"create":"data"});
45+
CouponBatch couponBatch = await wooSignal.batchCoupon(
46+
data: {
47+
"create": [
48+
{
49+
"code": "15off",
50+
"discount_type": "percent",
51+
"amount": "20",
52+
"individual_use": "true",
53+
"exclude_sale_items": "true",
54+
"minimum_amount": "100.00"
55+
}
56+
],
57+
"update": [
58+
{"id": "518", "minimum_amount": "100.00"}
59+
],
60+
"delete": [517],
61+
},
62+
);
63+
64+
print(couponBatch.create[0].id);
17265

17366
setState(() {
174-
_productName = coupons.id.toString();
67+
_productName = couponBatch.create[0].id.toString();
17568
});
17669
}
17770

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
// To parse this JSON data, do
2+
//
3+
// final couponBatch = couponBatchFromJson(jsonString);
4+
import 'dart:convert';
5+
6+
CouponBatch couponBatchFromJson(String str) =>
7+
CouponBatch.fromJson(json.decode(str));
8+
9+
String couponBatchToJson(CouponBatch data) => json.encode(data.toJson());
10+
11+
class CouponBatch {
12+
CouponBatch({
13+
this.create,
14+
this.update,
15+
this.delete,
16+
});
17+
18+
List<Create> create;
19+
List<Create> update;
20+
List<Create> delete;
21+
22+
factory CouponBatch.fromJson(Map<String, dynamic> json) => CouponBatch(
23+
create:
24+
List<Create>.from(json["create"].map((x) => Create.fromJson(x))),
25+
update:
26+
List<Create>.from(json["update"].map((x) => Create.fromJson(x))),
27+
delete:
28+
List<Create>.from(json["delete"].map((x) => Create.fromJson(x))),
29+
);
30+
31+
Map<String, dynamic> toJson() => {
32+
"create": List<dynamic>.from(create.map((x) => x.toJson())),
33+
"update": List<dynamic>.from(update.map((x) => x.toJson())),
34+
"delete": List<dynamic>.from(delete.map((x) => x.toJson())),
35+
};
36+
}
37+
38+
class Create {
39+
Create({
40+
this.id,
41+
this.code,
42+
this.amount,
43+
this.dateCreated,
44+
this.dateCreatedGmt,
45+
this.dateModified,
46+
this.dateModifiedGmt,
47+
this.discountType,
48+
this.description,
49+
this.dateExpires,
50+
this.dateExpiresGmt,
51+
this.usageCount,
52+
this.individualUse,
53+
this.productIds,
54+
this.excludedProductIds,
55+
this.usageLimit,
56+
this.usageLimitPerUser,
57+
this.limitUsageToXItems,
58+
this.freeShipping,
59+
this.productCategories,
60+
this.excludedProductCategories,
61+
this.excludeSaleItems,
62+
this.minimumAmount,
63+
this.maximumAmount,
64+
this.emailRestrictions,
65+
this.usedBy,
66+
this.metaData,
67+
this.links,
68+
});
69+
70+
int id;
71+
String code;
72+
String amount;
73+
DateTime dateCreated;
74+
DateTime dateCreatedGmt;
75+
DateTime dateModified;
76+
DateTime dateModifiedGmt;
77+
String discountType;
78+
String description;
79+
dynamic dateExpires;
80+
dynamic dateExpiresGmt;
81+
int usageCount;
82+
bool individualUse;
83+
List<dynamic> productIds;
84+
List<dynamic> excludedProductIds;
85+
dynamic usageLimit;
86+
dynamic usageLimitPerUser;
87+
dynamic limitUsageToXItems;
88+
bool freeShipping;
89+
List<dynamic> productCategories;
90+
List<dynamic> excludedProductCategories;
91+
bool excludeSaleItems;
92+
String minimumAmount;
93+
String maximumAmount;
94+
List<dynamic> emailRestrictions;
95+
List<dynamic> usedBy;
96+
List<dynamic> metaData;
97+
Links links;
98+
99+
factory Create.fromJson(Map<String, dynamic> json) => Create(
100+
id: json["id"],
101+
code: json["code"],
102+
amount: json["amount"],
103+
dateCreated: DateTime.parse(json["date_created"]),
104+
dateCreatedGmt: DateTime.parse(json["date_created_gmt"]),
105+
dateModified: DateTime.parse(json["date_modified"]),
106+
dateModifiedGmt: DateTime.parse(json["date_modified_gmt"]),
107+
discountType: json["discount_type"],
108+
description: json["description"],
109+
dateExpires: json["date_expires"],
110+
dateExpiresGmt: json["date_expires_gmt"],
111+
usageCount: json["usage_count"],
112+
individualUse: json["individual_use"],
113+
productIds: List<dynamic>.from(json["product_ids"].map((x) => x)),
114+
excludedProductIds:
115+
List<dynamic>.from(json["excluded_product_ids"].map((x) => x)),
116+
usageLimit: json["usage_limit"],
117+
usageLimitPerUser: json["usage_limit_per_user"],
118+
limitUsageToXItems: json["limit_usage_to_x_items"],
119+
freeShipping: json["free_shipping"],
120+
productCategories:
121+
List<dynamic>.from(json["product_categories"].map((x) => x)),
122+
excludedProductCategories: List<dynamic>.from(
123+
json["excluded_product_categories"].map((x) => x)),
124+
excludeSaleItems: json["exclude_sale_items"],
125+
minimumAmount: json["minimum_amount"],
126+
maximumAmount: json["maximum_amount"],
127+
emailRestrictions:
128+
List<dynamic>.from(json["email_restrictions"].map((x) => x)),
129+
usedBy: List<dynamic>.from(json["used_by"].map((x) => x)),
130+
metaData: List<dynamic>.from(json["meta_data"].map((x) => x)),
131+
links: Links.fromJson(json["_links"]),
132+
);
133+
134+
Map<String, dynamic> toJson() => {
135+
"id": id,
136+
"code": code,
137+
"amount": amount,
138+
"date_created": dateCreated.toIso8601String(),
139+
"date_created_gmt": dateCreatedGmt.toIso8601String(),
140+
"date_modified": dateModified.toIso8601String(),
141+
"date_modified_gmt": dateModifiedGmt.toIso8601String(),
142+
"discount_type": discountType,
143+
"description": description,
144+
"date_expires": dateExpires,
145+
"date_expires_gmt": dateExpiresGmt,
146+
"usage_count": usageCount,
147+
"individual_use": individualUse,
148+
"product_ids": List<dynamic>.from(productIds.map((x) => x)),
149+
"excluded_product_ids":
150+
List<dynamic>.from(excludedProductIds.map((x) => x)),
151+
"usage_limit": usageLimit,
152+
"usage_limit_per_user": usageLimitPerUser,
153+
"limit_usage_to_x_items": limitUsageToXItems,
154+
"free_shipping": freeShipping,
155+
"product_categories":
156+
List<dynamic>.from(productCategories.map((x) => x)),
157+
"excluded_product_categories":
158+
List<dynamic>.from(excludedProductCategories.map((x) => x)),
159+
"exclude_sale_items": excludeSaleItems,
160+
"minimum_amount": minimumAmount,
161+
"maximum_amount": maximumAmount,
162+
"email_restrictions":
163+
List<dynamic>.from(emailRestrictions.map((x) => x)),
164+
"used_by": List<dynamic>.from(usedBy.map((x) => x)),
165+
"meta_data": List<dynamic>.from(metaData.map((x) => x)),
166+
"_links": links.toJson(),
167+
};
168+
}
169+
170+
class Links {
171+
Links({
172+
this.self,
173+
this.collection,
174+
});
175+
176+
List<Collection> self;
177+
List<Collection> collection;
178+
179+
factory Links.fromJson(Map<String, dynamic> json) => Links(
180+
self: List<Collection>.from(
181+
json["self"].map((x) => Collection.fromJson(x))),
182+
collection: List<Collection>.from(
183+
json["collection"].map((x) => Collection.fromJson(x))),
184+
);
185+
186+
Map<String, dynamic> toJson() => {
187+
"self": List<dynamic>.from(self.map((x) => x.toJson())),
188+
"collection": List<dynamic>.from(collection.map((x) => x.toJson())),
189+
};
190+
}
191+
192+
class Collection {
193+
Collection({
194+
this.href,
195+
});
196+
197+
String href;
198+
199+
factory Collection.fromJson(Map<String, dynamic> json) => Collection(
200+
href: json["href"],
201+
);
202+
203+
Map<String, dynamic> toJson() => {
204+
"href": href,
205+
};
206+
}

0 commit comments

Comments
 (0)