@@ -11,25 +11,39 @@ import 'package:woocommerce_api/query_string.dart';
1111import 'package:http/http.dart' as http;
1212
1313class WooCommerceAPI {
14- var url;
15- var consumerKey;
16- var consumerSecret;
14+ String url;
15+ String consumerKey;
16+ String consumerSecret;
17+ bool isHttps;
1718
1819 WooCommerceAPI (url, consumerKey, consumerSecret){
1920 this .url = url;
2021 this .consumerKey = consumerKey;
2122 this .consumerSecret = consumerSecret;
23+
24+ if (this .url.startsWith ("https" )){
25+ this .isHttps = true ;
26+ } else {
27+ this .isHttps = false ;
28+ }
29+
2230 }
2331
2432
2533 _getOAuthURL (String request_method, String endpoint) {
2634 var consumerKey = this .consumerKey; //"ck_4e943ec0f3c76eba33fffac4b7fc0d2f1f3ca91a";
2735 var consumerSecret = this .consumerSecret; //"cs_fbb723138e354e30c3d4d4e0c0f95389bf610044";
36+
2837 var token = "" ;
2938 var token_secret = "" ;
3039 var url = this .url + "/wp-json/wc/v2/" + endpoint;
3140 var containsQueryParams = url.contains ("?" );
3241
42+ // If website is HTTPS based, no need for OAuth, just return the URL with CS and CK as query params
43+ if (this .isHttps == true ){
44+ return url + (containsQueryParams == true ? "&consumerKey=" + this .consumerKey + "&consumerSecret=" + this .consumerSecret : "?consumerKey=" + this .consumerKey + "&consumerSecret=" + this .consumerSecret);
45+ }
46+
3347 var rand = new Random ();
3448 var codeUnits = new List .generate (10 , (index) {
3549 return rand.nextInt (26 ) + 97 ;
@@ -129,7 +143,9 @@ class WooCommerceAPI {
129143
130144 var url = this ._getOAuthURL ("GET" , endPoint);
131145
132- return http.get (url);
146+ final response = await http.get (url);
147+
148+ return json.decode (response.body);
133149
134150 }
135151
0 commit comments