Skip to content

Commit c13e0a9

Browse files
committed
v3.3.5
1 parent 0ff3fd0 commit c13e0a9

File tree

9 files changed

+227
-33
lines changed

9 files changed

+227
-33
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [3.3.5] - 2024-03-15
2+
3+
* Added new networking methods for WooCommerce Points and Rewards
4+
* Dependency updates
5+
16
## [3.3.4] - 2024-01-01
27

38
* Update license date

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ In your flutter project add the dependency:
2828
``` dart
2929
dependencies:
3030
...
31-
wp_json_api: ^3.3.4
31+
wp_json_api: ^3.4.0
3232
```
3333

3434
### Usage example #
@@ -240,6 +240,29 @@ WCCustomerUpdatedResponse wcCustomerUpdatedResponse = await WPJsonAPI.instance
240240
));
241241
```
242242

243+
#### WooCommerce Points and Rewards - Get user's points
244+
- This is used to get the user's current points in the [WooCommerce Points and Rewards](https://woo.com/products/woocommerce-points-and-rewards/) plugin
245+
- The first parameter is the **userToken** which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
246+
247+
``` dart
248+
WcPointsAndRewardUser wcPointsAndRewardUser = await WPJsonAPI.instance
249+
.api((request) => request.wcPointsAndRewardsUser(
250+
userToken
251+
));
252+
```
253+
254+
#### WooCommerce Points and Rewards - Calculate the value of points
255+
- This is used to calculate the value of points in the [WooCommerce Points and Rewards](https://woo.com/products/woocommerce-points-and-rewards/) plugin
256+
- The first parameter is the **userToken** which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
257+
258+
``` dart
259+
WcPointsAndRewardCalculatePoints wcPointsAndRewardsCalculatePoints = await WPJsonAPI.instance
260+
.api((request) => request.wcPointsAndRewardsCalculatePoints(
261+
userToken,
262+
points: 100
263+
));
264+
```
265+
243266
For help getting started with WooSignal, view our
244267
[online documentation](https://woosignal.com/docs/flutter/wp-json-api), which offers a more detailed guide.
245268

example/pubspec.lock

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ packages:
4545
dependency: transitive
4646
description:
4747
name: dio
48-
sha256: "797e1e341c3dd2f69f2dad42564a6feff3bfb87187d05abb93b9609e6f1645c3"
48+
sha256: "49af28382aefc53562459104f64d16b9dfd1e8ef68c862d5af436cc8356ce5a8"
4949
url: "https://pub.dev"
5050
source: hosted
51-
version: "5.4.0"
51+
version: "5.4.1"
5252
fake_async:
5353
dependency: transitive
5454
description:
@@ -75,38 +75,62 @@ packages:
7575
url: "https://pub.dev"
7676
source: hosted
7777
version: "4.0.2"
78+
leak_tracker:
79+
dependency: transitive
80+
description:
81+
name: leak_tracker
82+
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
83+
url: "https://pub.dev"
84+
source: hosted
85+
version: "10.0.0"
86+
leak_tracker_flutter_testing:
87+
dependency: transitive
88+
description:
89+
name: leak_tracker_flutter_testing
90+
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
91+
url: "https://pub.dev"
92+
source: hosted
93+
version: "2.0.1"
94+
leak_tracker_testing:
95+
dependency: transitive
96+
description:
97+
name: leak_tracker_testing
98+
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
99+
url: "https://pub.dev"
100+
source: hosted
101+
version: "2.0.1"
78102
matcher:
79103
dependency: transitive
80104
description:
81105
name: matcher
82-
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
106+
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
83107
url: "https://pub.dev"
84108
source: hosted
85-
version: "0.12.16"
109+
version: "0.12.16+1"
86110
material_color_utilities:
87111
dependency: transitive
88112
description:
89113
name: material_color_utilities
90-
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
114+
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
91115
url: "https://pub.dev"
92116
source: hosted
93-
version: "0.5.0"
117+
version: "0.8.0"
94118
meta:
95119
dependency: transitive
96120
description:
97121
name: meta
98-
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
122+
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
99123
url: "https://pub.dev"
100124
source: hosted
101-
version: "1.10.0"
125+
version: "1.11.0"
102126
path:
103127
dependency: transitive
104128
description:
105129
name: path
106-
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
130+
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
107131
url: "https://pub.dev"
108132
source: hosted
109-
version: "1.8.3"
133+
version: "1.9.0"
110134
sky_engine:
111135
dependency: transitive
112136
description: flutter
@@ -176,14 +200,14 @@ packages:
176200
url: "https://pub.dev"
177201
source: hosted
178202
version: "2.1.4"
179-
web:
203+
vm_service:
180204
dependency: transitive
181205
description:
182-
name: web
183-
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
206+
name: vm_service
207+
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
184208
url: "https://pub.dev"
185209
source: hosted
186-
version: "0.3.0"
210+
version: "13.0.0"
187211
wp_json_api:
188212
dependency: "direct dev"
189213
description:
@@ -192,5 +216,5 @@ packages:
192216
source: path
193217
version: "3.3.4"
194218
sdks:
195-
dart: ">=3.2.0-194.0.dev <4.0.0"
219+
dart: ">=3.2.0-0 <4.0.0"
196220
flutter: ">=1.17.0"

lib/enums/wp_route_type.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,8 @@ enum WPRouteType {
6161
/// Route type [WPRouteType.WCCustomerUpdateInfo] is used to Update WooCommerce details for a customer.
6262
/// For WooCommerce
6363
WCCustomerUpdateInfo,
64+
65+
WCPointsAndRewardsUser,
66+
67+
WCPointsAndRewardsCalculatePoints,
6468
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2024, WooSignal Ltd.
2+
// All rights reserved.
3+
//
4+
// Redistribution and use in source and binary forms are permitted
5+
// provided that the above copyright notice and this paragraph are
6+
// duplicated in all such forms and that any documentation,
7+
// advertising materials, and other materials related to such
8+
// distribution and use acknowledge that the software was developed
9+
// by the WooSignal. The name of the
10+
// WooSignal may not be used to endorse or promote products derived
11+
// from this software without specific prior written permission.
12+
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13+
// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14+
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15+
16+
class WcPointsAndRewardCalculatePoints {
17+
String? value;
18+
19+
WcPointsAndRewardCalculatePoints({this.value});
20+
21+
WcPointsAndRewardCalculatePoints.fromJson(Map<String, dynamic> json) {
22+
value = json['value'];
23+
}
24+
25+
Map<String, dynamic> toJson() {
26+
final Map<String, dynamic> data = new Map<String, dynamic>();
27+
data['value'] = this.value;
28+
return data;
29+
}
30+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2024, WooSignal Ltd.
2+
// All rights reserved.
3+
//
4+
// Redistribution and use in source and binary forms are permitted
5+
// provided that the above copyright notice and this paragraph are
6+
// duplicated in all such forms and that any documentation,
7+
// advertising materials, and other materials related to such
8+
// distribution and use acknowledge that the software was developed
9+
// by the WooSignal. The name of the
10+
// WooSignal may not be used to endorse or promote products derived
11+
// from this software without specific prior written permission.
12+
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13+
// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14+
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15+
16+
class WcPointsAndRewardUser {
17+
int? id;
18+
int? points;
19+
String? value;
20+
21+
WcPointsAndRewardUser({this.id, this.points, this.value});
22+
23+
WcPointsAndRewardUser.fromJson(Map<String, dynamic> json) {
24+
id = json['id'];
25+
points = json['points'];
26+
value = json['value'];
27+
}
28+
29+
Map<String, dynamic> toJson() {
30+
final Map<String, dynamic> data = new Map<String, dynamic>();
31+
data['id'] = this.id;
32+
data['points'] = this.points;
33+
data['value'] = this.value;
34+
return data;
35+
}
36+
}

lib/networking/network_manager.dart

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import 'package:wp_json_api/exceptions/username_taken_exception.dart';
3232
import 'package:wp_json_api/exceptions/woocommerce_not_found_exception.dart';
3333
import 'package:wp_json_api/models/responses/wc_customer_info_response.dart';
3434
import 'package:wp_json_api/models/responses/wc_customer_updated_response.dart';
35+
import 'package:wp_json_api/models/responses/wc_points_and_rewards_calculate_points.dart';
36+
import 'package:wp_json_api/models/responses/wc_points_and_rewards_user.dart';
3537
import 'package:wp_json_api/models/responses/wp_nonce_response.dart';
3638
import 'package:wp_json_api/models/responses/wp_nonce_verified_response.dart';
3739
import 'package:wp_json_api/models/responses/wp_user_add_role_response.dart';
@@ -344,6 +346,44 @@ class WPAppNetworkManager {
344346
: WCCustomerInfoResponse.fromJson(json);
345347
}
346348

349+
/// Get the users points and rewards information using the [userToken].
350+
///
351+
/// Returns a [WcPointsAndRewardUser] future.
352+
/// Throws an [Exception] if fails.
353+
Future<WcPointsAndRewardUser> wcPointsAndRewardsUser(String userToken) async {
354+
// send http request
355+
final json = await _http(
356+
method: "POST",
357+
url: _urlForRouteType(WPRouteType.WCPointsAndRewardsUser),
358+
userToken: userToken,
359+
);
360+
361+
// return response
362+
return _jsonHasBadStatus(json)
363+
? this._throwExceptionForStatusCode(json)
364+
: WcPointsAndRewardUser.fromJson(json['data']);
365+
}
366+
367+
/// Calculate the value of points using the [userToken] and [points].
368+
///
369+
/// Returns a [WcPointsAndRewardCalculatePoints] future.
370+
/// Throws an [Exception] if fails.
371+
Future<WcPointsAndRewardCalculatePoints> wcPointsAndRewardsCalculatePoints(
372+
String userToken,
373+
{required double points}) async {
374+
// send http request
375+
final json = await _http(
376+
method: "POST",
377+
url: _urlForRouteType(WPRouteType.WCPointsAndRewardsCalculatePoints),
378+
userToken: userToken,
379+
body: {"points": points});
380+
381+
// return response
382+
return _jsonHasBadStatus(json)
383+
? this._throwExceptionForStatusCode(json)
384+
: WcPointsAndRewardCalculatePoints.fromJson(json['data']);
385+
}
386+
347387
/// Sends a request to update a users WooCommerce details using
348388
/// a valid [userToken], set optional parameters for updating user.
349389
///
@@ -579,6 +619,14 @@ class WPAppNetworkManager {
579619
{
580620
return "/wpapp/wc/$apiVersion/update/user/info";
581621
}
622+
case WPRouteType.WCPointsAndRewardsUser:
623+
{
624+
return "/wpapp/wc-points-and-rewards/$apiVersion/user";
625+
}
626+
case WPRouteType.WCPointsAndRewardsCalculatePoints:
627+
{
628+
return "/wpapp/wc-points-and-rewards/$apiVersion/calculate_points";
629+
}
582630
default:
583631
{
584632
return "";

0 commit comments

Comments
 (0)