cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to validate the payment items that are added to a receipt?

former_member333938
Participant
0 Likes
672

Hello all,

I would like to know in what way, I can make validations when payment items are added to a receipt.

For example:

When I add a payment method, such as a credit card. I would like to make a validation and if the validation fails, prevent the payment method (credit card) from being added to the receipt.

anyone knows how to do this?

Thanks in advance.

Jose.

Accepted Solutions (1)

Accepted Solutions (1)

R_Zieschang
Active Contributor
0 Likes

Hi joerg.ceo & josehrmatos ,

you can check out the method addOrUpdatePaymentItem in the ReceiptPosService.class.

You plugin method should look something like this:

@PluginAt(pluginClass = ReceiptPosService.class, method = "addOrUpdatePaymentItem", where = POSITION.BEFORE)
    public void addSalesItem(Object proxy, Object[] args, StackTraceElement[] ste) throws BreakExecutionException

The method is overloaded, so your method should be called multiple times with a different count of arguments in the Object[] args array.

Check for count 6.

You'll get receipt, the type, the amount, the tip, the currencyCode and a internal helper class.

If these informations are enough to do your validation you may throw a BreakExecutionException if your validation fails, so CCO does not add the paymentItem...

If you need the paymentItem added to the receipt to do your validation, then you should use the POSITION.AFTER, then look for the last added paymentItem, do your validation and remove the paymentItem if your validation fails.

hth

Robert

JoergAldinger
Active Contributor
0 Likes

Exactly what we were looking for! Thanks a lot, rzieschang .

Will confirm back once we have tried it out.

Best regards!

Joerg.

former_member333938
Participant
0 Likes

Thank you very much for answering rzieschang. This solved my problem.

AaronMendieta
Participant
0 Likes

Hi Robert Zieschang!

I hope you are doing great, I have tried to test the code lines but I cannot get the event to be triggered in the backend when debugging, I have tried to do it the next ways:

1.- Just trying to catch the event and printing a message in the console

2.- Getting the argument in position 6 and trying to get its data

3.- Getting the argument in position 0 for the Receipt data and 1 for the PaymentItam data

@PluginAt(pluginClass = ReceiptPosService.class, method = "addOrUpdatePaymentItem", where = POSITION.BEFORE)
    public void addSalesItem(Object proxy, Object[] args, StackTraceElement[] ste) throws BreakExecutionException
    {
		System.out.println("Add Payment Item Event Triggered");
    }
@PluginAt(pluginClass = ReceiptPosService.class, method = "addOrUpdatePaymentItem", where = POSITION.BEFORE)
    public void addSalesItem(Object proxy, Object[] args, StackTraceElement[] ste) throws BreakExecutionException
    {
        PaymentItemEntity paymentItem = (PaymentItemEntity) args[6];	
	if (!paymentItem.getKey().isEmpty())
	{
		String PaymentKey = paymentItem.getKey();
		String PaymentAmount = paymentItem.getBusinessTransactionAmount().toString();	
	}
	System.out.println("Add Payment Item Event Triggered");
    }
@PluginAt(pluginClass = ReceiptPosService.class, method = "addOrUpdatePaymentItem", where = POSITION.BEFORE)
    public void addSalesItem(Object proxy, Object[] args, StackTraceElement[] ste) throws BreakExecutionException
    {
		ReceiptEntity receipt = (ReceiptEntity)args[0];
		PaymentItemEntity PaymentItem = (PaymentItemEntity)args[1];
		
		if(PaymentItem.getKey() != null) 
                {
			System.out.println(PaymentItem.getKey().toString());
		}
		System.out.println("Entro OK");
    }

I do think this event is triggered once the button "OK" is clicked (which performs adding payment item action), right?

I would really appreciate it if you could tell me what step I am missing or if the method has been changed or deprecated.

Thanks in advace for all and best regards Robert!

Answers (1)

Answers (1)

JoergAldinger
Active Contributor
0 Likes

rzieschang Can you help here? What we need is the correct ExitPoint to intercept and validate individual payment items added to the receipt...!? Should be easy enough... 🙂

Thanks!

Joerg.