Implementation
Future<void> callPaymentTransactionCreateApi(
String couponTransactionId, String type, String amount) async {
BuildContext context = Get.context!;
transactionId = "";
var partnerId = SecureStorageService.readSecureData(
SecureStorageService.partnerIdLogin,
) ??
"";
var phone = SecureStorageService.readSecureData(
SecureStorageService.mobileNo,
) ??
"";
var firstName = SecureStorageService.readSecureData(
SecureStorageService.fullName,
) ??
"";
var email = SecureStorageService.readSecureData(
SecureStorageService.emailId,
) ??
"";
var lastName = SecureStorageService.readSecureData(
SecureStorageService.lastName,
) ??
"";
var bodyRequest = {
"couponTransactionId": couponTransactionId,
"transactionType": "COUPON_TOP_UP",
"operationContext": "UpFront",
"paymentMethod": type == "QrCode" ? "WEB_LINK" : "DEEP_LINK",
"orderId": "",
"cartId": null,
"paymentCollectionRequest": {},
"submitStockRequest": {},
"relatedParty": [
{
"id": 1,
"role": "source-information",
"name": "entityId",
"value": partnerId
},
{
"id": 2,
"role": "source-information",
"name": "firstName",
"value": firstName
},
{
"id": 3,
"role": "source-information",
"name": "lastName",
"value": lastName
},
{
"id": 4,
"role": "source-information",
"name": "phoneNumber",
"value": phone
},
{
"id": 5,
"role": "transaction-information",
"name": "amount",
"value": amount
},
{
"id": 6,
"role": "transaction-information",
"name": "currency",
"value": "USD"
},
// {
// "id": 7,
// "role": "transaction-information",
// "name": "Discount",
// "value": "0.0"
// },
{
"id": 8,
"role": "target-information",
"name": "entityId",
"value": targetSourceEntityId
},
{
"id": 9,
"role": "target-information",
"name": "firstName",
"value": targetSourceFirstName
},
{
"id": 10,
"role": "target-information",
"name": "lastName",
"value": targetSourceLastName
},
{
"id": 11,
"role": "target-information",
"name": "PhoneNumber",
"value": targetSourcePhone
},
{
"id": 12,
"role": "target-information",
"name": "Email",
"value": targetSourceEmailID
},
],
};
Helper.progressDialog(Get.context!, "");
String requestTime = "";
String responseTime = "";
try {
await ApiClient(
baseUrl: ApiConstant.posBFF,
onFetchRequestTime: (time) {
requestTime = time;
},
onFetchResponseTime: (time) {
responseTime = time;
},
screenName: "stockOrder",
)
.getPaymentGatewayTransactionCreate(
body: bodyRequest,
xUserId: SecureStorageService.readSecureData(
SecureStorageService.xUserId,
),
xUserName: SecureStorageService.readSecureData(
SecureStorageService.xUserName,
),
)
.then((response) async {
PaymentResponseModel model = response;
if (model.status == "POS200") {
Helper.logEvent(
"RESPONSE_EVENT",
success: true,
endPoint: Api.paymentGatewayTransactionCreate,
responseDate: responseTime,
screenName: "stockOrder",
requestDate: requestTime,
);
Helper.close();
if (model.data != null) {
var deeplink = model.data?.paymentDetails?.deepLink ?? "";
transactionId = model.data?.paymentDetails?.transactionId ?? "";
var transactionCode =
model.data?.paymentDetails?.transactionStatus ?? "";
paymentCreateTransactionId.value =
model.data?.paymentDetails?.transactionId ?? "";
paymentStatus.value = "Start";
if (transactionCode == "INITIATED") {
if (paymentmodestatus == 2) {
var qrCode = model.data?.paymentDetails?.webLink ?? "";
Future.delayed(const Duration(seconds: 2), () {
startApiPolling(transactionId);
});
await Get.to(() => WalletQrcodeScreen(weblink: qrCode));
//Check status api response when we come back to screen.
await checkDataOnLoad(amount);
isDiscardPayment = false;
} else {
launchPaymentGateway(deeplink, transactionId, amount);
}
} else if (transactionCode == "SUCCESS") {
// Helper.messageDialog(
// Get.context!,
// localization.translate('tryAgain'),
// model.data?.paymentDetails?.statusMessage ??
// localization.translate('technicalErrorMsg'),
// );
callSubmitCouponApi(paymentCreateTransactionId.value, amount);
} else {
Helper.messageDialog(
Get.context!,
localization.translate('tryAgain'),
model.data?.paymentDetails?.statusMessage ??
localization.translate('technicalErrorMsg'),
);
}
// _launchPaymentGateway();
}
} else {
Helper.close();
Helper.messageDialog(
Get.context!,
model.data?.paymentDetails?.statusCode ??
localization.translate('tryAgain'),
model.data?.paymentDetails?.statusMessage ??
localization.translate('somethingWrong'),
);
}
}).catchError((error) {
Helper.close();
if (error is DioException) {
UDID.setTraceId(
error.response?.headers.map[Constants.traceIdKey]?[0] ?? "",
);
Helper.logEvent(
"ERROR_EVENT",
failure: true,
requestDate: requestTime,
endPoint: Api.paymentGatewayTransactionCreate,
responseDate: DateTime.now().toString(),
screenName: "stockOrder",
error: error,
);
}
Helper.messageDialog(
context,
localization.translate('tryAgain'),
error.toString(),
);
});
} catch (error, st) {
Helper.close();
if (error is DioException) {
UDID.setTraceId(
error.response?.headers.map[Constants.traceIdKey]?[0] ?? "",
);
Helper.logEvent(
"ERROR_EVENT",
failure: true,
requestDate: requestTime,
endPoint: Api.paymentGatewayTransactionCreate,
responseDate: DateTime.now().toString(),
screenName: "stockOrder",
error: error,
);
}
print(st);
}
}