Developer forum

Forum » Development » Call external provider

Call external provider

Per Ljung
Reply
Hi!

I'm writing a custom checkout handler that connects to an external payment provider. The connection is requiring either a submitted form using POST  or a redirect call using GET. I used base.SubmitForm(url, parameters) inside the StartCheckOut method, but get an error that the thread is being aborted.

How can you integrate and external provider using a custom checkout  class? Where do I place the code to connect to the external provider?

Best regards,
Per


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Per

The reason you get a ThreadAbortException is because SubmitForm does a Response.Redirect. This is the standard way .NET handles this. If you catch the exception then simply return string.Empty. You can see how we do it in either the QuickPay3 or Dibs providers available for download here: http://developer.dynamicweb-cms.com/downloads/source-code.aspx


Hope this helps :)

- Jeppe
 
Per Ljung
Reply
Hi!

Have a very strange problem, the request to the external provider crashes when I use SubmitForm, but not when call the same page with the same hardcoded values.

Does SubmitForm for use a special encoding or something?

Best regards,
Per
 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Because of the way SubmitForm works, the form action url and dictionary keys and values are url encoded. Do you know which values fail?

 
Per Ljung
Reply

Hi again!

So the form is actually submitted by GET and not by POST?

/Per
 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

No, it does do a POST, but the CheckoutHandler cannot do that by itself. What actually happens is that all values are passed to a dedicated page which then does the actual POST. And when the values are passed, they are also url encoded.

 
Per Ljung
Reply
Hi!

Here is the error:

"Viewstate verification failed. Reason: The viewstate supplied failed integrity check. "

Is it possible to disable url encoding or use a GET call instead?

Can't see so many ways to do a submit to an external page if you can't use the method SubmitForm.

Best regards,
Per

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
I don't know why you're getting this error, I have never seen it with any CheckoutHandler. You cannot disable the url encoding, but there are a number of ways to submit a form to an external provider without using the SubmitForm method.

One way, and presumably the easiest, is to render a template that is submitted using JS after it's been shown.

Something like this:
<form id="myForm" action="http://yourprovider.com" method="POST">
    <input type="hidden" name="SomeProviderKey" value="<!--@MyProvider.SomeProviderKeyValue-->" />
</form>

<script type="text/javascript">
    document.getElementById("myForm").submit();
</script>
And in your CheckoutHandlers StartCheckout method do this:
var template = new Dynamicweb.Templatev2.Template("pathToTemplateFile");
template.SetTag("MyProvider.SomeProviderKeyValue", "My value");
return template.Output();
This is of course a very simple example but I think you get the idea :)

 

You must be logged in to post in the forum