use of net.iGap.model.qrCodePayment.Token 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) {
}
});
}
}
}
});
}
Aggregations