You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
3.2 KiB
Dart
84 lines
3.2 KiB
Dart
import 'package:amazon_payfort/amazon_payfort.dart';
|
|
import 'package:diplomaticquarterapp/config/config.dart';
|
|
import 'package:diplomaticquarterapp/core/enum/PayfortEnums.dart';
|
|
import 'package:diplomaticquarterapp/locator.dart';
|
|
import 'package:diplomaticquarterapp/services/payfort_services/payfort_project_details_resp_model.dart';
|
|
import 'package:diplomaticquarterapp/services/payfort_services/payfort_service.dart';
|
|
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
|
|
import 'package:diplomaticquarterapp/uitl/utils.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
class PayfortViewModel extends ChangeNotifier {
|
|
PayfortService _payfortService = locator<PayfortService>();
|
|
|
|
Future<void> initPayfort() async {
|
|
await _payfortService.initPayfortSDK();
|
|
}
|
|
|
|
Future<PayfortProjectDetailsRespModel> getProjectDetailsForPayfort({int serviceId, int projectId}) async {
|
|
PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = PayfortProjectDetailsRespModel();
|
|
try {
|
|
payfortProjectDetailsRespModel = await _payfortService.getPayfortConfigurations(serviceId: serviceId, projectId: projectId);
|
|
|
|
String signature =
|
|
await _payfortService.getPayfortSignature(payfortProjectDetailsRespModel.accessCode, payfortProjectDetailsRespModel.merchantIdentifier, payfortProjectDetailsRespModel.shaRequest);
|
|
payfortProjectDetailsRespModel.signature = signature;
|
|
|
|
return payfortProjectDetailsRespModel;
|
|
} on Exception catch (e, s) {
|
|
print(s);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
Future<void> addPayfortApplePayResponse({PayFortResult result}) async {
|
|
try {
|
|
await _payfortService.addPayfortApplePayResponse(result: result);
|
|
} on Exception catch (e, s) {
|
|
print(s);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
Future<void> initiateApplePayWithPayfort({
|
|
String customerName,
|
|
String customerEmail,
|
|
String orderDescription,
|
|
String merchantReference,
|
|
double orderAmount,
|
|
PayfortProjectDetailsRespModel payfortProjectDetailsRespModel,
|
|
SucceededCallback onSuccess,
|
|
FailedCallback onFailed,
|
|
ServiceTypeEnum serviceTypeEnum,
|
|
int projectId,
|
|
}) async {
|
|
// GifLoaderDialogUtils.showMyDialog(AppGlobal.context);
|
|
// PayfortProjectDetailsRespModel payfortProjectDetailsRespModel = await getProjectDetailsForPayfort(projectId: projectId, serviceId: serviceTypeEnum.getIdFromServiceEnum());
|
|
//
|
|
// if (payfortProjectDetailsRespModel == null) {
|
|
// GifLoaderDialogUtils.hideDialog(AppGlobal.context);
|
|
// return;
|
|
// }
|
|
|
|
try {
|
|
await _payfortService.paymentWithApplePay(
|
|
onSucceeded: onSuccess,
|
|
onFailed: onFailed,
|
|
customerName: customerName,
|
|
customerEmail: customerEmail,
|
|
orderDescription: orderDescription,
|
|
orderAmount: orderAmount,
|
|
merchantReference: merchantReference,
|
|
merchantIdentifier: payfortProjectDetailsRespModel.merchantIdentifier ?? "",
|
|
applePayAccessCode: payfortProjectDetailsRespModel.accessCode ?? "",
|
|
applePayShaRequestPhrase: payfortProjectDetailsRespModel.shaRequest ?? "",
|
|
);
|
|
GifLoaderDialogUtils.hideDialog(AppGlobal.context);
|
|
} catch (e) {
|
|
Utils.showErrorToast(e.toString());
|
|
GifLoaderDialogUtils.hideDialog(AppGlobal.context);
|
|
throw e;
|
|
}
|
|
}
|
|
}
|