wepay-rails 0.1.82 → 0.1.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -17,27 +17,62 @@ Your model:
17
17
 
18
18
  Adding wepayable to your model also adds some helpful methods to your model, like save_<your column name>
19
19
 
20
- You will have to set up a few new controllers to handle callbacks from wepay.
20
+ You need to also create a new model called WepayCheckoutRecord. In future versions, I'll include a generator - but for now, here's the migration to use:
21
+
22
+ class CreateWepayCheckoutRecords < ActiveRecord::Migration
23
+ def self.up
24
+
25
+ create_table :wepay_checkout_records do |t|
26
+ t.integer :checkout_id
27
+ t.integer :account_id
28
+ t.string :auth_code
29
+ t.string :state
30
+ t.string :short_description
31
+ t.text :long_description
32
+ t.string :currency
33
+ t.decimal :amount
34
+ t.decimal :app_fee
35
+ t.string :fee_payer
36
+ t.decimal :gross
37
+ t.decimal :fee
38
+ t.string :reference_id
39
+ t.text :redirect_uri
40
+ t.text :callback_uri
41
+ t.text :checkout_uri
42
+ t.string :payer_email
43
+ t.string :payer_name
44
+ t.text :cancel_reason
45
+ t.text :refund_reason
46
+ t.boolean :auto_capture
47
+ t.boolean :require_shipping
48
+ t.text :shipping_address
49
+ t.decimal :tax
50
+
51
+ t.timestamps
52
+ end
53
+
54
+ add_index :wepay_checkout_records, :checkout_id
55
+ end
56
+
57
+ def self.down
58
+ drop_table :wepay_checkout_records
59
+ end
60
+ end
61
+
62
+
63
+ You will have to set up a few new controllers to handle callbacks and redirects from wepay back to your app.
21
64
  One is for handling the Oauth handshake. I called mine authorize_controller.rb
22
- Another is for handling IPN (Instant Payment Notifications) - for me, it's ipn_controller.rb
23
65
 
24
66
  I created a directory under my controllers directory called wepay so I can keep my wepay callback controllers in one place.
25
67
  app
26
68
  |_ controllers
27
69
  |_ wepay
28
- |_ application_controller.rb
29
70
  |_ authorize_controller.rb
30
- |_ ipn_controller.rb
31
71
  |_ purchase
32
72
  |_ checkout_controller.rb
33
73
  |_ finalize_controller.rb
34
74
 
35
- class Wepay::ApplicationController < ApplicationController
36
- include WepayRails::Payments
37
- end
38
-
39
75
  class Wepay::AuthorizeController < Wepay::ApplicationController
40
- before_filter :authenticate_account! # I use devise
41
76
  def index
42
77
  current_profile.save_wepay_auth_code params[:code]
43
78
  initialize_wepay_access_token(params[:code])
@@ -46,6 +81,10 @@ I created a directory under my controllers directory called wepay so I can keep
46
81
  end
47
82
  end
48
83
 
84
+ The wepay-rails gem comes with an IpnController already built in for
85
+ handling requests from wepay about a specific checkout. If you wish to override it,
86
+ you can create an IpnController in your rails app.
87
+
49
88
  class IpnController < Wepay::ApplicationController
50
89
  def index
51
90
  #Do something with the instant payment notifications back from Wepay
@@ -55,7 +94,6 @@ I created a directory under my controllers directory called wepay so I can keep
55
94
  Routes for these:
56
95
  namespace :wepay do
57
96
  resources :authorize, :only => [:index]
58
- resources :ipn, :only => [:index]
59
97
  end
60
98
 
61
99
  wepay.yml will also need these directives. See the section on wepay.yml
