-
-
Save pixobe/b7fa028b71537a7ac0be84b735eb5860 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:dio/dio.dart'; | |
class WooCommerceService { | |
final String baseUrl = 'https://your-woocommerce-site.com/wp-json/wc/v3/'; | |
final String consumerKey = 'your_consumer_key'; | |
final String consumerSecret = 'your_consumer_secret'; | |
Dio dio = Dio(); | |
WooCommerceService() { | |
dio.options.baseUrl = baseUrl; | |
dio.options.headers['Authorization'] = | |
'Basic ' + base64Encode(utf8.encode('$consumerKey:$consumerSecret')); | |
} | |
Future<Response> authenticateUser(String username, String password) async { | |
try { | |
Response response = await dio.post('customers', data: { | |
'username': username, | |
'password': password, | |
}); | |
return response; | |
} catch (error) { | |
print('Error: $error'); | |
throw error; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment