From 34ac576bf7efbddac0a89731292eac8974f95114 Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 18 Dec 2013 00:10:01 -0800 Subject: enable billing engine by default, consolidate APP_CONFIG[:payments] and APP_CONFIG[:braintree] into APP_CONFIG[:billing][:braintree] --- Gemfile | 9 ++---- app/views/layouts/_navigation.html.haml | 2 +- billing/README.md | 49 ++++++++++++++++++++++++++++++++ billing/README.rdoc | 25 ---------------- billing/config/initializers/braintree.rb | 31 ++++++++++++++------ config/defaults.yml | 5 ++-- users/app/views/users/show.html.haml | 2 +- 7 files changed, 78 insertions(+), 45 deletions(-) create mode 100644 billing/README.md delete mode 100644 billing/README.rdoc diff --git a/Gemfile b/Gemfile index a346afa..e111a4e 100644 --- a/Gemfile +++ b/Gemfile @@ -4,28 +4,23 @@ eval(File.read(File.dirname(__FILE__) + '/common_dependencies.rb')) eval(File.read(File.dirname(__FILE__) + '/ui_dependencies.rb')) # EITHER fetch all of the leap_web gems in one go -# gem 'leap_web' +# gem 'leap_web' # OR use the local versions for development instead: gem "leap_web_core", :path => 'core' gem 'leap_web_users', :path => 'users' gem 'leap_web_certs', :path => 'certs' gem 'leap_web_help', :path => 'help' -# gem 'leap_web_billing', :path => 'billing' # for now, this gem will be included for development and test environments only +gem 'leap_web_billing', :path => 'billing' # To use debugger gem 'debugger', :platforms => :mri_19 # ruby 1.8 is not supported anymore # gem 'ruby-debug', :platforms => :mri_18 -group :development do - gem 'leap_web_billing', :path => 'billing' -end - group :test do gem 'fake_braintree', require: false gem 'capybara', require: false gem 'launchy' # so save_and_open_page works in integration tests - gem 'leap_web_billing', :path => 'billing' end # unreleased so far ... but leap_web_certs need it diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index 6de567a..f90ed16 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -3,5 +3,5 @@ = link_to_navigation t(:account_settings), edit_user_path(@user), :active => controller?(:users) - # will want link for identity settings = link_to_navigation t(:support_tickets), auto_tickets_path, :active => controller?(:tickets) - = link_to_navigation t(:billing_settings), billing_top_link(@user), :active => controller?(:customer, :payments, :subscriptions, :credit_card_info) if APP_CONFIG[:payment].present? + = link_to_navigation t(:billing_settings), billing_top_link(@user), :active => controller?(:customer, :payments, :subscriptions, :credit_card_info) if APP_CONFIG[:billing] = link_to_navigation t(:logout), logout_path, :method => :delete 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/config/defaults.yml b/config/defaults.yml index 260915e..a1b6235 100644 --- a/config/defaults.yml +++ b/config/defaults.yml @@ -44,6 +44,7 @@ common: &common # see /users/app/views/users/_edit.html.haml for a list. user_actions: ['destroy_account'] admin_actions: ['change_pgp_key', 'change_service_level', 'destroy_account'] + billing: ~ service_levels: &service_levels service_levels: @@ -75,7 +76,6 @@ development: admins: [blue, admin, admin2] domain: example.org secret_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' - payment: [] reraise_errors: true test: @@ -87,8 +87,8 @@ test: admins: [admin, admin2] domain: test.me secret_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' - payment: [billing] reraise_errors: true + billing: true production: <<: *downloads @@ -96,5 +96,4 @@ production: <<: *common admins: [] domain: example.net - payment: [] # logfile: /path/to/your/logs diff --git a/users/app/views/users/show.html.haml b/users/app/views/users/show.html.haml index 7bea370..4c710a0 100644 --- a/users/app/views/users/show.html.haml +++ b/users/app/views/users/show.html.haml @@ -19,4 +19,4 @@ %li= icon('user') + link_to(t(:overview_account), edit_user_path(@user)) - # %li= icon('envelope') + link_to(t(:overview_email), {insert path for user identities, presuambly} %li= icon('question-sign') + link_to(t(:overview_tickets), user_tickets_path(@user)) - %li= icon('shopping-cart') + link_to(t(:overview_billing), billing_top_link(@user)) if APP_CONFIG[:payment].present? + %li= icon('shopping-cart') + link_to(t(:overview_billing), billing_top_link(@user)) if APP_CONFIG[:billing] -- cgit v1.2.3 From 5818a2a101cc89c778c5a5e62271ab42b1fa4c70 Mon Sep 17 00:00:00 2001 From: elijah Date: Fri, 20 Dec 2013 10:53:40 -0800 Subject: fixed billing tests (added dummy billing hash to config, include required testing gem phantomjs-binaries) --- Gemfile | 1 + Gemfile.lock | 6 ++++++ config/defaults.yml | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index e111a4e..2e0b8d0 100644 --- a/Gemfile +++ b/Gemfile @@ -21,6 +21,7 @@ group :test do gem 'fake_braintree', require: false gem 'capybara', require: false gem 'launchy' # so save_and_open_page works in integration tests + gem 'phantomjs-binaries' end # unreleased so far ... but leap_web_certs need it diff --git a/Gemfile.lock b/Gemfile.lock index 918fdba..cd65c89 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -138,6 +138,7 @@ GEM thin faker (1.2.0) i18n (~> 0.5) + ffi (1.9.3) haml (3.1.8) haml-rails (0.3.5) actionpack (>= 3.1, < 4.1) @@ -169,6 +170,8 @@ GEM multi_json (1.8.2) nokogiri (1.6.0) mini_portile (~> 0.5.0) + phantomjs-binaries (1.9.2.3) + sys-uname (= 0.9.0) poltergeist (1.4.1) capybara (~> 2.1.0) cliver (~> 0.2.1) @@ -229,6 +232,8 @@ GEM multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) + sys-uname (0.9.0) + ffi (>= 1.0.0) therubyracer (0.10.2) libv8 (~> 3.3.10) thin (1.5.1) @@ -277,6 +282,7 @@ DEPENDENCIES leap_web_help! leap_web_users! mocha (~> 0.13.0) + phantomjs-binaries poltergeist quiet_assets rails-i18n diff --git a/config/defaults.yml b/config/defaults.yml index a1b6235..eb31301 100644 --- a/config/defaults.yml +++ b/config/defaults.yml @@ -88,7 +88,7 @@ test: domain: test.me secret_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' reraise_errors: true - billing: true + billing: {} production: <<: *downloads -- cgit v1.2.3