Search in sources :

Example 1 with RetrofitFactory

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) {
                        }
                    });
                }
            }
        }
    });
}
Also used : Call(retrofit2.Call) PaymentResult(net.iGap.model.payment.PaymentResult) JsonObject(com.google.gson.JsonObject) Token(net.iGap.model.qrCodePayment.Token) IOException(java.io.IOException) Response(retrofit2.Response) Callback(retrofit2.Callback) PaymentCallBack(net.iGap.observers.interfaces.PaymentCallBack) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory) HelperFragment(net.iGap.helper.HelperFragment)

Example 2 with RetrofitFactory

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();
        }
    });
}
Also used : DecodeCallback(net.iGap.libs.codescanner.DecodeCallback) View(android.view.View) Result(com.google.zxing.Result) MerchantInfo(net.iGap.model.qrCodePayment.MerchantInfo) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory)

Example 3 with RetrofitFactory

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);
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) HandShakeCallback(net.iGap.observers.interfaces.HandShakeCallback) FrameLayout(android.widget.FrameLayout) RadioButton(android.widget.RadioButton) FavoriteNumber(net.iGap.model.paymentPackage.FavoriteNumber) ConfigData(net.iGap.model.paymentPackage.ConfigData) Theme(net.iGap.module.Theme) G(net.iGap.G) HelperPermission(net.iGap.helper.HelperPermission) HelperPermission.showDeniedPermissionMessage(net.iGap.helper.HelperPermission.showDeniedPermissionMessage) View(android.view.View) ChargeContactNumberAdapter(net.iGap.adapter.payment.ChargeContactNumberAdapter) HelperError(net.iGap.helper.HelperError) RecyclerView(androidx.recyclerview.widget.RecyclerView) HelperFragment(net.iGap.helper.HelperFragment) OperatorAdapter(net.iGap.adapter.OperatorAdapter) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) HelperString.isNumeric(net.iGap.helper.HelperString.isNumeric) AppCompatEditText(androidx.appcompat.widget.AppCompatEditText) BaseFragment(net.iGap.fragments.BaseFragment) ViewGroup(android.view.ViewGroup) PaymentRepository(net.iGap.repository.PaymentRepository) List(java.util.List) Nullable(androidx.annotation.Nullable) BackDrawable(net.iGap.messenger.ui.toolBar.BackDrawable) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) InternetHistoryPackageAdapter(net.iGap.adapter.payment.InternetHistoryPackageAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) PackageChargeType(net.iGap.model.paymentPackage.PackageChargeType) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) NotNull(org.jetbrains.annotations.NotNull) Call(retrofit2.Call) TextWatcher(android.text.TextWatcher) AndroidUtils(net.iGap.module.AndroidUtils) ResourcesCompat(androidx.core.content.res.ResourcesCompat) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) Response(retrofit2.Response) RadioGroup(android.widget.RadioGroup) Editable(android.text.Editable) ArrayList(java.util.ArrayList) MaterialButton(com.google.android.material.button.MaterialButton) LayoutCreator(net.iGap.helper.LayoutCreator) TokenContainer(net.iGap.api.apiService.TokenContainer) Toolbar(net.iGap.messenger.ui.toolBar.Toolbar) Config(net.iGap.model.paymentPackage.Config) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) ContactNumber(net.iGap.adapter.payment.ContactNumber) LayoutInflater(android.view.LayoutInflater) Operator(net.iGap.model.paymentPackage.Operator) MaterialDesignTextView(net.iGap.module.MaterialDesignTextView) IOException(java.io.IOException) CircleImageView(net.iGap.module.CircleImageView) PhoneContactProvider(net.iGap.controllers.PhoneContactProvider) Gravity(android.view.Gravity) GetFavoriteNumber(net.iGap.model.paymentPackage.GetFavoriteNumber) ChargeApi(net.iGap.api.ChargeApi) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory) Callback(retrofit2.Callback) ScrollView(android.widget.ScrollView) R(net.iGap.R) DbManager(net.iGap.module.accountManager.DbManager) EditText(android.widget.EditText) OperatorAdapter(net.iGap.adapter.OperatorAdapter) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory) RadioButton(android.widget.RadioButton) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) HelperFragment(net.iGap.helper.HelperFragment) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo)

Example 4 with RetrofitFactory

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);
        }
    });
}
Also used : JsonObject(com.google.gson.JsonObject) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory) ResponseBody(okhttp3.ResponseBody)

Example 5 with RetrofitFactory

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();
}
Also used : Bundle(android.os.Bundle) FrameLayout(android.widget.FrameLayout) BackDrawable(net.iGap.messenger.ui.toolBar.BackDrawable) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Toolbar(net.iGap.messenger.ui.toolBar.Toolbar)

Aggregations

RetrofitFactory (net.iGap.api.apiService.RetrofitFactory)5 Bundle (android.os.Bundle)2 View (android.view.View)2 FrameLayout (android.widget.FrameLayout)2 JsonObject (com.google.gson.JsonObject)2 IOException (java.io.IOException)2 HelperFragment (net.iGap.helper.HelperFragment)2 Call (retrofit2.Call)2 Callback (retrofit2.Callback)2 Response (retrofit2.Response)2 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 Gravity (android.view.Gravity)1 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 EditText (android.widget.EditText)1 RadioButton (android.widget.RadioButton)1 RadioGroup (android.widget.RadioGroup)1 ScrollView (android.widget.ScrollView)1 NonNull (androidx.annotation.NonNull)1