I will attempt to post the commit I did (to a private repo) to get Dwolla integration up and running. Quick and easy, once I figured out the config options, and signed up here for the key/sig: https://www.dwolla.com/applications/create. A "Reflector" account can be used for live-fire testing here: http://developers.dwolla.com/dev/docs/testing.
Created
December 7, 2012 21:00
-
-
Save hoffmanc/4236467 to your computer and use it in GitHub Desktop.
Dwolla Active Merchant Integration Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DwollaController < ApplicationController | |
include ActiveMerchant::Billing::Integrations | |
def cancel | |
backer = Backer.find params[:id] | |
flash[:failure] = t('projects.backers.checkout.dwolla_cancel') | |
redirect_to new_project_backer_path(backer.project) | |
end | |
def confirm | |
backer = Backer.find(params[:id]) | |
notify = ActiveMerchant::Billing::Integrations::Dwolla::Notification.new(params.to_json) | |
if notify.complete? | |
backer.update_attributes( | |
:key => checkout.payment_info.first.transaction_id, | |
:payment_method => 'Dwolla', | |
:payment_token => params[:token] | |
) | |
backer.build_payment_detail.update_from_service | |
backer.confirm! | |
flash[:success] = t('projects.backers.checkout.success') | |
redirect_to thank_you_path | |
else | |
#flash[:failure] = t('projects.backers.checkout.dwolla_error') | |
flash[:failure] = "#{t('projects.backers.checkout.error_header')} #{params[:error_description]}" | |
return redirect_to new_project_backer_path(backer.project) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// snipped out some bits, but this is what was added | |
#dwolla_payment | |
- payment_service_for("backer-#{@backer.id}", | |
Configuration.find_by_name('dwolla_destination_id').value, | |
:credential2 => Configuration.find_by_name('dwolla_key').value, | |
:credential3 => Configuration.find_by_name('dwolla_secret').value, | |
:amount => @backer.display_value.gsub(/[^0-9.]/,'').to_i, | |
:currency => 'USD', | |
:service => :dwolla, | |
:html => { :id => 'payment-form' }) do |service| | |
- bu = @backer.user | |
- service.customer(:first_name => bu.first_name, :last_name => bu.last_name, :phone => bu.phone_number, :email => bu.email) | |
- service.billing_address(:city => bu.address_city, :address1 => bu.address_street, :address2 => bu.address_number, :state => bu.address_state, :country => 'USA', :zip => bu.address_zip_code) | |
- service.shipping '0.00' | |
- service.tax '0.00' | |
- service.notify_url url_for(done_dwolla_path(@backer, :only_path => false)) | |
- service.redirect_url url_for(thank_you_path(@backer, :only_path => false)) | |
- service.return_url url_for(confirm_dwolla_path(@backer, :only_path => false)) | |
%h1 | |
%input(type='submit' value="Pay with Dwolla") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load the rails application | |
require File.expand_path('../application', __FILE__) | |
# Initialize the rails application | |
Catarse::Application.initialize! | |
require 'money' | |
require 'active_merchant' | |
require 'active_merchant/billing/integrations/action_view_helper' | |
ActionView::Base.send(:include, ActiveMerchant::Billing::Integrations::ActionViewHelper) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Catarse::Application.routes.draw do | |
# this is what was added | |
resources :dwolla do | |
member do | |
get :done # er | |
get :cancel | |
get :confirm | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DwollaController < ApplicationController | |
include ActiveMerchant::Billing::Integrations | |
def cancel | |
backer = Backer.find params[:id] | |
flash[:failure] = t('projects.backers.checkout.dwolla_cancel') | |
redirect_to new_project_backer_path(backer.project) | |
end | |
def confirm | |
backer = Backer.find(params[:id]) | |
notify = ActiveMerchant::Billing::Integrations::Dwolla::Notification.new(params.to_json) | |
if notify.complete? | |
backer.update_attributes( | |
:key => checkout.payment_info.first.transaction_id, | |
:payment_method => 'Dwolla', | |
:payment_token => params[:token] | |
) | |
backer.build_payment_detail.update_from_service | |
backer.confirm! | |
flash[:success] = t('projects.backers.checkout.success') | |
redirect_to thank_you_path | |
else | |
#flash[:failure] = t('projects.backers.checkout.dwolla_error') | |
flash[:failure] = "#{t('projects.backers.checkout.error_header')} #{params[:error_description]}" | |
return redirect_to new_project_backer_path(backer.project) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load the rails application | |
require File.expand_path('../application', __FILE__) | |
# Initialize the rails application | |
Catarse::Application.initialize! | |
require 'money' | |
require 'active_merchant' | |
require 'active_merchant/billing/integrations/action_view_helper' | |
ActionView::Base.send(:include, ActiveMerchant::Billing::Integrations::ActionViewHelper) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# added | |
gem 'activemerchant' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// snipped out some bits, but this is what was added | |
#dwolla_payment | |
- payment_service_for("backer-#{@backer.id}", | |
Configuration.find_by_name('dwolla_destination_id').value, | |
:credential2 => Configuration.find_by_name('dwolla_key').value, | |
:credential3 => Configuration.find_by_name('dwolla_secret').value, | |
:amount => @backer.display_value.gsub(/[^0-9.]/,'').to_i, | |
:currency => 'USD', | |
:service => :dwolla, | |
:html => { :id => 'payment-form' }) do |service| | |
- bu = @backer.user | |
- service.customer(:first_name => bu.first_name, :last_name => bu.last_name, :phone => bu.phone_number, :email => bu.email) | |
- service.billing_address(:city => bu.address_city, :address1 => bu.address_street, :address2 => bu.address_number, :state => bu.address_state, :country => 'USA', :zip => bu.address_zip_code) | |
- service.shipping '0.00' | |
- service.tax '0.00' | |
- service.notify_url url_for(done_dwolla_path(@backer, :only_path => false)) | |
- service.redirect_url url_for(thank_you_path(@backer, :only_path => false)) | |
- service.return_url url_for(confirm_dwolla_path(@backer, :only_path => false)) | |
%h1 | |
%input(type='submit' value="Pay with Dwolla") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Catarse::Application.routes.draw do | |
# this is what was added | |
resources :dwolla do | |
member do | |
get :done # er | |
get :cancel | |
get :confirm | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment