Using webtask.io (migrating from webscript.io)


(Rahul Varshney ) #1

Hello, I am trying to port my code over from webscript.io (which was using lua) to webtask.io which uses javascript and node-js (and many other node modules https://tehsis.github.io/webtaskio-canirequire/ ) . I was using my app (https://preview.c9users.io/irentez740/irentez740/index.html?_c9_id=livepreview0&_c9_host=https://ide.c9.io – this is an html version and not the original lustache version that was hosted on webscript) to make payments (in production mode) as recently as November 30, 2017. Webscript shut down on December 15, 2017, so here I am.

The code below is what I have so far ported over as a webtask script; this is the portion of the code that was called when “Pay with Bank” was clicked, originally calling the webscript endpoint http://740irentez.webscript.io/oauth/dwolla/checkout. This will now be calling https://wt-4be0c38760dbec5e388b02b801f4a631-0.run.webtask.io/reqtest once I get it working.

The result ***.run.webtask.io/reqtest is the following error:
{“Result”:“Failure”,“Message”:“Invalid destination user.”}

I have seen this article: https://www.dwolla.com/updates/important-sandbox-updates-subdomain-change-and-sunsetting-of-the-sandbox-console/

and have tried the different endpoints mentioned, but no luck.

Any help is greatly appreciated.

====Begin code at ****webtask.io/reqtest========
var request = require(‘request’);

return function (context, callback) {

var destinationId;
var url;
var client_id;
var client_secret;

//sandbox
destinationId = ‘8127418252’;
url = ‘https://uat.dwolla.com/payment/request’;

client_id = 'CLIENT ID';
client_secret = 'CLIENT SECRET';

var checkout = {
orderId : 1,
purchaseOrder : {
destinationId : destinationId,
total : ‘11.26’
}
};

var payload = {
url: url,
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’//;charset=utf-8’
},
json: true,
body: {
Key : client_id,
Secret : client_secret,
callback : “https://wt-4be0c38760dbec5e388b02b801f4a631-0.run.webtask.io/hello”,
redirect : “https://wt-4be0c38760dbec5e388b02b801f4a631-0.run.webtask.io/hello”,
purchaseOrder : checkout,
allowGuestCheckout : “true”,
allowFundingSources : “true”,
orderId : checkout.orderId
}
};

request(payload, function (error, res, body) {
if (error) console.log('ERROR: ', error);
else console.log(‘SUCCESS’);

callback(error, body);

});
};


(Spencer Hunter) #2

@RahulVarshney, purchaseOrder is an object that contains destinationId and total. Take a look at the example raw HTTP request below. I included the latest request URL that you should be calling as well.

POST https://sandbox.dwolla.com/oauth/rest/offsitegateway/checkouts
Content-Type: application/json

{
  "client_id": "CLIENT ID",
  "client_secret": "CLIENT SECRET",
  "allowFundingSources": true,
  "allowGuestCheckout": true,
  "redirect": "http://requestb.in/",
  "callback": "http://requestb.in/",
  "purchaseOrder": {    
    "destinationId": "812-xxx-xxxx",
    "total": 9,
    "notes": "A note on this order",
	"metadata": {
        "foo": "bar",
        "bar": "baz"
    }
  }
}

(Rahul Varshney ) #3

{“Success”:true,“Message”:“Success”,“Response”:{“CheckoutId”:“2bf81b7c-b40f-4bba-884a-08b8a17546e4”},"_links":null}

VICTORY!

Love u guys. Thought this bug was going to set me back another week.

Happy new Years folks! :fireworks::sparkler::tada: