auth_net_receiver 1.0.beta1 → 1.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -3
- data/app/controllers/auth_net_receiver/raw_transactions_controller.rb +9 -0
- data/app/jobs/auth_net_receiver/process_transaction_job.rb +10 -0
- data/lib/auth_net_receiver/configuration.rb +2 -1
- data/lib/auth_net_receiver/version.rb +1 -1
- data/spec/controllers/auth_net_receiver/raw_transactions_controller_spec.rb +1 -1
- data/spec/dummy/bin/delayed_job +5 -0
- data/spec/dummy/config/environments/test.rb +2 -0
- data/spec/dummy/db/migrate/20141214034049_create_auth_net_receiver_raw_transactions.auth_net_receiver.rb +11 -0
- data/spec/dummy/db/migrate/20141214034050_create_auth_net_receiver_transactions.auth_net_receiver.rb +20 -0
- data/spec/dummy/db/migrate/20141214034232_create_delayed_jobs.rb +22 -0
- data/spec/dummy/db/schema.rb +34 -18
- data/spec/jobs/auth_net_receiver/process_transaction_job_spec.rb +7 -0
- metadata +23 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8a7dac5bb13d948a9e61e2c2d1ee8833f39dee2
|
4
|
+
data.tar.gz: c57e624ca342235e98954af74de284b0023ac14d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00a140441b4099d4d2656472880ca631b50165e7861963cb96ac47e9767f9d4e606491fffa0fbf6e3cd4f89b4390d228c93f2102e60577760a711c5c0a7fe13a
|
7
|
+
data.tar.gz: ef0db621f7e2d1fbba3e63f5c8dc1f00f8ac5e7dfce2173d041cb99b0a7024fe59f200857b014c4f829cc91c84ed90bd45fcc3dd60dca35afa8db7e5af3472b0
|
data/README.md
CHANGED
@@ -4,7 +4,13 @@ The goal of this project is to capture and process transactions posted via the A
|
|
4
4
|
|
5
5
|
## What is that?
|
6
6
|
|
7
|
-
The Silent Post URL is a feature of Authorize.Net that makes a post to a user-defined URL any time a transaction is made.
|
7
|
+
The Silent Post URL is a feature of Authorize.Net that makes a post to a user-defined URL any time a transaction is made. Take note of the following rules:
|
8
|
+
|
9
|
+
- Transactions are sent in real time
|
10
|
+
- Each transaction is only ever sent once, regardless of server response
|
11
|
+
- A transaction must be accepted within 2 seconds.
|
12
|
+
|
13
|
+
For this reason, Authorize.net recommends that the post action is only used to collect raw data, while parsing and validation is pushed off to a later time.
|
8
14
|
|
9
15
|
This is primarily useful for those using the [Automated Recurring Billing](http://developer.authorize.net/api/arb/) system, or ARB for short. Subscriptions created in ARB will make their transactions at the requested schedule, but (at this time) there is no direct API for pulling down those transactions. By making use of the Silent Post, you can capture all ARB transactions and use that data to reconcile the state of your user's subscription.
|
10
16
|
|
@@ -46,9 +52,13 @@ As a final step, you should log in to your Authorize.Net account and enter the d
|
|
46
52
|
|
47
53
|
**NOTE:** Because Authorize.Net has to actually make an HTTP post to your endpoint, it is not possible to run this application on localhost without a bit of work on the networking side. I won't attempt to cover the entire topic here, but if you are comfortable with DNS and port forwards you can probably figure out the rest.
|
48
54
|
|
49
|
-
## Processing
|
55
|
+
## Processing with ActiveJob
|
56
|
+
|
57
|
+
If you are running Rails 4.2, we can take advantage of [ActiveJob](http://edgeguides.rubyonrails.org/active_job_basics.html) and process transactions in the background. Set `AuthNetReceiver.config.active_job = false` if you wish to disable this feature.
|
58
|
+
|
59
|
+
## Processing without ActiveJob
|
50
60
|
|
51
|
-
Run the `auth_net_receiver:process` rake task to process all pending transactions:
|
61
|
+
If you are not using ActiveJob, raw transactions will pile up in the database and need to be processed manually. Run the `auth_net_receiver:process` rake task to process all pending transactions:
|
52
62
|
|
53
63
|
$ rake auth_net_receiver:process
|
54
64
|
D, [2014-11-06T19:31:38.191435 #39766] DEBUG -- : Processing Authorize.Net transactions...
|
@@ -4,6 +4,7 @@ module AuthNetReceiver
|
|
4
4
|
class RawTransactionsController < ApplicationController
|
5
5
|
|
6
6
|
skip_before_filter :verify_authenticity_token
|
7
|
+
after_action :perform_job
|
7
8
|
|
8
9
|
def create
|
9
10
|
@raw_transaction = RawTransaction.create({
|
@@ -12,5 +13,13 @@ module AuthNetReceiver
|
|
12
13
|
render :nothing => true, :status => 200
|
13
14
|
end
|
14
15
|
|
16
|
+
private
|
17
|
+
|
18
|
+
def perform_job
|
19
|
+
if AuthNetReceiver.config.active_job
|
20
|
+
AuthNetReceiver::ProcessTransactionJob.perform_later(@raw_transaction)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
15
24
|
end
|
16
25
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module AuthNetReceiver
|
2
2
|
include ActiveSupport::Configurable
|
3
|
-
config_accessor :hash_value, :gateway_login
|
3
|
+
config_accessor :hash_value, :gateway_login, :active_job
|
4
4
|
self.hash_value = nil
|
5
5
|
self.gateway_login = nil
|
6
|
+
self.active_job = defined?(ActiveJob) != nil
|
6
7
|
end
|
@@ -6,7 +6,7 @@ module AuthNetReceiver
|
|
6
6
|
it "should create a new raw transaction" do
|
7
7
|
post :create, {:use_route => :auth_net_receiver}
|
8
8
|
expect(response).to be_success
|
9
|
-
expect(AuthNetReceiver::RawTransaction.
|
9
|
+
expect(AuthNetReceiver::RawTransaction.count).to eq(1)
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# This migration comes from auth_net_receiver (originally 20141106200527)
|
2
|
+
class CreateAuthNetReceiverRawTransactions < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
create_table :auth_net_receiver_raw_transactions do |t|
|
5
|
+
t.boolean :is_processed, :default => false
|
6
|
+
t.boolean :is_authentic, :default => false
|
7
|
+
t.text :data
|
8
|
+
t.timestamps :null => false
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/spec/dummy/db/migrate/20141214034050_create_auth_net_receiver_transactions.auth_net_receiver.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This migration comes from auth_net_receiver (originally 20141106200940)
|
2
|
+
class CreateAuthNetReceiverTransactions < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
create_table :auth_net_receiver_transactions do |t|
|
5
|
+
t.references :raw_transaction, :index => true
|
6
|
+
t.references :transaction, :index => true, :limit => 8
|
7
|
+
t.references :subscription, :index => true, :limit => 8
|
8
|
+
t.integer :subscription_paynum
|
9
|
+
t.string :invoice_num
|
10
|
+
t.string :transaction_type
|
11
|
+
t.decimal :amount, :precision => 10, :scale => 2, :default => 0
|
12
|
+
t.string :card_type
|
13
|
+
t.string :account_number
|
14
|
+
t.string :description
|
15
|
+
t.integer :response_reason_code
|
16
|
+
t.string :response_reason_text
|
17
|
+
t.timestamps :null => false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class CreateDelayedJobs < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :delayed_jobs, :force => true do |table|
|
4
|
+
table.integer :priority, :default => 0, :null => false # Allows some jobs to jump to the front of the queue
|
5
|
+
table.integer :attempts, :default => 0, :null => false # Provides for retries, but still fail eventually.
|
6
|
+
table.text :handler, :null => false # YAML-encoded string of the object that will do work
|
7
|
+
table.text :last_error # reason for last failure (See Note below)
|
8
|
+
table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
|
9
|
+
table.datetime :locked_at # Set when a client is working on this object
|
10
|
+
table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
|
11
|
+
table.string :locked_by # Who is working on this object (if locked)
|
12
|
+
table.string :queue # The name of the queue this job is in
|
13
|
+
table.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.down
|
20
|
+
drop_table :delayed_jobs
|
21
|
+
end
|
22
|
+
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,35 +11,51 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20141214034232) do
|
15
15
|
|
16
16
|
create_table "auth_net_receiver_raw_transactions", force: true do |t|
|
17
|
-
t.boolean "is_processed", default: false
|
18
|
-
t.boolean "is_authentic", default: false
|
19
|
-
t.text "data"
|
20
|
-
t.datetime "created_at",
|
21
|
-
t.datetime "updated_at",
|
17
|
+
t.boolean "is_processed", limit: 1, default: false
|
18
|
+
t.boolean "is_authentic", limit: 1, default: false
|
19
|
+
t.text "data", limit: 65535
|
20
|
+
t.datetime "created_at", null: false
|
21
|
+
t.datetime "updated_at", null: false
|
22
22
|
end
|
23
23
|
|
24
24
|
create_table "auth_net_receiver_transactions", force: true do |t|
|
25
|
-
t.integer "raw_transaction_id"
|
25
|
+
t.integer "raw_transaction_id", limit: 4
|
26
26
|
t.integer "transaction_id", limit: 8
|
27
27
|
t.integer "subscription_id", limit: 8
|
28
|
-
t.integer "subscription_paynum"
|
29
|
-
t.string "invoice_num"
|
30
|
-
t.string "transaction_type"
|
31
|
-
t.decimal "amount",
|
32
|
-
t.string "card_type"
|
33
|
-
t.string "account_number"
|
34
|
-
t.string "description"
|
35
|
-
t.integer "response_reason_code"
|
36
|
-
t.string "response_reason_text"
|
37
|
-
t.datetime "created_at",
|
38
|
-
t.datetime "updated_at",
|
28
|
+
t.integer "subscription_paynum", limit: 4
|
29
|
+
t.string "invoice_num", limit: 255
|
30
|
+
t.string "transaction_type", limit: 255
|
31
|
+
t.decimal "amount", precision: 10, scale: 2, default: 0.0
|
32
|
+
t.string "card_type", limit: 255
|
33
|
+
t.string "account_number", limit: 255
|
34
|
+
t.string "description", limit: 255
|
35
|
+
t.integer "response_reason_code", limit: 4
|
36
|
+
t.string "response_reason_text", limit: 255
|
37
|
+
t.datetime "created_at", null: false
|
38
|
+
t.datetime "updated_at", null: false
|
39
39
|
end
|
40
40
|
|
41
41
|
add_index "auth_net_receiver_transactions", ["raw_transaction_id"], name: "index_auth_net_receiver_transactions_on_raw_transaction_id", using: :btree
|
42
42
|
add_index "auth_net_receiver_transactions", ["subscription_id"], name: "index_auth_net_receiver_transactions_on_subscription_id", using: :btree
|
43
43
|
add_index "auth_net_receiver_transactions", ["transaction_id"], name: "index_auth_net_receiver_transactions_on_transaction_id", using: :btree
|
44
44
|
|
45
|
+
create_table "delayed_jobs", force: true do |t|
|
46
|
+
t.integer "priority", limit: 4, default: 0, null: false
|
47
|
+
t.integer "attempts", limit: 4, default: 0, null: false
|
48
|
+
t.text "handler", limit: 65535, null: false
|
49
|
+
t.text "last_error", limit: 65535
|
50
|
+
t.datetime "run_at"
|
51
|
+
t.datetime "locked_at"
|
52
|
+
t.datetime "failed_at"
|
53
|
+
t.string "locked_by", limit: 255
|
54
|
+
t.string "queue", limit: 255
|
55
|
+
t.datetime "created_at"
|
56
|
+
t.datetime "updated_at"
|
57
|
+
end
|
58
|
+
|
59
|
+
add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree
|
60
|
+
|
45
61
|
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auth_net_receiver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Woods
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.1.8
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
22
|
+
version: '5.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 4.1.8
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
32
|
+
version: '5.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: mysql2
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,6 +113,7 @@ files:
|
|
107
113
|
- Rakefile
|
108
114
|
- app/controllers/auth_net_receiver/application_controller.rb
|
109
115
|
- app/controllers/auth_net_receiver/raw_transactions_controller.rb
|
116
|
+
- app/jobs/auth_net_receiver/process_transaction_job.rb
|
110
117
|
- app/models/auth_net_receiver/raw_transaction.rb
|
111
118
|
- app/models/auth_net_receiver/transaction.rb
|
112
119
|
- config/routes.rb
|
@@ -126,6 +133,7 @@ files:
|
|
126
133
|
- spec/dummy/app/helpers/application_helper.rb
|
127
134
|
- spec/dummy/app/views/layouts/application.html.erb
|
128
135
|
- spec/dummy/bin/bundle
|
136
|
+
- spec/dummy/bin/delayed_job
|
129
137
|
- spec/dummy/bin/rails
|
130
138
|
- spec/dummy/bin/rake
|
131
139
|
- spec/dummy/bin/setup
|
@@ -148,6 +156,9 @@ files:
|
|
148
156
|
- spec/dummy/config/locales/en.yml
|
149
157
|
- spec/dummy/config/routes.rb
|
150
158
|
- spec/dummy/config/secrets.yml
|
159
|
+
- spec/dummy/db/migrate/20141214034049_create_auth_net_receiver_raw_transactions.auth_net_receiver.rb
|
160
|
+
- spec/dummy/db/migrate/20141214034050_create_auth_net_receiver_transactions.auth_net_receiver.rb
|
161
|
+
- spec/dummy/db/migrate/20141214034232_create_delayed_jobs.rb
|
151
162
|
- spec/dummy/db/schema.rb
|
152
163
|
- spec/dummy/public/404.html
|
153
164
|
- spec/dummy/public/422.html
|
@@ -155,6 +166,7 @@ files:
|
|
155
166
|
- spec/dummy/public/favicon.ico
|
156
167
|
- spec/factories/auth_net_receiver_raw_transactions.rb
|
157
168
|
- spec/factories/auth_net_receiver_transactions.rb
|
169
|
+
- spec/jobs/auth_net_receiver/process_transaction_job_spec.rb
|
158
170
|
- spec/models/auth_net_receiver/raw_transaction_spec.rb
|
159
171
|
- spec/models/auth_net_receiver/transaction_spec.rb
|
160
172
|
- spec/rails_helper.rb
|
@@ -192,6 +204,7 @@ test_files:
|
|
192
204
|
- spec/dummy/app/helpers/application_helper.rb
|
193
205
|
- spec/dummy/app/views/layouts/application.html.erb
|
194
206
|
- spec/dummy/bin/bundle
|
207
|
+
- spec/dummy/bin/delayed_job
|
195
208
|
- spec/dummy/bin/rails
|
196
209
|
- spec/dummy/bin/rake
|
197
210
|
- spec/dummy/bin/setup
|
@@ -214,6 +227,9 @@ test_files:
|
|
214
227
|
- spec/dummy/config/routes.rb
|
215
228
|
- spec/dummy/config/secrets.yml
|
216
229
|
- spec/dummy/config.ru
|
230
|
+
- spec/dummy/db/migrate/20141214034049_create_auth_net_receiver_raw_transactions.auth_net_receiver.rb
|
231
|
+
- spec/dummy/db/migrate/20141214034050_create_auth_net_receiver_transactions.auth_net_receiver.rb
|
232
|
+
- spec/dummy/db/migrate/20141214034232_create_delayed_jobs.rb
|
217
233
|
- spec/dummy/db/schema.rb
|
218
234
|
- spec/dummy/public/404.html
|
219
235
|
- spec/dummy/public/422.html
|
@@ -223,6 +239,7 @@ test_files:
|
|
223
239
|
- spec/dummy/README.rdoc
|
224
240
|
- spec/factories/auth_net_receiver_raw_transactions.rb
|
225
241
|
- spec/factories/auth_net_receiver_transactions.rb
|
242
|
+
- spec/jobs/auth_net_receiver/process_transaction_job_spec.rb
|
226
243
|
- spec/models/auth_net_receiver/raw_transaction_spec.rb
|
227
244
|
- spec/models/auth_net_receiver/transaction_spec.rb
|
228
245
|
- spec/rails_helper.rb
|