@@ -73,13 +111,13 @@ Finally, your checkout controller (or some controller that will interact with th
73
111
  if wepay_access_token_exists? # Temporary Oauth Access token from wepay
74
112
 
75
113
  cart = current_account.cart # EXAMPLE - get my shopping cart
76
- tx_id = cart.init_transaction # EXAMPLE - I use a transaction table to capture attempts to checkout
114
+ tx_id = cart.transaction_id # EXAMPLE - I use a column in my cart to have a way to look up the cart upon the user's return from wepay
77
115
 
78
116
  checkout_params = {
79
117
  :amount => cart.grand_total,
80
118
  :short_description => cart.short_description,
81
119
  :long_description => cart.long_description,
82
- :callback_uri => purchase_finalize_index_url(:txID => tx_id) # Wepay redirects the user back to this url after purchase
120
+ :redirect_uri => purchase_finalize_index_url(:txID => tx_id) # Wepay redirects the user back to this url after purchase
83
121
  }
84
122
 
85
123
  init_checkout_and_send_user_to_wepay(checkout_params) # Send the customer to wepay to finish payment
@@ -112,39 +150,57 @@ If not, we can initialize the access token. If it is there, go ahead and make an
112
150
 
113
151
  Configuration is done through config/wepay.yml:
114
152
  production:
115
- client_id: <your wepay client id>
116
- client_secret: <your wepay client secret>
117
- authorize_redirect_uri: "http://prod.example.com/wepay/authorize"
118
- scope: ['refund_payments','collect_payments','view_balance','view_user']
119
- wepay_api_uri: "https://api.wepay.com"
120
- wepay_api_version: "v2"
121
- ipn_callback_uri: "http://prod.example.com/wepay/ipn"
122
- checkout_redirect_uri: "http://prod.example.com/purchase/finalize"
123
- fee_payer: Payee
124
- checkout_type: GOODS
125
- charge_tax: false
126
- app_fee: 0
127
- auto_capture: true
128
- require_shipping: false
129
- shipping_fee: 0
130
- charge_tax: false
153
+ client_id: <your client_id from wepay>
154
+ client_secret: <your client_secret from wepay>
155
+ authorize_redirect_uri: "http://www.example.com/wepay/authorize"
156
+ scope: ['refund_payments','collect_payments','view_balance','view_user']
157
+ #wepay_api_uri: "https://api.wepay.com"
158
+ wepay_api_uri: "https://stage.wepay.com"
159
+ wepay_api_version: "v2"
160
+ ipn_callback_uri: "http://www.example.com/wepay/ipn"
161
+ checkout_redirect_uri: "http://www.example.com/purchase/finalize"
162
+ fee_payer: Payee
163
+ checkout_type: GOODS
164
+ charge_tax: false
165
+ app_fee: 0
166
+ auto_capture: true
167
+ require_shipping: false
168
+ shipping_fee: 0
169
+ charge_tax: false
131
170
  development:
132
- client_id: <your dev client id>
133
- client_secret: <your dev client secret>
134
- redirect_uri: "http://dev.example.com/wepay/authorize"
135
- scope: ['refund_payments','collect_payments','view_balance','view_user']
136
- wepay_api_uri: "https://stage.wepay.com"
137
- wepay_api_version: "v2"
138
- ipn_callback_uri: "http://dev.example.com/wepay/ipn"
139
- checkout_redirect_uri: "http://dev.example.com/purchase/finalize"
140
- fee_payer: Payee
141
- checkout_type: GOODS
142
- charge_tax: false
143
- app_fee: 0
144
- require_shipping: false
145
- shipping_fee: 0
146
- charge_tax: false
147
- auto_capture: true
171
+ client_id: <your client_id from wepay>
172
+ client_secret: <your client_secret from wepay>
173
+ redirect_uri: "http://dev.example.com/wepay/authorize"
174
+ scope: ['refund_payments','collect_payments','view_balance','view_user']
175
+ wepay_api_uri: "https://stage.wepay.com"
176
+ wepay_api_version: "v2"
177
+ ipn_callback_uri: "http://dev.example.com/wepay/ipn"
178
+ checkout_redirect_uri: "http://dev.example.com/purchase/finalize"
179
+ fee_payer: Payee
180
+ checkout_type: GOODS
181
+ charge_tax: false
182
+ app_fee: 0
183
+ require_shipping: false
184
+ shipping_fee: 0
185
+ charge_tax: false
186
+ auto_capture: true
187
+ test:
188
+ client_id: <your client_id from wepay>
189
+ client_secret: <your client_secret from wepay>
190
+ redirect_uri: "http://dev.example.com/wepay/authorize"
191
+ scope: ['refund_payments','collect_payments','view_balance','view_user']
192
+ wepay_api_uri: "https://stage.wepay.com"
193
+ wepay_api_version: "v2"
194
+ ipn_callback_uri: "http://test.example.com/wepay/ipn"
195
+ checkout_redirect_uri: "http://dev.example.com/purchase/finalize"
196
+ fee_payer: Payee
197
+ checkout_type: GOODS
198
+ charge_tax: false
199
+ app_fee: 0
200
+ auto_capture: true
201
+ charge_tax: false
202
+ require_shipping: false
203
+ shipping_fee: 0
148
204
 
149
205
 
150
206
  == Contributing to wepay-rails
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.82
1
+ 0.1.83
@@ -1,21 +1,15 @@
1
1
  class Wepay::IpnController < Wepay::ApplicationController
2
2
  def index
3
3
 
4
- log = File.open('/tmp/ipn.log','a')
5
-
6
4
  record = WepayCheckoutRecord.find_by_checkout_id(params[:checkout_id])
7
5
 
8
- log.puts record.inspect
9
-
10
6
  if record.present?
11
7
  wepay_gateway.access_token(record.auth_code)
12
8
  checkout = wepay_gateway.lookup_checkout(record.checkout_id)
13
- log.puts checkout.inspect
14
9
  record.update_attributes(checkout)
10
+ render :text => 'ok'
15
11
  else
16
12
  raise StandardError.new("Wepay IPN: No record found for checkout_id #{params[:checkout_id]}")
17
13
  end
18
-
19
- render :text => 'ok'
20
14
  end
21
15
  end
@@ -87,7 +87,6 @@ module WepayRails
87
87
  # :charge_tax No A boolean value (0 or 1). If set to 1 and the account has a relevant tax entry (see /account/set_tax), then tax will be charged.
88
88
  def init_checkout_and_send_user_to_wepay(parms)
89
89
  response = wepay_gateway.perform_checkout(parms)
90
- File.open('/tmp/noisebytes.log','a') {|f|f.write(response.inspect)}
91
90
  raise WepayRails::Exceptions::InitializeCheckoutError.new("A problem occurred while trying to checkout. Wepay didn't send us back a checkout uri") unless response && response.has_key?('checkout_uri')
92
91
  redirect_to response['checkout_uri'] and return
93
92
  end
data/lib/wepay-rails.rb CHANGED
@@ -30,9 +30,7 @@ module WepayRails
30
30
  @wepay_access_token = args.first
31
31
 
32
32
  yml = Rails.root.join('config', 'wepay.yml').to_s
33
- File.open('/tmp/wepay.log','a') {|f| f.write("Yaml for wepay is found at #{yml}")}
34
33
  @config = YAML.load_file(yml)[Rails.env].symbolize_keys
35
- File.open('/tmp/wepay.log','a') {|f| f.write("config is #{@config.inspect}")}
36
34
 
37
35
  @scope = @config.delete(:scope)
38
36
 
@@ -97,14 +95,10 @@ module WepayRails
97
95
  # retrieved from the first call.
98
96
  def wepay_user
99
97
  user_api = lambda {|headers|
100
- File.open('/tmp/noisebytes.log','a') {|f|f.write("Base uri inside lambda is #{@base_uri}")}
101
- File.open('/tmp/noisebytes.log','a') {|f|f.write("Headers inside lambda is #{headers}")}
102
98
  response = self.class.get("#{@base_uri}/user", {:headers => headers})
103
99
  JSON.parse(response.body)
104
100
  }
105
101
 
106
- File.open('/tmp/noisebytes.log','a'){|f|f.write("User is #{user_api.call(wepay_auth_header)}")}
107
-
108
102
  @wepay_user ||= user_api.call(wepay_auth_header)
109
103
  end
110
104
 
@@ -157,9 +151,6 @@ module WepayRails
157
151
  :account_id => @config[:account_id]
158
152
  }.merge(parms)
