Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dwolla Direct integration #2

Merged
merged 2 commits into from Nov 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions README.md
Expand Up @@ -40,9 +40,20 @@ KB_URL='http://<host>:<port>' DWOLLA_CLIENT_ID='<MERCHANT_DWOLLA_CLIENT_ID>' DWO
```


Then go to [http://localhost:4567/](http://localhost:4567/) where you should see the Dwolla **Add Bank** button.
Then go to [http://localhost:4567/](http://localhost:4567/) where you should see both Dwolla solutions.

Select a Bank, follow the steps with dummy data and complete the checkout process.
The first option is the White Label solution, that you don't need a Dwolla account and where you are able to select your bank and account by your bank credentials.
Steps:

* Press **Add Bank by White Label Solution** button.
* Select a Bank, follow the steps with any dummy data and complete the checkout process.


The other option is the Dwolla Direct solution, where you are redirect to Dwolla page and you have to login with you Dwolla account. It's also have the option to create a new Dwolla account if you don't have one.
Steps:

* Press **Sign in by Dwolla Direct Solution** link.
* Log in or sign up and complete the checkout process.

This will:

Expand All @@ -57,5 +68,7 @@ This will:

![Shopping cart](./screen1.png)

![Checkout](./screen2.png)
![White Label solution](./screen2.png)

![Dwolla Direct solution](./screen3.png)

38 changes: 30 additions & 8 deletions app.rb
Expand Up @@ -7,6 +7,7 @@
set :client_id, ENV['DWOLLA_CLIENT_ID']
set :client_secret, ENV['DWOLLA_CLIENT_SECRET']
set :dwolla_access_token, ENV['DWOLLA_ACCESS_TOKEN']
set :customer_id, ''

#
# Kill Bill configuration and helpers
Expand All @@ -29,20 +30,20 @@

def create_kb_account(dwolla_customer_id, user, reason, comment, options)
account = KillBillClient::Model::Account.new
account.name = 'John Doe'
account.name = "John Doe #{dwolla_customer_id}"
account.currency = 'USD'
account.external_key = dwolla_customer_id
account.create(user, reason, comment, options)
end

def create_kb_payment_method(account, funding_source, customer_id, user, reason, comment, options)
def create_kb_payment_method(account, funding_source, customer_id, authCode, user, reason, comment, options)
puts "Customer ID: #{customer_id}"
puts "Funding Source: #{funding_source}"

pm = KillBillClient::Model::PaymentMethod.new
pm.account_id = account.account_id
pm.plugin_name = 'killbill-dwolla'
pm.plugin_info = {'fundingSource' => funding_source, 'customerId' => customer_id }
pm.plugin_info = {'fundingSource' => funding_source, 'customerId' => customer_id, 'code' => authCode}
pm.create(true, user, reason, comment, options)
end

Expand Down Expand Up @@ -111,17 +112,20 @@ def get_key_from_url(url, path_to_remove)
customer_iav = account_token.post "#{customer_url}/iav-token"
@iav = customer_iav.token
@customerId = get_key_from_url(customer_url, '/customers/')
@clientId = settings.client_id

settings.customer_id = @customerId

erb :index
end

post '/charge' do
# Create an account
account = create_kb_account(@customerId, user, reason, comment, options)
account = create_kb_account(settings.customer_id, user, reason, comment, options)

# Add a payment method associated with the Dwolla funding source
fundingSourceId = get_key_from_url(params['fundingSource'], '/funding-sources/')
create_kb_payment_method(account, fundingSourceId, params['customerId'], user, reason, comment, options)
create_kb_payment_method(account, fundingSourceId, params['customerId'], nil, user, reason, comment, options)

# Add a subscription
create_subscription(account, user, reason, comment, options)
Expand All @@ -133,6 +137,22 @@ def get_key_from_url(url, path_to_remove)
erb :charge
end

get '/callback' do
# Create an account
account = create_kb_account(nil, user, reason, comment, options)

# Add a payment method associated with the Dwolla Direct auth code
create_kb_payment_method(account, nil, nil, params['code'], user, reason, comment, options)

# Add a subscription
create_subscription(account, user, reason, comment, options)

# Retrieve the invoice
@invoice = account.invoices(true, options).first

erb :charge
end

__END__

@@ layout
Expand All @@ -155,7 +175,9 @@ def get_key_from_url(url, path_to_remove)
</label>
</article>
<div id="mainContainer">
<input type="button" id="start" value="Add Bank">
<input type="button" id="start" value="Add Bank by White Label Solution">
<br> or <br>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 💯

Could you update the screenshots and README too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will!

<a id="direct" href="<%= "https://uat.dwolla.com/oauth/v2/authenticate?client_id=#{@clientId}&response_type=code&redirect_uri=http://localhost:4567/callback&scope=Send|Funding" %>">Sign in by Dwolla Direct Solution"</a>
</div>

<div id="iavContainer"></div>
Expand All @@ -175,8 +197,8 @@ def get_key_from_url(url, path_to_remove)
'http://fonts.googleapis.com/css?family=Lato&subset=latin,latin-ext',
'http://localhost:8080/iav/customStylesheet.css'
],
microDeposits: 'true',
fallbackToMicroDeposits : 'true'
microDeposits: 'false',
fallbackToMicroDeposits : 'false'
}, function(err, res) {
if (err) console.log('Error: ' + JSON.stringify(err) + ' -- Response: ' + JSON.stringify(res));
var fundingUrl = res._links['funding-source'].href;
Expand Down
Binary file modified screen1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screen2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screen3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.