wepay-rails 0.1.116 → 0.2.0

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
@@ -15,76 +15,30 @@ Your migration:
15
15
 
16
16
  add_column :my_model, :wepay_auth_code, :string
17
17
 
18
- Now, tell wepay_rails where it should store/retrieve the auth code.
19
-
20
- You will need a wepay.yml file added to your config directory. Please copy one from the lib/examples folder of the
21
- wepay-rails gem and modify it to your needs. In a future release, the copy will happen via a generator. For now, please
22
- manually copy it over.
23
-
24
- Snippet of wepay.yml showing the auth_code_location directive:
18
+ You need to also create a new model called WepayCheckoutRecord. It will be updated by wepay's IPN system as changes to the checkout change - such as the status.
19
+ Wepay-rails handles those IPN notifications for you. You can write observers watching the WepayCheckoutRecord model if you need to have
20
+ something specific occur when the checkout changes.
25
21
 
26
- production:
27
- auth_code_location: MyModel.wepay_auth_code
22
+ To create your WepayCheckoutRecord model and migration:
28
23
 
29
- Your model:
24
+ script/rails g wepay_rails:install
30
25
 
31
- class MyModel < ActiveRecord::Base
32
- wepayable
33
- end
26
+ This will create 3 files for you, a migration file for a table to hold the checkout results, the model and a wepay.yml.example file. Next run:
34
27
 
35
- Now you will have some convenience methods added to your model, such as save_<your column name> (eg. save_wepay_auth_code)
28
+ rake db:migrate
36
29
 
37
- You need to also create a new model called WepayCheckoutRecord. It will be updated by wepay's IPN system as changes to the checkout change - such as the status.
38
- Wepay-rails handles those IPN notifications for you. You can write observers watching the WepayCheckoutRecord model if you need to have
39
- something specific occur when the checkout changes. In future versions, I'll include a generator - but for now, here's the migration to use:
40
-
41
- class CreateWepayCheckoutRecords < ActiveRecord::Migration
42
- def self.up
43
-
44
- create_table :wepay_checkout_records do |t|
45
- t.integer :checkout_id
46
- t.integer :account_id
47
- t.string :auth_code
48
- t.string :state
49
- t.string :short_description
50
- t.text :long_description
51
- t.string :currency
52
- t.decimal :amount
53
- t.decimal :app_fee
54
- t.string :fee_payer
55
- t.decimal :gross
56
- t.decimal :fee
57
- t.string :reference_id
58
- t.text :redirect_uri
59
- t.text :callback_uri
60
- t.text :checkout_uri
61
- t.string :payer_email
62
- t.string :payer_name
63
- t.text :cancel_reason
64
- t.text :refund_reason
65
- t.boolean :auto_capture
66
- t.boolean :require_shipping
67
- t.text :shipping_address
68
- t.decimal :tax
69
-
70
- t.timestamps
71
- end
72
-
73
- add_index :wepay_checkout_records, :checkout_id
74
- end
30
+ Modify config/wepay.yml.example to your needs. You will need to set the model and column where you are storing your wepay auth code:
75
31
 
76
- def self.down
77
- drop_table :wepay_checkout_records
78
- end
79
- end
32
+ Snippet of wepay.yml showing the auth_code_location directive:
80
33
 
34
+ production:
35
+ auth_code_location: MyModel.wepay_auth_code
81
36
 
82
- You will have to set up a few new controllers to handle callbacks and redirects from wepay back to your app.
37
+ You will have to set up a few new controllers in your rails app to handle callbacks and redirects from wepay.
83
38
  I created one called finalize_controller and I use it for a landing page when the customer is finished paying
84
- their order. The other controller I created is a checkout_controller - this controller glues all of the auth
85
- stuff together - it checks if the user has an auth code and access token so it can do the checkout for you. I am
86
- going to look into ways to have wepay-rails do most of the heavy lifting - look for this to change in future versions.
87
- For now, here's how to handle it...
39
+ their order. The other controller I created is a checkout_controller - I send my customers to it when they click checkout
40
+ in the cart. Your app is surely differnt than mine. Do what makes sense to you.
41
+ For now, here's what I am doing in my rails app to handle it...
88
42
 
