59 lines
2.0 KiB
Java
59 lines
2.0 KiB
Java
package com.billpaymentservice.bbps.serviceImpl;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import com.billpaymentservice.bbps.dto.PaymentPollBackResponse;
|
|
import com.billpaymentservice.bbps.dto.ResponseModel;
|
|
import com.billpaymentservice.bbps.dto.request.PaymentStartUserRequest;
|
|
import com.billpaymentservice.bbps.dto.request.PollBackRequest;
|
|
import com.billpaymentservice.bbps.entites.PaymentStartRecord;
|
|
import com.billpaymentservice.bbps.repository.PaymentStartRecordRepository;
|
|
import com.billpaymentservice.bbps.service.PollBackService;
|
|
import com.billpaymentservice.bbps.util.Helper;
|
|
|
|
@Service
|
|
public class PollBackServiceImpl implements PollBackService {
|
|
|
|
private final PaymentStartRecordRepository paymentStartRecordRepository;
|
|
private final Helper helper;
|
|
|
|
PollBackServiceImpl(PaymentStartRecordRepository paymentStartRecordRepository,
|
|
Helper helper) {
|
|
this.paymentStartRecordRepository = paymentStartRecordRepository;
|
|
this.helper = helper;
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel managePollBack(PollBackRequest request) {
|
|
|
|
String requestId = request.getReqId();
|
|
String apiName = "PollBackRequest";
|
|
String txnId = helper.generateTxnId(15);
|
|
|
|
// Validate MID
|
|
helper.validateMerchant(request.getMid());
|
|
|
|
// Fetch payment record
|
|
PaymentStartRecord paymentStartRecord = paymentStartRecordRepository
|
|
.findByOrderNo(request.getOrderId())
|
|
.orElseThrow(() -> new RuntimeException(
|
|
"No payment record found for ReqID: " + requestId));
|
|
|
|
// Prepare response
|
|
PaymentPollBackResponse response = new PaymentPollBackResponse();
|
|
response.setOrderId(paymentStartRecord.getOrderNo());
|
|
response.setTxnId(paymentStartRecord.getTxnId());// Correct mapping
|
|
response.setTxnStatus(paymentStartRecord.getTxnStatus()); // Correct mapping
|
|
|
|
return new ResponseModel(
|
|
"Poll Back processed successfully",
|
|
"SUCCESS",
|
|
200,
|
|
response
|
|
);
|
|
}
|
|
|
|
|
|
|
|
}
|