diff options
Diffstat (limited to 'billing')
-rw-r--r-- | billing/README.md | 49 | ||||
-rw-r--r-- | billing/README.rdoc | 25 | ||||
-rw-r--r-- | billing/config/initializers/braintree.rb | 31 | ||||
-rw-r--r-- | billing/config/routes.rb | 33 | ||||
-rw-r--r-- | billing/leap_web_billing.gemspec | 2 | ||||
-rw-r--r-- | billing/test/integration/subscription_test.rb | 2 |
6 files changed, 91 insertions, 51 deletions
diff --git a/billing/README.md b/billing/README.md new file mode 100644 index 0000000..3ef6153 --- /dev/null +++ b/billing/README.md @@ -0,0 +1,49 @@ +Billing Engine +==================== + +Currently, this engine support billing via Braintree. More backends to come later. + +Configuration +---------------------------------- + +Start with a sandbox account, which you can get here: https://www.braintreepayments.com/get-started + +Once you have registered for the sandbox, logging in will show you three important variables you will need to configure: + +* merchantId +* publicKey +* privatekey + +To configure the billing engine, edit `config/config.yaml` like so: + + production: (or "development", as you prefer) + billing: + braintree: + environment: sandbox + merchant_id: Ohp2aijaaqu6oJ4w + public_key: ahnar0UwLahwe6Ce + private_key: aemie2Geohgah2EaOad9DeeruW4Iegh4 + +If deploying via puppet, the same data in webapp.json would like this: + + "billing": { + "braintree": { + "environment": "sandbox", + "merchant_id": "Ohp2aijaaqu6oJ4w", + "public_key": "ahnar0UwLahwe6Ce", + "private_key": "aemie2Geohgah2EaOad9DeeruW4Iegh4" + } + } + +Now, you should be able to add charges to your own sandbox when you run the webapp. + +The acceptable values for `billing.braintree.environment` are: `development`, `qa`, `sandbox`, or `production`. + +Plans +-------------------------------- + +You also will want to add a Plan to your Sandbox. Within the Braintree Sandbox, navigate to 'Recurring Billing' -> 'Plans'. From here, you can add a new Plan. The values of the test plan are not important, but the ID will be displayed, so should pick something descriptive. + +Here are credit cared numbers to try in the Sandbox: + +https://www.braintreepayments.com/docs/ruby/reference/sandbox
\ No newline at end of file diff --git a/billing/README.rdoc b/billing/README.rdoc deleted file mode 100644 index 30ca0d6..0000000 --- a/billing/README.rdoc +++ /dev/null @@ -1,25 +0,0 @@ -= Billing - -This project rocks and uses MIT-LICENSE. - -The gem leap_web_billing will need to be included in whatever environment you are running, and billing will also need to be included in the configuration for that environment. You can set billing to be included in config/defaults.yml, by making sure the payment key is set to an array including billing (by default it will be set for the test environment, so you can look at that.) - -To set up your own Braintree Sandbox, create an account at: -https://www.braintreepayments.com/get-started - -Login to the Braintree Sandbox. -In the top right, navigate to your username, and then 'My User' -> 'API Keys' - -Click the button to generate a new API key, and then click the 'View' link to the right of the key. - -There is a section to copy a snippet of code. The simplest way to get this working is to select 'Ruby' in the dropdown, and then the button to the right to copy this code to your clipboard, and then paste the contents of the clipboard into billing/config/initializers/braintree.rb -However, you should not check the private key into version control, so you should not check in this file. -The better way to do this is to leave billing/config/initializers/braintree.rb as is, and instead set the braintree variables for the appropriate environment in config/config.yml, which is excluded from version control. - -Now, you should be able to add charges to your own Sandbox when you run the webapp locally. - -You also will want to add a Plan to your Sandbox. Within the Braintree Sandbox, navigate to 'Recurring Billing' -> 'Plans'. From here, you can add a new Plan. The values of the test plan are not important, but the ID will be displayed, so should pick something descriptive. - -Here are credit cared numbers to try in the Sandbox: - -https://www.braintreepayments.com/docs/ruby/reference/sandbox
\ No newline at end of file diff --git a/billing/config/initializers/braintree.rb b/billing/config/initializers/braintree.rb index d6ae565..c0c89e2 100644 --- a/billing/config/initializers/braintree.rb +++ b/billing/config/initializers/braintree.rb @@ -1,16 +1,31 @@ -require 'braintree_test_app' - -Braintree::Configuration.logger = Logger.new('log/braintree.log') +# +# set logger +# +if APP_CONFIG[:logfile].blank? + require 'syslog/logger' + Braintree::Configuration.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new('webapp')) +else + Braintree::Configuration.logger = Logger.new('log/braintree.log') +end +# # we use fake braintree in tests +# if Rails.env.test? + require 'braintree_test_app' Rails.application.config.middleware.use BraintreeTestApp end +# # You can set these per environment in config/config.yml: -if braintree_conf = APP_CONFIG[:braintree] - Braintree::Configuration.environment = braintree_conf[:environment] - Braintree::Configuration.merchant_id = braintree_conf[:merchant_id] - Braintree::Configuration.public_key = braintree_conf[:public_key] - Braintree::Configuration.private_key = braintree_conf[:private_key] +# +# Environment must be one of: :development, :qa, :sandbox, :production +# +if billing = APP_CONFIG[:billing] + if braintree = billing[:braintree] + Braintree::Configuration.environment = braintree[:environment].downcase.to_sym + Braintree::Configuration.merchant_id = braintree[:merchant_id] + Braintree::Configuration.public_key = braintree[:public_key] + Braintree::Configuration.private_key = braintree[:private_key] + end end diff --git a/billing/config/routes.rb b/billing/config/routes.rb index dbdc24b..7263dff 100644 --- a/billing/config/routes.rb +++ b/billing/config/routes.rb @@ -1,24 +1,25 @@ Rails.application.routes.draw do - match 'payments/new' => 'payments#new', :as => :new_payment - match 'payments/confirm' => 'payments#confirm', :as => :confirm_payment - resources :users do - resources :payments, :only => [:index] - resources :subscriptions, :only => [:index, :show, :destroy] - end - - resources :customer, :only => [:new, :edit] - resources :credit_card_info, :only => [:edit] + scope "(:locale)", :locale => MATCH_LOCALE do + match 'payments/new' => 'payments#new', :as => :new_payment + match 'payments/confirm' => 'payments#confirm', :as => :confirm_payment + resources :users do + resources :payments, :only => [:index] + resources :subscriptions, :only => [:index, :show, :destroy] + end - match 'customer/confirm/' => 'customer#confirm', :as => :confirm_customer - match 'customer/show/:id' => 'customer#show', :as => :show_customer - match 'credit_card_info/confirm' => 'credit_card_info#confirm', :as => :confirm_credit_card_info + resources :customer, :only => [:new, :edit] + resources :credit_card_info, :only => [:edit] - resources :subscriptions, :only => [:new, :create, :update] # index, show & destroy are within users path - match 'billing_admin' => 'billing_admin#show', :as => :billing_admin + match 'customer/confirm/' => 'customer#confirm', :as => :confirm_customer + match 'customer/show/:id' => 'customer#show', :as => :show_customer + match 'credit_card_info/confirm' => 'credit_card_info#confirm', :as => :confirm_credit_card_info - #match 'transactions/:product_id/new' => 'transactions#new', :as => :new_transaction - #match 'transactions/confirm/:product_id' => 'transactions#confirm', :as => :confirm_transaction + resources :subscriptions, :only => [:new, :create, :update] # index, show & destroy are within users path + match 'billing_admin' => 'billing_admin#show', :as => :billing_admin + #match 'transactions/:product_id/new' => 'transactions#new', :as => :new_transaction + #match 'transactions/confirm/:product_id' => 'transactions#confirm', :as => :confirm_transaction + end end diff --git a/billing/leap_web_billing.gemspec b/billing/leap_web_billing.gemspec index 17f7f92..94d92e0 100644 --- a/billing/leap_web_billing.gemspec +++ b/billing/leap_web_billing.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |s| s.summary = "Billing for LeapWeb" s.description = "Billing System for a Leap provider" - s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "Readme.md"] + s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "README.md"] s.test_files = Dir["test/**/*"] s.add_dependency "leap_web_core", LeapWeb::VERSION diff --git a/billing/test/integration/subscription_test.rb b/billing/test/integration/subscription_test.rb index 6356177..b95bfac 100644 --- a/billing/test/integration/subscription_test.rb +++ b/billing/test/integration/subscription_test.rb @@ -29,7 +29,7 @@ class SubscriptionTest < ActionDispatch::IntegrationTest login_as @admin @customer.stubs(:subscriptions).returns([@subscription]) @subscription.stubs(:balance).returns 0 - visit user_subscriptions_path(@customer.user_id) + visit user_subscriptions_path(@customer.user_id, :locale => nil) assert page.has_content?("Subscriptions") assert page.has_content?("Status: Active") page.save_screenshot('/tmp/subscriptions.png') |