couponApply
This commit is contained in:
@@ -7,6 +7,8 @@ import 'package:grocery_app/src/core/network_services/service_locator.dart';
|
||||
import 'package:grocery_app/src/core/routes/routes.dart';
|
||||
import 'package:grocery_app/src/data/address.dart';
|
||||
import 'package:grocery_app/src/data/all_cart_items.dart';
|
||||
import 'package:grocery_app/src/data/coupon_model.dart';
|
||||
import 'package:grocery_app/src/data/coupon_response.dart';
|
||||
import 'package:grocery_app/src/logic/repo/product_repo.dart';
|
||||
import 'package:grocery_app/src/ui/payment/payment_webView.dart';
|
||||
import 'package:grocery_app/utils/extensions/extensions.dart';
|
||||
@@ -125,6 +127,16 @@ class AddtocartProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
double _totalPrice = 0.0;
|
||||
double _grandPrice = 0.0;
|
||||
double _discount = 0.0;
|
||||
|
||||
double get totalPrice => _totalPrice;
|
||||
|
||||
double get grandPrice => _grandPrice;
|
||||
|
||||
double get discount => _discount;
|
||||
|
||||
final _homeRepo = getIt<ProductRepo>();
|
||||
|
||||
AllCartItems allitem = AllCartItems();
|
||||
@@ -144,6 +156,9 @@ class AddtocartProvider extends ChangeNotifier {
|
||||
},
|
||||
(response) {
|
||||
allitem = response!;
|
||||
_totalPrice = double.parse(response.subtotal.toString());
|
||||
_grandPrice = double.parse(response.subtotal.toString());
|
||||
|
||||
isLoaddcartItem = false;
|
||||
notifyListeners();
|
||||
},
|
||||
@@ -154,36 +169,118 @@ class AddtocartProvider extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
//////////////////////////////////// coupon ////////////////////////////
|
||||
|
||||
bool iscouponLoading = true;
|
||||
|
||||
CouponDataModel couponDataModel = CouponDataModel();
|
||||
Future<void> offerCoupon(BuildContext context) async {
|
||||
iscouponLoading = true;
|
||||
notifyListeners();
|
||||
var data = {};
|
||||
try {
|
||||
var result = await _homeRepo.offerCoupon(data);
|
||||
|
||||
return result.fold(
|
||||
(error) {
|
||||
iscouponLoading = false;
|
||||
notifyListeners();
|
||||
},
|
||||
(response) {
|
||||
couponDataModel = response!;
|
||||
iscouponLoading = false;
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
iscouponLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
bool isCouponApply = false;
|
||||
CouponResponse couponResponse = CouponResponse();
|
||||
|
||||
String _couponId = '';
|
||||
String get couponId => _couponId;
|
||||
|
||||
Future<bool> applyCoupon(
|
||||
BuildContext context, String cartId, String couponscode, id) async {
|
||||
context.showLoader(show: true);
|
||||
isCouponApply = true;
|
||||
|
||||
notifyListeners();
|
||||
|
||||
var data = {"couponCode": couponscode, "cartId": cartId};
|
||||
try {
|
||||
var result = await _homeRepo.applyCoupon(data);
|
||||
|
||||
return result.fold(
|
||||
(error) {
|
||||
context.showLoader(show: false);
|
||||
isCouponApply = false;
|
||||
Fluttertoast.showToast(
|
||||
msg: "Coupon Code invalid!",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
backgroundColor: Colors.red,
|
||||
textColor: Colors.white,
|
||||
fontSize: 14.0,
|
||||
);
|
||||
notifyListeners();
|
||||
return false;
|
||||
},
|
||||
(response) {
|
||||
if (response != null) {
|
||||
couponResponse = response;
|
||||
_couponId = id;
|
||||
_grandPrice = double.parse(response.finalPrice.toString());
|
||||
_discount = double.parse(response.discountAmount.toString());
|
||||
context.showLoader(show: false);
|
||||
isCouponApply = false;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
context.showLoader(show: false);
|
||||
isCouponApply = false;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
context.showLoader(show: false);
|
||||
Fluttertoast.showToast(
|
||||
msg: "Coupon Code invalid!",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
backgroundColor: Colors.red,
|
||||
textColor: Colors.white,
|
||||
fontSize: 14.0,
|
||||
);
|
||||
isCouponApply = false;
|
||||
notifyListeners();
|
||||
return false; // Return false on exception
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////orderPaymnet///////////////////////////
|
||||
bool ispaymentLoader = false;
|
||||
Future<void> orderPaymnet(
|
||||
BuildContext context,
|
||||
double amount,
|
||||
String currency,
|
||||
double originalAmount,
|
||||
String name,
|
||||
String phone,
|
||||
String email,
|
||||
String userI,
|
||||
String cartId,
|
||||
String addressId,
|
||||
String remarks,
|
||||
String couponId,
|
||||
) async {
|
||||
ispaymentLoader = true;
|
||||
notifyListeners();
|
||||
|
||||
var data = {
|
||||
"amount": amount,
|
||||
"currency": currency,
|
||||
"originalAmount": amount,
|
||||
"name": name,
|
||||
"phone": phone,
|
||||
"email": email,
|
||||
"userId": userI,
|
||||
"cartId": cartId,
|
||||
"amount": originalAmount,
|
||||
"addressId": addressId,
|
||||
"remarks": remarks
|
||||
"cartId": cartId,
|
||||
"couponId": couponId
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -221,16 +318,13 @@ class AddtocartProvider extends ChangeNotifier {
|
||||
BuildContext context,
|
||||
double subtotal,
|
||||
double deliverCharge,
|
||||
double discountPrice,
|
||||
double grandTotal,
|
||||
String couponId,
|
||||
String addressId,
|
||||
) async {
|
||||
print("sdkjfhgkjdfhgjkldfkjghkdf");
|
||||
ispaymentLoader = true;
|
||||
notifyListeners();
|
||||
var data;
|
||||
if (couponId != '00') {
|
||||
if (couponId.isNotEmpty) {
|
||||
data = {
|
||||
"addressId": addressId,
|
||||
"paymentMethod": "COD",
|
||||
@@ -238,12 +332,10 @@ class AddtocartProvider extends ChangeNotifier {
|
||||
"orderStatus": "PENDING",
|
||||
"subtotal": subtotal,
|
||||
"deliveryCharge": deliverCharge,
|
||||
"discount": discountPrice,
|
||||
"grandTotal": grandTotal,
|
||||
"transactionId": "phonepe_transaction_123",
|
||||
"couponId": couponId
|
||||
};
|
||||
} else {
|
||||
print("skfdjdsjfg");
|
||||
data = {
|
||||
"addressId": addressId,
|
||||
"paymentMethod": "COD",
|
||||
@@ -251,8 +343,6 @@ class AddtocartProvider extends ChangeNotifier {
|
||||
"orderStatus": "PENDING",
|
||||
"subtotal": subtotal,
|
||||
"deliveryCharge": deliverCharge,
|
||||
"discount": discountPrice,
|
||||
"grandTotal": grandTotal,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -254,15 +254,16 @@ class ProductProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
void toggleWishlist1(String productId) {
|
||||
for (var product in products) {
|
||||
if (product.id == productId) {
|
||||
product.isInWishlist = !product.isInWishlist; // Toggle value
|
||||
notifyListeners(); // Refresh UI
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// void toggleWishlist1(String productId)
|
||||
// {
|
||||
// for (var product in products) {
|
||||
// if (product.id == productId) {
|
||||
// product.isInWishlist = !product.isInWishlist; // Toggle value
|
||||
// notifyListeners(); // Refresh UI
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// Future<bool> addToCart(BuildContext context, String productId) async
|
||||
// {
|
||||
|
||||
@@ -13,6 +13,8 @@ import 'package:grocery_app/src/data/banners.dart';
|
||||
import 'package:grocery_app/src/data/best_dealProduct.dart';
|
||||
import 'package:grocery_app/src/data/check_pin_response.dart';
|
||||
import 'package:grocery_app/src/data/cod_order_response.dart';
|
||||
import 'package:grocery_app/src/data/coupon_model.dart';
|
||||
import 'package:grocery_app/src/data/coupon_response.dart';
|
||||
import 'package:grocery_app/src/data/login_response.dart';
|
||||
import 'package:grocery_app/src/data/order_paymnet.dart';
|
||||
import 'package:grocery_app/src/data/product_category.dart';
|
||||
@@ -53,7 +55,7 @@ class ProductRepo {
|
||||
var response = await _productService.getProductDetails(data, id);
|
||||
|
||||
ProductDetailsData loginResponse =
|
||||
productDetailsdataFromJson(response.toString());
|
||||
productDetailsDataFromJson(response.toString());
|
||||
|
||||
final String model = response.toString();
|
||||
|
||||
@@ -102,7 +104,7 @@ class ProductRepo {
|
||||
try {
|
||||
var response = await _productService.paymentOrder(data);
|
||||
print("kjdfglkjfdgjklfgkldj${data} ${response} ");
|
||||
|
||||
|
||||
OrderPaymnet productCategory = orderPaymnetFromJson(response.toString());
|
||||
|
||||
print("lkjdflkjfhgdkhfgkd ");
|
||||
@@ -115,13 +117,11 @@ class ProductRepo {
|
||||
}
|
||||
}
|
||||
|
||||
FutureResult<CodOrderResponse> paymentCODOrder(data) async {
|
||||
FutureResult<CodOrderResponse> paymentCODOrder(data) async {
|
||||
try {
|
||||
|
||||
var response = await _productService.paymentCODOrder(data);
|
||||
CodOrderResponse productCategory = codOrderResponseFromJson(response.toString());
|
||||
|
||||
|
||||
CodOrderResponse productCategory =
|
||||
codOrderResponseFromJson(response.toString());
|
||||
|
||||
return right(productCategory);
|
||||
} on DioException catch (e) {
|
||||
@@ -130,11 +130,6 @@ class ProductRepo {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
FutureResult<List<Product>> similarProduct(
|
||||
data, BuildContext context, id) async {
|
||||
try {
|
||||
@@ -165,6 +160,34 @@ class ProductRepo {
|
||||
}
|
||||
}
|
||||
|
||||
FutureResult<CouponDataModel> offerCoupon(data) async {
|
||||
try {
|
||||
var response = await _productService.offerCoupon(data);
|
||||
|
||||
CouponDataModel couponmodel = couponDataFromJson(response.toString());
|
||||
return right(couponmodel);
|
||||
} on DioException catch (e) {
|
||||
var error = CustomDioExceptions.handleError(e);
|
||||
return left(error);
|
||||
}
|
||||
}
|
||||
|
||||
FutureResult<CouponResponse> applyCoupon(data) async {
|
||||
try {
|
||||
var response = await _productService.applyCoupon(data);
|
||||
|
||||
CouponResponse couponresponse = couponResponseFromJson(response.toString());
|
||||
return right(couponresponse);
|
||||
} on DioException catch (e) {
|
||||
var error = CustomDioExceptions.handleError(e);
|
||||
return left(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
FutureResult<AddressResponse> getAddress(data) async {
|
||||
try {
|
||||
var response = await _productService.getAddress(data);
|
||||
|
||||
@@ -80,6 +80,22 @@ class ProductService extends ApiService {
|
||||
|
||||
return response;
|
||||
}
|
||||
Future offerCoupon(data) async {
|
||||
var response = await api.get(APIURL.offerCoupon, data: jsonEncode(data));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Future applyCoupon(data) async {
|
||||
var response = await api.post(APIURL.applyCoupon, data: jsonEncode(data));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Future checkPin(data, pin) async {
|
||||
var response = await api.get(APIURL.checkPin + pin, data: jsonEncode(data));
|
||||
|
||||
Reference in New Issue
Block a user