Skip to content

Instantly share code, notes, and snippets.

@pixobe
Created November 29, 2023 07:46
Show Gist options
  • Save pixobe/b7fa028b71537a7ac0be84b735eb5860 to your computer and use it in GitHub Desktop.
Save pixobe/b7fa028b71537a7ac0be84b735eb5860 to your computer and use it in GitHub Desktop.
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