Can I use REST responses in an ecommerce form?


(Charlotte Westney) #1

Hi everyone,

 

I'm just after some advice, and hopefully reassurance, before I start trying to build something.

 

My quick question: Can you integrate data from a REST resource asset into an eCommerce form, and then take responses from a completed payment process and send them back via a REST call?

 

The full story:

We have a database full of items out in the National Park that need replacing; signposts, gates, bridges etc. And we're going to be offering people the chance to donate or 'buy' these items (people love buying a bench as a memorial for a loved one, this is a continuation of that). The database does a whole lot of other things for the ranger teams, so rather than re-creating that data in Matrix as product assets, we'd like to create an API and have Matrix call the API to get details of the items. Those details, including cost, need to be integrated into an eCommerce form, that will allow users to enter their details and then pay (via a SagePay payment gateway).

Is that possible?

I'm envisaging that I'll have to create the form questions as normal, view the output, copy the html, paste that html into the form bodycopy and then 'edit' it to include the data that is coming from my API call.

Would you recommend one API call and use the js pre-processor to wrap it in the right tags, or have seperate API calls just for the bits of data that are needed, and place those into the form elements?

I've hacked forms a bit like this before, but will the values from the API calls get carried across into the form payment process?

There will also be some 'normal' ecommerce form questions (user contact and address details).

And then lastly, once the payment process is completed, I'll need to make an API call back, and pass it a bunch of values about the order, some about the item and some that the user entered in the normal fields. As well as send the usual 'thankyou' email back to the user with details about their transaction.

 

Is that going to work?

 

Will I be able to make a call back - the only 'submission action' on an eCommerce form seems to be 'Make a SOAP' form - whereas a custom form has 'Call REST resource'.. so can an Ecommerce form make a call back to an API to update the database to show the item has been bought?

 

Any advice really appreciated!

Thanks,

Charlie.

 

 

 

 


(Bart Banda) #2

Not sure about the other things, but you could use a trigger to fire the rest call when the form submission is processed. You won't be able to do any validation on it though server side but that path might be worth trying. 

 

You could then access the response data using the session var you can create as part of that trigger action and then use the session keyword to use it in the form. 

 

I'm not sure why the other submission actions were never ported to the ecommerce form, but probably something we could add in the future. 


(Charlotte Westney) #3

Hi Bart,

 

Many thanks for your reply, I'm going to try the trigger method as you suggested. I've now got a test system setup, which pulls data from the API and uses that in the eCommerce form, all works wonderfully, and was incredibly easy to do actually!

 

So, I've now set up a trigger action to fire when an order asset is created. I just need to get some of the details from that order to go into the API call. You said I could "access the response data using the session var you can create as part of that trigger action" - which sounds great, but I have no idea how to do that! Any chance you could break that down into the steps I need to make that work?

 

Thanks again for your help! Charlie.


(Charlotte Westney) #4

Actually - I think I've done it!

Set a session variable with name of Answer and value of Value, then use a dynamic parameter to set the Value to asset keyword response_12345_q1

 

Then in my emails and in my Call REST resource Request Body just use %globals_session_Answer% and it outputs the response to q1 into the request string. Repeat for each response and Ecommerce form question responses sent back to my API. I believe the technical term here is "BINGO!".

 

Thanks Bart!

 

Charlie.