use of net.iGap.api.apiService.RetrofitFactory in project iGap-Android by KianIranian-STDG.
the class QRCodePaymentFragment method setObservers.
private void setObservers() {
mViewModel.getConfirmButtonClick().observe(getViewLifecycleOwner(), new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
if (!mMerchantPcqr && mBinding.desireAmount == null || !mMerchantPcqr && mBinding.desireAmount.getText().toString().replaceAll("\\D", "").length() == 0) {
Toast.makeText(getActivity(), R.string.you_have_not_specified_the_amount, Toast.LENGTH_SHORT).show();
} else if (!mMerchantPcqr && mBinding.desireAmount.getText().toString().replaceAll("\\D", "").length() != 0 && Integer.parseInt(mBinding.desireAmount.getText().toString().replaceAll("\\D", "")) < 1000) {
Toast.makeText(getActivity(), R.string.the_amount_can_not_be_less_than_1000_rials, Toast.LENGTH_SHORT).show();
} else if (!mMerchantPcqr && mBinding.desireAmount.getText().toString().replaceAll("\\D", "").length() != 0 && Integer.parseInt(mBinding.desireAmount.getText().toString().replaceAll("\\D", "")) > 500000000) {
Toast.makeText(getActivity(), R.string.the_amount_can_not_be_more_than_500_million_rials, Toast.LENGTH_SHORT).show();
} else {
mBinding.progressBar.setVisibility(View.VISIBLE);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("qr_code", mMerchantCode);
if (mMerchantPcqr) {
/**
*1000 is a default amount for pcqr true state. true pcqr means that The amount is filled automatically and do not need to get amount from customer
*/
jsonObject.addProperty("amount", 1000);
} else {
jsonObject.addProperty("amount", Integer.parseInt(mBinding.desireAmount.getText().toString().replaceAll("\\D", "")));
}
Call<Token> call = new RetrofitFactory().getPecQrRetrofit().getPaymentToken(jsonObject);
call.enqueue(new Callback<Token>() {
@Override
public void onResponse(Call<Token> call, Response<Token> response) {
if (response.isSuccessful()) {
Token token = response.body();
new HelperFragment(getActivity().getSupportFragmentManager(), PaymentFragment.getInstance(getActivity().getResources().getString(R.string.payment), token.getToken(), new PaymentCallBack() {
@Override
public void onPaymentFinished(PaymentResult result) {
}
})).setReplace(false).setAddToBackStack(true).load();
mBinding.progressBar.setVisibility(View.GONE);
} else {
try {
String[] splittedErrorBody = response.errorBody().string().split("\"");
Toast.makeText(getActivity(), splittedErrorBody[splittedErrorBody.length - 2], Toast.LENGTH_LONG).show();
mBinding.progressBar.setVisibility(View.GONE);
getActivity().getSupportFragmentManager().popBackStackImmediate();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
public void onFailure(Call<Token> call, Throwable t) {
}
});
}
}
}
});
}
use of net.iGap.api.apiService.RetrofitFactory in project iGap-Android by KianIranian-STDG.
the class ScanCodeQRCodePaymentFragment method initCodeScanner.
private void initCodeScanner() {
mCodeScanner.setCamera(CodeScanner.CAMERA_BACK);
mCodeScanner.setFormats(CodeScanner.ALL_FORMATS);
mCodeScanner.setAutoFocusMode(AutoFocusMode.SAFE);
mCodeScanner.setScanMode(ScanMode.SINGLE);
mCodeScanner.setAutoFocusEnabled(true);
mCodeScanner.setFlashEnabled(false);
mCodeScanner.startPreview();
mCodeScanner.setDecodeCallback(new DecodeCallback() {
@Override
public void onDecoded(@NonNull Result result) {
G.runOnUiThread(new Runnable() {
@Override
public void run() {
if (result.getText().contains("https://qr.top.ir/?qrcode")) {
mBinding.progressBar.setVisibility(View.VISIBLE);
String[] rawResult = result.getText().split("=");
String qrCode = rawResult[1];
Call<MerchantInfo> call = new RetrofitFactory().getPecQrRetrofit().getMerchantInfo(qrCode);
call.enqueue(new Callback<MerchantInfo>() {
@Override
public void onResponse(Call<MerchantInfo> call, Response<MerchantInfo> response) {
MerchantInfo merchantInfo = response.body();
assert merchantInfo != null;
getActivity().getSupportFragmentManager().beginTransaction().add(R.id.mainFrame, QRCodePaymentFragment.newInstance(merchantInfo.getMerchantName(), merchantInfo.getQrCode(), merchantInfo.isPcqr())).addToBackStack(null).commit();
mBinding.progressBar.setVisibility(View.GONE);
initCodeScanner();
}
@Override
public void onFailure(Call<MerchantInfo> call, Throwable t) {
Log.e("onFailure", "onFailure: " + t.getMessage());
}
});
} else {
Toast.makeText(getActivity(), R.string.invalid_qr_code, Toast.LENGTH_LONG).show();
mCodeScanner.stopPreview();
mCodeScanner.releaseResources();
initCodeScanner();
}
}
});
}
});
mBinding.codeScanner.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCodeScanner.startPreview();
}
});
}
use of net.iGap.api.apiService.RetrofitFactory in project iGap-Android by KianIranian-STDG.
the class InternetFragment method initForm.
private void initForm() {
DbManager.getInstance().doRealmTask(realm -> {
RealmRegisteredInfo userInfo = realm.where(RealmRegisteredInfo.class).findFirst();
if (userInfo != null) {
userNumber = userInfo.getPhoneNumber();
if (phoneNumber != null && !phoneNumber.isEmpty() && !phoneNumber.equals("0")) {
setPhoneNumberEditText(phoneNumber);
if (peerId != 0) {
avatarHandler.getAvatar(new ParamWithAvatarType(avatar, peerId).avatarType(AvatarHandler.AvatarType.ROOM).showMain());
}
}
if (phoneNumber != null && phoneNumber.equals("0")) {
avatar.setVisibility(View.GONE);
editTextNumber.setHint(getActivity().getString(R.string.please_enter_phone_number));
removeButton.setText(R.string.icon_edit);
} else {
avatar.setVisibility(View.GONE);
setPhoneNumberEditText(userNumber);
}
if (editTextNumber.getText() != null && editTextNumber.getText().length() == 11) {
hideKeyboard();
}
editTextNumber.setSelection(editTextNumber.getText() == null ? 0 : editTextNumber.getText().length());
}
});
operatorAdapter = new OperatorAdapter(getContext(), operators, operatorName -> {
if (currentConfigData != null) {
changeOperator(currentConfigData.getOperator());
} else {
operatorAdapter.setCheckedRadioButton(null);
HelperError.showSnackMessage(getActivity().getString(R.string.please_enter_phone_number), false);
}
});
lstOperator.setAdapter(operatorAdapter);
detectOperatorByNumber(editTextNumber.getText().toString());
chargeApi = new RetrofitFactory().getChargeRetrofit();
editTextNumber.addTextChangedListener(editTextNumberWatcher());
removeButton.setOnClickListener(removeNumberClicked());
frameContact.setOnClickListener(v -> onContactNumberButtonClick());
frameHistory.setOnClickListener(v -> onHistoryNumberButtonClick());
radioGroup.setOnCheckedChangeListener((group, checkedId) -> InternetFragment.this.changeSimType());
goNextButton.setOnClickListener(v -> {
RadioButton radioButton = radioGroup.findViewById(radioGroup.getCheckedRadioButtonId());
if (radioButton != null) {
if (currentSimType == null) {
showError(getActivity().getString(R.string.invalid_sim_type));
return;
}
if (editTextNumber.getText() == null) {
editTextNumber.setError(getString(R.string.phone_number_is_not_valid));
return;
}
String rechargeableNumber = editTextNumber.getText().toString().trim();
if (!isNumeric(rechargeableNumber) || rechargeableNumber.length() < 11) {
editTextNumber.setError(getString(R.string.phone_number_is_not_valid));
return;
}
if (!isNumberFromIran(rechargeableNumber)) {
editTextNumber.setError(getString(R.string.phone_number_is_not_valid));
return;
}
int packageType = historyNumber != null ? Integer.parseInt(historyNumber.getPackageType()) : -1;
new HelperFragment(getActivity().getSupportFragmentManager(), PaymentInternetFragment.newInstance(userNumber, rechargeableNumber, currentOperator.getKey(), currentSimType, packageType)).setAnimated(false).setReplace(false).load();
} else {
showError(getActivity().getString(R.string.sim_type_not_choosed));
}
});
progressBar.setVisibility(View.GONE);
scrollView.setVisibility(View.VISIBLE);
}
use of net.iGap.api.apiService.RetrofitFactory in project iGap-Android by KianIranian-STDG.
the class PaymentInternetPackageViewModel method savePayment.
public void savePayment() {
loadingVisibility.setValue(true);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("phone_number", rechargeableNumber);
jsonObject.addProperty("package_type", String.valueOf(selectedPackageType));
jsonObject.addProperty("charge_type", simType);
new RetrofitFactory().getChargeRetrofit().setFavoriteInternetPackage(operator, jsonObject).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NotNull Call<ResponseBody> call, @NotNull Response<ResponseBody> response) {
loadingVisibility.setValue(false);
}
@Override
public void onFailure(@NotNull Call<ResponseBody> call, @NotNull Throwable t) {
loadingVisibility.setValue(false);
showErrorMessage.setValue(R.string.server_do_not_response);
}
});
}
use of net.iGap.api.apiService.RetrofitFactory in project iGap-Android by KianIranian-STDG.
the class ChargeFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
scrollView = view.findViewById(R.id.scroll_payment);
contactButton = view.findViewById(R.id.frame_contact);
historyButton = view.findViewById(R.id.frame_history);
buttonAmount = view.findViewById(R.id.choose_amount);
buttonChargeType = view.findViewById(R.id.btn_charge_type);
amountPlusButton = view.findViewById(R.id.add_amount);
amountMinesButton = view.findViewById(R.id.low_amount);
editTextNumber = view.findViewById(R.id.phoneNumber);
buttonEnter = view.findViewById(R.id.btn_pay);
progressBar = view.findViewById(R.id.loadingView);
iconRemove = view.findViewById(R.id.btnRemoveSearch);
recyclerViewOperator = view.findViewById(R.id.lstOperator);
imageViewAvatar = view.findViewById(R.id.avatar);
compositeDisposable = new CompositeDisposable();
chargeApi = new RetrofitFactory().getChargeRetrofit();
progressBar.setVisibility(View.VISIBLE);
// get phoneNumber AND peerId
Bundle bundle = this.getArguments();
if (bundle != null) {
phoneNumber = bundle.getString("phoneNumber", "");
peerId = bundle.getLong("peerId", 0);
}
// init toolbar
FrameLayout toolbarContainer = view.findViewById(R.id.charge_toolbar);
Toolbar toolbar = new Toolbar(requireContext());
toolbar.setTitle(getString(R.string.buy_charge));
toolbar.setBackIcon(new BackDrawable(false));
toolbarContainer.addView(toolbar, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, 64, Gravity.TOP));
toolbar.setListener(i -> {
if (i == -1) {
getActivity().onBackPressed();
}
});
if (G.themeColor == Theme.DARK) {
historyButton.setBackground(getContext().getResources().getDrawable(R.drawable.shape_payment_charge_dark));
contactButton.setBackground(getContext().getResources().getDrawable(R.drawable.shape_payment_charge_dark));
}
paymentRepository = PaymentRepository.getInstance();
paymentRepository.getConfigs(TokenContainer.getInstance().getToken(), config -> {
if (config != null) {
this.config = config;
initForm();
}
});
favoriteNumberCall = chargeApi.getFavoriteChargeNUmber();
}
Aggregations