From 451bca08e34e9a543674ce295def7a2ecbad277f Mon Sep 17 00:00:00 2001 From: Jesse Grant Date: Mon, 14 Jan 2013 16:40:43 -0500 Subject: [PATCH] moved payment options configuration out of settings.yml and into a model --- app/models/payment_option.rb | 3 + app/views/preorder/_payment_options.html.erb | 12 +-- config/settings.yml | 22 +----- .../20130106183354_create_payment_options.rb | 15 ++++ db/schema.rb | 14 +++- db/seeds.rb | 75 +++++++++++++++++++ spec/models/payment_option_spec.rb | 5 ++ 7 files changed, 120 insertions(+), 26 deletions(-) create mode 100644 app/models/payment_option.rb create mode 100644 db/migrate/20130106183354_create_payment_options.rb create mode 100644 spec/models/payment_option_spec.rb diff --git a/app/models/payment_option.rb b/app/models/payment_option.rb new file mode 100644 index 0000000..0d14133 --- /dev/null +++ b/app/models/payment_option.rb @@ -0,0 +1,3 @@ +class PaymentOption < ActiveRecord::Base + attr_accessible :amount, :amount_display, :delivery_desc, :description, :limit, :purchased_count, :shipping_desc +end diff --git a/app/views/preorder/_payment_options.html.erb b/app/views/preorder/_payment_options.html.erb index 3c18e81..d5b3892 100644 --- a/app/views/preorder/_payment_options.html.erb +++ b/app/views/preorder/_payment_options.html.erb @@ -2,16 +2,16 @@
    - <% Settings.payment_options.each_with_index do |p, index| %> + <% PaymentOption.all.each_with_index do |p, index| %>
  1. - <%= radio_button_tag "payment_option", p[0], false, class: 'payment_radio' %> - <%= label_tag("payment_option_#{index}", p[1]) %> + <%= radio_button_tag "payment_option", p.amount, false, class: 'payment_radio' %> + <%= label_tag("payment_option_#{index}", p.amount_display) %>
    - <%= p[2] %> + <%= p.shipping_desc %>
    -

    <%= raw p[3] %>

    -

    <%= p[4] %>

    +

    <%= raw p.description %>

    +

    <%= p.delivery_desc %>

  2. <% end %> diff --git a/config/settings.yml b/config/settings.yml index 4916977..fd2e4d5 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -37,27 +37,11 @@ amazon_access_key: "YOUR_AMAZON_ACCESS_KEY" amazon_secret_key: "YOUR_AMAZON_SECRET_KEY" price: 19.95 -# To allow different packages ("rewards" for funding) with different pricing on the payments page, set this to true +# if use_payment_options is set to true, then a set of radio buttons will be displayed with various payment options. +# There is a PaymentOption model for storing info about payment options. To set up your payment options you should +# put code in seeds.rb use_payment_options: true -# if use_payment_options is set to true, then a set of radio buttons will be displayed with various payment options -# payment_options is a comma delimited list of: -# amount (the cost of the package in dd.cc), -# display ammount (the text to display on the web page for the cost) -# shipping description, -# package text (description of what they get if they select this payment option - kickstarter calls these "rewards"), -# delivery text -payment_options: [ - ["10.00", "$10", "", "Basic level: You receive a great big thankyou from us! You Rock", ""], - ["100.00", "$100", "add $3 to ship outside the US", "Package 1: You receive our print edition", "Estimated delivery: Oct 2013"], - ["125.00", "$125", "add $3 to ship outside the US", "Package 2: You will receive both our print and digital edition", "Estimated delivery: Oct 2013"], - ["125.00", "$125", "add $3 to ship outside the US", "You will receive both our print and digital edition", "Estimated delivery: Oct 2013"], - ["125.00", "$125", "add $3 to ship outside the US", "You will receive both our print and digital edition", "Estimated delivery: Oct 2013"], - ["125.00", "$125", "add $3 to ship outside the US", "You will receive both our print and digital edition", "Estimated delivery: Oct 2013"], - ["125.00", "$125", "add $3 to ship outside the US", "You will receive both our print and digital edition", "Estimated delivery: Oct 2013"], - ["125.00", "$125", "add $3 to ship outside the US", "You will receive both our print and digital edition", "Estimated delivery: Oct 2013"] -] - payment_description: "You really should change this text because people will see it on Amazon's order page!!!!!" # Amazon limits how much we can charge people with their Multi-Use tokens. diff --git a/db/migrate/20130106183354_create_payment_options.rb b/db/migrate/20130106183354_create_payment_options.rb new file mode 100644 index 0000000..2c72b1b --- /dev/null +++ b/db/migrate/20130106183354_create_payment_options.rb @@ -0,0 +1,15 @@ +class CreatePaymentOptions < ActiveRecord::Migration + def change + create_table :payment_options do |t| + t.decimal :amount + t.string :amount_display + t.text :description + t.string :shipping_desc + t.string :delivery_desc + t.integer :limit + t.integer :purchased_count + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 5feda63..079ad3a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20121004072706) do +ActiveRecord::Schema.define(:version => 20130106183354) do create_table "orders", :id => false, :force => true do |t| t.string "token" @@ -36,6 +36,18 @@ ActiveRecord::Schema.define(:version => 20121004072706) do t.datetime "updated_at", :null => false end + create_table "payment_options", :force => true do |t| + t.decimal "amount" + t.string "amount_display" + t.text "description" + t.string "shipping_desc" + t.string "delivery_desc" + t.integer "limit" + t.integer "purchased_count" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "users", :force => true do |t| t.string "email" t.datetime "created_at", :null => false diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e8..46299ef 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,78 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) +PaymentOption.create( + [ + { + amount: 10.00, + amount_display: '$10', + description: 'Basic level: You receive a great big thankyou from us! You Rock', + shipping_desc: '', + delivery_desc: '', + limit: -1, + purchased_count: 0 + }, + { + amount: 100.00, + amount_display: '$100', + description: 'Package 1: You receive our print edition', + shipping_desc: 'add $3 to ship outside the US', + delivery_desc: 'Estimated delivery: Oct 2013', + limit: 250, + purchased_count: 0 + }, + { + amount: 125.00, + amount_display: '$125', + description: 'Package 2: You will receive both our print and digital edition', + shipping_desc: 'add $3 to ship outside the US', + delivery_desc: 'Estimated delivery: Oct 2013', + limit: -1, + purchased_count: 0 + }, + { + amount: 200.00, + amount_display: '$200', + description: 'Package 3: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', + shipping_desc: 'add $3 to ship outside the US', + delivery_desc: 'Estimated delivery: Oct 2013', + limit: -1, + purchased_count: 0 + }, + { + amount: 250.00, + amount_display: '$250', + description: 'Package 4: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', + shipping_desc: 'add $3 to ship outside the US', + delivery_desc: 'Estimated delivery: Oct 2013', + limit: -1, + purchased_count: 0 + }, + { + amount: 300.00, + amount_display: '$300', + description: 'Package 5: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', + shipping_desc: 'add $3 to ship outside the US', + delivery_desc: 'Estimated delivery: Oct 2013', + limit: -1, + purchased_count: 0 + }, + { + amount: 500.00, + amount_display: '$500', + description: 'Package 6: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', + shipping_desc: 'add $3 to ship outside the US', + delivery_desc: 'Estimated delivery: Oct 2013', + limit: -1, + purchased_count: 0 + }, + { + amount: 1000.00, + amount_display: '$1000', + description: 'Package 7: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', + shipping_desc: 'add $3 to ship outside the US', + delivery_desc: 'Estimated delivery: Oct 2013', + limit: -1, + purchased_count: 0 + } + ]) \ No newline at end of file diff --git a/spec/models/payment_option_spec.rb b/spec/models/payment_option_spec.rb new file mode 100644 index 0000000..1a9d6bf --- /dev/null +++ b/spec/models/payment_option_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe PaymentOption do + pending "add some examples to (or delete) #{__FILE__}" +end