|
1 | 1 | class CountriesResponse { |
2 | | - Shop? shop; |
| 2 | + List<Country>? countries; |
3 | 3 |
|
4 | 4 | CountriesResponse({ |
5 | | - this.shop, |
| 5 | + this.countries, |
6 | 6 | }); |
7 | 7 |
|
8 | 8 | factory CountriesResponse.fromJson(Map<String, dynamic> json) => CountriesResponse( |
9 | | - shop: json["shop"] == null ? null : Shop.fromJson(json["shop"]), |
| 9 | + countries: json["countries"] == null ? [] : List<Country>.from(json["countries"]!.map((x) => Country.fromJson(x))), |
10 | 10 | ); |
11 | 11 |
|
12 | 12 | Map<String, dynamic> toJson() => { |
13 | | - "shop": shop?.toJson(), |
| 13 | + "countries": countries == null ? [] : List<dynamic>.from(countries!.map((x) => x.toJson())), |
14 | 14 | }; |
15 | 15 | } |
16 | 16 |
|
17 | | -class Shop { |
| 17 | +class Country { |
18 | 18 | int? id; |
19 | 19 | String? name; |
20 | | - String? email; |
21 | | - String? domain; |
22 | | - String? province; |
23 | | - String? country; |
24 | | - String? address1; |
25 | | - String? zip; |
26 | | - String? city; |
27 | | - dynamic source; |
28 | | - String? phone; |
29 | | - double? latitude; |
30 | | - double? longitude; |
31 | | - String? primaryLocale; |
32 | | - String? address2; |
33 | | - DateTime? createdAt; |
34 | | - DateTime? updatedAt; |
35 | | - String? countryCode; |
36 | | - String? countryName; |
37 | | - String? currency; |
38 | | - String? customerEmail; |
39 | | - String? timezone; |
40 | | - String? ianaTimezone; |
41 | | - String? shopOwner; |
42 | | - String? moneyFormat; |
43 | | - String? moneyWithCurrencyFormat; |
44 | | - String? weightUnit; |
45 | | - String? provinceCode; |
46 | | - bool? taxesIncluded; |
47 | | - dynamic autoConfigureTaxInclusivity; |
48 | | - dynamic taxShipping; |
49 | | - bool? countyTaxes; |
50 | | - String? planDisplayName; |
51 | | - String? planName; |
52 | | - bool? hasDiscounts; |
53 | | - bool? hasGiftCards; |
54 | | - String? myshopifyDomain; |
55 | | - dynamic googleAppsDomain; |
56 | | - dynamic googleAppsLoginEnabled; |
57 | | - String? moneyInEmailsFormat; |
58 | | - String? moneyWithCurrencyInEmailsFormat; |
59 | | - bool? eligibleForPayments; |
60 | | - bool? requiresExtraPaymentsAgreement; |
61 | | - bool? passwordEnabled; |
62 | | - bool? hasStorefront; |
63 | | - bool? finances; |
64 | | - int? primaryLocationId; |
65 | | - String? cookieConsentLevel; |
66 | | - bool? checkoutApiSupported; |
67 | | - bool? multiLocationEnabled; |
68 | | - bool? setupRequired; |
69 | | - bool? preLaunchEnabled; |
70 | | - List<String>? enabledPresentmentCurrencies; |
71 | | - bool? transactionalSmsDisabled; |
72 | | - bool? marketingSmsConsentEnabledAtCheckout; |
73 | | - |
74 | | - Shop({ |
| 20 | + String? code; |
| 21 | + String? taxName; |
| 22 | + int? tax; |
| 23 | + List<Province>? provinces; |
| 24 | + |
| 25 | + Country({ |
75 | 26 | this.id, |
76 | 27 | this.name, |
77 | | - this.email, |
78 | | - this.domain, |
79 | | - this.province, |
80 | | - this.country, |
81 | | - this.address1, |
82 | | - this.zip, |
83 | | - this.city, |
84 | | - this.source, |
85 | | - this.phone, |
86 | | - this.latitude, |
87 | | - this.longitude, |
88 | | - this.primaryLocale, |
89 | | - this.address2, |
90 | | - this.createdAt, |
91 | | - this.updatedAt, |
92 | | - this.countryCode, |
93 | | - this.countryName, |
94 | | - this.currency, |
95 | | - this.customerEmail, |
96 | | - this.timezone, |
97 | | - this.ianaTimezone, |
98 | | - this.shopOwner, |
99 | | - this.moneyFormat, |
100 | | - this.moneyWithCurrencyFormat, |
101 | | - this.weightUnit, |
102 | | - this.provinceCode, |
103 | | - this.taxesIncluded, |
104 | | - this.autoConfigureTaxInclusivity, |
105 | | - this.taxShipping, |
106 | | - this.countyTaxes, |
107 | | - this.planDisplayName, |
108 | | - this.planName, |
109 | | - this.hasDiscounts, |
110 | | - this.hasGiftCards, |
111 | | - this.myshopifyDomain, |
112 | | - this.googleAppsDomain, |
113 | | - this.googleAppsLoginEnabled, |
114 | | - this.moneyInEmailsFormat, |
115 | | - this.moneyWithCurrencyInEmailsFormat, |
116 | | - this.eligibleForPayments, |
117 | | - this.requiresExtraPaymentsAgreement, |
118 | | - this.passwordEnabled, |
119 | | - this.hasStorefront, |
120 | | - this.finances, |
121 | | - this.primaryLocationId, |
122 | | - this.cookieConsentLevel, |
123 | | - this.checkoutApiSupported, |
124 | | - this.multiLocationEnabled, |
125 | | - this.setupRequired, |
126 | | - this.preLaunchEnabled, |
127 | | - this.enabledPresentmentCurrencies, |
128 | | - this.transactionalSmsDisabled, |
129 | | - this.marketingSmsConsentEnabledAtCheckout, |
| 28 | + this.code, |
| 29 | + this.taxName, |
| 30 | + this.tax, |
| 31 | + this.provinces, |
130 | 32 | }); |
131 | 33 |
|
132 | | - factory Shop.fromJson(Map<String, dynamic> json) => Shop( |
| 34 | + factory Country.fromJson(Map<String, dynamic> json) => Country( |
133 | 35 | id: json["id"], |
134 | 36 | name: json["name"], |
135 | | - email: json["email"], |
136 | | - domain: json["domain"], |
137 | | - province: json["province"], |
138 | | - country: json["country"], |
139 | | - address1: json["address1"], |
140 | | - zip: json["zip"], |
141 | | - city: json["city"], |
142 | | - source: json["source"], |
143 | | - phone: json["phone"], |
144 | | - latitude: json["latitude"]?.toDouble(), |
145 | | - longitude: json["longitude"]?.toDouble(), |
146 | | - primaryLocale: json["primary_locale"], |
147 | | - address2: json["address2"], |
148 | | - createdAt: json["created_at"] == null ? null : DateTime.parse(json["created_at"]), |
149 | | - updatedAt: json["updated_at"] == null ? null : DateTime.parse(json["updated_at"]), |
150 | | - countryCode: json["country_code"], |
151 | | - countryName: json["country_name"], |
152 | | - currency: json["currency"], |
153 | | - customerEmail: json["customer_email"], |
154 | | - timezone: json["timezone"], |
155 | | - ianaTimezone: json["iana_timezone"], |
156 | | - shopOwner: json["shop_owner"], |
157 | | - moneyFormat: json["money_format"], |
158 | | - moneyWithCurrencyFormat: json["money_with_currency_format"], |
159 | | - weightUnit: json["weight_unit"], |
160 | | - provinceCode: json["province_code"], |
161 | | - taxesIncluded: json["taxes_included"], |
162 | | - autoConfigureTaxInclusivity: json["auto_configure_tax_inclusivity"], |
163 | | - taxShipping: json["tax_shipping"], |
164 | | - countyTaxes: json["county_taxes"], |
165 | | - planDisplayName: json["plan_display_name"], |
166 | | - planName: json["plan_name"], |
167 | | - hasDiscounts: json["has_discounts"], |
168 | | - hasGiftCards: json["has_gift_cards"], |
169 | | - myshopifyDomain: json["myshopify_domain"], |
170 | | - googleAppsDomain: json["google_apps_domain"], |
171 | | - googleAppsLoginEnabled: json["google_apps_login_enabled"], |
172 | | - moneyInEmailsFormat: json["money_in_emails_format"], |
173 | | - moneyWithCurrencyInEmailsFormat: json["money_with_currency_in_emails_format"], |
174 | | - eligibleForPayments: json["eligible_for_payments"], |
175 | | - requiresExtraPaymentsAgreement: json["requires_extra_payments_agreement"], |
176 | | - passwordEnabled: json["password_enabled"], |
177 | | - hasStorefront: json["has_storefront"], |
178 | | - finances: json["finances"], |
179 | | - primaryLocationId: json["primary_location_id"], |
180 | | - cookieConsentLevel: json["cookie_consent_level"], |
181 | | - checkoutApiSupported: json["checkout_api_supported"], |
182 | | - multiLocationEnabled: json["multi_location_enabled"], |
183 | | - setupRequired: json["setup_required"], |
184 | | - preLaunchEnabled: json["pre_launch_enabled"], |
185 | | - enabledPresentmentCurrencies: json["enabled_presentment_currencies"] == null ? [] : List<String>.from(json["enabled_presentment_currencies"]!.map((x) => x)), |
186 | | - transactionalSmsDisabled: json["transactional_sms_disabled"], |
187 | | - marketingSmsConsentEnabledAtCheckout: json["marketing_sms_consent_enabled_at_checkout"], |
| 37 | + code: json["code"], |
| 38 | + taxName: json["tax_name"], |
| 39 | + tax: json["tax"], |
| 40 | + provinces: json["provinces"] == null ? [] : List<Province>.from(json["provinces"]!.map((x) => Province.fromJson(x))), |
188 | 41 | ); |
189 | 42 |
|
190 | 43 | Map<String, dynamic> toJson() => { |
191 | 44 | "id": id, |
192 | 45 | "name": name, |
193 | | - "email": email, |
194 | | - "domain": domain, |
195 | | - "province": province, |
196 | | - "country": country, |
197 | | - "address1": address1, |
198 | | - "zip": zip, |
199 | | - "city": city, |
200 | | - "source": source, |
201 | | - "phone": phone, |
202 | | - "latitude": latitude, |
203 | | - "longitude": longitude, |
204 | | - "primary_locale": primaryLocale, |
205 | | - "address2": address2, |
206 | | - "created_at": createdAt?.toIso8601String(), |
207 | | - "updated_at": updatedAt?.toIso8601String(), |
208 | | - "country_code": countryCode, |
209 | | - "country_name": countryName, |
210 | | - "currency": currency, |
211 | | - "customer_email": customerEmail, |
212 | | - "timezone": timezone, |
213 | | - "iana_timezone": ianaTimezone, |
214 | | - "shop_owner": shopOwner, |
215 | | - "money_format": moneyFormat, |
216 | | - "money_with_currency_format": moneyWithCurrencyFormat, |
217 | | - "weight_unit": weightUnit, |
218 | | - "province_code": provinceCode, |
219 | | - "taxes_included": taxesIncluded, |
220 | | - "auto_configure_tax_inclusivity": autoConfigureTaxInclusivity, |
221 | | - "tax_shipping": taxShipping, |
222 | | - "county_taxes": countyTaxes, |
223 | | - "plan_display_name": planDisplayName, |
224 | | - "plan_name": planName, |
225 | | - "has_discounts": hasDiscounts, |
226 | | - "has_gift_cards": hasGiftCards, |
227 | | - "myshopify_domain": myshopifyDomain, |
228 | | - "google_apps_domain": googleAppsDomain, |
229 | | - "google_apps_login_enabled": googleAppsLoginEnabled, |
230 | | - "money_in_emails_format": moneyInEmailsFormat, |
231 | | - "money_with_currency_in_emails_format": moneyWithCurrencyInEmailsFormat, |
232 | | - "eligible_for_payments": eligibleForPayments, |
233 | | - "requires_extra_payments_agreement": requiresExtraPaymentsAgreement, |
234 | | - "password_enabled": passwordEnabled, |
235 | | - "has_storefront": hasStorefront, |
236 | | - "finances": finances, |
237 | | - "primary_location_id": primaryLocationId, |
238 | | - "cookie_consent_level": cookieConsentLevel, |
239 | | - "checkout_api_supported": checkoutApiSupported, |
240 | | - "multi_location_enabled": multiLocationEnabled, |
241 | | - "setup_required": setupRequired, |
242 | | - "pre_launch_enabled": preLaunchEnabled, |
243 | | - "enabled_presentment_currencies": enabledPresentmentCurrencies == null ? [] : List<dynamic>.from(enabledPresentmentCurrencies!.map((x) => x)), |
244 | | - "transactional_sms_disabled": transactionalSmsDisabled, |
245 | | - "marketing_sms_consent_enabled_at_checkout": marketingSmsConsentEnabledAtCheckout, |
| 46 | + "code": code, |
| 47 | + "tax_name": taxName, |
| 48 | + "tax": tax, |
| 49 | + "provinces": provinces == null ? [] : List<dynamic>.from(provinces!.map((x) => x.toJson())), |
246 | 50 | }; |
247 | 51 | } |
| 52 | + |
| 53 | +class Province { |
| 54 | + int? id; |
| 55 | + int? countryId; |
| 56 | + String? name; |
| 57 | + String? code; |
| 58 | + TaxName? taxName; |
| 59 | + String? taxType; |
| 60 | + dynamic shippingZoneId; |
| 61 | + int? tax; |
| 62 | + int? taxPercentage; |
| 63 | + |
| 64 | + Province({ |
| 65 | + this.id, |
| 66 | + this.countryId, |
| 67 | + this.name, |
| 68 | + this.code, |
| 69 | + this.taxName, |
| 70 | + this.taxType, |
| 71 | + this.shippingZoneId, |
| 72 | + this.tax, |
| 73 | + this.taxPercentage, |
| 74 | + }); |
| 75 | + |
| 76 | + factory Province.fromJson(Map<String, dynamic> json) => Province( |
| 77 | + id: json["id"], |
| 78 | + countryId: json["country_id"], |
| 79 | + name: json["name"], |
| 80 | + code: json["code"], |
| 81 | + taxName: taxNameValues.map[json["tax_name"]]!, |
| 82 | + taxType: json["tax_type"], |
| 83 | + shippingZoneId: json["shipping_zone_id"], |
| 84 | + tax: json["tax"], |
| 85 | + taxPercentage: json["tax_percentage"], |
| 86 | + ); |
| 87 | + |
| 88 | + Map<String, dynamic> toJson() => { |
| 89 | + "id": id, |
| 90 | + "country_id": countryId, |
| 91 | + "name": name, |
| 92 | + "code": code, |
| 93 | + "tax_name": taxNameValues.reverse[taxName], |
| 94 | + "tax_type": taxType, |
| 95 | + "shipping_zone_id": shippingZoneId, |
| 96 | + "tax": tax, |
| 97 | + "tax_percentage": taxPercentage, |
| 98 | + }; |
| 99 | +} |
| 100 | + |
| 101 | +enum TaxName { |
| 102 | + GRT, |
| 103 | + GST, |
| 104 | + HST, |
| 105 | + PST, |
| 106 | + QST, |
| 107 | + RST, |
| 108 | + SST, |
| 109 | + STATE_TAX, |
| 110 | + TAX, |
| 111 | + THE_00, |
| 112 | + VAT |
| 113 | +} |
| 114 | + |
| 115 | +final taxNameValues = EnumValues({ |
| 116 | + "GRT": TaxName.GRT, |
| 117 | + "GST": TaxName.GST, |
| 118 | + "HST": TaxName.HST, |
| 119 | + "PST": TaxName.PST, |
| 120 | + "QST": TaxName.QST, |
| 121 | + "RST": TaxName.RST, |
| 122 | + "SST": TaxName.SST, |
| 123 | + "State Tax": TaxName.STATE_TAX, |
| 124 | + "Tax": TaxName.TAX, |
| 125 | + "0.0": TaxName.THE_00, |
| 126 | + "VAT": TaxName.VAT |
| 127 | +}); |
| 128 | + |
| 129 | +class EnumValues<T> { |
| 130 | + Map<String, T> map; |
| 131 | + late Map<T, String> reverseMap; |
| 132 | + |
| 133 | + EnumValues(this.map); |
| 134 | + |
| 135 | + Map<T, String> get reverse { |
| 136 | + reverseMap = map.map((k, v) => MapEntry(v, k)); |
| 137 | + return reverseMap; |
| 138 | + } |
| 139 | +} |
0 commit comments