couponApply

This commit is contained in:
2025-02-10 02:37:06 +05:30
parent 630a918307
commit b6ef70cfb6
21 changed files with 3308 additions and 1181 deletions

View File

@@ -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,
};
}