Wong Joon Hui
3 years ago
13 changed files with 615 additions and 264 deletions
@ -1,17 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||||
<project version="4"> |
|
||||||
<component name="deploymentTargetDropDown"> |
|
||||||
<runningDeviceTargetSelectedWithDropDown> |
|
||||||
<Target> |
|
||||||
<type value="RUNNING_DEVICE_TARGET" /> |
|
||||||
<deviceKey> |
|
||||||
<Key> |
|
||||||
<type value="SERIAL_NUMBER" /> |
|
||||||
<value value="1640011591" /> |
|
||||||
</Key> |
|
||||||
</deviceKey> |
|
||||||
</Target> |
|
||||||
</runningDeviceTargetSelectedWithDropDown> |
|
||||||
<timeTargetWasSelectedWithDropDown value="2022-04-19T01:28:28.927516800Z" /> |
|
||||||
</component> |
|
||||||
</project> |
|
@ -0,0 +1,352 @@ |
|||||||
|
package com.cst.im30; |
||||||
|
|
||||||
|
import android.content.Context; |
||||||
|
import android.content.Intent; |
||||||
|
import android.os.Bundle; |
||||||
|
import android.widget.Toast; |
||||||
|
|
||||||
|
import com.cst.im30.activity.ResponseActivity; |
||||||
|
import com.cst.im30.common.Constants; |
||||||
|
import com.cst.im30.model.CancelRequest; |
||||||
|
import com.cst.im30.model.CancelResponse; |
||||||
|
import com.cst.im30.model.EventLogDetailed; |
||||||
|
import com.cst.im30.model.PreAuthRequest; |
||||||
|
import com.cst.im30.model.PreAuthResponse; |
||||||
|
import com.cst.im30.model.SaleCompletionRequest; |
||||||
|
import com.cst.im30.model.SaleCompletionResponse; |
||||||
|
import com.cst.im30.model.SaleRequest; |
||||||
|
import com.cst.im30.model.SaleResponse; |
||||||
|
import com.cst.im30.model.VoidRequest; |
||||||
|
import com.cst.im30.model.VoidResponse; |
||||||
|
import com.cst.im30.service.UploadTransactionPreAuthPaymentService; |
||||||
|
import com.cst.im30.service.UploadTransactionSaleCompletionPaymentService; |
||||||
|
import com.cst.im30.service.UploadTransactionSalePaymentService; |
||||||
|
import com.cst.im30.utility.Logger; |
||||||
|
import com.cst.im30.utility.PaymentUtils; |
||||||
|
|
||||||
|
public class PaymentHandler { |
||||||
|
|
||||||
|
private final Context context; |
||||||
|
|
||||||
|
public PaymentHandler(Context context) { |
||||||
|
this.context = context; |
||||||
|
} |
||||||
|
|
||||||
|
public void handlePayFunctionSale(EventLogDetailed eventLogDetailed) { |
||||||
|
SaleRequest request = PaymentUtils.createSaleRequest(eventLogDetailed); |
||||||
|
if (PaymentUtils.validateSaleRequest(request)) { |
||||||
|
initSalePayment(request); |
||||||
|
} else { |
||||||
|
Toast.makeText(context, "Invalid Sale Request", Toast.LENGTH_SHORT).show(); |
||||||
|
Logger.logW("Invalid Sale Request: " + request.toString()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void handlePayFunctionVoid(EventLogDetailed eventLogDetailed) { |
||||||
|
VoidRequest request = PaymentUtils.createVoidRequest(eventLogDetailed); |
||||||
|
if (PaymentUtils.validateVoidRequest(request)) { |
||||||
|
initVoid(request); |
||||||
|
} else { |
||||||
|
Toast.makeText(context, "Invalid Void Request", Toast.LENGTH_SHORT).show(); |
||||||
|
Logger.logW("Invalid Void Request: " + request.toString()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void handlePayFunctionCancel() { |
||||||
|
CancelRequest request = new CancelRequest(); |
||||||
|
initCancel(request); |
||||||
|
} |
||||||
|
|
||||||
|
public void handlePayFunctionPreAuth(EventLogDetailed eventLogDetailed) { |
||||||
|
PreAuthRequest request = PaymentUtils.createPreAuthRequest(eventLogDetailed); |
||||||
|
if (PaymentUtils.validatePreAuthRequest(request)) { |
||||||
|
initPreAuth(request); |
||||||
|
} else { |
||||||
|
Toast.makeText(context, "Invalid Pre Auth Request", Toast.LENGTH_SHORT).show(); |
||||||
|
Logger.logW("Invalid Pre Auth Request: " + request.toString()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void handlePayFunctionSaleCompletion(EventLogDetailed eventLogDetailed) { |
||||||
|
SaleCompletionRequest request = PaymentUtils.createSaleCompletionRequest(eventLogDetailed); |
||||||
|
if (PaymentUtils.validateSaleCompletionRequest(request)) { |
||||||
|
initSaleCompletion(request); |
||||||
|
} else { |
||||||
|
Toast.makeText(context, "Invalid Sale Completion Request", Toast.LENGTH_SHORT).show(); |
||||||
|
Logger.logW("Invalid Sale Completion Request: " + request.toString()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void initSalePayment(SaleRequest request) { |
||||||
|
Logger.logD("Direct Payment: " + request.toString()); |
||||||
|
|
||||||
|
Bundle extra = new Bundle(); |
||||||
|
extra.putString("pay_function", request.getPayFunction()); |
||||||
|
extra.putString("pay_amount", String.valueOf(request.getPayAmount())); |
||||||
|
extra.putString("pay_type", request.getPayType()); |
||||||
|
|
||||||
|
String payCameraMode = request.getPayCameraMode(); |
||||||
|
if (payCameraMode != null && !payCameraMode.isEmpty()) { |
||||||
|
extra.putString("pay_camera_mode", payCameraMode); |
||||||
|
} |
||||||
|
|
||||||
|
String payPosTxnId = request.getPayPosTxnId(); |
||||||
|
if (payPosTxnId != null && !payPosTxnId.isEmpty()) { |
||||||
|
extra.putString("pay_pos_txn_id", payPosTxnId); |
||||||
|
} |
||||||
|
|
||||||
|
extra.putString("pay_print_receipt_id", request.getPayPrintReceiptId()); |
||||||
|
|
||||||
|
MainApplication.currentSaleRequest = request; |
||||||
|
|
||||||
|
app2app(extra); |
||||||
|
} |
||||||
|
|
||||||
|
public void initVoid(VoidRequest request) { |
||||||
|
Logger.logD("Void Payment: " + request.toString()); |
||||||
|
|
||||||
|
Bundle extra = new Bundle(); |
||||||
|
extra.putString("pay_function", request.getPayFunction()); |
||||||
|
extra.putString("pay_amount", String.valueOf(request.getPayAmount())); |
||||||
|
extra.putString("pay_print_receipt_id", request.getPayPrintReceiptId()); |
||||||
|
extra.putString("pay_trace_no", request.getPayTraceNo()); |
||||||
|
extra.putString("pay_invoice_no", request.getPayInvoiceNo()); |
||||||
|
|
||||||
|
String payPosTxnId = request.getPayPosTxnId(); |
||||||
|
if (payPosTxnId != null && !payPosTxnId.isEmpty()) { |
||||||
|
extra.putString("pay_pos_txn_id", payPosTxnId); |
||||||
|
} |
||||||
|
|
||||||
|
MainApplication.currentVoidRequest = request; |
||||||
|
|
||||||
|
app2app(extra); |
||||||
|
} |
||||||
|
|
||||||
|
public void initCancel(CancelRequest request) { |
||||||
|
Logger.logD(request.toString()); |
||||||
|
|
||||||
|
Bundle extra = new Bundle(); |
||||||
|
extra.putString("pay_function", request.getPayFunction()); |
||||||
|
|
||||||
|
MainApplication.currentCancelRequest = request; |
||||||
|
|
||||||
|
app2app(extra); |
||||||
|
} |
||||||
|
|
||||||
|
public void initPreAuth(PreAuthRequest request) { |
||||||
|
Logger.logD(request.toString()); |
||||||
|
|
||||||
|
Bundle extra = new Bundle(); |
||||||
|
extra.putString("pay_function", request.getPayFunction()); |
||||||
|
extra.putString("pay_amount", String.valueOf(request.getPayAmount())); |
||||||
|
|
||||||
|
String payPosTxnId = request.getPayPosTxnId(); |
||||||
|
if (payPosTxnId != null && !payPosTxnId.isEmpty()) { |
||||||
|
extra.putString("pay_pos_txn_id", payPosTxnId); |
||||||
|
} |
||||||
|
|
||||||
|
extra.putString("pay_print_receipt_id", request.getPayPrintReceiptId()); |
||||||
|
|
||||||
|
MainApplication.currentPreAuthRequest = request; |
||||||
|
|
||||||
|
app2app(extra); |
||||||
|
} |
||||||
|
|
||||||
|
public void initSaleCompletion(SaleCompletionRequest request) { |
||||||
|
Logger.logD(request.toString()); |
||||||
|
|
||||||
|
Bundle extra = new Bundle(); |
||||||
|
extra.putString("pay_function", request.getPayFunction()); |
||||||
|
extra.putString("pay_amount", String.valueOf(request.getPayAmount())); |
||||||
|
|
||||||
|
extra.putString("pay_auth_code", request.getPayAuthCode()); |
||||||
|
extra.putString("pay_ref_num", request.getPayRefNum()); |
||||||
|
|
||||||
|
String payPosTxnId = request.getPayPosTxnId(); |
||||||
|
if (payPosTxnId != null && !payPosTxnId.isEmpty()) { |
||||||
|
extra.putString("pay_pos_txn_id", payPosTxnId); |
||||||
|
} |
||||||
|
|
||||||
|
extra.putString("pay_print_receipt_id", request.getPayPrintReceiptId()); |
||||||
|
extra.putString("token", request.getToken()); |
||||||
|
|
||||||
|
MainApplication.currentSaleCompletionRequest = request; |
||||||
|
|
||||||
|
app2app(extra); |
||||||
|
} |
||||||
|
|
||||||
|
private void app2app(Bundle bundle) { |
||||||
|
Intent intent = new Intent(Constants.APP_2_APP); |
||||||
|
intent.putExtras(bundle); |
||||||
|
|
||||||
|
Logger.logD("App2App Call to: " + Constants.APP_2_APP); |
||||||
|
|
||||||
|
context.startActivity(intent); |
||||||
|
} |
||||||
|
|
||||||
|
public void handlePayFunctionSaleResponse(Bundle extra) { |
||||||
|
SaleResponse response = new SaleResponse(); |
||||||
|
|
||||||
|
response.setPayAmount(extra.getString("pay_amount")); |
||||||
|
response.setPayFunction(extra.getString("pay_function")); |
||||||
|
response.setPayType(extra.getString("pay_type")); |
||||||
|
response.setPayCameraMode(extra.getString("pay_camera_mode")); |
||||||
|
response.setPayPrintReceiptId(extra.getString("pay_print_receipt_id")); |
||||||
|
response.setPayRespTxnDate(extra.getString("pay_resp_txn_date")); |
||||||
|
response.setPayRespTxnTime(extra.getString("pay_resp_txn_time")); |
||||||
|
response.setPayRespInvoiceNo(extra.getString("pay_resp_invoice_no")); |
||||||
|
response.setPayRespTraceNo(extra.getString("pay_resp_trace_no")); |
||||||
|
response.setPayRespBatchNo(extra.getString("pay_resp_batch_no")); |
||||||
|
response.setPayRespScheme(extra.getString("pay_resp_scheme")); |
||||||
|
response.setPayRespTid(extra.getString("pay_resp_tid")); |
||||||
|
response.setPayRespMid(extra.getString("pay_resp_mid")); |
||||||
|
response.setPayRespCardAuthCode(extra.getString("pay_resp_card_auth_code")); |
||||||
|
response.setPayRespCardRefNum(extra.getString("pay_resp_card_ref_num")); |
||||||
|
response.setPayRespCardNo(extra.getString("pay_resp_card_no")); |
||||||
|
response.setPayRespIssuerId(extra.getString("pay_resp_issuer_id")); |
||||||
|
response.setPayRespCardAid(extra.getString("pay_resp_card_aid")); |
||||||
|
response.setPayRespCardAppCryptogram(extra.getString("pay_resp_card_app_cryptogram")); |
||||||
|
response.setPayRespQrTxnId(extra.getString("pay_resp_qr_txn_id")); |
||||||
|
response.setPayRespQrWalletId(extra.getString("pay_resp_qr_wallet_id")); |
||||||
|
response.setPayRespCustomerId(extra.getString("pay_resp_customer_id")); |
||||||
|
response.setPayRespCode(extra.getString("pay_resp_code")); |
||||||
|
response.setPayRespErrorDesc(extra.getString("pay_resp_error_desc")); |
||||||
|
response.setPayRespMerchInfo(extra.getString("pay_resp_merch_info")); |
||||||
|
response.setPayRespTvr(extra.getString("pay_resp_tvr")); |
||||||
|
response.setPayRespCvmDesc(extra.getString("pay_resp_cvm_desc")); |
||||||
|
response.setPayRespAppLabel(extra.getString("pay_resp_app_label")); |
||||||
|
response.setPayRespHashPan(extra.getString("pay_resp_hash_pan")); |
||||||
|
|
||||||
|
Logger.logD(response.toString()); |
||||||
|
|
||||||
|
MainApplication.currentSaleResponse = response; |
||||||
|
|
||||||
|
MainApplication.code = response.getPayRespCode(); |
||||||
|
MainApplication.status = response.getPayRespErrorDesc(); |
||||||
|
} |
||||||
|
|
||||||
|
public void handlePayFunctionVoidResponse(Bundle extra) { |
||||||
|
VoidResponse response = new VoidResponse(); |
||||||
|
|
||||||
|
response.setPayAmount(extra.getString("pay_amount")); |
||||||
|
response.setPayFunction(extra.getString("pay_function")); |
||||||
|
response.setPayType(extra.getString("pay_type")); |
||||||
|
response.setPayPrintReceiptId(extra.getString("pay_print_receipt_id")); |
||||||
|
response.setPayRespTxnDate(extra.getString("pay_resp_txn_date")); |
||||||
|
response.setPayRespTxnTime(extra.getString("pay_resp_txn_time")); |
||||||
|
response.setPayRespInvoiceNo(extra.getString("pay_resp_invoice_no")); |
||||||
|
response.setPayRespTraceNo(extra.getString("pay_resp_trace_no")); |
||||||
|
response.setPayRespBatchNo(extra.getString("pay_resp_batch_no")); |
||||||
|
response.setPayRespScheme(extra.getString("pay_resp_scheme")); |
||||||
|
response.setPayRespTid(extra.getString("pay_resp_tid")); |
||||||
|
response.setPayRespMid(extra.getString("pay_resp_mid")); |
||||||
|
response.setPayRespCardAuthCode(extra.getString("pay_resp_card_auth_code")); |
||||||
|
response.setPayRespCardRefNum(extra.getString("pay_resp_card_ref_num")); |
||||||
|
response.setPayRespQrTxnId(extra.getString("pay_resp_qr_txn_id")); |
||||||
|
response.setPayRespQrWalletId(extra.getString("pay_resp_qr_wallet_id")); |
||||||
|
response.setPayRespCardNo(extra.getString("pay_resp_card_no")); |
||||||
|
response.setPayRespIssuerId(extra.getString("pay_resp_issuer_id")); |
||||||
|
response.setPayRespCustomerId(extra.getString("pay_resp_customer_id")); |
||||||
|
response.setPayRespCardAppCryptogram(extra.getString("pay_resp_card_app_cryptogram")); |
||||||
|
response.setPayRespCode(extra.getString("pay_resp_code")); |
||||||
|
response.setPayRespErrorDesc(extra.getString("pay_resp_error_desc")); |
||||||
|
response.setPayRespMerchInfo(extra.getString("pay_resp_merch_info")); |
||||||
|
response.setPayRespTvr(extra.getString("pay_resp_tvr")); |
||||||
|
response.setPayRespCvmDesc(extra.getString("pay_resp_cvm_desc")); |
||||||
|
response.setPayRespAppLabel(extra.getString("pay_resp_app_label")); |
||||||
|
|
||||||
|
Logger.logD(response.toString()); |
||||||
|
|
||||||
|
MainApplication.currentVoidResponse = response; |
||||||
|
|
||||||
|
MainApplication.code = response.getPayRespCode(); |
||||||
|
MainApplication.status = response.getPayRespErrorDesc(); |
||||||
|
} |
||||||
|
|
||||||
|
public void handlePayFunctionCancelResponse(Bundle extra) { |
||||||
|
CancelResponse response = new CancelResponse(); |
||||||
|
|
||||||
|
response.setPayFunction(extra.getString("pay_function")); |
||||||
|
response.setPayRespCode(extra.getString("pay_resp_code")); |
||||||
|
|
||||||
|
Logger.logD(response.toString()); |
||||||
|
|
||||||
|
MainApplication.currentCancelResponse = response; |
||||||
|
} |
||||||
|
|
||||||
|
public void handlePayFunctionPreAuthResponse(Bundle extra) { |
||||||
|
PreAuthResponse response = new PreAuthResponse(); |
||||||
|
|
||||||
|
response.setPayAmount(extra.getString("pay_amount")); |
||||||
|
response.setPayFunction(extra.getString("pay_function")); |
||||||
|
response.setPayType(extra.getString("pay_type")); |
||||||
|
response.setPayPrintReceiptId(extra.getString("pay_print_receipt_id")); |
||||||
|
response.setPayRespTxnDate(extra.getString("pay_resp_txn_date")); |
||||||
|
response.setPayRespTxnTime(extra.getString("pay_resp_txn_time")); |
||||||
|
response.setPayRespInvoiceNo(extra.getString("pay_resp_invoice_no")); |
||||||
|
response.setPayRespTraceNo(extra.getString("pay_resp_trace_no")); |
||||||
|
response.setPayRespBatchNo(extra.getString("pay_resp_batch_no")); |
||||||
|
response.setPayRespScheme(extra.getString("pay_resp_scheme")); |
||||||
|
response.setPayRespTid(extra.getString("pay_resp_tid")); |
||||||
|
response.setPayRespMid(extra.getString("pay_resp_mid")); |
||||||
|
response.setPayRespCardAuthCode(extra.getString("pay_resp_card_auth_code")); |
||||||
|
response.setPayRespCardRefNum(extra.getString("pay_resp_card_ref_num")); |
||||||
|
response.setPayRespCardNo(extra.getString("pay_resp_card_no")); |
||||||
|
response.setPayRespIssuerId(extra.getString("pay_resp_issuer_id")); |
||||||
|
response.setPayRespCardAid(extra.getString("pay_resp_card_aid")); |
||||||
|
response.setPayRespCardAppCryptogram(extra.getString("pay_resp_card_app_cryptogram")); |
||||||
|
response.setPayRespCode(extra.getString("pay_resp_code")); |
||||||
|
response.setPayRespErrorDesc(extra.getString("pay_resp_error_desc")); |
||||||
|
response.setPayRespMerchInfo(extra.getString("pay_resp_merch_info")); |
||||||
|
response.setPayRespTvr(extra.getString("pay_resp_tvr")); |
||||||
|
response.setPayRespCvmDesc(extra.getString("pay_resp_cvm_desc")); |
||||||
|
response.setPayRespAppLabel(extra.getString("pay_resp_app_label")); |
||||||
|
response.setPayRespHashPan(extra.getString("pay_resp_hash_pan")); |
||||||
|
response.setToken(extra.getString("token")); |
||||||
|
|
||||||
|
Logger.logD(response.toString()); |
||||||
|
|
||||||
|
MainApplication.code = response.getPayRespCode(); |
||||||
|
MainApplication.status = response.getPayRespErrorDesc(); |
||||||
|
|
||||||
|
MainApplication.currentPreAuthResponse = response; |
||||||
|
} |
||||||
|
|
||||||
|
public void handlePayFunctionSaleCompletionResponse(Bundle extra) { |
||||||
|
SaleCompletionResponse response = new SaleCompletionResponse(); |
||||||
|
|
||||||
|
response.setPayAmount(extra.getString("pay_amount")); |
||||||
|
response.setPayFunction(extra.getString("pay_function")); |
||||||
|
response.setPayType(extra.getString("pay_type")); |
||||||
|
response.setPayPrintReceiptId(extra.getString("pay_print_receipt_id")); |
||||||
|
response.setPayRespTxnDate(extra.getString("pay_resp_txn_date")); |
||||||
|
response.setPayRespTxnTime(extra.getString("pay_resp_txn_time")); |
||||||
|
response.setPayRespInvoiceNo(extra.getString("pay_resp_invoice_no")); |
||||||
|
response.setPayRespTraceNo(extra.getString("pay_resp_trace_no")); |
||||||
|
response.setPayRespBatchNo(extra.getString("pay_resp_batch_no")); |
||||||
|
response.setPayRespScheme(extra.getString("pay_resp_scheme")); |
||||||
|
response.setPayRespTid(extra.getString("pay_resp_tid")); |
||||||
|
response.setPayRespMid(extra.getString("pay_resp_mid")); |
||||||
|
response.setPayRespCardAuthCode(extra.getString("pay_resp_card_auth_code")); |
||||||
|
response.setPayRespCardRefNum(extra.getString("pay_resp_card_ref_num")); |
||||||
|
response.setPayRespCardNo(extra.getString("pay_resp_card_no")); |
||||||
|
response.setPayRespIssuerId(extra.getString("pay_resp_issuer_id")); |
||||||
|
response.setPayRespCardAid(extra.getString("pay_resp_card_aid")); |
||||||
|
response.setPayRespCardAppCryptogram(extra.getString("pay_resp_card_app_cryptogram")); |
||||||
|
response.setPayRespCode(extra.getString("pay_resp_code")); |
||||||
|
response.setPayRespErrorDesc(extra.getString("pay_resp_error_desc")); |
||||||
|
response.setPayRespMerchInfo(extra.getString("pay_resp_merch_info")); |
||||||
|
response.setPayRespTvr(extra.getString("pay_resp_tvr")); |
||||||
|
response.setPayRespCvmDesc(extra.getString("pay_resp_cvm_desc")); |
||||||
|
response.setPayRespAppLabel(extra.getString("pay_resp_app_label")); |
||||||
|
response.setPayRespHashPan(extra.getString("pay_resp_hash_pan")); |
||||||
|
|
||||||
|
Logger.logD(response.toString()); |
||||||
|
|
||||||
|
MainApplication.code = response.getPayRespCode(); |
||||||
|
MainApplication.status = response.getPayRespErrorDesc(); |
||||||
|
|
||||||
|
MainApplication.currentSaleCompletionResponse = response; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue