Created
January 12, 2026 16:39
-
-
Save vishalpatelbacancy/8609898d4027a9c29ae5c494d46a1839 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private class AddDiscountAsyncTask extends AsyncTask<Void, Void, Order> { | |
| ProgressDialog dialog = new ProgressDialog(ChooserActivity.this); | |
| Long order_amount; | |
| public AddDiscountAsyncTask(Long amount) { | |
| super(); | |
| order_amount = amount; | |
| } | |
| @Override | |
| protected void onPreExecute() { | |
| super.onPreExecute(); | |
| dialog.setMessage("Please wait..."); | |
| dialog.setCancelable(false); | |
| dialog.setCanceledOnTouchOutside(false); | |
| dialog.show(); | |
| if (orderConnector == null) { | |
| try { | |
| Thread.sleep(3000); | |
| } catch (InterruptedException e) { | |
| e.printStackTrace(); | |
| } | |
| Log.e("=====>>>>>", "only check" + orderConnector); | |
| } | |
| } | |
| @Override | |
| protected final Order doInBackground(Void... params) { | |
| try { | |
| Log.e("=======>", "OrderConnector:" + orderConnector + " OrderID:" + OrderId); | |
| Order od = orderConnector.getOrder(OrderId); | |
| //od.setTaxRemoved(true); | |
| if (is_redeem) { | |
| try { | |
| //orderConnector.getOrder(OrderId).setNote("Redeem reward point"); | |
| od.setNote(getString(R.string.order_note_redeem)); | |
| } catch (Exception e1) { | |
| Log.d("note", "==" + e1.toString()); | |
| } | |
| } else if (is_gift_redeem) { | |
| try { | |
| //orderConnector.getOrder(OrderId).setNote("Redeem reward point"); | |
| od.setNote(getString(R.string.order_note_gift)); | |
| } catch (Exception e1) { | |
| Log.d("note", "==" + e1.toString()); | |
| } | |
| } else { | |
| try { | |
| String nt = od.getNote(); | |
| if (nt.toString().contains(getString(R.string.order_note_redeem))) { | |
| nt = nt.replace(getString(R.string.order_note_redeem), ""); | |
| od.setNote(nt); | |
| } | |
| } catch (Exception e1) { | |
| Log.d("note", "==" + e1.toString()); | |
| } | |
| } | |
| orderConnector.updateOrder(od); | |
| return od; | |
| } catch (Exception e2) { | |
| e2.printStackTrace(); | |
| } | |
| return null; | |
| } | |
| @Override | |
| protected final void onPostExecute(Order order) { | |
| // Populate the UI | |
| if (!ChooserActivity.this.isFinishing()) { | |
| dialog.dismiss(); | |
| } | |
| if (order != null) { | |
| long Amount = order.getTotal(); | |
| // OrderCalc order_calc = new OrderCalc(order); | |
| // long subtotal = order_calc.getLineSubtotal(order.getLineItems()); | |
| long taxInCent; | |
| try { | |
| taxInCent = new OrderCalc(order).getTax(); | |
| //tax = 0; | |
| } catch (Exception e) { | |
| taxInCent = 0; | |
| } | |
| orderTaxAmount = BigDecimal.valueOf(taxInCent).divide(BigDecimal.valueOf(100)).toString(); | |
| TotalAmount = BigDecimal.valueOf(Amount).divide(BigDecimal.valueOf(100)).toString(); | |
| if (is_redeem) { | |
| ///if (payment_mode.equalsIgnoreCase("cash")) | |
| ///{ | |
| ///double d = (Double.parseDouble(TotalAmount)) * 100; | |
| String redeem_value = ""; | |
| try { | |
| redeem_value = Pref.getValue(ChooserActivity.this, "redeem_amount", "0"); | |
| } catch (Exception e) { | |
| } | |
| double redeem_point_val = 0; | |
| try { | |
| redeem_point_val = Double.parseDouble(Pref.getValue(ChooserActivity.this, "redeem_point", "0")); | |
| } catch (Exception e) { | |
| redeem_point_val = 0; | |
| } | |
| double redAmount = 0; | |
| if (!TextUtils.isEmpty(redeem_amount) && !redeem_amount.equals("0")) | |
| redAmount = Double.parseDouble(redeem_amount); | |
| else if (!TextUtils.isEmpty(redeem_value) && !redeem_value.equals("0")) | |
| redAmount = Double.parseDouble(redeem_value); | |
| Log.d("redAmount", "" + redAmount); | |
| Log.d("amounts", "" + min_redeem_amount + " < " + redeem_amount); | |
| if (min_redeem_amount <= redAmount) { | |
| //double d = (Double.parseDouble(TotalAmount)) * 100; | |
| String redeem_value_new = Pref.getValue(ChooserActivity.this, "redeem_amount", "0"); | |
| long redeemVal = 0; | |
| if (!TextUtils.isEmpty(redeem_value_new) && !redeem_value_new.equals("0")) | |
| redeemVal = (long) Math.round(Double.parseDouble(redeem_value_new) * 100); | |
| Log.d("redAmount", "" + redeemVal); | |
| // Check expiry token | |
| if (Pref.getValue(ChooserActivity.this, "DeviceID", "") == "") { | |
| Utility.getDeviceId(ChooserActivity.this, new DeviceIdCallback() { | |
| @Override | |
| public void onDeviceIdReceived(String device_id) { | |
| getExpiryTokenAndCallSetPaymentAPI(redeem_value_new, "Reward Point redeemed", device_id); | |
| } | |
| @Override | |
| public void onError(String error) { | |
| AlertUtils.showSimpleAlert(ChooserActivity.this, error); | |
| } | |
| }); | |
| } else { | |
| getExpiryTokenAndCallSetPaymentAPI(redeem_value_new, "Reward Point redeemed", Pref.getValue(ChooserActivity.this, "DeviceID", "")); | |
| } | |
| } else { | |
| if (!ChooserActivity.this.isFinishing()) { | |
| AlertUtils.showSimpleAlert(ChooserActivity.this, getString(R.string.app_name), | |
| getString(R.string.min_redeem_amount)).show(); | |
| } | |
| } | |
| } else if (is_gift_redeem) { | |
| /*int redeem_value = 0; | |
| try { | |
| redeem_value = Pref.getValueInt(ChooserActivity.this, "redeem_amount", 0); | |
| } catch (Exception e) { | |
| } | |
| int redeem_point_val = 0; | |
| try { | |
| redeem_point_val = Pref.getValueInt(ChooserActivity.this, "redeem_point", 0); | |
| } catch (Exception e) { | |
| redeem_point_val = 0; | |
| } | |
| Log.d("amounts", "" + min_redeem_amount + " < " + redeem_amount);*/ | |
| String gift_card_id; | |
| long gift_card_balance = 0l; | |
| try { | |
| gift_card_id = Pref.getValue(ChooserActivity.this, "gift_id", "0"); | |
| } catch (Exception e) { | |
| gift_card_id = "0"; | |
| } | |
| try { | |
| gift_card_balance = Long.parseLong(Pref.getValue(ChooserActivity.this, "gift_balance", "0")); | |
| } catch (Exception e) { | |
| gift_card_balance = 0l; | |
| } | |
| //RedeemGIFTAPI(gift_card_id, (+Long.parseLong(String.valueOf(Math.round((Integer.parseInt(gift_card_balance)))))), OrderId); | |
| RedeemGIFTAPI(gift_card_id, gift_card_balance, OrderId); | |
| /*if (min_redeem_amount <= redeem_amount) { | |
| RedeemGIFTAPI(selected_cust_id, (+Long.parseLong(String.valueOf(Math.round(redeem_value)))) | |
| , redeem_point_val, OrderId); | |
| } else { | |
| if (!ChooserActivity.this.isFinishing()) { | |
| AlertUtils.showSimpleAlert(ChooserActivity.this, getString(R.string.app_name), | |
| getString(R.string.min_redeem_amount)).show(); | |
| } | |
| }*/ | |
| } else { | |
| if (Pref.getValueboolean(ChooserActivity.this, "merchant_available_called", false)) { | |
| if (TextUtils.isEmpty(Pref.getValue(ChooserActivity.this, "m_id", ""))) { | |
| AlertUtils.showSimpleAlert(ChooserActivity.this, getString(R.string.merchant_id_not_found)); | |
| } else { | |
| add_order_api(OrderId, TotalAmount, "1", orderTaxAmount, Pref.getValue(ChooserActivity.this, "DeviceID", "")); | |
| } | |
| } else { | |
| AlertUtils.showSimpleAlert(ChooserActivity.this, getString(R.string.merchant_available_not_called)); | |
| } | |
| // } | |
| } | |
| } else { | |
| if (!ChooserActivity.this.isFinishing()) { | |
| AlertUtils.showSimpleAlert(ChooserActivity.this, getString(R.string.app_name), | |
| getString(R.string.clover_order_error)).show(); | |
| } | |
| } | |
| } | |
| } | |
| public void getExpiryTokenAndCallSetPaymentAPI(String orderAmount, String note, String deviceId) { | |
| HashMap<String, String> data = new HashMap<>(); | |
| data.put("merchant_id", merchantID); | |
| data.put("token", Pref.getValue(ChooserActivity.this, "a_token", "0")); | |
| data.put("clover_url", getResources().getString(R.string.clover_environment)); | |
| data.put("device_id", deviceId); | |
| progressUtils.showProgressDialog("Please wait"); | |
| Call<CheckExpiryTokenResponse> call = ApiClient.getClient(ChooserActivity.this).checkExpireAccessToken(data); | |
| call.enqueue(new Callback<CheckExpiryTokenResponse>() { | |
| CheckExpiryTokenResponse myresp; | |
| @Override | |
| public void onResponse(Call<CheckExpiryTokenResponse> call, Response<CheckExpiryTokenResponse> response) { | |
| progressUtils.dismissProgressDialog(); | |
| if (response.isSuccessful()) { | |
| myresp = response.body(); | |
| String msg = android.text.TextUtils.join(",", response.body().getMessage()); | |
| if (myresp.isStatus()) { | |
| callSetPaymentAPINew(orderAmount, note, myresp.getData().get(0).getAccess_token()); | |
| } else { | |
| if (!ChooserActivity.this.isFinishing()) { | |
| AlertUtils.showSimpleAlert(ChooserActivity.this, ChooserActivity.this.getString(R.string.app_name), | |
| msg).show(); | |
| } | |
| } | |
| } else { | |
| if (!ChooserActivity.this.isFinishing()) { | |
| Utility.getErrorString(response.code(), response.message(), errorString -> runOnUiThread(() -> AlertUtils.showSimpleAlert(ChooserActivity.this, | |
| getString(R.string.app_name), errorString).show())); | |
| } | |
| } | |
| } | |
| @Override | |
| public void onFailure(Call<CheckExpiryTokenResponse> call, Throwable t) { | |
| if (!ChooserActivity.this.isFinishing()) { | |
| progressUtils.dismissProgressDialog(); | |
| Log.e("errrrrrr", t.toString()); | |
| if (!ChooserActivity.this.isFinishing()) { | |
| Utility.getErrorString(t, errorString -> runOnUiThread(() -> AlertUtils.showSimpleAlert(ChooserActivity.this, | |
| getString(R.string.app_name), errorString).show())); | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| public void callSetPaymentAPINew(String orderAmount, String note, String token) { | |
| progressUtils.showProgressDialog("Please wait..."); | |
| SendJson sendJson = new SendJson(); | |
| SendJson.TenderBean tenderBean = new SendJson.TenderBean(); | |
| String tenderID = Pref.getValue(ChooserActivity.this, "tenderID", ""); | |
| if (!StringUtils.isEmpty(tenderID)) { | |
| tenderBean.setId(tenderID); | |
| tenderBean.setLabelKey("com.mybmr.rewards"); | |
| tenderBean.setLabel(!TextUtils.isEmpty(note) ? note : getResources().getString(R.string.tender_name)); | |
| sendJson.setTender(tenderBean); | |
| double d = 0; | |
| if (TextUtils.isEmpty(orderAmount)) { | |
| d = (Double.parseDouble(TotalAmount)) * 100; | |
| } else { | |
| d = (Double.parseDouble(orderAmount)) * 100; | |
| } | |
| //sendJson.setAmount(String.valueOf(Math.round(d))); | |
| sendJson.setAmount("" + Long.parseLong(String.valueOf(Math.round(d)))); | |
| Log.i("CHeckJSON", "++" + sendJson.toString()); | |
| Call<PaymentRestAPIResponse> call = ApiClient.getClientPaymentNew(this) | |
| .setPaymentRestAPI(sendJson, merchantID, OrderId, "Bearer " + token); | |
| call.enqueue(new Callback<PaymentRestAPIResponse>() { | |
| public PaymentRestAPIResponse myresp; | |
| @Override | |
| public void onResponse(Call<PaymentRestAPIResponse> call, Response<PaymentRestAPIResponse> response) { | |
| progressUtils.dismissProgressDialog(); | |
| Log.e("onResponse", "" + response.toString()); | |
| if (response.isSuccessful()) { | |
| myresp = response.body(); | |
| if (myresp != null && myresp.getResult().equals("SUCCESS")) { | |
| is_redeem_payment = true; | |
| LogM.v("amount:**" + amount); | |
| // progressUtils.showProgressDialog("Please wait while completing payment..."); | |
| paymentID = myresp.getId(); | |
| Log.i("09/01","Called UpdateOrderAsyncTask 1928"); | |
| new UpdateOrderAsyncTask().execute(); | |
| } else { | |
| if (!ChooserActivity.this.isFinishing()) { | |
| String msg = response.message(); | |
| if (msg.contains("Not Found")) { | |
| msg = "Order Not Found , Please try again"; | |
| } | |
| AlertUtils.showSimpleAlert(ChooserActivity.this, getString(R.string.app_name), | |
| msg).show(); | |
| } | |
| } | |
| } else { | |
| Pref.setValueboolean(getApplicationContext(), "printCashDiscount", false); | |
| if (!ChooserActivity.this.isFinishing()) { | |
| // Log response details for debugging | |
| Log.e("PaymentAPIError", "Response code: " + response.code() + ", message: " + response.message()); | |
| // Check for 404 status code (Order not found) | |
| if (response.code() == 404) { | |
| // Show dialog with retry option for 404 errors | |
| Log.i("PaymentAPIError", "404 detected, showing retry dialog"); | |
| show404RetryDialog(orderAmount, note, token); | |
| } else { | |
| // For other errors, continue as before | |
| Log.i("PaymentAPIError", "Non-404 error, showing simple alert"); | |
| String msg = response.message(); | |
| if (msg.contains("Not Found")) { | |
| msg = "Clover Order Not Found , Please try again"; | |
| } | |
| Utility.getErrorString(response.code(), response.message(), errorString -> runOnUiThread(() -> AlertUtils.showSimpleAlert(ChooserActivity.this, | |
| getString(R.string.app_name), errorString).show())); | |
| } | |
| } | |
| } | |
| } | |
| @Override | |
| public void onFailure(Call<PaymentRestAPIResponse> call, Throwable t) { | |
| // Log error here since request failed | |
| progressUtils.dismissProgressDialog(); | |
| Log.i("PAYMENT_ERROR", "" + t.getMessage()); | |
| if (!ChooserActivity.this.isFinishing()) { | |
| Utility.getErrorString(t, errorString -> runOnUiThread(() -> AlertUtils.showSimpleAlert(ChooserActivity.this, | |
| getString(R.string.app_name), errorString).show())); | |
| } | |
| } | |
| }); | |
| } else { | |
| if (!ChooserActivity.this.isFinishing()) { | |
| AlertUtils.showSimpleAlert(ChooserActivity.this, | |
| getString(R.string.app_name), getString(R.string.clover_payment_tender)).show(); | |
| if (progressUtils != null) { | |
| progressUtils.dismissProgressDialog(); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment