payment handler
This commit is contained in:
@@ -992,7 +992,7 @@
|
||||
"languageVersion": "3.4"
|
||||
}
|
||||
],
|
||||
"generated": "2025-02-03T12:46:17.320058Z",
|
||||
"generated": "2025-02-03T13:28:33.681422Z",
|
||||
"generator": "pub",
|
||||
"generatorVersion": "3.4.4",
|
||||
"flutterRoot": "file:///Users/rajeevsingh/Documents/allSoftwares/flutter",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -7,7 +7,6 @@ import 'package:grocery_app/utils/constants/shared_pref_utils.dart';
|
||||
import 'package:grocery_app/utils/extensions/common_utils.dart';
|
||||
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
||||
|
||||
|
||||
/// Dio class wrapper for sending api request to the network
|
||||
class DioClient {
|
||||
final Dio _dio;
|
||||
@@ -178,8 +177,7 @@ class DioClient {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<Response> uploadImage(String url, File imageFile,
|
||||
Future<Response> uploadImage(String url, File imageFile,
|
||||
{Map<String, dynamic>? additionalFields,
|
||||
Options? options,
|
||||
CancelToken? cancelToken,
|
||||
@@ -195,7 +193,8 @@ Future<Response> uploadImage(String url, File imageFile,
|
||||
try {
|
||||
String fileName = imageFile.path.split('/').last;
|
||||
FormData formData = FormData.fromMap({
|
||||
"image": await MultipartFile.fromFile(imageFile.path, filename: fileName),
|
||||
"image":
|
||||
await MultipartFile.fromFile(imageFile.path, filename: fileName),
|
||||
...?additionalFields,
|
||||
});
|
||||
|
||||
@@ -215,5 +214,4 @@ Future<Response> uploadImage(String url, File imageFile,
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -153,8 +153,9 @@ class AddtocartProvider extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
///////////////////////////////////orderPaymnet///////////////////////////
|
||||
|
||||
///////////////////////////////////orderPaymnet///////////////////////////
|
||||
bool ispaymentLoader = false;
|
||||
Future<void> orderPaymnet(
|
||||
BuildContext context,
|
||||
double amount,
|
||||
@@ -168,41 +169,49 @@ class AddtocartProvider extends ChangeNotifier {
|
||||
String addressId,
|
||||
String remarks,
|
||||
) async {
|
||||
ispaymentLoader = true;
|
||||
notifyListeners();
|
||||
|
||||
var data = {
|
||||
{
|
||||
"amount": amount,
|
||||
"currency": currency,
|
||||
"originalAmount": amount,
|
||||
"name": name,
|
||||
"phone": phone,
|
||||
"email": email,
|
||||
"userId": userI,
|
||||
"cartId": cartId,
|
||||
"addressId": addressId,
|
||||
"remarks": remarks
|
||||
}
|
||||
"amount": amount,
|
||||
"currency": currency,
|
||||
"originalAmount": amount,
|
||||
"name": name,
|
||||
"phone": phone,
|
||||
"email": email,
|
||||
"userId": userI,
|
||||
"cartId": cartId,
|
||||
"addressId": addressId,
|
||||
"remarks": remarks
|
||||
};
|
||||
|
||||
print("kjdfhgkj ${data}");
|
||||
|
||||
|
||||
try {
|
||||
var result = await _homeRepo.paymentOrder(data);
|
||||
return result.fold(
|
||||
(error) {
|
||||
ispaymentLoader = false;
|
||||
notifyListeners();
|
||||
},
|
||||
(response) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PaymentWebView(paymentUrl: ''),
|
||||
),
|
||||
);
|
||||
if (response.data!.instrumentResponse!.redirectInfo != null &&
|
||||
response.data!.instrumentResponse!.redirectInfo != '') {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PaymentWebView(
|
||||
paymentUrl:
|
||||
response.data!.instrumentResponse!.redirectInfo!.url),
|
||||
),
|
||||
);
|
||||
}
|
||||
ispaymentLoader = false;
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
ispaymentLoader = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ 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/login_response.dart';
|
||||
import 'package:grocery_app/src/data/order_paymnet.dart';
|
||||
import 'package:grocery_app/src/data/product_category.dart';
|
||||
import 'package:grocery_app/src/data/product_details.dart';
|
||||
import 'package:grocery_app/src/data/upload_image.dart';
|
||||
@@ -91,33 +92,28 @@ class ProductRepo {
|
||||
|
||||
return right(productCategory);
|
||||
} on DioException catch (e) {
|
||||
|
||||
var error = CustomDioExceptions.handleError(e);
|
||||
return left(error);
|
||||
}
|
||||
}
|
||||
|
||||
FutureResult<ProductCategory> paymentOrder(
|
||||
data) async
|
||||
{
|
||||
FutureResult<OrderPaymnet> paymentOrder(data) async {
|
||||
try {
|
||||
var response = await _productService.paymentOrder(data);
|
||||
print("kjdfglkjfdgjklfgkldj${data} ${response} ");
|
||||
|
||||
OrderPaymnet productCategory = orderPaymnetFromJson(response.toString());
|
||||
|
||||
ProductCategory productCategory = productCategoryFromJson(response.toString());
|
||||
|
||||
print("lkjdflkjfhgdkhfgkd ");
|
||||
// final String model = response.toString();
|
||||
|
||||
return right(productCategory);
|
||||
} on DioException catch (e) {
|
||||
|
||||
var error = CustomDioExceptions.handleError(e);
|
||||
return left(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FutureResult<List<Product>> similarProduct(
|
||||
data, BuildContext context, id) async {
|
||||
try {
|
||||
@@ -176,33 +172,30 @@ class ProductRepo {
|
||||
return left(error);
|
||||
}
|
||||
}
|
||||
FutureResult<String> updateProfile(data) async {
|
||||
|
||||
FutureResult<String> updateProfile(data) async {
|
||||
try {
|
||||
var response = await _productService.updateProfile(data);
|
||||
|
||||
print("kdjfgkljfdkjlghflkgjh ${response}");
|
||||
final String model = response.toString();
|
||||
return right(model);
|
||||
final String model = response.toString();
|
||||
return right(model);
|
||||
} on DioException catch (e) {
|
||||
var error = CustomDioExceptions.handleError(e);
|
||||
return left(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
FutureResult<UploadImage> uploadImage(File imageFile)
|
||||
async {
|
||||
FutureResult<UploadImage> uploadImage(File imageFile) async {
|
||||
try {
|
||||
final response = await _productService.uploadImage(imageFile);
|
||||
UploadImage upload=uploadImageFromJson(response.toString());
|
||||
UploadImage upload = uploadImageFromJson(response.toString());
|
||||
return right(upload);
|
||||
} on DioException catch (e) {
|
||||
final error = CustomDioExceptions.handleError(e);
|
||||
return left(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FutureResult<CheckPinResponse> checkPin(data, pin) async {
|
||||
try {
|
||||
@@ -270,7 +263,8 @@ FutureResult<String> updateProfile(data) async {
|
||||
return left(error);
|
||||
}
|
||||
}
|
||||
FutureResult<String> decreaseQuantity(data) async {
|
||||
|
||||
FutureResult<String> decreaseQuantity(data) async {
|
||||
try {
|
||||
var response = await _productService.decreaseQuantity(data);
|
||||
|
||||
@@ -284,9 +278,6 @@ FutureResult<String> decreaseQuantity(data) async {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FutureResult<WishListModel> gettAllWishList(data) async {
|
||||
try {
|
||||
var response = await _productService.gettAllWishList(data);
|
||||
@@ -337,9 +328,7 @@ FutureResult<String> decreaseQuantity(data) async {
|
||||
var response = await _productService.refresh_token(data);
|
||||
LoginResponse loginResponse = loginResponseFromJson(response.toString());
|
||||
|
||||
if (loginResponse.accessToken != null)
|
||||
{
|
||||
|
||||
if (loginResponse.accessToken != null) {
|
||||
await SharedPrefUtils.setToken(
|
||||
authToken: loginResponse.accessToken ?? "");
|
||||
await SharedPrefUtils.setRefreshToken(
|
||||
@@ -349,10 +338,7 @@ FutureResult<String> decreaseQuantity(data) async {
|
||||
final String model = response.toString();
|
||||
|
||||
return right(model);
|
||||
} on DioException catch (e)
|
||||
{
|
||||
|
||||
|
||||
} on DioException catch (e) {
|
||||
var error = CustomDioExceptions.handleError(e);
|
||||
return left(error);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,9 @@ class ProductService extends ApiService {
|
||||
|
||||
return response;
|
||||
}
|
||||
Future paymentOrder(data) async {
|
||||
|
||||
Future paymentOrder(data) async {
|
||||
print("kdjfgkjjkdfgkjdkfgjkdfgj ${data}");
|
||||
var response = await api.post(APIURL.paymentOrder, data: jsonEncode(data));
|
||||
|
||||
return response;
|
||||
@@ -83,23 +85,25 @@ class ProductService extends ApiService {
|
||||
await api.delete(APIURL.deleteItem + id, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
Future addAddress(data) async {
|
||||
|
||||
Future addAddress(data) async {
|
||||
var response = await api.post(APIURL.addAddress, data: jsonEncode(data));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Future getProfile(data) async {
|
||||
Future getProfile(data) async {
|
||||
var response = await api.get(APIURL.getprofile, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
|
||||
Future updateProfile(data) async {
|
||||
var response = await api.patch(APIURL.updateProfile, data: jsonEncode(data));
|
||||
var response =
|
||||
await api.patch(APIURL.updateProfile, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
Future<Response> uploadImage(File imageFile,
|
||||
Future<Response> uploadImage(File imageFile,
|
||||
{Map<String, dynamic>? additionalFields}) async {
|
||||
const String url = APIURL.uploadImage;
|
||||
return await api.uploadImage(
|
||||
@@ -109,13 +113,11 @@ class ProductService extends ApiService {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Future getAddress
|
||||
(data) async {
|
||||
var response =
|
||||
await api.get(APIURL.userAddress, data: jsonEncode(data));
|
||||
Future getAddress(data) async {
|
||||
var response = await api.get(APIURL.userAddress, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
|
||||
Future addToWish(data) async {
|
||||
var response = await api.post(APIURL.addToWish, data: jsonEncode(data));
|
||||
|
||||
@@ -128,7 +130,7 @@ class ProductService extends ApiService {
|
||||
return response;
|
||||
}
|
||||
|
||||
Future decreaseQuantity(data) async {
|
||||
Future decreaseQuantity(data) async {
|
||||
var response = await api.patch(APIURL.addToCart, data: jsonEncode(data));
|
||||
|
||||
return response;
|
||||
|
||||
@@ -80,6 +80,8 @@ class _CardCheckoutScreenState extends State<CardCheckoutScreen> {
|
||||
Expanded(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
print("kjdhfkhjghjkdf");
|
||||
|
||||
paymentProvider.orderPaymnet(
|
||||
context,
|
||||
widget.amount,
|
||||
@@ -99,10 +101,12 @@ class _CardCheckoutScreenState extends State<CardCheckoutScreen> {
|
||||
color: APPCOLOR.lightGreen,
|
||||
borderRadius: BorderRadius.circular(10)),
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Continue",
|
||||
style: context.customRegular(Colors.white, 16),
|
||||
),
|
||||
child: paymentProvider.ispaymentLoader
|
||||
? CircularProgressIndicator()
|
||||
: Text(
|
||||
"Continue",
|
||||
style: context.customRegular(Colors.white, 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -908,8 +908,9 @@ class _MycartState extends State<Mycart> {
|
||||
// }
|
||||
|
||||
Widget cartPlace() {
|
||||
return Consumer<AddtocartProvider>(builder: (context, provider, child) {
|
||||
print("jdhfgkdfkjg ${provider.allitem.createdAt}");
|
||||
return Consumer<AddtocartProvider>(builder: (context, provider, child)
|
||||
{
|
||||
|
||||
if (provider.isLoaddcartItem) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 120),
|
||||
@@ -1186,10 +1187,12 @@ class _AddressBottomSheetState extends State<AddressBottomSheet> {
|
||||
"prxvsvxvice ${double.parse(paymentProvider.allitem.subtotal.toString())} ${paymentProvider.selecteUserName} ${paymentProvider.selectedAddress} ${paymentProvider.selecteEmail} ${paymentProvider.selecteUserPhone}");
|
||||
return ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return CardCheckoutScreen(
|
||||
amount: double.parse( paymentProvider.allitem.subtotal.toString()),
|
||||
amount: double.parse(
|
||||
paymentProvider.allitem.subtotal.toString()),
|
||||
currency: "INR",
|
||||
originalAmount: double.parse(
|
||||
paymentProvider.allitem.subtotal.toString()),
|
||||
@@ -1205,7 +1208,6 @@ class _AddressBottomSheetState extends State<AddressBottomSheet> {
|
||||
|
||||
// showPaymentMethodBottomSheet(context);
|
||||
// context.push(MyRoutes.SELECTPAYMENTSCREEN);
|
||||
//Navigator.pop(context);
|
||||
},
|
||||
label: Text(
|
||||
"Continue",
|
||||
|
||||
@@ -1,3 +1,36 @@
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
|
||||
// class PaymentWebView extends StatefulWidget {
|
||||
// final String paymentUrl;
|
||||
|
||||
// PaymentWebView({required this.paymentUrl});
|
||||
|
||||
// @override
|
||||
// _PaymentWebViewState createState() => _PaymentWebViewState();
|
||||
// }
|
||||
|
||||
// class _PaymentWebViewState extends State<PaymentWebView> {
|
||||
// InAppWebViewController? webViewController;
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Scaffold(
|
||||
// appBar: AppBar(title: Text("Complete Your Payment")),
|
||||
// body: InAppWebView(
|
||||
// initialUrlRequest: URLRequest(url: WebUri.uri(Uri.parse(widget.paymentUrl))),
|
||||
// onWebViewCreated: (controller)
|
||||
// {
|
||||
// webViewController = controller;
|
||||
// },
|
||||
// onLoadStop: (controller, url) async
|
||||
// {
|
||||
// print("Payment page loaded: $url");
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
|
||||
@@ -12,19 +45,62 @@ class PaymentWebView extends StatefulWidget {
|
||||
|
||||
class _PaymentWebViewState extends State<PaymentWebView> {
|
||||
InAppWebViewController? webViewController;
|
||||
bool isErrorPage = false; // Track error state
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text("Complete Your Payment")),
|
||||
body: InAppWebView(
|
||||
initialUrlRequest: URLRequest(url: WebUri.uri(Uri.parse(widget.paymentUrl))),
|
||||
onWebViewCreated: (controller) {
|
||||
webViewController = controller;
|
||||
},
|
||||
onLoadStop: (controller, url) async {
|
||||
print("Payment page loaded: $url");
|
||||
},
|
||||
body: Stack(
|
||||
children: [
|
||||
Visibility(
|
||||
visible: !isErrorPage, // Show WebView only if there's no error
|
||||
child: InAppWebView(
|
||||
initialUrlRequest:
|
||||
URLRequest(url: WebUri.uri(Uri.parse(widget.paymentUrl))),
|
||||
onWebViewCreated: (controller) {
|
||||
webViewController = controller;
|
||||
},
|
||||
onLoadStop: (controller, url) async {
|
||||
print("Payment page loaded: $url");
|
||||
},
|
||||
onReceivedHttpError: (controller, request, response)
|
||||
{
|
||||
if (response.statusCode == 404)
|
||||
{
|
||||
setState(() {
|
||||
isErrorPage = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
if (isErrorPage) _buildErrorPage(context), // Show custom error page
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildErrorPage(BuildContext context) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.error_outline, color: Colors.red, size: 80),
|
||||
SizedBox(height: 10),
|
||||
Text("Payment Failed",
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
|
||||
SizedBox(height: 10),
|
||||
Text("Something went wrong. Please try again.",
|
||||
textAlign: TextAlign.center),
|
||||
SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context); // Navigate back to previous screen
|
||||
},
|
||||
child: Text("Go Back"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user