|
@@ -68,7 +68,12 @@ import com.bgy.autosale.payutil.PayMixDialog;
|
|
|
import com.bgy.autosale.payutil.PaySuccessConstant;
|
|
|
import com.bgy.autosale.payutil.ScanDialog;
|
|
|
import com.bgy.autosale.payutil.ShoppingCartBean;
|
|
|
+import com.bgy.autosale.payutil.dialog.GkashPayDialog;
|
|
|
+import com.bgy.autosale.payutil.dialog.HttpCreditCardDialog;
|
|
|
import com.bgy.autosale.payutil.dialog.ShoppingTrolleyDialogChoosePay;
|
|
|
+import com.bgy.autosale.payutil.gkash.GkashApi;
|
|
|
+import com.bgy.autosale.payutil.gkash.GkashCardBean;
|
|
|
+import com.bgy.autosale.payutil.gkash.LordGkashBean;
|
|
|
import com.bgy.autosale.ui.MainActivity;
|
|
|
import com.bgy.autosale.ui.adapters.ShopCartAdapter;
|
|
|
import com.bgy.autosale.ui.base.BaseAutoExitFragment;
|
|
@@ -110,8 +115,10 @@ import com.hboxs.base_library.http.exception.BaseException;
|
|
|
import com.hboxs.base_library.http.exception.ExceptionFactory;
|
|
|
import com.hboxs.base_library.http.observer.HttpResultNotActivityObserver;
|
|
|
import com.hboxs.base_library.http.observer.HttpResultObserver;
|
|
|
+import com.hboxs.base_library.http.response.HttpJapanResultHandler;
|
|
|
import com.hboxs.base_library.http.response.HttpResult;
|
|
|
import com.hboxs.base_library.http.response.HttpResultHandler;
|
|
|
+import com.hboxs.base_library.http.response.HttpStringResultHandler;
|
|
|
import com.hboxs.base_library.util.DialogUtil;
|
|
|
import com.hboxs.base_library.util.DrawableSelectorUtils;
|
|
|
import com.hboxs.base_library.util.FileUtil;
|
|
@@ -119,6 +126,7 @@ import com.hboxs.base_library.util.LanguageUtil;
|
|
|
import com.hboxs.base_library.util.LogUtil;
|
|
|
import com.hboxs.base_library.util.LogUtils;
|
|
|
import com.hboxs.base_library.util.PreventSpeedClickUtil;
|
|
|
+import com.hboxs.base_library.util.RSASignUtil;
|
|
|
import com.hboxs.base_library.util.ReturnTomainScreenUtil;
|
|
|
import com.hboxs.base_library.util.SharedPreferencesUtils;
|
|
|
import com.hboxs.base_library.util.UiUtil;
|
|
@@ -131,6 +139,7 @@ import org.greenrobot.eventbus.EventBus;
|
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
|
import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.DecimalFormat;
|
|
@@ -159,6 +168,7 @@ import io.reactivex.observers.DisposableObserver;
|
|
|
import io.reactivex.schedulers.Schedulers;
|
|
|
import okhttp3.MediaType;
|
|
|
import okhttp3.RequestBody;
|
|
|
+import okhttp3.ResponseBody;
|
|
|
import top.keepempty.sph.library.SerialPortHelper;
|
|
|
import top.keepempty.sph.library.SphCmdEntity;
|
|
|
import top.keepempty.sph.library.SphResultCallback;
|
|
@@ -734,6 +744,9 @@ public class IceCreamFragment extends BaseAutoExitFragment implements View.OnCli
|
|
|
} else if (App.app.payChannel == Constant.PAY_POS_DEVICE_PAY_MIX || manualReason != null) {
|
|
|
dismissLoading();
|
|
|
showDialogChoosePay();
|
|
|
+ } else if (App.app.payChannel == Constant.GKash || manualReason != null) {
|
|
|
+ dismissLoading();
|
|
|
+ showDialogChoosePay();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -781,6 +794,14 @@ public class IceCreamFragment extends BaseAutoExitFragment implements View.OnCli
|
|
|
case R.id.btn_discounts_code:
|
|
|
handlePaymentSelection(0, R.id.btn_discounts_code, null);
|
|
|
break;
|
|
|
+ case R.id.iv_mlxy_gkash:
|
|
|
+ showLoading();
|
|
|
+ handlePaymentSelection(5, R.id.iv_mlxy_gkash, ()->getGkashQrcode(String.valueOf(pri), currentDish.name));
|
|
|
+ break;
|
|
|
+ case R.id.iv_mlxy_gkash_card:
|
|
|
+ showLoading();
|
|
|
+ handlePaymentSelection(4, R.id.iv_mlxy_gkash_card, ()->getGkashCard(String.valueOf(pri), currentDish.name));
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -1546,6 +1567,15 @@ public class IceCreamFragment extends BaseAutoExitFragment implements View.OnCli
|
|
|
scanDialog.dismiss();
|
|
|
scanDialog.stopTimeDown();
|
|
|
}
|
|
|
+ if (gkashPayDialog != null) {
|
|
|
+ gkashPayDialog.dismiss();
|
|
|
+ gkashPayDialog.stopTimeDown();
|
|
|
+ }
|
|
|
+ if (httpCreditCardDialog != null) {
|
|
|
+ httpCreditCardDialog.dismiss();
|
|
|
+ httpCreditCardDialog.stopTimeDown();
|
|
|
+ }
|
|
|
+
|
|
|
if (ispaySuccess) {
|
|
|
ispaySuccess = false;
|
|
|
showDialogPaySuccess(R.string.pay_success, R.drawable.icon_zhifu_pay);
|
|
@@ -2738,4 +2768,229 @@ public class IceCreamFragment extends BaseAutoExitFragment implements View.OnCli
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ private String gkashCid=Hawk.get(Name.GkashCID, Global.GkashCID);
|
|
|
+ private String gkashKey=Hawk.get(Name.GkashsignatureKey, Global.GkashsignatureKey);
|
|
|
+ private String gkashTid=Hawk.get(Name.GkashterminalID, Global.GkashterminalID);
|
|
|
+ //马来西亚Gkash主扫
|
|
|
+ public void getGkashQrcode(String price, String productName) {
|
|
|
+ StringBuilder productdesc= new StringBuilder();
|
|
|
+ for (int i = 0; i < orderHelper.getOrderList().size(); i++) {
|
|
|
+ Log.d(TAG, "onClick: 冰淇淋组合:" + orderHelper.getOrderList().get(i).selectTag);
|
|
|
+ Log.d(TAG, "单个商品需要制作的杯数:" + orderHelper.getOrderList().get(i).buyCount);
|
|
|
+ productdesc.append(orderHelper.getOrderList().get(i).selectTag).append("*").append(orderHelper.getOrderList().get(i).buyCount).append(";");
|
|
|
+ }
|
|
|
+ Log.d(TAG, "getGkashQrcode: "+productdesc);
|
|
|
+ Map<String, String> params1 = new HashMap<>();
|
|
|
+ params1.put("version", "1.5.5");
|
|
|
+ params1.put("v_amount", price);
|
|
|
+ params1.put("CID", gkashCid);
|
|
|
+ params1.put("v_currency", "MYR");
|
|
|
+ String payGkashOrderNo = UUID.randomUUID().toString().replace("-", "").toUpperCase();
|
|
|
+ params1.put("v_cartid", payGkashOrderNo);
|
|
|
+ double priceValue = Double.parseDouble(price);
|
|
|
+ String price1Value = String.format("%03d", (int) (priceValue * 100));
|
|
|
+ String signatureKey = gkashKey.toUpperCase();
|
|
|
+ String signature = RSASignUtil.signature(signatureKey, gkashCid, payGkashOrderNo, price1Value, "MYR");
|
|
|
+ params1.put("signature", signature);
|
|
|
+ params1.put("v_productdesc", String.valueOf(productdesc));
|
|
|
+ params1.put("paymentid", Global.Gkashpaymentid);
|
|
|
+ params1.put("terminalID", gkashTid);
|
|
|
+ Log.d(TAG, "getGkashQrcode:price1Value: " + price + ":" + price1Value);
|
|
|
+ Log.d(TAG, "getGkashQrcode: " + params1);
|
|
|
+ addSubscription(GkashApi.api.lordEsau(params1).compose(HttpStringResultHandler.<String>transformer()),
|
|
|
+ new HttpResultObserver<String>(mView, BaseApplication.getContext()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(String data) {
|
|
|
+ Log.d(TAG, "getGkashQrcode onNext: " + data);
|
|
|
+ Gson gson = new Gson();
|
|
|
+ LordGkashBean lordGkashBean = gson.fromJson(data, LordGkashBean.class);
|
|
|
+ Log.d(TAG, "getGkashQrcode onNext:lordGkashBean " + lordGkashBean);
|
|
|
+ PaySuccessConstant.sn = lordGkashBean.getCartid();
|
|
|
+ if ("11 - Pending".equals(lordGkashBean.getStatus())) {
|
|
|
+ getGkashCodeSuccess(lordGkashBean.getDescription().replace("DecodedQRText:", ""), lordGkashBean.getCartid(), payGkashOrderNo, price, signature);
|
|
|
+ //存儲訂單編號。
|
|
|
+ Global.mapOrderReference.put(lordGkashBean.getCartid(), lordGkashBean.getCartid());
|
|
|
+ } else {
|
|
|
+ nihaoPayFail(lordGkashBean.getDescription());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Throwable t) {
|
|
|
+ super.onError(t);
|
|
|
+ t.printStackTrace();
|
|
|
+ Log.d(TAG, "getGkashQrcode onError: " + t.getMessage());
|
|
|
+ nihaoPayFail(t.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //马来西亚Gkash刷卡
|
|
|
+ public void getGkashCard(String price, String productName) {
|
|
|
+ Map<String, Object> params1 = new HashMap<>();
|
|
|
+ params1.put("Amount", price);
|
|
|
+ params1.put("Currency", "MYR");
|
|
|
+ String payGkashOrderNo = UUID.randomUUID().toString().replace("-", "").toUpperCase();
|
|
|
+ params1.put("ReferenceNo", payGkashOrderNo);
|
|
|
+ params1.put("TerminalId", gkashTid);
|
|
|
+ double priceValue = Double.parseDouble(price);
|
|
|
+ String price1Value = String.format("%03d", (int) (priceValue * 100));
|
|
|
+ String signature = RSASignUtil.signature(gkashKey, price1Value, "MYR", payGkashOrderNo, gkashTid);
|
|
|
+ String signature1 = RSASignUtil.signature(gkashKey.toUpperCase(),gkashCid, payGkashOrderNo, price1Value, "MYR");
|
|
|
+ params1.put("signature", signature);
|
|
|
+ params1.put("PaymentType", 1);
|
|
|
+ Log.d(TAG, "getGkashCard: " + params1);
|
|
|
+ String body = new Gson().toJson(params1);
|
|
|
+ addSubscription(GkashApi.api.swipeCard(getRequestBody(body)).compose(HttpJapanResultHandler.<ResponseBody>transformer()),
|
|
|
+ new HttpResultObserver<ResponseBody>(mView, BaseApplication.getContext()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(ResponseBody data) {
|
|
|
+ Log.d(TAG, "getGkashCard onNext: " + data);
|
|
|
+ Gson gson = new Gson();
|
|
|
+ try {
|
|
|
+ GkashCardBean gkashCardBean = gson.fromJson(data.string(), GkashCardBean.class);
|
|
|
+ Log.d(TAG, "getGkashCardBean onNext: " + gkashCardBean);
|
|
|
+ Log.d(TAG, "americaNihaoPayMerchantBean11: "+gkashCardBean);
|
|
|
+ if ("Request successful".equals(gkashCardBean.getMessage()) && payGkashOrderNo.equals(gkashCardBean.getReferenceNo())) {
|
|
|
+ sendGkashCardSuccess(payGkashOrderNo, price, signature1);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Throwable t) {
|
|
|
+ super.onError(t);
|
|
|
+ t.printStackTrace();
|
|
|
+ Log.d(TAG, "getGkashCard onError: " + t.getMessage());
|
|
|
+ nihaoPayFail(t.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private int gkashCancelInt = 0;
|
|
|
+
|
|
|
+ //马来西亚Gkash刷卡取消
|
|
|
+ public void sendGkashCardCancel(String TerminalId) {
|
|
|
+ Map<String, Object> params1 = new HashMap<>();
|
|
|
+ params1.put("TerminalId", gkashTid);
|
|
|
+ String signature = RSASignUtil.signature(gkashKey, gkashTid);
|
|
|
+ params1.put("signature", signature);
|
|
|
+ Log.d(TAG, "sendGkashCardCancel: " + params1);
|
|
|
+ String body = new Gson().toJson(params1);
|
|
|
+ addSubscription(GkashApi.api.swipeCardCancel(getRequestBody(body)).compose(HttpJapanResultHandler.<ResponseBody>transformer()),
|
|
|
+ new HttpResultObserver<ResponseBody>(mView, BaseApplication.getContext()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(ResponseBody data) {
|
|
|
+ Log.d(TAG, "sendGkashCardCancel onNext1: " + data);
|
|
|
+ Gson gson = new Gson();
|
|
|
+ try {
|
|
|
+ GkashCardBean gkashCardBean = gson.fromJson(data.string(), GkashCardBean.class);
|
|
|
+ Log.d(TAG, "sendGkashCardCancel onNext: " + gkashCardBean);
|
|
|
+ if ("Request successful".equals(gkashCardBean.getMessage())) {
|
|
|
+ nihaoPayFail(gkashCardBean.getMessage());
|
|
|
+ }
|
|
|
+ gkashCancelInt = 0;
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Throwable t) {
|
|
|
+ super.onError(t);
|
|
|
+ t.printStackTrace();
|
|
|
+ if (gkashCancelInt < 3) {
|
|
|
+ new Handler().postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ gkashCancelInt++;
|
|
|
+ sendGkashCardCancel(TerminalId);
|
|
|
+ }
|
|
|
+ }, 3000);
|
|
|
+ }
|
|
|
+ Log.d(TAG, "sendGkashCardCancel onError: " + t.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private RequestBody getRequestBody(String body) {
|
|
|
+ return RequestBody.create(MediaType.parse("Content-Type:application/json"), body);
|
|
|
+ }
|
|
|
+
|
|
|
+ private HttpCreditCardDialog httpCreditCardDialog;
|
|
|
+
|
|
|
+ public void sendGkashCardSuccess(String TerminalId,String price,String signature) {
|
|
|
+ dismissLoading();
|
|
|
+ httpCreditCardDialog = new HttpCreditCardDialog(getContext(), getActivity());
|
|
|
+ httpCreditCardDialog.setListener(new DialogClickListener() {
|
|
|
+ public void onClickListener(int type) {
|
|
|
+ switch (type) {
|
|
|
+ case 125:
|
|
|
+// if (dialogChoosePay != null) {
|
|
|
+// dialogChoosePay.startTimeDown(60);
|
|
|
+// }
|
|
|
+// if (shoppingTrolleyDialogChoosePay != null) {
|
|
|
+// shoppingTrolleyDialogChoosePay.startTimeDown(60);
|
|
|
+// }
|
|
|
+ showLoading();
|
|
|
+ sendGkashCardCancel(TerminalId);
|
|
|
+ break;
|
|
|
+ case 130:
|
|
|
+ break;
|
|
|
+ case R.id.btn_cancel:
|
|
|
+ showLoading();
|
|
|
+ sendGkashCardCancel(TerminalId);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ httpCreditCardDialog.startTimeDown();
|
|
|
+ httpCreditCardDialog.setParams(TerminalId,price,signature) ;
|
|
|
+ httpCreditCardDialog.setImageView(R.drawable.icon_xinyongka_pay);
|
|
|
+ httpCreditCardDialog.show();
|
|
|
+ }
|
|
|
+ private void closeGkashCardDialog(){
|
|
|
+ if (httpCreditCardDialog!=null){
|
|
|
+ httpCreditCardDialog.dismiss();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private GkashPayDialog gkashPayDialog;
|
|
|
+
|
|
|
+ public void getGkashCodeSuccess(String rd_Pic, String sn,String cartid,String price,String signature) {
|
|
|
+// stopFinishTimer();
|
|
|
+ showGkashDialogScan(rd_Pic,sn,cartid,price,signature);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void showGkashDialogScan(String rd_Pic, String sn,String cartid,String price,String signature) {
|
|
|
+ gkashPayDialog = new GkashPayDialog(getContext(), getActivity());
|
|
|
+ gkashPayDialog.setListener(type -> {
|
|
|
+ switch (type) {
|
|
|
+ case 125:
|
|
|
+ BaseConstant.CANCEL_POLL = false;
|
|
|
+ break;
|
|
|
+ case 130:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ gkashPayDialog.setGifType(1);
|
|
|
+ gkashPayDialog.setCodeData(rd_Pic, sn,cartid,price,signature);
|
|
|
+ gkashPayDialog.show();
|
|
|
+ /**
|
|
|
+ * 二維碼出現的時候開啓定時任務。
|
|
|
+ * 1.使用傳遞過來的訂單編號開啓一個定時任務。
|
|
|
+ */
|
|
|
+ //scanDialog.startGetTime(sn);
|
|
|
+ loadingDialog.dismiss();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void nihaoPayFail(String message) {
|
|
|
+ dismissLoading();
|
|
|
+ com.hboxs.base_library.util.ToastUtil.showToast(message);
|
|
|
+ closeGkashCardDialog();
|
|
|
+ }
|
|
|
}
|