callELoadTransactionForGraphQl method

Future<void> callELoadTransactionForGraphQl(
  1. String? pogId,
  2. String? offerId,
  3. String? amount,
  4. String? receiverMsisdn,
  5. String? paymentTransactionId,
)

Implementation

Future<void> callELoadTransactionForGraphQl(
  String? pogId,
  String? offerId,
  String? amount,
  String? receiverMsisdn,
  String? paymentTransactionId,
) async {
  String? sendermobileNumber =
      (SingletonSotrage.secureStorageInterface.readSecureData(
    SecureStorageService.preferedUserName,
  ));
  String? partnerId = (SingletonSotrage.secureStorageInterface.readSecureData(
    SecureStorageService.partnerIdLogin,
  ));
  String? userCategory =
      SingletonSotrage.secureStorageInterface.readSecureData(
    SecureStorageService.userCategory,
  );
  sendermobileNumber = "${AppConfig.getCountryCode()}$sendermobileNumber";
  try {
    Helper.progressDialog(Get.context!, "");

    ///Temporary purpose request.
//       String updateStarterPackMutation = """
// mutation UpdateStarterPack {
//   updateStarterPack(
//     action: "update-eload"
//     transactionWorkflowRequest: {
//       transactionId: "${eLoadTnxId.value}"
//       relatedParty: [
//         {
//           id: "2",
//           role: "update-eload-candidate",
//           name: "offerId",
//           value: "$offerId"
//         },
//         {
//           id: "3",
//           role: "update-eload-candidate",
//           name: "pogId",
//           value: "$pogId"
//         },
//         {
//           id: "7",
//           role: "update-eload-candidate",
//           name: "receiverMsisdn",
//           value: "$receiverMsisdn"
//         },
//         {
//           id: "8",
//           role: "update-eload-candidate",
//           name: "updatedOverridePrice",
//           value: "$amount"
//         },
//         {
//           id: "9",
//           role: "update-eload-candidate",
//           name: "amount",
//           value: "$amount"
//         },
//         {
//           id: "10",
//           role: "update-eload-candidate",
//           name: "currency",
//           value: "USD"
//         },
//         {
//           id: "11",
//           role: "update-eload-candidate",
//           name: "paymentTransactionReferenceNumber",
//           value: "${eLoadTnxId.value}"
//         },
//         {
//           id: "12",
//           role: "update-eload-candidate",
//           name: "senderType",
//           value: "OPERATOR"
//         }
//       ]
//       commitType: IMMEDIATE
//       saleContext: {
//         sellerPartyEntityId: "$partnerId"
//         sellerPartyType: "OP"
//         buyerPartyType: "DU"
//       }
//     }
//   ) {
//     details {
//       label
//       name
//       value
//       type
//     }
//     summary {
//       label
//       name
//       value
//       type
//     }
//   }
// }
// """;

    String updateStarterPackMutation = """
    mutation PaymentAcknowledgeTxn {
      paymentAcknowledgeTxn(
       transactionType: SELL_OUT
       transactionWorkflowRequest: {
          cartId: "$cartId"
          transactionId: "${eLoadTnxId.value}"
          relatedParty: null
          qrCodeRequired: true
          commitType: IMMEDIATE
          saleContext: {
              sellerPartyEntityId: "$partnerId"
              sellerPartyType: "OP"
              buyerPartyType: "DU"
          }
      }
    ) {
      details {
          label
          name
          value
          type
      }
      summary {
          label
          name
          value
          type
      }
  }
  }
""";

    final client = GraphqlConfig().clientToQuery(url: "/graphql");
    debugPrint("request  ${updateStarterPackMutation}");

    final QueryResult response = await client.query(QueryOptions(
        onComplete: (data) {
          log("DATA from COMPLETE >>>>$data");
        },
        onError: (error) {
          log("ON ERROR>>>>>$error");
        },
        fetchPolicy: FetchPolicy.noCache,
        document: gql(updateStarterPackMutation)));
    Helper.close();
    debugPrint("Response From Graph  ${response.data}");
    if (response.hasException) {
      log("Response  ${response.exception?.raw}");
      var data = GenericGraphQlException.fromJson(
          response.exception?.raw?.firstOrNull ?? {});
      log("Response after convert ${data.toJson()}");
      Helper.messageDialog(
        Get.context!,
        data.extensions?.errors?.elementAtOrNull(0)?.code ?? "tryAgain2".tr,
        data.extensions?.errors?.elementAtOrNull(0)?.description ??
            "somethingWrong".tr,
      );
    } else if (response.data != null) {
      log("Response111  ${response.data}");

      final dataSuccess = GenericGraphqlSuccessModel.fromJson(
          response.data?['paymentAcknowledgeTxn'] ?? {});
      detailsList.value = dataSuccess.details ?? [];
      log("ResponseList  $dataSuccess");
      for (var info in detailsList) {
        if (info.label == "pos.eload.details.rechargeAmount") {
          rechargeAmount.value =
              info.value == null ? "" : info.value.toString();
          print("rechargeAmount: ${rechargeAmount.value}");
        }
        // Check for "transactionId"
        if (info.label == "pos.eload.details.transactionId") {
          eLoadTnxId.value = info.value == null ? "" : info.value.toString();
        }
        // Check for "transactionDate"
        if (info.label == "pos.eload.details.transactionDate") {
          if (txnDate.value == "") {
            txnDate.value = info.value == null ? "" : info.value.toString();
          }
        }

        if (info.label == "pos.eload.details.balance.after.usd") {
          balanceAfterTopupUSD.value =
              info.value == null ? "" : info.value.toString();
          print("balanceAfterTopupUSD: ${balanceAfterTopupUSD.value}");
        }
        if (info.label == "pos.eload.details.balance.after.khr") {
          balanceAftertopUpKHR.value =
              info.value == null ? "" : info.value.toString();
          print("balanceAftertopUpKHR: ${balanceAftertopUpKHR.value}");
        }
      }
      // ELoad Success
      Get.to(() => const ELoadSuccess());
    } else {
      Helper.close();
      Helper.messageDialog(
        Get.context!,
        "tryAgain".tr,
        "technicalErrorMsg".tr,
      );
    }
  } catch (e, st) {
    Helper.close();
    Helper.messageDialog(
      Get.context!,
      "tryAgain".tr,
      "technicalErrorMsg".tr,
    );
    if (kDebugMode) {
      print("ch  $st");
    }
  }
}