Skip to content

Commit 9d7b091

Browse files
committed
shipping zones are fetched
1 parent c83f8d2 commit 9d7b091

File tree

5 files changed

+247
-1
lines changed

5 files changed

+247
-1
lines changed

.flutter-plugins-dependencies

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_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_android-2.2.0/","native_build":true,"dependencies":[]}],"macos":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":false,"dependencies":[]},{"name":"path_provider_linux","path":"/home/arif/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.11/","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.3.0/","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":false,"dependencies":[]},{"name":"path_provider_windows","path":"/home/arif/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.7/","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.3.0/","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","dependencies":[]},{"name":"shared_preferences_web","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_web-2.2.0/","dependencies":[]}]},"dependencyGraph":[{"name":"device_info_plus","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2023-07-26 00:42:30.060417","version":"3.10.5"}
1+
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_android-2.2.0/","native_build":true,"dependencies":[]}],"macos":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":false,"dependencies":[]},{"name":"path_provider_linux","path":"/home/arif/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.11/","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.3.0/","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":false,"dependencies":[]},{"name":"path_provider_windows","path":"/home/arif/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.7/","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.3.0/","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","dependencies":[]},{"name":"shared_preferences_web","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_web-2.2.0/","dependencies":[]}]},"dependencyGraph":[{"name":"device_info_plus","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2023-07-26 00:55:16.472508","version":"3.10.5"}

dart_test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ tags:
77
get-countries:
88
get-policies:
99
policies-properties:
10+
get-shipping-zones:
11+
shipping-zones-properties:
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
class ShippingZonesResponse {
2+
List<ShippingZone> shippingZones;
3+
4+
ShippingZonesResponse({
5+
required this.shippingZones,
6+
});
7+
8+
factory ShippingZonesResponse.fromJson(Map<String, dynamic> json) => ShippingZonesResponse(
9+
shippingZones: List<ShippingZone>.from(json["shipping_zones"].map((x) => ShippingZone.fromJson(x))),
10+
);
11+
12+
Map<String, dynamic> toJson() => {
13+
"shipping_zones": List<dynamic>.from(shippingZones.map((x) => x.toJson())),
14+
};
15+
}
16+
17+
class ShippingZone {
18+
int id;
19+
String name;
20+
String profileId;
21+
String locationGroupId;
22+
String adminGraphqlApiId;
23+
List<Country> countries;
24+
List<dynamic> weightBasedShippingRates;
25+
List<PriceBasedShippingRate> priceBasedShippingRates;
26+
List<dynamic> carrierShippingRateProviders;
27+
28+
ShippingZone({
29+
required this.id,
30+
required this.name,
31+
required this.profileId,
32+
required this.locationGroupId,
33+
required this.adminGraphqlApiId,
34+
required this.countries,
35+
required this.weightBasedShippingRates,
36+
required this.priceBasedShippingRates,
37+
required this.carrierShippingRateProviders,
38+
});
39+
40+
factory ShippingZone.fromJson(Map<String, dynamic> json) => ShippingZone(
41+
id: json["id"],
42+
name: json["name"],
43+
profileId: json["profile_id"],
44+
locationGroupId: json["location_group_id"],
45+
adminGraphqlApiId: json["admin_graphql_api_id"],
46+
countries: List<Country>.from(json["countries"].map((x) => Country.fromJson(x))),
47+
weightBasedShippingRates: List<dynamic>.from(json["weight_based_shipping_rates"].map((x) => x)),
48+
priceBasedShippingRates: List<PriceBasedShippingRate>.from(json["price_based_shipping_rates"].map((x) => PriceBasedShippingRate.fromJson(x))),
49+
carrierShippingRateProviders: List<dynamic>.from(json["carrier_shipping_rate_providers"].map((x) => x)),
50+
);
51+
52+
Map<String, dynamic> toJson() => {
53+
"id": id,
54+
"name": name,
55+
"profile_id": profileId,
56+
"location_group_id": locationGroupId,
57+
"admin_graphql_api_id": adminGraphqlApiId,
58+
"countries": List<dynamic>.from(countries.map((x) => x.toJson())),
59+
"weight_based_shipping_rates": List<dynamic>.from(weightBasedShippingRates.map((x) => x)),
60+
"price_based_shipping_rates": List<dynamic>.from(priceBasedShippingRates.map((x) => x.toJson())),
61+
"carrier_shipping_rate_providers": List<dynamic>.from(carrierShippingRateProviders.map((x) => x)),
62+
};
63+
}
64+
65+
class Country {
66+
int id;
67+
String name;
68+
double tax;
69+
String code;
70+
String taxName;
71+
int shippingZoneId;
72+
List<Province> provinces;
73+
74+
Country({
75+
required this.id,
76+
required this.name,
77+
required this.tax,
78+
required this.code,
79+
required this.taxName,
80+
required this.shippingZoneId,
81+
required this.provinces,
82+
});
83+
84+
factory Country.fromJson(Map<String, dynamic> json) => Country(
85+
id: json["id"],
86+
name: json["name"],
87+
tax: json["tax"]?.toDouble(),
88+
code: json["code"],
89+
taxName: json["tax_name"],
90+
shippingZoneId: json["shipping_zone_id"],
91+
provinces: List<Province>.from(json["provinces"].map((x) => Province.fromJson(x))),
92+
);
93+
94+
Map<String, dynamic> toJson() => {
95+
"id": id,
96+
"name": name,
97+
"tax": tax,
98+
"code": code,
99+
"tax_name": taxName,
100+
"shipping_zone_id": shippingZoneId,
101+
"provinces": List<dynamic>.from(provinces.map((x) => x.toJson())),
102+
};
103+
}
104+
105+
class Province {
106+
int id;
107+
int countryId;
108+
String name;
109+
String code;
110+
int tax;
111+
TaxName taxName;
112+
String? taxType;
113+
int taxPercentage;
114+
int shippingZoneId;
115+
116+
Province({
117+
required this.id,
118+
required this.countryId,
119+
required this.name,
120+
required this.code,
121+
required this.tax,
122+
required this.taxName,
123+
this.taxType,
124+
required this.taxPercentage,
125+
required this.shippingZoneId,
126+
});
127+
128+
factory Province.fromJson(Map<String, dynamic> json) => Province(
129+
id: json["id"],
130+
countryId: json["country_id"],
131+
name: json["name"],
132+
code: json["code"],
133+
tax: json["tax"],
134+
taxName: taxNameValues.map[json["tax_name"]]!,
135+
taxType: json["tax_type"],
136+
taxPercentage: json["tax_percentage"],
137+
shippingZoneId: json["shipping_zone_id"],
138+
);
139+
140+
Map<String, dynamic> toJson() => {
141+
"id": id,
142+
"country_id": countryId,
143+
"name": name,
144+
"code": code,
145+
"tax": tax,
146+
"tax_name": taxNameValues.reverse[taxName],
147+
"tax_type": taxType,
148+
"tax_percentage": taxPercentage,
149+
"shipping_zone_id": shippingZoneId,
150+
};
151+
}
152+
153+
enum TaxName { VAT, TAX, PST, RST, HST, QST, THE_00, SST, GST, STATE_TAX, GRT }
154+
155+
final taxNameValues = EnumValues({
156+
"GRT": TaxName.GRT,
157+
"GST": TaxName.GST,
158+
"HST": TaxName.HST,
159+
"PST": TaxName.PST,
160+
"QST": TaxName.QST,
161+
"RST": TaxName.RST,
162+
"SST": TaxName.SST,
163+
"State Tax": TaxName.STATE_TAX,
164+
"Tax": TaxName.TAX,
165+
"0.0": TaxName.THE_00,
166+
"VAT": TaxName.VAT
167+
});
168+
169+
class PriceBasedShippingRate {
170+
int id;
171+
String name;
172+
String price;
173+
int shippingZoneId;
174+
String minOrderSubtotal;
175+
dynamic maxOrderSubtotal;
176+
177+
PriceBasedShippingRate({
178+
required this.id,
179+
required this.name,
180+
required this.price,
181+
required this.shippingZoneId,
182+
required this.minOrderSubtotal,
183+
this.maxOrderSubtotal,
184+
});
185+
186+
factory PriceBasedShippingRate.fromJson(Map<String, dynamic> json) => PriceBasedShippingRate(
187+
id: json["id"],
188+
name: json["name"],
189+
price: json["price"],
190+
shippingZoneId: json["shipping_zone_id"],
191+
minOrderSubtotal: json["min_order_subtotal"],
192+
maxOrderSubtotal: json["max_order_subtotal"],
193+
);
194+
195+
Map<String, dynamic> toJson() => {
196+
"id": id,
197+
"name": name,
198+
"price": price,
199+
"shipping_zone_id": shippingZoneId,
200+
"min_order_subtotal": minOrderSubtotal,
201+
"max_order_subtotal": maxOrderSubtotal,
202+
};
203+
}
204+
205+
class EnumValues<T> {
206+
Map<String, T> map;
207+
late Map<T, String> reverseMap;
208+
209+
EnumValues(this.map);
210+
211+
Map<T, String> get reverse {
212+
reverseMap = map.map((k, v) => MapEntry(v, k));
213+
return reverseMap;
214+
}
215+
}

lib/woosignal_shopify.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import 'package:encrypt/encrypt.dart' as enc;
2626
import 'package:encrypt/encrypt.dart';
2727
import 'dart:convert';
2828

29+
import 'models/response/shipping_zones_response.dart';
30+
2931
/// WooSignal Package version
3032
const String wooSignalVersion = "1.0.0";
3133

@@ -278,5 +280,18 @@ class WooSignal {
278280
jsonResponse: (json) => PoliciesResponse.fromJson(json)
279281
);
280282
}
283+
/// https://woosignal.com/docs/api/1.0/shipping-zones
284+
Future<ShippingZonesResponse?> getShippingZones({String? fields,
285+
}) async {
286+
Map<String, dynamic> payload = {};
287+
if (fields != null) payload["fields"] = fields;
288+
289+
return await _wooSignalRequest<ShippingZonesResponse>(
290+
path: "shipping-zones",
291+
method: "post",
292+
payload: payload,
293+
jsonResponse: (json) => ShippingZonesResponse.fromJson(json)
294+
);
295+
}
281296

