authorizenet 1.8.1 → 1.8.2

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/authorize_net.rb +5 -0
  3. data/lib/authorize_net.rb~ +95 -0
  4. data/lib/authorize_net/aim/response.rb~ +131 -0
  5. data/lib/authorize_net/arb/fields.rb +24 -0
  6. data/lib/authorize_net/arb/fields.rb~ +13 -0
  7. data/lib/authorize_net/arb/paging.rb +33 -0
  8. data/lib/authorize_net/arb/paging.rb~ +25 -0
  9. data/lib/authorize_net/arb/response.rb~ +68 -0
  10. data/lib/authorize_net/arb/sorting.rb +43 -0
  11. data/lib/authorize_net/arb/sorting.rb~ +43 -0
  12. data/lib/authorize_net/arb/subscription.rb +5 -5
  13. data/lib/authorize_net/arb/subscription_detail.rb +14 -0
  14. data/lib/authorize_net/arb/subscription_detail.rb~ +56 -0
  15. data/lib/authorize_net/arb/subscription_list_response.rb +43 -0
  16. data/lib/authorize_net/arb/subscription_list_response.rb~ +45 -0
  17. data/lib/authorize_net/arb/transaction.rb +35 -4
  18. data/lib/authorize_net/arb/transaction.rb~ +176 -0
  19. data/lib/authorize_net/fields.rb +21 -3
  20. data/lib/authorize_net/fields.rb~ +767 -0
  21. data/lib/authorize_net/key_value_transaction.rb +0 -2
  22. data/lib/authorize_net/payment_methods/credit_card.rb +20 -32
  23. data/lib/authorize_net/xml_response.rb~ +173 -0
  24. data/lib/authorize_net/xml_transaction.rb +5 -5
  25. data/lib/authorize_net/xml_transaction.rb~ +276 -0
  26. data/lib/generators/authorize_net/{direct_post_generator.rb → direct_post/direct_post_generator.rb} +4 -2
  27. data/lib/generators/authorize_net/direct_post/templates/README-AuthorizeNet +49 -0
  28. data/lib/generators/authorize_net/direct_post/templates/config.yml.erb +8 -0
  29. data/lib/generators/authorize_net/direct_post/templates/config.yml.rails3.erb +8 -0
  30. data/lib/generators/authorize_net/direct_post/templates/controller.rb.erb +31 -0
  31. data/lib/generators/authorize_net/direct_post/templates/initializer.rb +4 -0
  32. data/lib/generators/authorize_net/direct_post/templates/layout.erb +18 -0
  33. data/lib/generators/authorize_net/direct_post/templates/payment.erb +10 -0
  34. data/lib/generators/authorize_net/direct_post/templates/payment.rails3.erb +10 -0
  35. data/lib/generators/authorize_net/direct_post/templates/receipt.erb +1 -0
  36. data/lib/generators/authorize_net/direct_post/templates/relay_response.erb +1 -0
  37. data/lib/generators/authorize_net/{sim_generator.rb → sim/sim_generator.rb} +2 -2
  38. data/lib/generators/authorize_net/sim/templates/README-AuthorizeNet +52 -0
  39. data/lib/generators/authorize_net/sim/templates/config.yml.erb +8 -0
  40. data/lib/generators/authorize_net/sim/templates/config.yml.rails3.erb +8 -0
  41. data/lib/generators/authorize_net/sim/templates/controller.rb.erb +21 -0
  42. data/lib/generators/authorize_net/sim/templates/initializer.rb +4 -0
  43. data/lib/generators/authorize_net/sim/templates/layout.erb +18 -0
  44. data/lib/generators/authorize_net/sim/templates/payment.erb +6 -0
  45. data/lib/generators/authorize_net/sim/templates/payment.rails3.erb +6 -0
  46. data/lib/generators/authorize_net/sim/templates/thank_you.erb +1 -0
  47. data/lib/generators/generator_extensions.rb +75 -0
  48. metadata +41 -10