89
43
  app
90
44
  |_ controllers
@@ -102,7 +56,7 @@ you can create an IpnController in your rails app.
102
56
  end
103
57
  end
104
58
 
105
- wepay.yml will also need these directives. See the section on wepay.yml
59
+ wepay.yml will also need these directives. See the wepay.yml.example file in config.
106
60
 
107
61
  When you include WepayRails::Payments, you get the controller actions you need. For instance, initialize_wepay_access_token(auth_code)
108
62
  which completes the Oauth2 handshake with Wepay and get's the access token for future comunications with Wepay.
@@ -113,40 +67,28 @@ Finally, your checkout controller (or some controller that will interact with th
113
67
  before_filter :authenticate_account! # I am using devise - this line depends on your authentication scheme
114
68
 
115
69
  # PLEASE READ
116
- # Notes: (By the way, I am looking into putting most of this heavy lifting into the actual wepay-rails gem
117
- # it's self - stay tuned for that)
118
70
  # I am saving the wepay_auth_code in my Profile model. Somewhere in my rails app, I have a method called
119
- # current_profile which I use to return the Profile object of my user - this is why I can use current_profile.wepay_auth_code
120
- # please dress this up to work for your application.
71
+ # current_profile which I use to return the Profile object of my user. I pass that object through the
72
+ # init_checkout_and_send_user_to_wepay method along with my checkout parameters.
121
73
 
122
- # Please pay attention to the flow here though (Note, I am going to find a way to move most of this pain to wepay-rails - stay tuned):
123
- # Step 1: check and see if we have saved a wepay_auth_code for the customer. If not, redirect them to wepay to get one
124
- # Step 2: check to see if we have a wepay access token to use for Oauth Communications. If not, go get one
125
- # Step 3: now do a checkout using the method init_checkout_and_send_user_to_wepay. When they are done paying you, they will be redirected
74
+ # After the customer is sent to wepay, when they are done paying you, they will be redirected
126
75
  # back to your application - you will set the location they will be redirected back to using the redirect_uri directive
127
76
  # either here - or in wepay.yml. Using it here overrides wepay.yml.
128
77
 
129
78
  def index
130
- if current_profile.wepay_auth_code.present? # Code used to get the Oauth Access Token
131
- if wepay_access_token_exists? # Temporary Oauth Access token from wepay
132
-
133
- cart = current_account.cart # EXAMPLE - get my shopping cart
134
- 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
135
-
136
- checkout_params = {
137
- :amount => cart.grand_total,
138
- :short_description => cart.short_description,
139
- :long_description => cart.long_description,
140
- :redirect_uri => purchase_finalize_index_url(:txID => tx_id) # Wepay redirects the user back to this url after purchase
141
- }
142
-
143
- init_checkout_and_send_user_to_wepay(checkout_params) # Send the customer to wepay to finish payment
144
- else
145
- initialize_wepay_access_token(current_profile.wepay_auth_code) # No access token - so go get one
146
- end
147
- else
148
- redirect_to_wepay_for_auth(current_profile) # Customer doesn't have an auth code yet from Wepay - so go get one
149
- end
79
+
80
+ cart = current_account.cart # EXAMPLE - get my shopping cart
81
+ 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
82
+
83
+ checkout_params = {
84
+ :amount => cart.grand_total,
85
+ :short_description => cart.short_description,
86
+ :long_description => cart.long_description,
87
+ :redirect_uri => purchase_finalize_index_url(:txID => tx_id) # Wepay redirects the user back to this url after purchase
88
+ }
89
+
90
+ # Finally, send the user off to wepay so you can get paid! - CASH MONEY
91
+ init_checkout_and_send_user_to_wepay(checkout_params, current_profile)
150
92
  end
151
93
  end
152
94
 
@@ -170,68 +112,9 @@ Example Routes for these:
170
112
  resources :finalize, :only => [:index]
171
113
  end
172
114
 
173
- First, we check to see if we have saved the auth code for the user, if so, we next need to see if we have an Oauth2 access token.
174
- If not, we can initialize the access token. If it is there, go ahead and make an api call - the example above initiates a checkout.
175
115
 
176
- Configuration is done through config/wepay.yml:
177
- production:
178
- client_id: <your client_id from wepay>
179
- client_secret: <your client_secret from wepay>
180
- auth_code_location: MyModel.wepay_auth_code
181
- redirect_uri: "http://www.example.com/wepay/authorize"
182
- after_authorize_redirect_uri: "http://www.example.com/purchase/checkout"
183
- scope: ['refund_payments','collect_payments','view_balance','view_user']
184
- #wepay_api_uri: "https://api.wepay.com"
185
- wepay_api_uri: "https://stage.wepay.com"
186
- wepay_api_version: "v2"
187
- ipn_callback_uri: "http://www.example.com/wepay/ipn"
188
- checkout_redirect_uri: "http://www.example.com/purchase/finalize"
189
- fee_payer: Payee
190
- checkout_type: GOODS
191
- charge_tax: false
192
- app_fee: 0
193
- auto_capture: true
194
- require_shipping: false
195
- shipping_fee: 0
196
- charge_tax: false
197
- development:
198
- client_id: <your client_id from wepay>
199
- client_secret: <your client_secret from wepay>
200
- auth_code_location: MyModel.wepay_auth_code
201
- redirect_uri: "http://dev.example.com/wepay/authorize"
202
- after_authorize_redirect_uri: "http://dev.example.com/purchase/checkout"
203
- scope: ['refund_payments','collect_payments','view_balance','view_user']
204
- wepay_api_uri: "https://stage.wepay.com"
205
- wepay_api_version: "v2"
206
- ipn_callback_uri: "http://dev.example.com/wepay/ipn"
207
- checkout_redirect_uri: "http://dev.example.com/purchase/finalize"
208
- fee_payer: Payee
209
- checkout_type: GOODS
210
- charge_tax: false
211
- app_fee: 0
212
- require_shipping: false
213
- shipping_fee: 0
214
- charge_tax: false
215
- auto_capture: true
216
- test:
217
- client_id: <your client_id from wepay>
218
- client_secret: <your client_secret from wepay>
219
- auth_code_location: MyModel.wepay_auth_code
220
- redirect_uri: "http://test.example.com/wepay/authorize"
221
- after_authorize_redirect_uri: "http://test.example.com/purchase/checkout"
222
- scope: ['refund_payments','collect_payments','view_balance','view_user']
223
- wepay_api_uri: "https://stage.wepay.com"
224
- wepay_api_version: "v2"
225
- ipn_callback_uri: "http://test.example.com/wepay/ipn"
226
- checkout_redirect_uri: "http://test.example.com/purchase/finalize"
227
- fee_payer: Payee
228
- checkout_type: GOODS
229
- charge_tax: false
230
- app_fee: 0
231
- auto_capture: true
232
- charge_tax: false
233
- require_shipping: false
234
- shipping_fee: 0
116
+ == Special Thanks to additional contributers of Wepay-Rails
117
+ * lucisferre (Chris Nicola) https://github.com/lucisferre
235
118
 
236
119
 
237
120
  == Contributing to wepay-rails
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.116
1
+ 0.2.0
@@ -0,0 +1,25 @@
1
+ require 'rails/generators/migration'
2
+
3
+ module WepayRails
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+ source_root File.expand_path('../templates', __FILE__)
8
+ desc "add a migration for the Wepay Rails - WepayCheckoutRecord Model - Used to capture your transactions from Wepay"
9
+ def self.next_migration_number(path)
10
+ unless @prev_migration_nr
11
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
12
+ else
13
+ @prev_migration_nr += 1
14
+ end
15
+ @prev_migration_nr.to_s
16
+ end
17
+
18
+ def copy_migrations
19
+ migration_template "create_wepay_checkout_records.rb", "db/migrate/create_wepay_checkout_records.rb"
20
+ copy_file "wepay_checkout_record.rb", "lib/models/wepay_checkout_record.rb"
21
+ copy_file "wepay.yml", "config/wepay.yml.example"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,39 @@
1
+ class CreateWepayCheckoutRecords < ActiveRecord::Migration
2
+ def self.up
3
+
4
+ create_table :wepay_checkout_records do |t|
5
+ t.integer :checkout_id
6
+ t.integer :account_id
7
+ t.string :auth_code
8
+ t.string :state
9
+ t.string :short_description
10
+ t.text :long_description
11
+ t.string :currency
12
+ t.decimal :amount
13
+ t.decimal :app_fee
14
+ t.string :fee_payer
15
+ t.decimal :gross
16
+ t.decimal :fee
17
+ t.string :reference_id
18
+ t.text :redirect_uri
19
+ t.text :callback_uri
20
+ t.text :checkout_uri
21
+ t.string :payer_email
22
+ t.string :payer_name
23
+ t.text :cancel_reason
24
+ t.text :refund_reason
25
+ t.boolean :auto_capture
26
+ t.boolean :require_shipping
27
+ t.text :shipping_address
28
+ t.decimal :tax
29
+
30
+ t.timestamps
31
+ end
32
+
33
+ add_index :wepay_checkout_records, :checkout_id
34
+ end
35
+
36
+ def self.down
37
+ drop_table :wepay_checkout_records
38
+ end
39
+ end
@@ -0,0 +1,23 @@
1
+ production:
2
+ client_id: <your client id from wepay>
3
+ client_secret: <your client secret from wepay>
4
+ account_id: <your account id from wepay>
5
+ auth_code_location: MyModel.wepay_auth_code #model and column where you store the auth code for each of your customers eg. Profile.wepay_auth_code
6
+ redirect_uri: "http://www.example.com/wepay/authorize" # where to send the user on their trip back from wepay for payment
7
+ after_authorize_redirect_uri: "http://www.example.com/purchase/checkout" # after the user gets an auth token from wepay, where should they come?
8
+ scope: [refund_payments,collect_payments,view_balance,view_user]
9
+ wepay_api_uri: "https://api.wepay.com" # Use https://stage.wepay.com for development
10
+ wepay_api_version: "v2"
11
+ ipn_callback_uri: "http://www.example.com/wepay/ipn" # Future requests from wepay to you should go where?
12
+ fee_payer: Payee
13
+ checkout_type: GOODS
14
+ charge_tax: false
15
+ app_fee: 0
16
+ auto_capture: true
17
+ require_shipping: false
18
+ shipping_fee: 0
19
+ charge_tax: false
20
+ wepay_checkout_model: WepayCheckoutRecord # This is where the transactions for the checkouts will be stored
21
+ development:
22
+
23
+ test:
@@ -0,0 +1,2 @@
1
+ class WepayCheckoutRecord < ActiveRecord::Base
2
+ end
@@ -35,7 +35,20 @@ module WepayRails
35
35
  # Response
36
36
  # {"user_id":"123456","access_token":"1337h4x0rzabcd12345","token_type":"BEARER"} Example
37
37
  def initialize_wepay_access_token(wepayable_object)
38
- session[unique_wepay_access_token_key] = wepay_gateway.access_token(wepayable_object)
38
+ return if wepay_access_token_exists?
39
+ begin
40
+ # check to see if they have an auth code
41
+ # If not, send them to wepay to get one
42
+ wepayable_column = WepayRails::Configuration.wepayable_column
43
+ raise unless wepayable_object.send(wepayable_column.to_sym).present?
44
+
45
+ # It's possible that we raise an exception here - probably the auth code
46
+ # was too old and they need an updated one. Send them to wepay to
47
+ # get a new one if a raise happens while we run the following line of code.
48
+ session[unique_wepay_access_token_key] = wepay_gateway.access_token(wepayable_object)
49
+ rescue
50
+ redirect_to_wepay_for_auth(wepayable_object)
51
+ end
39
52
  return
40
53
  end
41
54
 
@@ -95,7 +108,8 @@ module WepayRails
95
108
  # :require_shipping No A boolean value (0 or 1). If set to 1 then the payer will be asked to enter a shipping address when they pay. After payment you can retrieve this shipping address by calling /checkout
96
109
  # :shipping_fee No The amount that you want to charge for shipping.
97
110
  # :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.
98
- def init_checkout_and_send_user_to_wepay(params)
111
+ def init_checkout_and_send_user_to_wepay(params, wepayable_object=nil)
112
+ initialize_wepay_access_token(wepayable_object) if wepayable_object.present?
99
113
  response = wepay_gateway.perform_checkout(params)
100
114
  checkout = WepayCheckoutRecord.create(params.merge({ checkout_id: response['checkout_id'] }))
101
115
  raise WepayRails::Exceptions::InitializeCheckoutError.new("A problem occurred while trying to checkout. Wepay didn't send us back a checkout uri. Response was: #{response.inspect}, Params were: #{params}, Token was: #{wepay_access_token}") unless response && response.has_key?('checkout_uri')
data/wepay-rails.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "wepay-rails"
8
- s.version = "0.1.116"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Adam Medeiros"]
12
- s.date = "2011-11-15"
12
+ s.date = "2011-11-25"
13
13
  s.description = "Rails gem that interfaces with the WePay API"
14
14
  s.email = "adammede@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -31,6 +31,10 @@ Gem::Specification.new do |s|
31
31
  "app/controllers/wepay/ipn_controller.rb",
32
32
  "config/routes.rb",
33
33
  "lib/examples/wepay.yml",
34
+ "lib/generators/wepay_rails/install/install_generator.rb",
35
+ "lib/generators/wepay_rails/install/templates/create_wepay_checkout_records.rb",
36
+ "lib/generators/wepay_rails/install/templates/wepay.yml",
37
+ "lib/generators/wepay_rails/install/templates/wepay_checkout_record.rb",
34
38
  "lib/helpers/controller_helpers.rb",
35
39
  "lib/helpers/model_helpers.rb",
36
40
  "lib/wepay-rails.rb",
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.116
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-15 00:00:00.000000000Z
12
+ date: 2011-11-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &15515820 !ruby/object:Gem::Requirement
16
+ requirement: &24572180 !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: *15515820
24
+ version_requirements: *24572180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: shoulda
27
- requirement: &15514680 !ruby/object:Gem::Requirement
27
+ requirement: &24569700 !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: *15514680
35
+ version_requirements: *24569700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &15513480 !ruby/object:Gem::Requirement
38
+ requirement: &24537240 !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: *15513480
46
+ version_requirements: *24537240
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &15512360 !ruby/object:Gem::Requirement
49
+ requirement: &24534500 !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: *15512360
57
+ version_requirements: *24534500
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &15507620 !ruby/object:Gem::Requirement
60
+ requirement: &24531780 !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: *15507620
68
+ version_requirements: *24531780
69
69
  description: Rails gem that interfaces with the WePay API
70
70
  email: adammede@gmail.com
71
71
  executables: []
@@ -88,6 +88,10 @@ files:
88
88
  - app/controllers/wepay/ipn_controller.rb
89
89
  - config/routes.rb
90
90
  - lib/examples/wepay.yml
91
+ - lib/generators/wepay_rails/install/install_generator.rb
92
+ - lib/generators/wepay_rails/install/templates/create_wepay_checkout_records.rb
93
+ - lib/generators/wepay_rails/install/templates/wepay.yml
94
+ - lib/generators/wepay_rails/install/templates/wepay_checkout_record.rb
91
95
  - lib/helpers/controller_helpers.rb
92
96
  - lib/helpers/model_helpers.rb
93
97
  - lib/wepay-rails.rb
@@ -109,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
113
  version: '0'
110
114
  segments:
111
115
  - 0
112
- hash: 3634481726847388061
116
+ hash: -326143609003264246
113
117
  required_rubygems_version: !ruby/object:Gem::Requirement
114
118
  none: false
115
119
  requirements: