Reply
Member
Posts: 2
Registered: ‎03-11-2017
Accepted Solution

Accept.JS and Integration Testing

I am trying to set up an integration test for a workflow that uses Accept.JS but have run into an issue. Since the dataDescriptor and dataValue are retrieved using Accept.JS, I can't seem to figure out how to run a test transaction to our sandbox strictly using PHP. 

 

Has anyone had any success settong up testing for an Accept.JS workflow?

Administrator
Posts: 384
Registered: ‎11-03-2016

Re: Accept.JS and Integration Testing

Hi @greckers,

 

You've got a couple of options here. For a complete end to end test running in PHP, you could look into something like v8js, which is an extension to access the Chrome V8 interpreter from within PHP. Your test scripts could run independent of the browser, and get the dataDescriptor and dataValue by interacting with our accept.js script.

 

I can't promise this would work as I've not tried it myself. Our script does some checking to make sure it's being called from a page served from a secure connection, so you'd have to set up the v8js environment to make sure the protocol and window.location and everything looked right to our script.

 

Option 2: If you step through the Accept.js script and the AcceptCore.js script, you can see what they're actually doing is making a call to our API with the card data and getting a payment token back. This API request isn't documented anywhere, but if you follow every step through the scripts, and reference the schema XSD, you can see how it's constructed. I'll save a step and just post a sample request here:

<securePaymentContainerRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
    <merchantAuthentication>
        <name>{{loginId}}</name>
        <clientKey>{{clientKey}}</clientKey>
    </merchantAuthentication>
    <refId>12345</refId>
    <data>
    	<type>TOKEN</type>
    	<id>{{$guid}}</id>
    	<token>
    		<cardNumber>5424000000000015</cardNumber>
    		<expirationDate>122020</expirationDate>
    		<cardCode>900</cardCode>
    		<fullName>Testy McTesterson</fullName>
    	</token>
    </data>
</securePaymentContainerRequest>

Sending a request like this gets a response like so:

<?xml version="1.0" encoding="utf-8"?>
<securePaymentContainerResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
    <messages>
        <resultCode>Ok</resultCode>
        <message>
            <code>I00001</code>
            <text>Successful.</text>
        </message>
    </messages>
    <opaqueData>
        <dataDescriptor>COMMON.ACCEPT.INAPP.PAYMENT</dataDescriptor>
        <dataValue>eyJjb2RlIjoiNTBfMl8wNjAwMDUzRUE2QkJENEIzRUE2QzEyRDFEODFFQUZFQjYzMkRENUZCQkFEQzAwQTUyRjgxRUY2NDM1QTk2RDBEQTg2RjI3QkExQjY5MTJBRjFGMzRBMzI3MDQ2QjI2RDEwNURDNERBIiwidG9rZW4iOiI5NDg5NDM0NDk5MTExMzA0NzA0NjA0IiwidiI6IjEuMSJ9</dataValue>
    </opaqueData>
</securePaymentContainerResponse>

Using this format, you could write a script to get the payment nonce/token for your tests without interacting with JavaScript at all.

 

There's no guarantee that this would continue to work. It would be a hack on your part with no official support from us. But, it's what our scripts are doing currently.

 

-Aaron

Aaron Wright
Developer Advocate - Authorize.Net

Follow Authorize.Net developer news on Twitter!
Highlighted
Member
Posts: 2
Registered: ‎03-11-2017

Re: Accept.JS and Integration Testing

Hi Aaron,

 

This is perfect. Option 2 was exactly what I was hoping for. I tried to read through the scripts but figured somebody may have already figured out what the request would need to be and I didn't need to bang my head against the wall for hours figuring out the right request info.

 

I'm sure I will get some failed tests if the script changes but I think I can live with that for now and I'm sure its not going to change too often (hopefully).

Member
Posts: 4
Registered: ‎12-02-2011

Re: Accept.JS and Integration Testing

@greckers, did you have any luck with this, or do you have any advice to share on your experience or things to keep an eye out for?  I'm trying to do the same thing.  Thanks!