@@ -0,0 +1,43 @@
1
+ module AuthorizeNet::ARB
2
+
3
+ class Sorting
4
+
5
+ # Models Sorting
6
+ include AuthorizeNet::Model
7
+
8
+ attr_accessor :order_by, :order_descending
9
+
10
+ # Initializes Sorting object.
11
+ #
12
+ # Typical usage:
13
+ # sorting = AuthorizeNet::ARB::Sorting.new('name',true)
14
+ #
15
+ # Valid values for order_by values of the AuthorizeNet::ARB::Sorting:
16
+ # id
17
+ # name
18
+ # status
19
+ # createTimeStampUTC
20
+ # lastName
21
+ # firstName
22
+ # accountNumber
23
+ # amount
24
+ # pastOccurrences
25
+ #
26
+ # Valid values for order_descending: true, false, 1,0
27
+ #
28
+ def initialize(order_by, order_descending)
29
+ @order_by = order_by
30
+ @order_descending = order_descending
31
+ end
32
+
33
+ def to_hash
34
+ hash = {
35
+ :order_by => @order_by,
36
+ :order_descending => @order_descending
37
+ }
38
+ hash.delete_if {|k, v| v.nil?}
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -25,12 +25,12 @@ module AuthorizeNet::ARB
25
25
 
26
26
  attr_accessor :name, :length, :unit, :start_date, :total_occurrences, :trial_occurrences, :amount, :trial_amount, :invoice_number, :description, :subscription_id, :credit_card, :billing_address, :shipping_address, :customer
27
27
 
28
- # Override the length setter to provide support for :unlimited shortcut. Do not document this method in rdoc.
29
- def length=(new_length) #:nodoc:
30
- if new_length == :unlimited
31
- @length = UNLIMITED_OCCURRENCES
28
+ # Override the total_occurrences setter to provide support for :unlimited shortcut.
29
+ def total_occurrences=(new_total_occurrences) #:nodoc:
30
+ if new_total_occurrences == :unlimited
31
+ @total_occurrences = UNLIMITED_OCCURRENCES
32
32
  else
33
- @length = new_length
33
+ @total_occurrences = new_total_occurrences
34
34
  end
35
35
  end
36
36
 
