public
Description: A lighweight blogging platform. It is really really lightweight.
Homepage:
Clone URL: git://github.com/herestomwiththeweather/roll_my_blog.git
roll_my_blog / app / controllers / payments_controller.rb
100644 115 lines (96 sloc) 2.899 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
require 'oauth'
require 'oauth/consumer'
 
gem 'herestomwiththeweather-oscurrency-ruby-api-wrapper'
require 'oscurrency'
 
class PaymentsController < ApplicationController
  before_filter :find_article
  before_filter :setup
 
  # GET /payments
  # GET /payments.xml
  def index
    @payments = Payment.all
 
    respond_to do |format|
      format.html # index.html.erb
      format.xml { render :xml => @payments }
    end
  end
 
  # GET /payments/1
  # GET /payments/1.xml
  def show
    @payment = Payment.find(params[:id])
 
    respond_to do |format|
      format.html # show.html.erb
      format.xml { render :xml => @payment }
    end
  end
 
  # GET /payments/new
  # GET /payments/new.xml
  def new
    @payment = Payment.new
 
    respond_to do |format|
      format.html # new.html.erb
      format.xml { render :xml => @payment }
    end
  end
 
  # GET /payments/1/edit
  def edit
    @payment = Payment.find(params[:id])
    @request_token = OAuth::RequestToken.new(@consumer,session[:req_token],session[:req_token_secret])
    hr = @payment.wire_transfer(@@oscurrency_my_id, @@oscurrency_server, @request_token.get_access_token)
    if hr
      flash[:notice] = 'Payment succeeded.'
    else
      flash[:error] = 'Payment failed.'
    end
    redirect_to(@article)
  end
 
  # POST /payments
  def create
    @payment = Payment.new
    @payment.article = @article
    @payment.amount = 1.00
 
    if @payment.save
      @request_token = @consumer.get_request_token
      session[:req_token] = @request_token.token
      session[:req_token_secret] = @request_token.secret
      callback_url = edit_article_payment_url(@article,@payment)
      redirect_to "#{@@oscurrency_server}/oauth/authorize?oauth_token=#{@request_token.token}&oauth_callback=#{callback_url}"
      #redirect_to @request_token.authorize_url
    else
      flash[:notice] = 'Payment failed.'
      redirect_to(@article)
    end
  end
 
  # PUT /payments/1
  # PUT /payments/1.xml
  def update
    @payment = Payment.find(params[:id])
 
    respond_to do |format|
      if @payments.update_attributes(params[:payment])
        flash[:notice] = 'Payments was successfully updated.'
        format.html { redirect_to(@payment) }
        format.xml { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml { render :xml => @payment.errors, :status => :unprocessable_entity }
      end
    end
  end
 
  # DELETE /payments/1
  # DELETE /payments/1.xml
  def destroy
    @payment = Payment.find(params[:id])
    @payment.destroy
 
    respond_to do |format|
      format.html { redirect_to(payment_url) }
      format.xml { head :ok }
    end
  end
 
  def find_article
    article_id = params[:article_id]
    @article = Article.find(article_id)
  end
 
  def setup
    @consumer = Oscurrency::consumer(@@oscurrency_consumer_token,@@oscurrency_consumer_secret,@@oscurrency_server)
  end
end