159
153
 
160
- File.open('/tmp/noisebytes.log','a') {|f| f.write({:headers => wepay_auth_header}.merge!(defaults).inspect)}
161
-
162
-
163
154
  response = self.class.get("#{@base_uri}/checkout/create", {:headers => wepay_auth_header}.merge!(:query => defaults))
164
155
  JSON.parse(response.body)
165
156
  end
data/wepay-rails.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{wepay-rails}
8
- s.version = "0.1.82"
8
+ s.version = "0.1.83"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Adam Medeiros}]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wepay-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.82
4
+ version: 0.1.83
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-09-04 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &19124380 !ruby/object:Gem::Requirement
16
+ requirement: &19031220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *19124380
24
+ version_requirements: *19031220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: shoulda
27
- requirement: &19123780 !ruby/object:Gem::Requirement
27
+ requirement: &19030640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *19123780
35
+ version_requirements: *19030640
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &19123180 !ruby/object:Gem::Requirement
38
+ requirement: &19030120 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *19123180
46
+ version_requirements: *19030120
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &19122580 !ruby/object:Gem::Requirement
49
+ requirement: &19029520 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *19122580
57
+ version_requirements: *19029520
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &19121980 !ruby/object:Gem::Requirement
60
+ requirement: &19028920 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *19121980
68
+ version_requirements: *19028920
69
69
  description: Rails gem that interfaces with the WePay API
70
70
  email: adammede@gmail.com
71
71
  executables: []
@@ -108,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  segments:
110
110
  - 0
111
- hash: 1065642594911744828
111
+ hash: -782813271623262101
112
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements: