Do you need a customer id for _links when using action:customer.create for /client-tokens

I want to generate a client tokenUrl for my front end so businesses can complete the verify drop-in flow.

// Using DwollaV2 - https://github.com/Dwolla/dwolla-v2-node
var requestBody = {
  _links: {
    customer: {
      href: 'https://api-sandbox.dwolla.com/customers/707177c3-bf15-4e7e-b37c-55c3898d9bf4'
    }
  },
  action: 'customer.update'
};

appToken
 .post("/client-tokens", requestBody)
 .then(res => res.body.token); // => '4adF858jPeQ9RnojMHdqSD2KwsvmhO7Ti7cI5woOiBGCpH5krY'

The example in the docs is pasted above, but this uses the customer.update action on an existing customer. I want to create a business customer at the same time I verify them ideally. Is this possible using customer.create as the value of action, and, if so; what should the value of _links be since I won’t have a customer ID to use at the time of the call like what happens in the above example?

@shreya @kmoreira @spencer

I see that the business-vcr drop-in has css fields for customer creation (name, email, etc), which would lead me to believe you don’t have to call the /client-tokens endpoint on an existing customer id. Seems like a chicken and egg situation; how can I make the call to fetch the token I need to render the vcr drop-in without having the customer id yet?

Doing some postman test calls it looks like I can get successful responses from /client-tokens with an empty _links field in the request body. Is this what I should be doing?

{
  "_links": {
  },
  "action": "customer.create"
}

Hi @Cody_Eddings – ah yeah, for a “flow” type component (like Business VCR), you do not have to call the /client-tokens endpoint. You can actually specify a tokenUrl which would be a server-side endpoint that can be called by the dwolla-web library when an action needs to be performed within the flow to simplify the integration experience. Flow components are designed to support drop-ins that have multiple isolated functions connected together into a single user flow.

Here’s an example of setting up a tokenUrl using Express - Building With Drop-in Components | Dwolla API Documentation

Hope that helps! Please check out the above guide and let us know if you come across any questons!

1 Like

@shreya Ah I see, I didn’t realize this was called from the front-end. Thanks.

@shreya I’m having some trouble accessing the Dwolla web client from my Vue app. What’s wrong my approach below?

I get Uncaught (in promise) ReferenceError: dwolla is not defined when I call dwolla.configure().

<script>
export default {
  methods: {
    async getDwollaClientTokenUrl() {
      const url = `/client-tokens`;
      dwolla.configure("sandbox")
      await dwolla
          .post(url, "/tokenUrl")
          .then((response) => {
            console.log("Success response: " + response.body)
            return response.body;
          })
          .catch((error) => {
            console.log("Error response: " + error)
            return error;
          })
    }
    }
  },
  mounted() {
    let script = document.createElement("script");
    script.src = "https://cdn.dwolla.com/v2/dwolla-web.js";
    script.type = "text/javascript";
    document.head.appendChild(script);
  },
  created() {
    this.getDwollaClientTokenUrl()
  },
};
</script>

Hi Cody,

I’m afraid I don’t have any experience with Vue to be able help you out. :frowning:

I would imagine that this should work the same way as including dwolla-cards.js.

Apologies for not being able to provide much help!

@shreya

No worries, thanks for the link to the old post.

I’m a bit stuck unfortunately, is there anyone on your team that could offer some guidance on using the https://cdn.dwolla.com/v2/dwolla-web.js lib with a view app?

Following my previous approach, I tried import dwolla from "dwolla"; at the beginning of my script, and it does seem to successfully install Dwolla, but then I get a console error when I try to call `dwolla.configure(“sandbox”):

dwolla__WEBPACK_IMPORTED_MODULE_4___default.a.configure is not a function

For further reference, I found a node.js example in your github but I haven’t been able to translate it to my Vue app successfully. drop-ins-examples/business-vcr.hbs at main · Dwolla/drop-ins-examples · GitHub

@shreya

Circling back, I actually got the dwolla-v2 library installed successfully. I forgot to npm install dwolla-v2 which was my first problem, then I abandoned the dwolla.configure() approach and just followed the guide directly (who knew, following the instructions verbatim is important! lol)

My question comes full circle though, what should I be passing in as the body to the tokenUrl request?

  let Client = require("dwolla-v2").Client;
  let dwolla = new Client({
    key: "",
    secret: "",
    environment: "sandbox",
  });
  const url = `/client-tokens`;
  return dwolla
      .post(url, body)    //TODO: what should the body be?
      .then((response) => {
        return response.body;
      })
      .catch((error) => {
        return error;
      });

Like I mentioned earlier, I don’t have a customer ID yet since the customer is in the process of being created during this flow, so do I just pass in an empty _links object with and action of customer.create ?

Hi @Cody_Eddings

You shouldn’t need to pass anything as the body to the tokenUrl request.

Here’s an example from our docs for using tokenUrl in an Express app:

app.post("/tokenUrl", function (req, res) {
  generateClientTokenWithBody(req.body).then((clientTokenRes) => {
    console.log(clientTokenRes);
    res.send({ token: clientTokenRes.token });
  });
});

function generateClientTokenWithBody(body) {
  const url = `/client-tokens`;

  return dwolla
    .post(url, body)
    .then((response) => {
      return response.body;
    })
    .catch((error) => {
      return error;
    });
}

Here, the req object represents the HTTP request and has properties for the request query string, parameters, body, and HTTP headers. The res object represents the HTTP response that an Express app sends when it gets an HTTP request.

Some quick google search resulted in this article which might be helpful to reference - How To Use the req Object in Express | DigitalOcean