Payment Processor Assistance: Script with response based result

Right, not the testing server for the PMS is back online its time to have a go at working out the samba side of a room post.

So I have the script which generates the JSON ready to post the ticket details to the PMS all sorted and tested.

What I am looking to do is have it so a payment button of room post will;

A. Generate charge JSON and post to PMS

The following Samba side flow will depend on the result as being local --> cloud integration need to build in aspects for failed charges if nothing else but for in the internet goes down so plan so far is;

Correct charged responce;

  • Add a tag or similar of the charge numbers returned from the PMS
  • Mark as paid, dont think need to go to extent of accounts and can just have a ‘Room post’ payment type.
  • Print a specific template for room post.

Failed responses;
Cannot Connect: Retry/Manual/Cancel option, retry repeating the charge script. Cancel returning to ticket and possibly adding ticket log for failed attempt.
Error Response: some form of definition of the error reason, options of return to ticket or ‘Manual Charge’.

Manual Option: Manual option will be the solution to mark the ticket as paid (probably best to use an additional payment type of manual room post to ensure it is flagged on morning reconciliation to be checked.
This would be the option to cover any potential issues whatever it might be in that it can be cleared from till have then manually posted on the room in PMS.
This would print another special template which has REQUIRES MANUAL POST very clear on the ticket.

So, the question is what is the best way to achieve this?
Payment Processor = Execute Script?
Payment Processor = Automation Command?

I would be able to achieve this flow using automation using automation command but am less confident about the script options.
Also the flow would require some form of ‘validation’/not be processed if failed.
Using automation commands I would achieve by just having the process payment at the end of the flow but not so sure how this would work with payment processors.

I couldn’t find much on the forum on execute script option…
I am amusing it could be done as see pre process handler, process handler and validation handler which sounds positive but not sure on how to utilize these…

@QMcKay posted a great tutorial about script processor usage.

That demonstrates how to receive payment info, do something, send info back or break payment process operation.

PS: I have to say you’ll need some JScript code to be able to fulfill your requirements. Maybe you should evaluate Command based solutions first but you won’t have much control on how payments processed.


Thanks for confirming my thoughts @emre

Just to confirm, an exacute automation command payment processor would just fire the rule allong side the ticket being marked as paid right? So I would need a ‘Room Post’ automation command button on the payment screen.
We cannot yet place an automation command button in the column of payment buttons yet can we?

We have Execute Automation Command payment processor.

Yes but it wouldnt work is I wanted to ‘confirm’ the script had jun and responce was correct though would it?
Does this mean the payment selector would just run the automation command and not pay the ticket and the payment part would need to be in the rule/flow?

Hmm… I didn’t implemented something like that before so I’m not sure if any method will fulfill your requirements or not. You know what you need so you’ll have better idea if it will work fine or not. If you say won’t work… you can try scripts. You want to confirm the script…I don’t fully get what do you mean with confirm the script but If it is something already should work in a script, you should prefer implementing everything with scripts as @QMcKay demonstrated. As you want to try other options… yes you can test if it will work or not… hope it works, lol…

Sorry, by confirm I mean that if the response to the Json post is not the charges response something differ happens (payment not processed in samba)

Ideally I understand command workflow better so will start with that, ideally the responce would be pushed into an automation command as the command value and then I can constrain the rule/actions accordingly.

Your wanting to check response before payment processed? If response is bad what do you want it to do? How do you tell it to correct a bad response?

There are two main possibilities for a failed charge I have deduced so far.
Incorrect gl_account code set for PMSDepartment product tag which is why I was looking for a method of constraint on tags but either way will look to have some form of notification that there was an irrecoverable issue, maybe a send email notification to office/me encase someone sets a new product up wrong.
The BIG one would be connectivity, if Internet were to go down or if there was ever any issues with the PMS and/or their API which eventually is going to happen one way or the other.
The main thing is that the issue is recorded so that any required manual actions can be taken.
Connectivity is the big one as Internet has been known to drop out now and again as I’m sure everyone experiences from time to time. As a cloud system this would be an issue.
For no responce (connectivity issue) I would setup a retry option, so if just a temporary drop out it can just be tried again, a cancel option should they prefer to hold of and post after serving another customer and a manual option which would mark paid but as manual post payment method so it shows clearly on work period report and to print a template clearly showing that it needs manual posting.
The main consern is Internet connectivity and ensuring that should this happen it won’t disturb the workflow or cause any charges to a room to be left off a bill.
It’s not about correcting a bad charge but ensuring its clear that the charge has been processed correctly or requires further action to be taken.

This is my first intergration and am just being cautious of the fact that it’s intergrating a local system to a cloud based system and the main vulnerability will be the Internet connectivity.

While I’m sure you’ll say get a better Internet connection :-p we have BT business and next improvement would be a leased line which I can’t see happening anytime soon.
We do now have 2 adsl connection (soon to be FTTC) and plan to implement load balancing for fall over should one go down.
In the unlikely even both go down its most likely going to be power failure or ISP issue which is out of our control.

No I was thinking more about if you answered my question or not. But I guess you did lol. So you do need to check response before payment processed and if response is bad you want it to try again or at least not push the sale through and give the cashier a message?

@JTRTech you were anticipating a response and answering the question before even asked lol. Slow down and work with me one question at a time it really makes it easier.

LOL, OK so what was the question again :smile:

The main question is it sounds like your wanting to check for a response from the API before SambaPOS processes payment is that right?

Yes, selecting room post will run the room post script using the ticket id and the booking/guest account from the room entity custom data.

A good response will mark as paid with Room Post.
A bad response will offer options to retry, manual or cancel.

So you should definitely be using the Execute Script payment processor. You have access to Pre Process Handler, Pre Validation handler, Process Handler, Validation handler and even confirmation Message handler. This gives you full control over it via scripts.

Your not really wanting to confirm if the script ran… your wanting to read the response. Of course the script will run…and if internet drops off so the script cant run… well then your response will still be not good…So you still do not need to confirm if a script ran… you simply need to read the response.

All of that should be done inside the SambaPOS script. Your not triggering external scripts your running a SambaPOS script.

1 Like

So I put my charge script into the pre process handler field, then what? Will the responce be passed into the validation handler?

Handler is the script handler… Pre Process means it runs it before process. Validation Handler means it runs the handler for validation. Likely you need to create a new script or two for this.

Look at my Tutorial on the matter. It shows you how to implement the script into the processor, and how to stop or break the process.

    var cctype = dlg.AskQuestion("Choose Credit Card type","Amex=AMEX,Master Card=MAST,Visa=VISA,Discover=DISC,Other=OTHR,CANCEL=CANCEL");
    if (cctype=="CANCEL") {
      dlg.ShowMessage("Payment Cancelled");
      return 1;

Specifically, Data.Set("canContinue",false) does the trick. But you can implement whatever logic, checks, and if/thens as you see fit. Even do a loop for multiple attempts, check your “constraints” and continue or not.

1 Like

Where does canContinue come from?
Is is that what 'stops’the payment being processed?
Do you have any other scripts in the payment processor fields?
Where is the return 1 go to?

It is a mechanism that Emre put into SambaPOS, and yes it stops the process.

I have no other scripts at this time. The return 1 goes nowhere, but returns execution and control back to where it left off. In the example, we are returned to the Payment Screen.

1 Like

Thanks @QMcKay will plough into that over the weekend, have had to divert some time in do a different project… Have been asked to offer an alternative for a new phone system for the hotel so have been experimenting with FreePBX :smile: