Commits

xrd committed 1a75e26 Merge

Merged changes

Comments (0)

Files changed (14)

app/assets/javascripts/app.js.coffee

                 $scope.loans = response
                 for loan in $scope.loans
                         loan.progress ||= 0
-                        loan.donate_button = $sce.trustAsHtml( loan.donate_button )
+                        loan.button_code = $sce.trustAsHtml( loan.button_code )
         ]
 
 @app.controller 'LoansCtrl', [ '$scope', 'Loans', '$location', '$timeout', ( $scope, Loans, $location, $timeout ) ->

app/controllers/payment_controller.rb

   def payment_received
     loan = Loan.find_by_code params[:code]
     if loan
-      cents = params['order']['total_native']['cents'].to_i
-      loan.payment!( cents/100, params["order"]["transaction"]["id"] )
+      cents = params[:order][:total_native][:cents].to_i
+      loan.payment!( cents/100, params[:order][:transaction][:id] )
     end
-    render json: loan
+    render json: loan.reload
   end
   
   def button
-    @s = Sponsor.find_by_code( params[:code] )
+    @l = Loan.find_by_code( params[:code] )
   end
 end

app/models/loan.rb

   after_validation( on: :create ) do
     parse_amount()
     generate_secure_code()
+    generate_button_code()
   end
 
   def generate_secure_code
     self.code = SecureRandom.hex(5)
   end
 
+  def generate_button_code
+    self.button_code = donate_button()
+  end
+
   def generate_callback_url
     "#{APP_CONFIG['root_url']}/payment/#{self.code()}"
   end
   end
   
   def as_json( options={} )
-    super( options.merge( methods: [ :simple_description, :donate_button ] ) )
+    super( options.merge( methods: [ :simple_description ] ) )
   end
   
 end

app/views/loan_mailer/notify.html.erb

   <body>
     <h1>Donation received</h1>
     <p>
-      <%= progress %>% of the loan is covered by donations.
+      <%= @progress %>% of the loan is covered by donations.
     </p>
     <p>
-      $<%= amount %> was just donated.
+      $<%= @amount %> was just donated.
     </p>
   </body>
 </html>

app/views/payment/button.html.haml

 !!!
 %html
   %body
-    = @s.button_code
+    = @l.button_code

app/views/welcome/_problem.html.haml

 
 .item 
   Is there an alternative?
-  %strong Bitcoin
-  is an open source peer-to-peer currency. 
   %strong Coinbase
   has zero transaction fees for bitcoin exchange, which stands in stark contrast to the 
   payday loan companies which charge anywhere from 10% - 20% for cashing a check with 
   an offer for support to the person in need.
   %strong Donors on Sharkbit
   make small loans in bitcoin to help guarantee payday loans. Once a loan has been repaid to the sponsor, the bitcoin
-  are returned to the donor. And, in case a payday loan is not repaid, the sponsor is not left with a large
+  are returned to the donors. And, in case a payday loan is not repaid, the sponsor is not left with a large
   financial burden themselves.
 
 .item

config/environments/development.rb

   # number of complex assets.
   config.assets.debug = true
 
-  config.action_mailer.delivery_method = :smtp
-config.action_mailer.smtp_settings = {
-  :authentication => :plain,
-  :address => "smtp.mailgun.org",
-  :port => 587,
-  :domain => "smtp.mailgun.org",
-  :user_name => "postmaster@changingstatus.mailgun.org",
-  :password => "0uhukf15ci02"
-}
-
+   config.action_mailer.delivery_method = :sendmail
+# config.action_mailer.smtp_settings = {
+#   :authentication => :plain,
+#   :address => "smtp.mailgun.org",
+#   :port => 587,
+#   :domain => "smtp.mailgun.org",
+#   :user_name => "postmaster@changingstatus.mailgun.org",
+#   :password => "0uhukf15ci02"
+# }
+ 
 end
   get '/facebook/friends', to: "facebook#friends"
   post '/facebook/invite', to: "facebook#invite"
   post '/payment/:code', to: "payment#payment_received", as: 'received'
+  get '/payment/:code', to: "payment#button", as: 'button'
   
   get '/invite', to: 'welcome#index'
   get '/loans', to: 'welcome#index'

db/migrate/20140316073541_add_transaction_id.rb~

-class AddTransactionId < ActiveRecord::Migration
-  def change
-  end
-end

db/migrate/20140316084356_add_button_code_to_loan.rb

+class AddButtonCodeToLoan < ActiveRecord::Migration
+  def change
+    add_column :loans, :button_code, :text
+  end
+end
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20140316073541) do
+ActiveRecord::Schema.define(version: 20140316084356) do
 
   create_table "loans", force: true do |t|
     t.integer  "user_id"
     t.datetime "updated_at"
     t.integer  "progress"
     t.string   "code"
+    t.text     "button_code"
   end
 
   create_table "payments", force: true do |t|

public/t/app/views/welcome/_problem.html

-<div class='item'>
-  <strong>$7B is spent yearly on payday loans.</strong>
-  It's big business.
-  After adjusting for control factors, payday loan businesses primarily service
-  those without college degrees, home renters, African Americans and those earning less than $40,000/yr. Namely, the
-  most vulnerable to economic malaise. These payday loans don't typically cover short
-  term expenses (measured in a few weeks);
-  debtors are indebted for five months out of the year on average, and use the loans
-  for recurring expenses, not unexpected gaps in financial stability.
-  <a href='http://www.pewstates.org/uploadedFiles/PCS_Assets/2012/Pew_Payday_Lending_Report.pdf'>Read the full story at the Pew Report.</a>
-</div>
-<div class='item'>
-  Is there an alternative?
-  <strong>Bitcoin</strong>
-  is an open source peer-to-peer currency.
-  <strong>Coinbase</strong>
-  has zero transaction fees for bitcoin exchange, which stands in stark contrast to the
-  payday loan companies which charge anywhere from 10% - 20% for cashing a check with
-  rolling interest payments that add up to a much larger percentage of the initial loan.
-</div>
-<div class='item'>
-  Let's crowdsource payday loans using Bitcoin and Coinbase!
-  <strong>Sponsors on SharkBit</strong>
-  make payday loans to people in need, but with the full support of others
-  in the community who offer guarantees of small portions of the loan paid via bitcoin.
-  Sponsors can choose to make the loan only if a certain financial support level has been reached.
-  And, donations come not only with a real financial backing but often additionally with
-  an offer for support to the person in need.
-  <strong>Donors on Sharkbit</strong>
-  make small loans in bitcoin to help guarantee payday loans. Once a loan has been repaid to the sponsor, the bitcoin
-  are returned to the donor. And, in case a payday loan is not repaid, the sponsor is not left with a large
-  financial burden themselves.
-</div>
-<div class='item'>
-  Become a sponsor to someone and offer them a payday loan contingent on community financial support. Or,
-  loan your bitcoin to guarantee the payday loan.
-  Zero transaction fees mean even tiny donations can add up to real and substantial help.
-</div>

public/t/donate.html

     {{ loan.progress }}% of loan pledged.
     <progressbar value='loan.progress'></progressbar>
     <small>Donate $10 to help assist with this loan.</small>
-    <div ng-bind-html='loan.donate_button'></div>
+    <div ng-bind-html='loan.button_code'></div>
     <small>{{ loan.code }}</small>
   </div>
 </div>

templates/donate.haml

     {{ loan.progress }}% of loan pledged.
     %progressbar{ value: 'loan.progress' }
     %small Donate $10 to help assist with this loan.
-    %div{ 'ng-bind-html' => 'loan.donate_button' }
+    %div{ 'ng-bind-html' => 'loan.button_code' }
     %small {{ loan.code }}