@@ -0,0 +1,14 @@
1
+ module AuthorizeNet::ARB
2
+
3
+ # Models Subscription Detail.
4
+ class SubscriptionDetail
5
+
6
+ include AuthorizeNet::Model
7
+
8
+ attr_accessor :id, :name, :status, :create_time_stamp_utc, :first_name,
9
+ :last_name, :total_occurrences, :past_occurrences,
10
+ :payment_method, :account_number, :invoice, :amount, :currency_id
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,56 @@
1
+ module AuthorizeNet::ARB
2
+
3
+ # Models Subscription Detail.
4
+ class SubscriptionDetail
5
+
6
+ include AuthorizeNet::Model
7
+
8
+ attr_accessor :id, :name, :status, :create_time_stamp_utc, :first_name,
9
+ :last_name, :total_occurrences, :past_occurrences,
10
+ :payment_method, :account_number, :invoice, :amount, :currency_id
11
+
12
+ end
13
+
14
+ class Sorting
15
+
16
+ include AuthorizeNet::Model
17
+
18
+ attr_accessor :order_by, :order_descending
19
+
20
+ def initialize(order_by, order_descending)
21
+ @order_by = order_by
22
+ @order_descending = order_descending
23
+ end
24
+
25
+ def to_hash
26
+ hash = {
27
+ :order_by => @order_by,
28
+ :order_descending => @order_descending
29
+ }
30
+ hash.delete_if {|k, v| v.nil?}
31
+ end
32
+
33
+ end
34
+
35
+ class Paging
36
+
37
+ include AuthorizeNet::Model
38
+
39
+ attr_accessor :offset,:limit
40
+
41
+ def initialize(offset,limit)
42
+ @offset = offset
43
+ @limit = limit
44
+ end
45
+
46
+ def to_hash
47
+ hash = {
48
+ :offset => @offset,
49
+ :limit => @limit
50
+ }
51
+ hash.delete_if {|k, v| v.nil?}
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,43 @@
1
+ module AuthorizeNet::ARB
2
+
3
+ class SubscriptionListResponse < AuthorizeNet::XmlResponse
4
+ # Constructs a new response object from a +raw_response. You don't typically
5
+ # construct this object yourself, as AuthorizeNet::ARB::Transaction will
6
+ # build one for you when it makes the request to the gateway.
7
+ def initialize(raw_response, transaction)
8
+ super
9
+ unless connection_failure?
10
+ begin
11
+ @subscription_details = @root.at_css('subscriptionDetails')
12
+ @subscription_detail = @root.at_css('subscriptionDetail')
13
+ @total_num_in_resultset = node_content_unless_nil(@root.at_css('totalNumInResultSet'))
14
+
15
+ rescue
16
+ @raw_response = $!
17
+ end
18
+ end
19
+ end
20
+
21
+ # Returns total number of subscriptions matching the search criteria
22
+ def total_num_in_resultset
23
+ @total_num_in_resultset
24
+ end
25
+
26
+ # Returns an Array of SubscriptionDetail objects built from the entities returned in the response. Returns nil if no subscriptions were returned.
27
+ def subscription_details
28
+ unless @subscription_details.nil?
29
+ subscription_details = []
30
+ @subscription_details.element_children.each do |child|
31
+ unless child.nil?
32
+ subscription_detail = build_entity(child, Fields::SUBSCRIPTION_DETAIL_ENTITY_DESCRIPTION)
33
+
34
+ subscription_details <<= subscription_detail
35
+ end
36
+ end
37
+ return subscription_details unless subscription_details.length == 0
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,45 @@
1
+ module AuthorizeNet::ARB
2
+
3
+ class SubscriptionListResponse < AuthorizeNet::XmlResponse
4
+ # Constructs a new response object from a +raw_response. You don't typically
5
+ # construct this object yourself, as AuthorizeNet::ARB::Transaction will
6
+ # build one for you when it makes the request to the gateway.
7
+ def initialize(raw_response, transaction)
8
+ super
9
+ unless connection_failure?
10
+ begin
11
+ @subscription_details = @root.at_css('subscriptionDetails')
12
+ @subscription_detail = @root.at_css('subscriptionDetail')
13
+ @total_num_in_resultset = node_content_unless_nil(@root.at_css('totalNumInResultSet'))
14
+
15
+ puts "bla bla"
16
+
17
+ rescue
18
+ @raw_response = $!
19
+ end
20
+ end
21
+ end
22
+
23
+ # Returns total number of subscriptions matching the search criteria
24
+ def total_num_in_resultset
25
+ @total_num_in_resultset
26
+ end
27
+
28
+ # Returns an Array of SubscriptionDetail objects built from the entities returned in the response. Returns nil if no subscriptions were returned.
29
+ def subscription_details
30
+ unless @subscription_details.nil?
31
+ subscription_details = []
32
+ @subscription_details.element_children.each do |child|
33
+ unless child.nil?
34
+ subscription_detail = build_entity(child, Fields::SUBSCRIPTION_DETAIL_ENTITY_DESCRIPTION)
35
+
36
+ subscription_details <<= subscription_detail
37
+ end
38
+ end
39
+ return subscription_details unless subscription_details.length == 0
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -22,8 +22,7 @@ module AuthorizeNet::ARB
22
22
  @@date_fields = [:subscription_start_date]
23
23
 
24
24
  # The class to wrap our response in.
25
- @response_class = AuthorizeNet::ARB::Response
26
-
25
+ @response_class = AuthorizeNet::ARB::Response
27
26
 
28
27
  # Constructs an ARB transaction. You can use the new ARB transaction object
29
28
  # to issue a request to the payment gateway and parse the response into a new
@@ -106,7 +105,39 @@ module AuthorizeNet::ARB
106
105
  handle_subscription_id(subscription_id)
107
106
  run
108
107
  end
109
-
108
+
109
+ # Sets up and submits a subscription list query (ARBGetSubscriptionListRequest). Returns a response object
110
+ # which contains the list of subscription details and the total number of subscriptions matching the search
111
+ # criteria. Sorting and Paging are optional parameters.
112
+ #
113
+ # Valid values for search type parameter:
114
+ # cardExpiringThisMonth
115
+ # subscriptionActive
116
+ # subscriptionExpiringThisMonth
117
+ # subscriptionInactive
118
+ #
119
+ # Typical usage:
120
+ #
121
+ # sorting = AuthorizeNet::ARB::Sorting.new('name',true)
122
+ # paging = AuthorizeNet::ARB::Paging.new(1,1000)
123
+ # response = transaction.get_subscription_list('subscriptionActive',sorting,paging)
124
+ #
125
+ def get_subscription_list(search_type, sorting = nil, paging = nil)
126
+ unless search_type.nil?
127
+ self.class.instance_variable_set(:@response_class,SubscriptionListResponse)
128
+ @type = Type::ARB_GET_SUBSCRIPTION_LIST
129
+ set_fields(:search_type => search_type.to_s)
130
+ unless sorting.nil?
131
+ set_fields(sorting.to_hash)
132
+ end
133
+ unless paging.nil?
134
+ set_fields(paging.to_hash)
135
+ end
136
+ run
137
+ end
138
+ return response
139
+ end
140
+
110
141
  # Sets up and submits a subscription cancelation (ARBCancelSubscriptionRequest) transaction. Returns a response object. If the transaction
