Wong Joon Hui
3 years ago
32 changed files with 2010 additions and 768 deletions
@ -1,4 +1,4 @@
|
||||
package com.cst.im30.retrofit; |
||||
package com.cst.im30.api; |
||||
|
||||
import java.util.concurrent.TimeUnit; |
||||
|
@ -0,0 +1,23 @@
|
||||
package com.cst.im30.model; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class PreAuthRequest implements Serializable { |
||||
|
||||
/** Mandatory 2 - 09 - Pre Auth **/ |
||||
private String payFunction = "09"; |
||||
|
||||
/** Mandatory 12 - Amount in cents (RM5.00 is "500" **/ |
||||
private String payAmount; //
|
||||
|
||||
/** Optional 50 **/ |
||||
private String payPosTxnId; |
||||
|
||||
/** Optional 1 - Y or N for Print Receipt or Not **/ |
||||
private String payPrintReceiptId = "N"; |
||||
|
||||
|
||||
} |
@ -0,0 +1,37 @@
|
||||
package com.cst.im30.model; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class PreAuthResponse implements Serializable { |
||||
|
||||
private String payAmount; |
||||
private String payFunction; |
||||
private String payType; |
||||
private String payPrintReceiptId; |
||||
private String payRespTxnDate; |
||||
private String payRespTxnTime; |
||||
private String payRespInvoiceNo; |
||||
private String payRespTraceNo; |
||||
private String payRespBatchNo; |
||||
private String payRespScheme; |
||||
private String payRespTid; |
||||
private String payRespMid; |
||||
private String payRespCardAuthCode; |
||||
private String payRespCardRefNum; |
||||
private String payRespCardNo; |
||||
private String payRespIssuerId; |
||||
private String payRespCardAid; |
||||
private String payRespCardAppCryptogram; |
||||
private String payRespCode; |
||||
private String payRespErrorDesc; |
||||
private String payRespMerchInfo; |
||||
private String payRespTvr; |
||||
private String payRespCvmDesc; |
||||
private String payRespAppLabel; |
||||
private String payRespHashPan; |
||||
private String token; |
||||
|
||||
} |
@ -0,0 +1,31 @@
|
||||
package com.cst.im30.model; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class SaleCompletionRequest implements Serializable { |
||||
|
||||
/** Mandatory 2 - 10 - Sale Completion **/ |
||||
private String payFunction = "10"; |
||||
|
||||
/** Mandatory 12 - Amount in cents (RM5.00 is "500" **/ |
||||
private String payAmount; |
||||
|
||||
/** Mandatory 6 - Pre Auth Transaction Approval Code **/ |
||||
private String payAuthCode; |
||||
|
||||
/** Optional 12 - Pre Auth Transaction Reference Number **/ |
||||
private String payRefNum; |
||||
|
||||
/** Optional 50 **/ |
||||
private String payPosTxnId; |
||||
|
||||
/** Optional 1 - Y or N for Print Receipt or Not **/ |
||||
private String payPrintReceiptId = "N"; |
||||
|
||||
/** Optional 50 - Pre Auth Card Token (Token + AuthCode + RefNum must be sent together) **/ |
||||
private String token; |
||||
|
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.cst.im30.model; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class SaleCompletionResponse implements Serializable { |
||||
|
||||
private String payAmount; |
||||
private String payFunction; |
||||
private String payType; |
||||
private String payPrintReceiptId; |
||||
private String payRespTxnDate; |
||||
private String payRespTxnTime; |
||||
private String payRespInvoiceNo; |
||||
private String payRespTraceNo; |
||||
private String payRespBatchNo; |
||||
private String payRespScheme; |
||||
private String payRespTid; |
||||
private String payRespMid; |
||||
private String payRespCardAuthCode; |
||||
private String payRespCardRefNum; |
||||
private String payRespCardNo; |
||||
private String payRespIssuerId; |
||||
private String payRespCardAid; |
||||
private String payRespCardAppCryptogram; |
||||
private String payRespCode; |
||||
private String payRespErrorDesc; |
||||
private String payRespMerchInfo; |
||||
private String payRespTvr; |
||||
private String payRespCvmDesc; |
||||
private String payRespAppLabel; |
||||
private String payRespHashPan; |
||||
|
||||
} |
@ -0,0 +1,28 @@
|
||||
package com.cst.im30.model; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class SaleRequest implements Serializable { |
||||
|
||||
/** Mandatory 2 - 01 - Sale **/ |
||||
private String payFunction = "01"; |
||||
|
||||
/** Mandatory 12 - Amount in cents (RM5.00 is "500" **/ |
||||
private String payAmount; //
|
||||
|
||||
/** Mandatory 2 - 01 Card / 02 QR / 03 DuitNow QR **/ |
||||
private String payType = "01"; |
||||
|
||||
/** Conditional 2 - 01 Back / 02 Front **/ |
||||
private String payCameraMode = "01"; |
||||
|
||||
/** Optional 50 **/ |
||||
private String payPosTxnId; |
||||
|
||||
/** Optional 1 - Y or N for Print Receipt or Not **/ |
||||
private String payPrintReceiptId = "N"; |
||||
|
||||
} |
@ -0,0 +1,40 @@
|
||||
package com.cst.im30.model; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class SaleResponse implements Serializable { |
||||
|
||||
private String payAmount; |
||||
private String payFunction; |
||||
private String payType; |
||||
private String payCameraMode; |
||||
private String payPrintReceiptId; |
||||
private String payRespTxnDate; |
||||
private String payRespTxnTime; |
||||
private String payRespInvoiceNo; |
||||
private String payRespTraceNo; |
||||
private String payRespBatchNo; |
||||
private String payRespScheme; |
||||
private String payRespTid; |
||||
private String payRespMid; |
||||
private String payRespCardAuthCode; |
||||
private String payRespCardRefNum; |
||||
private String payRespCardNo; |
||||
private String payRespIssuerId; |
||||
private String payRespCardAid; |
||||
private String payRespCardAppCryptogram; |
||||
private String payRespQrTxnId; |
||||
private String payRespQrWalletId; |
||||
private String payRespCustomerId; |
||||
private String payRespCode; |
||||
private String payRespErrorDesc; |
||||
private String payRespMerchInfo; |
||||
private String payRespTvr; |
||||
private String payRespCvmDesc; |
||||
private String payRespAppLabel; |
||||
private String payRespHashPan; |
||||
|
||||
} |
@ -0,0 +1,188 @@
|
||||
package com.cst.im30.service; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
|
||||
import com.cst.im30.BuildConfig; |
||||
import com.cst.im30.common.CallableInterface; |
||||
import com.cst.im30.model.EventLogDetailed; |
||||
import com.cst.im30.api.RetrofitAPICollection; |
||||
import com.cst.im30.api.RetrofitClient; |
||||
import com.cst.im30.utility.JsonUtils; |
||||
import com.cst.im30.utility.Logger; |
||||
|
||||
import org.json.JSONException; |
||||
import org.json.JSONObject; |
||||
|
||||
import retrofit2.Call; |
||||
import retrofit2.Callback; |
||||
import retrofit2.Response; |
||||
|
||||
public class PaymentService { |
||||
public static final String TAG = "PaymentSaleService."; |
||||
|
||||
public static final String SUCCESS_GET_EVENT_LOG = TAG + "SUCCESS_GET_EVENT_LOG"; |
||||
public static final String FAIL_GET_EVENT_LOG = TAG + "FAIL_GET_EVENT_LOG"; |
||||
public static final String SUCCESS_UPDATE_EVENT_LOG = TAG + "SUCCESS_UPDATE_EVENT_LOG"; |
||||
public static final String FAIL_UPDATE_EVENT_LOG = TAG + "FAIL_UPDATE_EVENT_LOG"; |
||||
|
||||
private final CallableInterface callback; |
||||
|
||||
private final String hostUrl; |
||||
private final String clientId; |
||||
private final String clientSecret; |
||||
|
||||
public PaymentService(CallableInterface callback) { |
||||
this.callback = callback; |
||||
|
||||
this.hostUrl = BuildConfig.SERVER_URL; |
||||
this.clientId = BuildConfig.CLIENT_ID; |
||||
this.clientSecret = BuildConfig.CLIENT_SECRET; |
||||
} |
||||
|
||||
public void getEventLog(String code) { |
||||
RetrofitAPICollection service = RetrofitClient.getRetrofitClient(hostUrl).create(RetrofitAPICollection.class); |
||||
Call<String> call = service.getBroadcastEventLogDetails(clientId, clientSecret, code); |
||||
|
||||
Logger.logV(code); |
||||
|
||||
call.enqueue(new Callback<String>() { |
||||
|
||||
@Override |
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { |
||||
onResponseGetEventLog(response); |
||||
} |
||||
|
||||
@Override |
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { |
||||
onFailureGetEventLog(t); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void onResponseGetEventLog(Response<String> response) { |
||||
try { |
||||
if (!response.isSuccessful()) { |
||||
JSONObject responseJSON = null; |
||||
if (response.errorBody() != null) { |
||||
responseJSON = new JSONObject(response.errorBody().string()); |
||||
Logger.logV(responseJSON.toString()); |
||||
} |
||||
callback.callBack(FAIL_GET_EVENT_LOG, responseJSON); |
||||
} else { |
||||
JSONObject responseJSON = new JSONObject(response.body()); |
||||
Logger.logV(responseJSON.toString()); |
||||
EventLogDetailed eventLogDetailed = this.parseGetEventLogResponse(responseJSON); |
||||
callback.callBack(SUCCESS_GET_EVENT_LOG, eventLogDetailed); |
||||
} |
||||
} catch (Exception e) { |
||||
Logger.logE(e.getMessage()); |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
private void onFailureGetEventLog(Throwable t) { |
||||
if (t instanceof Exception) { |
||||
Logger.logE(t.getMessage()); |
||||
((Exception) t).printStackTrace(); |
||||
} |
||||
callback.callBack(FAIL_GET_EVENT_LOG, t.getMessage()); |
||||
} |
||||
|
||||
private void updateBroadcastEventLogDetail(String code, String status) { |
||||
JSONObject payload = new JSONObject(); |
||||
try { |
||||
payload.put("status", status); |
||||
} catch (JSONException e) { |
||||
Logger.logE(e.getMessage()); |
||||
e.printStackTrace(); |
||||
return; |
||||
} |
||||
|
||||
RetrofitAPICollection service = RetrofitClient.getRetrofitClient(hostUrl).create(RetrofitAPICollection.class); |
||||
Call<String> call = service.updateBroadcastEventLogDetails(clientId, clientSecret, payload.toString(), code); |
||||
|
||||
Logger.logV("Update: " + code + ":" + payload.toString()); |
||||
|
||||
call.enqueue(new Callback<String>() { |
||||
|
||||
@Override |
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { |
||||
onResponseUpdateBroadcastEventLogDetails(response); |
||||
} |
||||
|
||||
@Override |
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { |
||||
onFailureUpdateEventLog(t); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void onResponseUpdateBroadcastEventLogDetails(Response<String> response) { |
||||
try { |
||||
if (!response.isSuccessful()) { |
||||
JSONObject responseJSON = null; |
||||
if (response.errorBody() != null) { |
||||
responseJSON = new JSONObject(response.errorBody().string()); |
||||
Logger.logV(responseJSON.toString()); |
||||
} |
||||
callback.callBack(FAIL_UPDATE_EVENT_LOG, responseJSON); |
||||
} else { |
||||
JSONObject responseJSON = new JSONObject(response.body()); |
||||
Logger.logV(responseJSON.toString()); |
||||
callback.callBack(SUCCESS_UPDATE_EVENT_LOG, responseJSON); |
||||
} |
||||
} catch (Exception e) { |
||||
Logger.logE(e.getMessage()); |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
private void onFailureUpdateEventLog(Throwable t) { |
||||
if (t instanceof Exception) { |
||||
Logger.logE(t.getMessage()); |
||||
((Exception) t).printStackTrace(); |
||||
} |
||||
callback.callBack(FAIL_UPDATE_EVENT_LOG, t.getMessage()); |
||||
} |
||||
|
||||
public void verifySuccess(String code) { |
||||
updateBroadcastEventLogDetail(code, "success"); |
||||
} |
||||
|
||||
public void verifyFail(String code) { |
||||
updateBroadcastEventLogDetail(code, "fail"); |
||||
} |
||||
|
||||
public void verifyCancel(String code) { |
||||
updateBroadcastEventLogDetail(code, "cancelled"); |
||||
} |
||||
|
||||
private EventLogDetailed parseGetEventLogResponse(JSONObject jsonObject) { |
||||
if (jsonObject.has("data")) { |
||||
try { |
||||
JSONObject dataJSON = jsonObject.getJSONObject("data"); |
||||
JSONObject contentJSON = dataJSON.getJSONObject("content"); |
||||
|
||||
EventLogDetailed eventLogDetailed = new EventLogDetailed(); |
||||
eventLogDetailed.setId(JsonUtils.extractJsonInteger(dataJSON, "id")); |
||||
eventLogDetailed.setType(JsonUtils.extractJsonString(dataJSON, "type")); |
||||
eventLogDetailed.setStatus(JsonUtils.extractJsonString(dataJSON, "status")); |
||||
eventLogDetailed.setRemark(JsonUtils.extractJsonString(dataJSON, "remark")); |
||||
eventLogDetailed.setPayableAmount(JsonUtils.extractJsonString(dataJSON, "payable_amount")); |
||||
eventLogDetailed.setPayFunction(JsonUtils.extractJsonString(dataJSON, "pay_function")); |
||||
eventLogDetailed.setConfirmationNumber(JsonUtils.extractJsonString(contentJSON, "confirmation_number")); |
||||
eventLogDetailed.setReferenceNumber(JsonUtils.extractJsonString(contentJSON, "reference_number")); |
||||
eventLogDetailed.setPayAuthCode(JsonUtils.extractJsonString(dataJSON, "pay_auth_code")); |
||||
eventLogDetailed.setPayRefNum(JsonUtils.extractJsonString(dataJSON, "pay_ref_num")); |
||||
eventLogDetailed.setToken(JsonUtils.extractJsonString(dataJSON, "token")); |
||||
|
||||
return eventLogDetailed; |
||||
} catch (Exception e) { |
||||
Logger.logE(e.getMessage()); |
||||
e.printStackTrace(); |
||||
return null; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,156 @@
|
||||
package com.cst.im30.service; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
|
||||
import com.cst.im30.BuildConfig; |
||||
import com.cst.im30.api.RetrofitAPICollection; |
||||
import com.cst.im30.api.RetrofitClient; |
||||
import com.cst.im30.common.CallableInterface; |
||||
import com.cst.im30.model.EventLogDetailed; |
||||
import com.cst.im30.model.PreAuthRequest; |
||||
import com.cst.im30.model.PreAuthResponse; |
||||
import com.cst.im30.model.SaleRequest; |
||||
import com.cst.im30.model.SaleResponse; |
||||
import com.cst.im30.utility.Logger; |
||||
|
||||
import org.json.JSONObject; |
||||
|
||||
import retrofit2.Call; |
||||
import retrofit2.Callback; |
||||
import retrofit2.Response; |
||||
|
||||
public class UploadTransactionPreAuthPaymentService { |
||||
public static final String TAG = "UploadTransactionPreAuthPaymentService."; |
||||
|
||||
public static final String SUCCESS = TAG + "SUCCESS"; |
||||
public static final String FAIL = TAG + "FAIL"; |
||||
|
||||
private final CallableInterface callback; |
||||
|
||||
private final String hostUrl; |
||||
private final String clientId; |
||||
private final String clientSecret; |
||||
|
||||
public UploadTransactionPreAuthPaymentService(CallableInterface callback) { |
||||
this.callback = callback; |
||||
|
||||
this.hostUrl = BuildConfig.SERVER_URL; |
||||
this.clientId = BuildConfig.CLIENT_ID; |
||||
this.clientSecret = BuildConfig.CLIENT_SECRET; |
||||
} |
||||
|
||||
public void call(EventLogDetailed eventLogDetailed, PreAuthRequest request, PreAuthResponse response) { |
||||
JSONObject payload = new JSONObject(); |
||||
try { |
||||
payload.put("revpay_request", createPreAuthRequestJSONObject(eventLogDetailed, request)); |
||||
payload.put("revpay_response", createPreAuthResponseJSONObject(eventLogDetailed, response)); |
||||
} catch (Exception e) { |
||||
Logger.logE(e.getMessage()); |
||||
e.printStackTrace(); |
||||
return; |
||||
} |
||||
|
||||
RetrofitAPICollection service = RetrofitClient.getRetrofitClient(hostUrl).create(RetrofitAPICollection.class); |
||||
Call<String> call = service.uploadRevPayTransaction(clientId, clientSecret, payload.toString()); |
||||
|
||||
Logger.logD(payload.toString()); |
||||
|
||||
call.enqueue(new Callback<String>() { |
||||
@Override |
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { |
||||
onResponseHandler(response); |
||||
} |
||||
|
||||
@Override |
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { |
||||
onFailureHandler(t); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void onResponseHandler(Response<String> response) { |
||||
try { |
||||
if (!response.isSuccessful()) { |
||||
JSONObject responseJSON = null; |
||||
if (response.errorBody() != null) { |
||||
responseJSON = new JSONObject(response.errorBody().string()); |
||||
} |
||||
callback.callBack(FAIL, responseJSON); |
||||
} else { |
||||
JSONObject responseJSON = new JSONObject(response.body()); |
||||
callback.callBack(SUCCESS, responseJSON); |
||||
} |
||||
} catch (Exception e) { |
||||
Logger.logE(e.getMessage()); |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
private void onFailureHandler(Throwable t) { |
||||
if (t instanceof Exception) { |
||||
Logger.logE(t.getMessage()); |
||||
((Exception) t).printStackTrace(); |
||||
} |
||||
callback.callBack(FAIL, t.getMessage()); |
||||
} |
||||
|
||||
private JSONObject createPreAuthRequestJSONObject(EventLogDetailed eventLogDetailed, PreAuthRequest request) { |
||||
JSONObject requestJSON = new JSONObject(); |
||||
try { |
||||
requestJSON.put("confirmation_number", eventLogDetailed.getConfirmationNumber()); |
||||
requestJSON.put("reference_number", eventLogDetailed.getReferenceNumber()); |
||||
|
||||
requestJSON.put("pay_function", request.getPayFunction()); |
||||
requestJSON.put("pay_amount", request.getPayAmount()); |
||||
requestJSON.put("pay_pos_txn_id", request.getPayPosTxnId()); |
||||
requestJSON.put("pay_print_receipt_id", request.getPayPrintReceiptId()); |
||||
|
||||
requestJSON.put("remark", eventLogDetailed.getRemark()); |
||||
} catch (Exception e) { |
||||
Logger.logE(e.getMessage()); |
||||
e.printStackTrace(); |
||||
} |
||||
return requestJSON; |
||||
} |
||||
|
||||
private JSONObject createPreAuthResponseJSONObject(EventLogDetailed eventLogDetailed, PreAuthResponse response) { |
||||
JSONObject requestJSON = new JSONObject(); |
||||
try { |
||||
requestJSON.put("confirmation_number", eventLogDetailed.getConfirmationNumber()); |
||||
requestJSON.put("reference_number", eventLogDetailed.getReferenceNumber()); |
||||
|
||||
requestJSON.put("pay_amount", response.getPayAmount()); |
||||
requestJSON.put("pay_function", response.getPayFunction()); |
||||
requestJSON.put("pay_type", response.getPayType()); |
||||
requestJSON.put("pay_print_receipt_id", response.getPayPrintReceiptId()); |
||||
requestJSON.put("pay_resp_txn_date", response.getPayRespTxnDate()); |
||||
requestJSON.put("pay_resp_txn_time", response.getPayRespTxnTime()); |
||||
requestJSON.put("pay_resp_invoice_no", response.getPayRespInvoiceNo()); |
||||
requestJSON.put("pay_resp_trace_no", response.getPayRespTraceNo()); |
||||
requestJSON.put("pay_resp_batch_no", response.getPayRespBatchNo()); |
||||
requestJSON.put("pay_resp_scheme", response.getPayRespScheme()); |
||||
requestJSON.put("pay_resp_tid", response.getPayRespTid()); |
||||
requestJSON.put("pay_resp_mid", response.getPayRespMid()); |
||||
requestJSON.put("pay_resp_card_auth_code", response.getPayRespCardAuthCode()); |
||||
requestJSON.put("pay_resp_card_ref_num", response.getPayRespCardRefNum()); |
||||
requestJSON.put("pay_resp_card_no", response.getPayRespCardNo()); |
||||
requestJSON.put("pay_resp_issuer_id", response.getPayRespIssuerId()); |
||||
requestJSON.put("pay_resp_card_aid", response.getPayRespCardAid()); |
||||
requestJSON.put("pay_resp_card_app_cryptogram", response.getPayRespCardAppCryptogram()); |
||||
requestJSON.put("pay_resp_code", response.getPayRespCode()); |
||||
requestJSON.put("pay_resp_error_desc", response.getPayRespErrorDesc()); |
||||
requestJSON.put("pay_resp_merch_info", response.getPayRespMerchInfo()); |
||||
requestJSON.put("pay_resp_tvr", response.getPayRespTvr()); |
||||
requestJSON.put("pay_resp_cvm_desc", response.getPayRespCvmDesc()); |
||||
requestJSON.put("pay_resp_app_label", response.getPayRespAppLabel()); |
||||
requestJSON.put("pay_resp_hash_pan", response.getPayRespHashPan()); |
||||
requestJSON.put("token", response.getToken()); |
||||
|
||||
requestJSON.put("remark", eventLogDetailed.getRemark()); |
||||
} catch (Exception e) { |
||||
Logger.logE(e.getMessage()); |
||||
e.printStackTrace(); |
||||
} |
||||
return requestJSON; |
||||
} |
||||
} |
@ -0,0 +1,158 @@
|
||||
package com.cst.im30.service; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
|
||||
import com.cst.im30.BuildConfig; |
||||
import com.cst.im30.api.RetrofitAPICollection; |
||||
import com.cst.im30.api.RetrofitClient; |
||||
import com.cst.im30.common.CallableInterface; |
||||
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.utility.Logger; |
||||
|
||||
import org.json.JSONObject; |
||||
|
||||
import retrofit2.Call; |
||||
import retrofit2.Callback; |
||||
import retrofit2.Response; |
||||
|
||||
public class UploadTransactionSaleCompletionPaymentService { |
||||
public static final String TAG = "UploadTransactionSaleCompletionPaymentService."; |
||||
|
||||
public static final String SUCCESS = TAG + "SUCCESS"; |
||||
public static final String FAIL = TAG + "FAIL"; |
||||
|
||||
private final CallableInterface callback; |
||||
|
||||
private final String hostUrl; |
||||
private final String clientId; |
||||
private final String clientSecret; |
||||
|
||||
public UploadTransactionSaleCompletionPaymentService(CallableInterface callback) { |
||||
this.callback = callback; |
||||
|
||||
this.hostUrl = BuildConfig.SERVER_URL; |
||||
this.clientId = BuildConfig.CLIENT_ID; |
||||
this.clientSecret = BuildConfig.CLIENT_SECRET; |
||||
} |
||||
|
||||
public void call(EventLogDetailed eventLogDetailed, SaleCompletionRequest request, SaleCompletionResponse response) { |
||||
JSONObject payload = new JSONObject(); |
||||
try { |
||||
payload.put("revpay_request", createSaleCompletionRequestJSONObject(eventLogDetailed, request)); |
||||
payload.put("revpay_response", createSaleCompletionResponseJSONObject(eventLogDetailed, response)); |
||||
} catch (Exception e) { |
||||
Logger.logE(e.getMessage()); |
||||
e.printStackTrace(); |
||||
return; |
||||
} |
||||
|
||||
RetrofitAPICollection service = RetrofitClient.getRetrofitClient(hostUrl).create(RetrofitAPICollection.class); |
||||
Call<String> call = service.uploadRevPayTransaction(clientId, clientSecret, payload.toString()); |
||||
|
||||
Logger.logD(payload.toString()); |
||||
|
||||
call.enqueue(new Callback<String>() { |
||||
@Override |
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { |
||||
onResponseHandler(response); |
||||
} |
||||
|
||||
@Override |
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { |
||||
onFailureHandler(t); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void onResponseHandler(Response<String> response) { |
||||
try { |
||||
if (!response.isSuccessful()) { |
||||
JSONObject responseJSON = null; |
||||
if (response.errorBody() != null) { |
||||
responseJSON = new JSONObject(response.errorBody().string()); |
||||
} |
||||
callback.callBack(FAIL, responseJSON); |
||||
} else { |
||||
JSONObject responseJSON = new JSONObject(response.body()); |
||||
callback.callBack(SUCCESS, responseJSON); |
||||
} |
||||
} catch (Exception e) { |
||||
Logger.logE(e.getMessage()); |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
private void onFailureHandler(Throwable t) { |
||||
if (t instanceof Exception) { |
||||
Logger.logE(t.getMessage()); |
||||
((Exception) t).printStackTrace(); |
||||
} |
||||
callback.callBack(FAIL, t.getMessage()); |
||||
} |
||||
|
||||
private JSONObject createSaleCompletionRequestJSONObject(EventLogDetailed eventLogDetailed, SaleCompletionRequest request) { |
||||
JSONObject requestJSON = new JSONObject(); |
||||
try { |
||||
requestJSON.put("confirmation_number", eventLogDetailed.getConfirmationNumber()); |
||||
requestJSON.put("reference_number", eventLogDetailed.getReferenceNumber()); |
||||
|
||||
requestJSON.put("pay_function", request.getPayFunction()); |
||||
requestJSON.put("pay_amount", request.getPayAmount()); |
||||
requestJSON.put("pay_auth_code", request.getPayAuthCode()); |
||||
requestJSON.put("pay_ref_num", request.getPayRefNum()); |
||||
requestJSON.put("pay_pos_txn_id", request.getPayPosTxnId()); |
||||
requestJSON.put("pay_print_receipt_id", request.getPayPrintReceiptId()); |
||||
requestJSON.put("token", request.getToken()); |
||||
|
||||
requestJSON.put("remark", eventLogDetailed.getRemark()); |
||||
} catch (Exception e) { |
||||
Logger.logE(e.getMessage()); |
||||
e.printStackTrace(); |
||||
} |
||||
return requestJSON; |
||||
} |
||||
|
||||
private JSONObject createSaleCompletionResponseJSONObject(EventLogDetailed eventLogDetailed, SaleCompletionResponse response) { |
||||
JSONObject requestJSON = new JSONObject(); |
||||
try { |
||||
requestJSON.put("confirmation_number", eventLogDetailed.getConfirmationNumber()); |
||||
requestJSON.put("reference_number", eventLogDetailed.getReferenceNumber()); |
||||
|
||||
requestJSON.put("pay_amount", response.getPayAmount()); |
||||
requestJSON.put("pay_function", response.getPayFunction()); |
||||
requestJSON.put("pay_type", response.getPayType()); |
||||
requestJSON.put("pay_print_receipt_id", response.getPayPrintReceiptId()); |
||||
requestJSON.put("pay_resp_txn_date", response.getPayRespTxnDate()); |
||||
requestJSON.put("pay_resp_txn_time", response.getPayRespTxnTime()); |
||||
requestJSON.put("pay_resp_invoice_no", response.getPayRespInvoiceNo()); |
||||
requestJSON.put("pay_resp_trace_no", response.getPayRespTraceNo()); |
||||
requestJSON.put("pay_resp_batch_no", response.getPayRespBatchNo()); |
||||
requestJSON.put("pay_resp_scheme", response.getPayRespScheme()); |
||||
requestJSON.put("pay_resp_tid", response.getPayRespTid()); |
||||
requestJSON.put("pay_resp_mid", response.getPayRespMid()); |
||||
requestJSON.put("pay_resp_card_auth_code", response.getPayRespCardAuthCode()); |
||||
requestJSON.put("pay_resp_card_ref_num", response.getPayRespCardRefNum()); |
||||
requestJSON.put("pay_resp_card_no", response.getPayRespCardNo()); |
||||
requestJSON.put("pay_resp_issuer_id", response.getPayRespIssuerId()); |
||||
requestJSON.put("pay_resp_card_aid", response.getPayRespCardAid()); |
||||
requestJSON.put("pay_resp_card_app_cryptogram", response.getPayRespCardAppCryptogram()); |
||||
requestJSON.put("pay_resp_code", response.getPayRespCode()); |
||||
requestJSON.put("pay_resp_error_desc", response.getPayRespErrorDesc()); |
||||
requestJSON.put("pay_resp_merch_info", response.getPayRespMerchInfo()); |
||||
requestJSON.put("pay_resp_tvr", response.getPayRespTvr()); |
||||
requestJSON.put("pay_resp_cvm_desc", response.getPayRespCvmDesc()); |
||||
requestJSON.put("pay_resp_app_label", response.getPayRespAppLabel()); |
||||
requestJSON.put("pay_resp_hash_pan", response.getPayRespHashPan()); |
||||
|
||||
requestJSON.put("remark", eventLogDetailed.getRemark()); |
||||
} catch (Exception e) { |
||||
Logger.logE(e.getMessage()); |
||||
e.printStackTrace(); |
||||
} |
||||
return requestJSON; |
||||
} |
||||
} |
@ -0,0 +1,159 @@
|
||||
package com.cst.im30.service; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
|
||||
import com.cst.im30.BuildConfig; |
||||
import com.cst.im30.api.RetrofitAPICollection; |
||||
import com.cst.im30.api.RetrofitClient; |
||||
import com.cst.im30.common.CallableInterface; |
||||
import com.cst.im30.model.EventLogDetailed; |
||||
import com.cst.im30.model.SaleRequest; |
||||
import com.cst.im30.model.SaleResponse; |
||||
import com.cst.im30.utility.Logger; |
||||
|
||||
import org.json.JSONObject; |
||||
|
||||
import retrofit2.Call; |
||||
import retrofit2.Callback; |
||||
import retrofit2.Response; |
||||
|
||||
public class UploadTransactionSalePaymentService { |
||||
public static final String TAG = "UploadTransactionSalePaymentService."; |
||||
|
||||
public static final String SUCCESS = TAG + "SUCCESS"; |
||||
public static final String FAIL = TAG + "FAIL"; |
||||
|
||||
private final CallableInterface callback; |
||||
|
||||
private final String hostUrl; |
||||
private final String clientId; |
||||
private final String clientSecret; |
||||
|
||||
public UploadTransactionSalePaymentService(CallableInterface callback) { |
||||
this.callback = callback; |
||||
|
||||
this.hostUrl = BuildConfig.SERVER_URL; |
||||
this.clientId = BuildConfig.CLIENT_ID; |
||||
this.clientSecret = BuildConfig.CLIENT_SECRET; |
||||
} |
||||
|
||||
public void call(EventLogDetailed eventLogDetailed, SaleRequest saleRequest, SaleResponse saleResponse) { |
||||
JSONObject payload = new JSONObject(); |
||||
try { |
||||
payload.put("revpay_request", createSaleRequestJSONObject(eventLogDetailed, saleRequest)); |
||||
payload.put("revpay_response", createSaleResponseJSONObject(eventLogDetailed, saleResponse)); |
||||
} catch (Exception e) { |
||||
Logger.logE(e.getMessage()); |
||||
e.printStackTrace(); |
||||
return; |
||||
} |
||||
|
||||
RetrofitAPICollection service = RetrofitClient.getRetrofitClient(hostUrl).create(RetrofitAPICollection.class); |
||||
Call<String> call = service.uploadRevPayTransaction(clientId, clientSecret, payload.toString()); |
||||
|
||||
Logger.logD(payload.toString()); |
||||
|
||||
call.enqueue(new Callback<String>() { |
||||
@Override |
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { |
||||
onResponseHandler(response); |
||||
} |
||||
|
||||
@Override |
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { |
||||
onFailureHandler(t); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void onResponseHandler(Response<String> response) { |
||||
try { |
||||
if (!response.isSuccessful()) { |
||||
JSONObject responseJSON = null; |
||||
if (response.errorBody() != null) { |
||||
responseJSON = new JSONObject(response.errorBody().string()); |
||||
} |
||||
callback.callBack(FAIL, responseJSON); |
||||
} else { |
||||
JSONObject responseJSON = new JSONObject(response.body()); |
||||
callback.callBack(SUCCESS, responseJSON); |
||||
} |
||||
} catch (Exception e) { |
||||
Logger.logE(e.getMessage()); |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
private void onFailureHandler(Throwable t) { |
||||
if (t instanceof Exception) { |
||||
Logger.logE(t.getMessage()); |
||||
((Exception) t).printStackTrace(); |
||||
} |
||||
callback.callBack(FAIL, t.getMessage()); |
||||
} |
||||
|
||||
private JSONObject createSaleRequestJSONObject(EventLogDetailed eventLogDetailed, SaleRequest saleRequest) { |
||||
JSONObject request = new JSONObject(); |
||||
try { |
||||
request.put("confirmation_number", eventLogDetailed.getConfirmationNumber()); |
||||
request.put("reference_number", eventLogDetailed.getReferenceNumber()); |
||||
|
||||
request.put("pay_function", saleRequest.getPayFunction()); |
||||
request.put("pay_amount", saleRequest.getPayAmount()); |
||||
request.put("pay_type", saleRequest.getPayType()); |
||||
request.put("pay_camera_mode", saleRequest.getPayCameraMode()); |
||||
request.put("pay_pos_txn_id", saleRequest.getPayPosTxnId()); |
||||
request.put("pay_print_receipt_id", saleRequest.getPayPrintReceiptId()); |
||||
|
||||
request.put("remark", eventLogDetailed.getRemark()); |
||||
} catch (Exception e) { |
||||
Logger.logE(e.getMessage()); |
||||
e.printStackTrace(); |
||||
} |
||||
return request; |
||||
} |
||||
|
||||
private JSONObject createSaleResponseJSONObject(EventLogDetailed eventLogDetailed, SaleResponse saleResponse) { |
||||
JSONObject request = new JSONObject(); |
||||
try { |
||||
request.put("confirmation_number", eventLogDetailed.getConfirmationNumber()); |
||||
request.put("reference_number", eventLogDetailed.getReferenceNumber()); |
||||
|
||||
request.put("pay_amount", saleResponse.getPayAmount()); |
||||
request.put("pay_function", saleResponse.getPayFunction()); |
||||
request.put("pay_type", saleResponse.getPayType()); |
||||
request.put("pay_camera_mode", saleResponse.getPayCameraMode()); |
||||
request.put("pay_print_receipt_id", saleResponse.getPayPrintReceiptId()); |
||||
request.put("pay_resp_txn_date", saleResponse.getPayRespTxnDate()); |
||||
request.put("pay_resp_txn_time", saleResponse.getPayRespTxnTime()); |
||||
request.put("pay_resp_invoice_no", saleResponse.getPayRespInvoiceNo()); |
||||
request.put("pay_resp_trace_no", saleResponse.getPayRespTraceNo()); |
||||
request.put("pay_resp_batch_no", saleResponse.getPayRespBatchNo()); |
||||
request.put("pay_resp_scheme", saleResponse.getPayRespScheme()); |
||||
request.put("pay_resp_tid", saleResponse.getPayRespTid()); |
||||
request.put("pay_resp_mid", saleResponse.getPayRespMid()); |
||||
request.put("pay_resp_card_auth_code", saleResponse.getPayRespCardAuthCode()); |
||||
request.put("pay_resp_card_ref_num", saleResponse.getPayRespCardRefNum()); |
||||
request.put("pay_resp_card_no", saleResponse.getPayRespCardNo()); |
||||
request.put("pay_resp_issuer_id", saleResponse.getPayRespIssuerId()); |
||||
request.put("pay_resp_card_aid", saleResponse.getPayRespCardAid()); |
||||
request.put("pay_resp_card_app_cryptogram", saleResponse.getPayRespCardAppCryptogram()); |
||||
request.put("pay_resp_qr_txn_id", saleResponse.getPayRespQrTxnId()); |
||||
request.put("pay_resp_qr_wallet_id", saleResponse.getPayRespQrWalletId()); |
||||
request.put("pay_resp_customer_id", saleResponse.getPayRespCustomerId()); |
||||
request.put("pay_resp_code", saleResponse.getPayRespCode()); |
||||
request.put("pay_resp_error_desc", saleResponse.getPayRespErrorDesc()); |
||||
request.put("pay_resp_merch_info", saleResponse.getPayRespMerchInfo()); |
||||
request.put("pay_resp_tvr", saleResponse.getPayRespTvr()); |
||||
request.put("pay_resp_cvm_desc", saleResponse.getPayRespCvmDesc()); |
||||
request.put("pay_resp_app_label", saleResponse.getPayRespAppLabel()); |
||||
request.put("pay_resp_hash_pan", saleResponse.getPayRespHashPan()); |
||||
|
||||
request.put("remark", eventLogDetailed.getRemark()); |
||||
} catch (Exception e) { |
||||
Logger.logE(e.getMessage()); |
||||
e.printStackTrace(); |
||||
} |
||||
return request; |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
package com.cst.im30.utility; |
||||
|
||||
import android.text.TextUtils; |
||||
|
||||
import org.json.JSONObject; |
||||
|
||||
public class JsonUtils { |
||||
|
||||
public static String extractJsonString(JSONObject responseJSON, String name) { |
||||
try { |
||||
if (responseJSON.has(name)) { |
||||
return responseJSON.getString(name); |
||||
} else { |
||||
return ""; // null json will return "";
|
||||
} |
||||
} catch (Exception ignored) { |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
public static int extractJsonInteger(JSONObject responseJSON, String name) { |
||||
return extractJsonInteger(responseJSON, name, -1); |
||||
} |
||||
|
||||
public static int extractJsonInteger(JSONObject responseJSON, String name, int defaultValue) { |
||||
try { |
||||
String rv = responseJSON.getString(name).trim(); |
||||
if (rv.isEmpty()) { |
||||
return defaultValue; |
||||
} else { |
||||
if (TextUtils.isDigitsOnly(rv)) { |
||||
return Integer.parseInt(rv); |
||||
} else { |
||||
return defaultValue; |
||||
} |
||||
} |
||||
} catch (Exception ignored) { |
||||
return defaultValue; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,122 @@
|
||||
package com.cst.im30.utility; |
||||
|
||||
import com.cst.im30.model.EventLogDetailed; |
||||
import com.cst.im30.model.PreAuthRequest; |
||||
import com.cst.im30.model.SaleCompletionRequest; |
||||
import com.cst.im30.model.SaleRequest; |
||||
|
||||
import java.text.DecimalFormat; |
||||
|
||||
public class PaymentUtils { |
||||
|
||||
|
||||
public static SaleRequest createSaleRequest(EventLogDetailed eventLogDetailed) { |
||||
SaleRequest request = new SaleRequest(); |
||||
|
||||
double doubleValue = Double.parseDouble(eventLogDetailed.getPayableAmount()); |
||||
double centValueDouble = doubleValue * 100; |
||||
DecimalFormat df = new DecimalFormat("#"); |
||||
request.setPayAmount(String.valueOf(df.format(centValueDouble))); |
||||
|
||||
request.setPayPosTxnId(eventLogDetailed.getReferenceNumber() + eventLogDetailed.getId()); |
||||
|
||||
return request; |
||||
} |
||||
|
||||
public static PreAuthRequest createPreAuthRequest(EventLogDetailed eventLogDetailed) { |
||||
PreAuthRequest request = new PreAuthRequest(); |
||||
|
||||
double doubleValue = Double.parseDouble(eventLogDetailed.getPayableAmount()); |
||||
double centValueDouble = doubleValue * 100; |
||||
DecimalFormat df = new DecimalFormat("#"); |
||||
request.setPayAmount(String.valueOf(df.format(centValueDouble))); |
||||
|
||||
request.setPayPosTxnId(eventLogDetailed.getReferenceNumber() + eventLogDetailed.getId()); |
||||
|
||||
return request; |
||||
} |
||||
|
||||
public static SaleCompletionRequest createSaleCompletionRequest(EventLogDetailed eventLogDetailed) { |
||||
SaleCompletionRequest request = new SaleCompletionRequest(); |
||||
|
||||
double doubleValue = Double.parseDouble(eventLogDetailed.getPayableAmount()); |
||||
double centValueDouble = doubleValue * 100; |
||||
DecimalFormat df = new DecimalFormat("#"); |
||||
request.setPayAmount(String.valueOf(df.format(centValueDouble))); |
||||
|
||||
request.setPayPosTxnId(eventLogDetailed.getReferenceNumber() + eventLogDetailed.getId()); |
||||
|
||||
request.setPayAuthCode(eventLogDetailed.getPayAuthCode()); |
||||
request.setPayRefNum(eventLogDetailed.getPayRefNum()); |
||||
request.setToken(eventLogDetailed.getToken()); |
||||
|
||||
return request; |
||||
} |
||||
|
||||
public static boolean validateSaleRequest(SaleRequest request) { |
||||
boolean valid = true; |
||||
|
||||
//todo
|
||||
|
||||
return valid; |
||||
} |
||||
|
||||
public static boolean validatePreAuthRequest(PreAuthRequest request) { |
||||
boolean valid = true; |
||||
|
||||
//todo
|
||||
|
||||
return valid; |
||||
} |
||||
|
||||
public static boolean validateSaleCompletionRequest(SaleCompletionRequest request) { |
||||
boolean valid = true; |
||||
|
||||
//todo
|
||||
|
||||
return valid; |
||||
} |
||||
|
||||
public static boolean validateResponseCodeAndMessage(String code, String status) { |
||||
if (code.equalsIgnoreCase("00") && status.equalsIgnoreCase("approved")) { |
||||
Logger.logD("Transaction Approved"); |
||||
return true; |
||||
} |
||||
|
||||
if (code.equalsIgnoreCase("00") && status.equalsIgnoreCase("Offline Approval")) { |
||||
Logger.logD("Offline Approval"); |
||||
return true; |
||||
} |
||||
|
||||
else if (code.equalsIgnoreCase("00") && status.equalsIgnoreCase("declined")) { |
||||
Logger.logD("Transaction Approved but Declined ErrorCode"); |
||||
return false; |
||||
} |
||||
|
||||
else if (code.equalsIgnoreCase("ND")) { |
||||
Logger.logD("User Cancel or No Host Response"); |
||||
return false; |
||||
} |
||||
|
||||
else if (code.equalsIgnoreCase("99")) { |
||||
Logger.logD("Transaction Declined"); |
||||
return false; |
||||
} |
||||
|
||||
else if (code.equalsIgnoreCase("CE")) { |
||||
Logger.logD("Transaction Declined"); |
||||
return false; |
||||
} |
||||
|
||||
else if (code.equalsIgnoreCase("TO") && status.equalsIgnoreCase("timeout")) { |
||||
Logger.logD("Payment Timeout"); |
||||
return false; |
||||
} |
||||
|
||||
else { |
||||
Logger.logD("FAIL: Unsupported Combination: " + code + ":" + status); |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:background="@drawable/pop_up_bg" |
||||
android:orientation="vertical"> |
||||
|
||||
<TextView |
||||
android:id="@+id/title" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:background="@drawable/pop_up_round_top_text" |
||||
android:paddingTop="20dp" |
||||
android:paddingBottom="20dp" |
||||
android:text="@string/txt_title" |
||||
android:textAlignment="center" |
||||
android:textColor="@color/white" |
||||
android:textSize="20sp" |
||||
android:textStyle="bold" /> |
||||
|
||||
<RelativeLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical" |
||||
android:paddingStart="20dp" |
||||
android:paddingTop="20dp" |
||||
android:paddingEnd="20dp" |
||||
android:paddingBottom="20dp" |
||||
tools:ignore="UseCompoundDrawables"> |
||||
|
||||
<ImageView |
||||
android:id="@+id/image" |
||||
android:layout_width="200dp" |
||||
android:layout_height="200dp" |
||||
android:layout_centerHorizontal="true" |
||||
android:contentDescription="@string/txt_image_description" |
||||
android:src="@drawable/ic_status_success_fancy" |
||||
android:textAlignment="center" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/message" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_below="@id/image" |
||||
android:layout_marginTop="16dp" |
||||
android:text="@string/txt_message" |
||||
android:textAlignment="center" |
||||
android:textSize="20sp" /> |
||||
|
||||
</RelativeLayout> |
||||
|
||||
</LinearLayout> |
Loading…
Reference in new issue