submitBluPay method
Implementation
Future<void> submitBluPay() async {
isPaymentLoading.value = true;
canGoBack = false;
update();
List<OrderItems> orderItems =
submitModel.orderLists
.mapMany(
(order) =>
order.orderDeliveries
.mapMany((item) => item.orderItems)
.toList(),
)
.toList();
List<Items> orderitems =
orderItems.map((e) {
return Items(
id: e.orderItemId.toString(),
amount: e.total.toString(),
);
}).toList();
const chars =
'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
final now = DateTime.now();
final tomorrow = DateTime(
now.year,
now.month,
now.day + 1,
now.hour,
now.minute,
now.second,
);
final resp = await paymentService.checkoutConfirm(
//! hardcode body
body: BluPaymentSubmit(
poinValue: isUsingBuySmartPoint.value ? totalPointUsed : 0,
orderId:
(submitModel.orderGroupID.isNotEmpty == true)
? submitModel.orderGroupID
: String.fromCharCodes(
Iterable.generate(
15,
(_) => chars.codeUnitAt(Random().nextInt(chars.length)),
),
),
custName: "Tester",
orderCreated: convertDateToStringFormat(now, "yyyy-MM-dd HH:mm:ss"),
orderExpired: convertDateToStringFormat(
tomorrow,
"yyyy-MM-dd HH:mm:ss",
),
items: orderitems,
).toSubmit(
(
//! VOUCHER
(submitModel.voucherSummary.totalVoucherNominal)
//! POINT
+
((isUsingBuySmartPoint.value ? totalPointUsed : 0) * pointValue)
//! DISCOUNT
+
(submitModel.totalDiscount) +
(submitModel.couponSummary.totalCouponDisc)
//! ORDER DISCOUNT
// +
// ((submitModel.orderDiscounts
// ?.map((e) => (e.total ?? 0))
// .toList() ??
// [])
// .reduce((a, b) => a + b)),
),
(submitModel.totalShippingCost - submitModel.discountShippingCost),
),
);
resp.fold(
(failure) {
onError?.call(failure.message);
},
(result) {
paymentResp = result;
},
);
isPaymentLoading.value = false;
canGoBack = true;
update();
}