getCartIdAndHandlerApi method

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

Implementation

Future<void> getCartIdAndHandlerApi(
  String? pogId,
  String? offerId,
  String? amount,
  String? receiverMsisdn,
) 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!, "");

    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: ATFINAL
    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?['updateStarterPack'] ?? {});
      detailsList.value = dataSuccess.details ?? [];
      log("ResponseList  $dataSuccess");
      for (var info in detailsList) {
        if (info.label == "pos.common.cartId") {
          cartId.value = info.value == null ? "" : info.value.toString();
        }
      }
    } 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");
    }
  }
}