cancel
Showing results for 
Search instead for 
Did you mean: 

Add a free voucher using JAVA

former_member333938
Participant

Hello all:

I would like to know how I can add a free voucher manually using code.

Trying to find the solution I found this object that has similar properties to when I add the free voucher through UI.

But it does not work.

anyone knows how to do this?

Thanks in advance.

Jose.

Hi, rzieschang maybe, you has some solution or idea for this questions for add free voucher via plugin?

Accepted Solutions (1)

Accepted Solutions (1)

R_Zieschang
Contributor
0 Kudos

Hi josehrmatos , Hi isaacceo

sorry for the late reply.

You need to add a new PaymentItemEntity to your ReceiptEntity. The type of the paymentitem needs to be 20 and the paymenitem also needs to have a voucherentity attached. I did not tested it myself so it could be possible that I am missing some fields in one of these entities which needs to be set, but this would be a good start.


try (CDBSession cdbSession = CDBSessionFactory.instance.createSession()) {
            ReceiptPosService receiptManager = ServiceFactory.INSTANCE.getOrCreateServiceInstance(ReceiptPosService.class, cdbSession);

PaymentItemEntity paymentItemEntity = new PaymentItemEntity();
paymentItemEntity.setBusinessTransactionAmount(new BigDecimal(50));
paymentItemEntity.setOriginalBusinessTransactionAmount(new BigDecimal(50));
paymentItemEntity.setBusinessTransactioncurrency("EUR");
paymentItemEntity.setCreditCardTypeCode(PaymentItemEntity.PaymentType.FREE_VOUCHER);
paymentItemEntity.setPaymentFormCode(PaymentItemEntity.PaymentFormCode.VOUCHER);
paymentItemEntity.setStatus(PaymentItemEntity.Status.CONFIRMED);

VoucherEntity voucher = new VoucherEntity();
voucher.setCashDeskId("MY cashdesk id");
voucher.setCurrency("EUR");
voucher.setFreeVoucher(true);
voucher.setOriginalAmount(new BigDecimal(50));
voucher.setValidTo(new Date(2020, 10, 20));

paymentItemEntity.setVoucher(voucher);

receiptManager .addPaymentItems(receipt, paymentItemEntity);
}

The receipt Pos service also validates your paymentItem and voucher. So if there is anything missing, it should throw an exception which hints you into the right direction.

hth

Robert

umerwaleed
Member
0 Kudos

Hi Robert,

I need your help. I have added 'Loyalty Point' in Credit Card Type. Now, I want to include this type from the backend. Please find the attached code. It's not showing that payment type in the payment area. Can you please help me out?

CDBSession cdbSession = CDBSessionFactory.instance.createSession();
StockLocationPosService stockLocationPosService = ServiceFactory.INSTANCE
.getOrCreateServiceInstance(StockLocationPosService.class, cdbSession);
ReceiptPosService receiptPosService = ServiceFactory.INSTANCE
.getOrCreateServiceInstance(ReceiptPosService.class, cdbSession);
ReceiptEntity receipt = receiptPosService.findOrCreate(UserRegistry.INSTANCE.getCurrentUser(), null,true);
if (receipt == null) {
throw new RuntimeException("Failed to retrieve or create a receipt.");
}
ReceiptManager rm = new ReceiptManager(cdbSession);
PaymentItemEntity paymentItemEntity = new PaymentItemEntity();
paymentItemEntity.setBusinessTransactionAmount(paymentTender.getLoyaltyAmount());
paymentItemEntity.setOriginalBusinessTransactionAmount(paymentTender.getLoyaltyAmount());
paymentItemEntity.setOriginalBusinessTransactioncurrency("LYD");
paymentItemEntity.setBusinessTransactioncurrency("LYD");
paymentItemEntity.setCreditCardTypeCode("16");
paymentItemEntity.setCreditCardErpTypeCode("101");
paymentItemEntity.setPaymentFormCode(PaymentItemEntity.PaymentFormCode.CARD_PAYMENT);
paymentItemEntity.setStatus(PaymentItemEntity.Status.CONFIRMED);
paymentItemEntity.setCreditCardTypeName("Loyalty Point");
paymentItemEntity.setExchangeRateUsed(new BigDecimal(1));
paymentItemEntity.setMarkChanged(false);
rm.addPaymentItems(receipt, paymentItemEntity);

Answers (0)