createCoupon method
Creates an coupon and returns the WooCoupon object.
Related endpoint: https://woocommerce.github.io/woocommerce-rest-api-docs/#coupons.
Implementation
Future<WooCoupon> createCoupon({
String? code,
String? discountType,
String? amount,
bool? individualUse,
bool? excludeSaleItems,
String? minimumAmount,
}) async {
Map<String, dynamic> payload = {};
({
'code': code,
'discount_type': discountType,
'amount': amount,
'individual_use': individualUse,
'exclude_sale_items': excludeSaleItems,
'minimum_amount': minimumAmount,
}).forEach((k, v) {
if (v != null) payload[k] = v.toString();
});
WooCoupon coupon;
_setApiResourceUrl(
path: 'coupons',
);
final response = await post(queryUri.toString(), payload);
_printToLog('response gotten : ' + response.toString());
coupon = WooCoupon.fromJson(response);
return coupon;
}