0

I need to create a HTTP end-point for receiving transaction notifications from a payment gateway.

How would I create a HTTP end-point which accepts POST requests with a variable set of parameters.

POST Request Body

txndate_processed=26%2F06%2F18+18%3A10%3A36
&ccbin=403587
&timezone=Europe%2FLondon
&oid=C-8080f191-df6f-41f6-99a0-b5f926cbcf8a
&cccountry=DEU
&expmonth=12
&hash_algorithm=SHA256
&endpointTransactionId=0005
&currency=826
&processor_response_code=00
&chargetotal=799.00
&terminal_id=21400840
&approval_code=XXXXXXX
&expyear=2048
&response_code_3dsecure=1
&notification_hash=XXXXXXXXXXX
&transactionNotificationURL=http%3A%2F%2F.example.com
&tdate=1530029436
&installments_interest=false
&bname=Mr+Smith
&ccbrand=VISA
&refnumber=866834
&txntype=sale
&paymentMethod=V
&txndatetime=2018%3A06%3A26-16%3A10%3A14
&cardnumber=%28VISA%29+...+4977
&ipgTransactionId=84516494556
&status=APPROVED

I don't think I can use a REST end-point, because the request body is not JSON or XML.

2

You still set up an ApexRest endpoint. There's nothing magic about it that requires JSON nor XML.

You can whip up a simple demo to prove ApexRest is sufficient for your needs:

@RestResource(UrlMapping='/Demo/*')
global class Demo
{
    @HttpPost
    global static void doStuff()
    {
        String body = RestContext.request.requestBody.toString();
        Map<String, String> params = new Map<String, String>();
        for (String param : body.split('&'))
        {
            if (param.contains('='))
            {
                params.put(param.substringBefore('=').trim(), param.substringAfter('=').trim());
            }
        }
        system.debug(JSON.serialize(params));
    }
}

Then post your payload to that endpoint. I used workbench and got exactly the expected results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.