111
142
  # has already been run, it will return nil.
112
143
  #
@@ -143,4 +174,4 @@ module AuthorizeNet::ARB
143
174
  end
144
175
 
145
176
  end
146
- end
177
+ end
@@ -0,0 +1,176 @@
1
+ module AuthorizeNet::ARB
2
+
3
+ # The ARB transaction class.
4
+ class Transaction < AuthorizeNet::XmlTransaction
5
+
6
+ include AuthorizeNet::ARB::Fields
7
+
8
+ # The default options for the constructor.
9
+ @@option_defaults = {
10
+ :gateway => :production,
11
+ :verify_ssl => false,
12
+ :reference_id => nil
13
+ }
14
+
15
+ # Fields to convert to/from booleans.
16
+ @@boolean_fields = []
17
+
18
+ # Fields to convert to/from BigDecimal.
19
+ @@decimal_fields = [:amount, :trial_amount]
20
+
21
+ # Fields to convert to/from Date.
22
+ @@date_fields = [:subscription_start_date]
23
+
24
+ # The class to wrap our response in.
25
+ @response_class = AuthorizeNet::ARB::Response
26
+
27
+ # Constructs an ARB transaction. You can use the new ARB transaction object
28
+ # to issue a request to the payment gateway and parse the response into a new
29
+ # AuthorizeNet::ARB::Response object.
30
+ #
31
+ # +api_login_id+:: Your API login ID, as a string.
32
+ # +api_transaction_key+:: Your API transaction key, as a string.
33
+ # +options+:: A hash of options. See below for values.
34
+ #
35
+ # Options
36
+ # +gateway+:: The gateway to submit the transaction to. Can be a URL string, an AuthorizeNet::ARB::Transaction::Gateway constant, or one of the convenience symbols :sandbox, :test, :production, or :live (:test is an alias for :sandbox, and :live is an alias for :production).
37
+ # +verify_ssl+:: A boolean indicating if the SSL certificate of the +gateway+ should be verified. Defaults to false.
38
+ # +reference_id+:: A string that can be used to identify a particular transaction with its response. Will be echo'd in the response, only if it was provided in the transaction. Defaults to nil.
39
+ #
40
+ def initialize(api_login_id, api_transaction_key, options = {})
41
+ super
42
+ end
43
+
44
+ # Sets up and submits a start of subscription (ARBCreateSubscriptionRequest) transaction. Returns a response object. If the transaction
45
+ # has already been run, it will return nil.
46
+ #
47
+ # +subscription+:: An instance of AuthorizeNet::ARB::Subscription describing the recurring payment you would like to create.
48
+ #
49
+ #
50
+ # Typical usage:
51
+ #
52
+ # subscription = AuthorizeNet::ARB::Subscription.new(
53
+ # :name => "Monthly Gift Basket",
54
+ # :length => 1,
55
+ # :unit => :month,
56
+ # :start_date => Date.today,
57
+ # :total_occurrences => :unlimited,
58
+ # :amount => 100.00,
59
+ # :invoice_number => '1234567',
60
+ # :description => "John Doe's Monthly Gift Basket",
61
+ # :credit_card => AuthorizeNet::CreditCard.new('4111111111111111', '1120'),
62
+ # :billing_address => AuthorizeNet::Address.new(:first_name => 'John', :last_name => 'Doe')
63
+ # )
64
+ # response = transaction.create(subscription)
65
+ #
66
+ def create(subscription)
67
+ @type = Type::ARB_CREATE
68
+ set_fields(subscription.to_hash)
69
+ run
70
+ end
71
+
72
+ # Sets up and submits a subscription update (ARBUpdateSubscriptionRequest) transaction. Returns a response object. If the transaction
73
+ # has already been run, it will return nil.
74
+ #
75
+ # +subscription+:: An instance of AuthorizeNet::ARB::Subscription describing the changes to make. It must have a value for subscription_id so that the API knows what subscription to update. Note that some information (intervals, start dates, etc) can't be changed. See the ARB guide for more details.
76
+ #
77
+ #
78
+ # Typical usage:
79
+ #
80
+ # subscription = AuthorizeNet::ARB::Subscription.new(
81
+ # :billing_address => AuthorizeNet::Address.new(:first_name => 'Jane', :last_name => 'Doe'),
82
+ # :subscription_id => '123456'
83
+ # )
84
+ # response = transaction.update(subscription)
85
+ #
86
+ def update(subscription)
87
+ @type = Type::ARB_UPDATE
88
+ set_fields(subscription.to_hash)
89
+ run
90
+ end
91
+
92
+ # Sets up and submits a subscription status query (ARBGetSubscriptionStatusRequest) transaction. Returns a response object (which contains the subscription status). If the transaction
93
+ # has already been run, it will return nil.
94
+ #
95
+ # +subscription_id+:: Either the subscription id of the subscription to get the status of as a string, or a Subscription instance with a value for subscription_id set on it.
96
+ #
97
+ #
98
+ # Typical usage:
99
+ #
100
+ # response = transaction.get_status('123456')
101
+ # response.subscription_status # A value from AuthorizeNet::ARB::Subscription::Status
102
+ #
103
+ def get_status(subscription_id)
104
+ @type = Type::ARB_GET_STATUS
105
+ handle_subscription_id(subscription_id)
106
+ run
107
+ end
108
+
109
+ # Sets up and submits a subscription list query (ARBGetSubscriptionListRequest). Returns a response object
110
+ # which contains the list of subscription details and the total number of subscriptions matching the search
111
+ # criteria. Sorting and Paging are optional parameters.
112
+ #
113
+ # Valid values for search type parameter:
114
+ # cardExpiringThisMonth
115
+ # subscriptionActive
116
+ # subscriptionExpiringThisMonth
117
+ # subscriptionInactive
118
+ #
119
+ # Typical usage:
120
+ #
121
+ # sorting = AuthorizeNet::ARB::Sorting.new('name',true)
122
+ # paging = AuthorizeNet::ARB::Paging.new(1,1000)
123
+ # response = transaction.get_subscription_list('subscriptionActive',sorting,paging)
124
+ #
125
+ def get_subscription_list(search_type, sorting = nil, paging = nil)
126
+ unless search_type.nil?
127
+ self.class.instance_variable_set(:@response_class,SubscriptionListResponse)
128
+ @type = Type::ARB_GET_SUBSCRIPTION_LIST
129
+ set_fields(:search_type => search_type.to_s)
130
+ unless sorting.nil?
131
+ set_fields(sorting.to_hash)
132
+ end
133
+ unless paging.nil?
134
+ set_fields(paging.to_hash)
135
+ end
136
+ run
137
+ end
138
+ end
139
+
140
+ # Sets up and submits a subscription cancelation (ARBCancelSubscriptionRequest) transaction. Returns a response object. If the transaction
141
+ # has already been run, it will return nil.
142
+ #
143
+ # +subscription_id+:: Either the subscription id of the subscription to get the status of as a string, or a Subscription instance with a value for subscription_id set on it.
144
+ #
145
+ #
146
+ # Typical usage:
147
+ #
148
+ # response = transaction.cancel('123456')
149
+ #
150
+ def cancel(subscription_id)
151
+ @type = Type::ARB_CANCEL
152
+ handle_subscription_id(subscription_id)
153
+ run
154
+ end
155
+
156
+ #:enddoc:
157
+ protected
158
+
159
+ # Internal method to handle multiple types of subscription id arguments.
160
+ def handle_subscription_id(subscription_id)
161
+ case subscription_id
162
+ when Subscription
163
+ set_fields(:subscription_id => subscription_id.subscription_id.to_s)
164
+ else
165
+ set_fields(:subscription_id => subscription_id.to_s)
166
+ end
167
+ end
168
+
169
+ # An internal method that builds the POST body, submits it to the gateway, and constructs a Response object with the response.
170
+ def make_request
171
+ set_fields(:reference_id => @reference_id)
172
+ super
173
+ end
174
+
175
+ end
176
+ end