Dwolla_V2: how to configure the gem?

(Luis Mojica) #1


Let me apologize for the wall of text first, I am a relatively new RoR developer in need of some assistance.

My company is building a RoR application that will utilize Dwolla services to request and send funds.

The functional nature of our application doesn’t require any user login through the OAuth flow, it relies on the application being capable to authenticate as itself and execute funding requests and outbound transfers.

After going through the documentation, an application was created on the UAT website this provided an API key and secret along with the ability to generate new token pairs.

A configuration object was implemented to securely store these values and make an initial hand-shake request with Dwolla API to validate the entered API config data is valid. The class “DwollaConfiguration” works for both the storage for API sensitive information and the execution of all web calls to Dwolla.

For the sake of simplicity, the validation will be done by exchanging the refresh token for a new token pair using the provided key and secret.

After some more research, the “Dwolla V2” gem will be used, instead of “Dwolla Swagger”, to implement the functionality described above. The gem is installed and can be referenced properly.

Here are some questions based on the gem documentation:

  1. Is there a suggested model structure for storing the token information?
  2. Is there a code sample for “YourSampleToken” class?
  3. To which “account_id” is the above code referring?
  4. Can I use my existing “DwollaConfiguration” object (as “YourTokenData”) by implementing an interface?

Thanks in advance for any help you can provide, I will appreciate any suggestions.

Dwolla_V2: implementation questions
(Luis Mojica) #2

I created another thread to discuss the technical implementation details of this solution:

(Stephen Ausman) #3

Thanks for the detailed questions Luis, hopefully I can help.

1 & 2 & 4) I threw together a Gist with some example code showing how to encrypt and store OAuth tokens. The end result is a TokenConcern concern that you can include in your classes to give them access to app_token and account_token methods (see the Foo class for example usage).

3) “account_id” is referring to the “account_id” returned in the token response. For example:

Let me know if you have any questions after looking at the example code, I’m glad to help!

(Luis Mojica) #4


Thanks for your help, the guide is very detailed. After adding the code from the article you sent I was presented with this error message:
`crypt’: key must be 32 bytes or longer (ArgumentError)

It’s being thrown by line 4 of file config-initializers-dwolla-rb

This is my current key in .env

Any ideas what might be the issue?

(Stephen Ausman) #5

Hey Luis,

I have gotten a similar error before and fixed it by making the SECRET_KEY value longer. The attr_encrypted gem requires it to be a certain length.

(Luis Mojica) #6


Thank you very much for all the help supplied, I was able to retrieve my funding sources just fine but I ran into another issue.

During development I had to reset my database and token data is no longer working, I keep getting DwollaV2::AccessDeniedError with message “Invalid refresh token”.

I tried to generate new refresh tokens with both the Token generator and from the dwolla console.

Can you please help me with this?

(Luis Mojica) #7


After some troubleshooting I was able to make the application connect again.