282297
}

test/woosignal_woocommerce_api_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import 'package:test/test.dart';
4343
import 'package:woosignal_shopify/models/response/countries_response.dart';
4444
import 'package:woosignal_shopify/models/response/policies_response.dart';
4545
import 'package:woosignal_shopify/models/response/products_response.dart';
46+
import 'package:woosignal_shopify/models/response/shipping_zones_response.dart';
4647
import 'package:woosignal_shopify/models/response/shop_response.dart';
4748
import 'package:woosignal_shopify/woosignal_shopify.dart';
4849

@@ -102,4 +103,17 @@ void main() {
102103
expect(policiesResponse != null, true);
103104
}, tags: ['get-policies']);
104105
}, tags: ['policies-properties']);
106+
107+
/// test for policies retrieval
108+
group('Testing Shopify shipping-zones', () {
109+
test('get shipping-zones', () async {
110+
ShippingZonesResponse? shippingZonesResponse =
111+
await WooSignal.instance.getShippingZones();
112+
113+
expect(shippingZonesResponse is ShippingZonesResponse, true);
114+
115+
expect(shippingZonesResponse != null, true);
116+
}, tags: ['get-shipping-zones']);
117+
}, tags: ['shipping-zones-properties']);
105118
}
119+

0 commit comments

Comments
 (0)