yankl 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/lib/app/helpers/authorize_net_helper.rb +24 -0
  3. data/lib/authorize-net.rb +4 -0
  4. data/lib/authorize_net.rb +92 -0
  5. data/lib/authorize_net/addresses/address.rb +29 -0
  6. data/lib/authorize_net/addresses/shipping_address.rb +26 -0
  7. data/lib/authorize_net/aim/response.rb +131 -0
  8. data/lib/authorize_net/aim/transaction.rb +184 -0
  9. data/lib/authorize_net/arb/response.rb +34 -0
  10. data/lib/authorize_net/arb/subscription.rb +72 -0
  11. data/lib/authorize_net/arb/transaction.rb +146 -0
  12. data/lib/authorize_net/authorize_net.rb +154 -0
  13. data/lib/authorize_net/cim/customer_profile.rb +19 -0
  14. data/lib/authorize_net/cim/payment_profile.rb +37 -0
  15. data/lib/authorize_net/cim/response.rb +110 -0
  16. data/lib/authorize_net/cim/transaction.rb +678 -0
  17. data/lib/authorize_net/customer.rb +27 -0
  18. data/lib/authorize_net/email_receipt.rb +24 -0
  19. data/lib/authorize_net/fields.rb +736 -0
  20. data/lib/authorize_net/key_value_response.rb +117 -0
  21. data/lib/authorize_net/key_value_transaction.rb +297 -0
  22. data/lib/authorize_net/line_item.rb +25 -0
  23. data/lib/authorize_net/order.rb +42 -0
  24. data/lib/authorize_net/payment_methods/credit_card.rb +74 -0
  25. data/lib/authorize_net/payment_methods/echeck.rb +72 -0
  26. data/lib/authorize_net/reporting/batch.rb +19 -0
  27. data/lib/authorize_net/reporting/batch_statistics.rb +19 -0
  28. data/lib/authorize_net/reporting/fds_filter.rb +11 -0
  29. data/lib/authorize_net/reporting/response.rb +127 -0
  30. data/lib/authorize_net/reporting/transaction.rb +116 -0
  31. data/lib/authorize_net/reporting/transaction_details.rb +25 -0
  32. data/lib/authorize_net/response.rb +27 -0
  33. data/lib/authorize_net/sim/hosted_payment_form.rb +38 -0
  34. data/lib/authorize_net/sim/hosted_receipt_page.rb +37 -0
  35. data/lib/authorize_net/sim/response.rb +142 -0
  36. data/lib/authorize_net/sim/transaction.rb +138 -0
  37. data/lib/authorize_net/transaction.rb +66 -0
  38. data/lib/authorize_net/xml +65 -0
  39. data/lib/authorize_net/xml_response.rb +172 -0
  40. data/lib/authorize_net/xml_transaction.rb +277 -0
  41. data/lib/generators/authorize_net/direct_post_generator.rb +51 -0
  42. data/lib/generators/authorize_net/sim_generator.rb +47 -0
  43. data/lib/yankl.rb +4 -0
  44. metadata +105 -0
@@ -0,0 +1,34 @@
1
+ module AuthorizeNet::ARB
2
+
3
+ # The ARB response class.
4
+ class Response < AuthorizeNet::XmlResponse
5
+
6
+ # Constructs a new response object from a +raw_response. You don't typically
7
+ # construct this object yourself, as AuthorizeNet::ARB::Transaction will
8
+ # build one for you when it makes the request to the gateway.
9
+ def initialize(raw_response, transaction)
10
+ super
11
+ unless connection_failure?
12
+ begin
13
+ @subscription_id = node_content_unless_nil(@root.at_css('subscriptionId'))
14
+ @subscription_status = node_content_unless_nil(@root.at_css('Status'))
15
+ rescue
16
+ @raw_response = $!
17
+ end
18
+ end
19
+ end
20
+
21
+ # Returns the subscriptionId from the response if there is one. Otherwise returns nil.
22
+ def subscription_id
23
+ @subscription_id
24
+ end
25
+
26
+ # Returns the status of the Subscription from the response if there is one. Otherwise returns nil. This value
27
+ # is only returned in response to a get_status transaction.
28
+ def subscription_status
29
+ @subscription_status
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,72 @@
1
+ module AuthorizeNet::ARB
2
+
3
+ # Models an ARB subscription.
4
+ class Subscription
5
+
6
+ # Use this constant for the value of total_occurrences to get a subscription with no end.
7
+ UNLIMITED_OCCURRENCES = 9999
8
+
9
+ # Constants for the various interval units supported by the ARB API.
10
+ module IntervalUnits
11
+ MONTH = 'months'
12
+ DAY = 'days'
13
+ end
14
+
15
+ # Constants for the various statuses a subscription can have. These are returned by the get_status call.
16
+ module Status
17
+ ACTIVE = 'active'
18
+ EXPIRED = 'expired'
19
+ SUSPENDED = 'suspended'
20
+ CANCELED = 'canceled'
21
+ TERMINATED = 'terminated'
22
+ end
23
+
24
+ include AuthorizeNet::Model
25
+
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
+
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
32
+ else
33
+ @length = new_length
34
+ end
35
+ end
36
+
37
+ # Override the unit setter to provide support for :day, :days, :month, :months shortcut. Do not document this method in rdoc.
38
+ def unit=(new_unit) #:nodoc:
39
+ case new_unit
40
+ when :day, :days
41
+ @unit = IntervalUnits::DAY
42
+ when :month, :months
43
+ @unit = IntervalUnits::MONTH
44
+ else
45
+ @unit = new_unit
46
+ end
47
+ end
48
+
49
+ def to_hash
50
+ hash = {
51
+ :subscription_name => @name,
52
+ :subscription_length => @length,
53
+ :subscription_unit => @unit,
54
+ :subscription_start_date => @start_date,
55
+ :subscription_total_occurrences => @total_occurrences,
56
+ :subscription_trial_occurrences => @trial_occurrences,
57
+ :subscription_amount => @amount,
58
+ :subscription_trial_amount => @trial_amount,
59
+ :invoice_num => @invoice_number,
60
+ :description => @description,
61
+ :subscription_id => @subscription_id
62
+ }
63
+ hash.merge!(@credit_card.to_hash) unless @credit_card.nil?
64
+ hash.merge!(@billing_address.to_hash) unless @billing_address.nil?
65
+ hash.merge!(@shipping_address.to_hash) unless @shipping_address.nil?
66
+ hash.merge!(@customer.to_hash) unless @customer.nil?
67
+ hash.delete_if {|k, v| v.nil?}
68
+ end
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,146 @@
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
+
28
+ # Constructs an ARB transaction. You can use the new ARB transaction object
29
+ # to issue a request to the payment gateway and parse the response into a new
30
+ # AuthorizeNet::ARB::Response object.
31
+ #
32
+ # +api_login_id+:: Your API login ID, as a string.
33
+ # +api_transaction_key+:: Your API transaction key, as a string.
34
+ # +options+:: A hash of options. See below for values.
35
+ #
36
+ # Options
37
+ # +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).
38
+ # +verify_ssl+:: A boolean indicating if the SSL certificate of the +gateway+ should be verified. Defaults to false.
39
+ # +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.
40
+ #
41
+ def initialize(api_login_id, api_transaction_key, options = {})
42
+ super
43
+ end
44
+
45
+ # Sets up and submits a start of subscription (ARBCreateSubscriptionRequest) transaction. Returns a response object. If the transaction
46
+ # has already been run, it will return nil.
47
+ #
48
+ # +subscription+:: An instance of AuthorizeNet::ARB::Subscription describing the recurring payment you would like to create.
49
+ #
50
+ #
51
+ # Typical usage:
52
+ #
53
+ # subscription = AuthorizeNet::ARB::Subscription.new(
54
+ # :name => "Monthly Gift Basket",
55
+ # :length => 1,
56
+ # :unit => :month,
57
+ # :start_date => Date.today,
58
+ # :total_occurrences => :unlimited,
59
+ # :amount => 100.00,
60
+ # :invoice_number => '1234567',
61
+ # :description => "John Doe's Monthly Gift Basket",
62
+ # :credit_card => AuthorizeNet::CreditCard.new('4111111111111111', '1120'),
63
+ # :billing_address => AuthorizeNet::Address.new(:first_name => 'John', :last_name => 'Doe')
64
+ # )
65
+ # response = transaction.create(subscription)
66
+ #
67
+ def create(subscription)
68
+ @type = Type::ARB_CREATE
69
+ set_fields(subscription.to_hash)
70
+ run
71
+ end
72
+
73
+ # Sets up and submits a subscription update (ARBUpdateSubscriptionRequest) transaction. Returns a response object. If the transaction
74
+ # has already been run, it will return nil.
75
+ #
76
+ # +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.
77
+ #
78
+ #
79
+ # Typical usage:
80
+ #
81
+ # subscription = AuthorizeNet::ARB::Subscription.new(
82
+ # :billing_address => AuthorizeNet::Address.new(:first_name => 'Jane', :last_name => 'Doe'),
83
+ # :subscription_id => '123456'
84
+ # )
85
+ # response = transaction.update(subscription)
86
+ #
87
+ def update(subscription)
88
+ @type = Type::ARB_UPDATE
89
+ set_fields(subscription.to_hash)
90
+ run
91
+ end
92
+
93
+ # Sets up and submits a subscription status query (ARBGetSubscriptionStatusRequest) transaction. Returns a response object (which contains the subscription status). If the transaction
94
+ # has already been run, it will return nil.
95
+ #
96
+ # +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.
97
+ #
98
+ #
99
+ # Typical usage:
100
+ #
101
+ # response = transaction.get_status('123456')
102
+ # response.subscription_status # A value from AuthorizeNet::ARB::Subscription::Status
103
+ #
104
+ def get_status(subscription_id)
105
+ @type = Type::ARB_GET_STATUS
106
+ handle_subscription_id(subscription_id)
107
+ run
108
+ end
109
+
110
+ # Sets up and submits a subscription cancelation (ARBCancelSubscriptionRequest) transaction. Returns a response object. If the transaction
111
+ # has already been run, it will return nil.
112
+ #
113
+ # +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.
114
+ #
115
+ #
116
+ # Typical usage:
117
+ #
118
+ # response = transaction.cancel('123456')
119
+ #
120
+ def cancel(subscription_id)
121
+ @type = Type::ARB_CANCEL
122
+ handle_subscription_id(subscription_id)
123
+ run
124
+ end
125
+
126
+ #:enddoc:
127
+ protected
128
+
129
+ # Internal method to handle multiple types of subscription id arguments.
130
+ def handle_subscription_id(subscription_id)
131
+ case subscription_id
132
+ when Subscription
133
+ set_fields(:subscription_id => subscription_id.subscription_id.to_s)
134
+ else
135
+ set_fields(:subscription_id => subscription_id.to_s)
136
+ end
137
+ end
138
+
139
+ # An internal method that builds the POST body, submits it to the gateway, and constructs a Response object with the response.
140
+ def make_request
141
+ set_fields(:reference_id => @reference_id)
142
+ super
143
+ end
144
+
145
+ end
146
+ end
@@ -0,0 +1,154 @@
1
+ # :title: Authorize.Net Ruby SDK
2
+ # The core AuthoizeNet module. The entire SDK is name-spaced inside of this module.
3
+ module AuthorizeNet
4
+
5
+ # Some type conversion routines that will be injected into our Transaction/Response
6
+ # classes.
7
+ module TypeConversions
8
+
9
+ API_FIELD_PREFIX = 'x_'
10
+
11
+ # Coverts a value received from Authorize.Net into a boolean if possible. This
12
+ # is designed to handle the wide range of boolean formats that Authorize.Net uses.
13
+ def value_to_boolean(value)
14
+ case value
15
+ when "TRUE", "T", "YES", "Y", "1", "true"
16
+ true
17
+ when "FALSE", "F", "NO", "N", "0", "false"
18
+ false
19
+ else
20
+ value
21
+ end
22
+ end
23
+
24
+ # Converts a boolean into an Authorize.Net boolean value string. This
25
+ # is designed to handle the wide range of boolean formats that Authorize.Net
26
+ # uses. If bool isn't a Boolean, its converted to a string and passed along.
27
+ def boolean_to_value(bool)
28
+ case bool
29
+ when TrueClass, FalseClass
30
+ bool ? 'TRUE' : 'FALSE'
31
+ else
32
+ bool.to_s
33
+ end
34
+ end
35
+
36
+ # Coverts a value received from Authorize.Net into a BigDecimal.
37
+ def value_to_decimal(value)
38
+ BigDecimal.new(value)
39
+ end
40
+
41
+ # Converts a BigDecimal (or Float) into an Authorize.Net float value string. If float isn't
42
+ # a BigDecimal (or Float), its converted to a string and passed along.
43
+ def decimal_to_value(float)
44
+ case float
45
+ when Float
46
+ "%0.2f" % float
47
+ when BigDecimal
48
+ float.truncate(2).to_s('F')
49
+ else
50
+ float.to_s
51
+ end
52
+ end
53
+
54
+ # Coverts a value received from Authorize.Net into a Date.
55
+ def value_to_date(value)
56
+ Date.strptime(value, '%Y-%m-%d')
57
+ end
58
+
59
+ # Converts a Date (or DateTime, or Time) into an Authorize.Net date value string. If date isn't
60
+ # a Date (or DateTime, or Time), its converted to a string and passed along.
61
+ def date_to_value(date)
62
+ case date
63
+ when Date, DateTime, Time
64
+ date.strftime('%Y-%m-%d')
65
+ else
66
+ date.to_s
67
+ end
68
+ end
69
+
70
+ # Coverts a value received from Authorize.Net into a DateTime.
71
+ def value_to_datetime(value)
72
+ DateTime.strptime(value, '%Y-%m-%dT%H:%M:%S')
73
+ end
74
+
75
+ # Converts a Date (or DateTime, or Time) into an Authorize.Net datetime value string. If date isn't
76
+ # a Date (or DateTime, or Time), its converted to a string and passed along.
77
+ def datetime_to_value(datetime)
78
+ case datetime
79
+ when Date, DateTime
80
+ datetime.new_offset(0).strftime('%Y-%m-%dT%H:%M:%SZ')
81
+ when Time
82
+ datetime.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
83
+ else
84
+ datetime.to_s
85
+ end
86
+ end
87
+
88
+ # Coverts a value received from Authorize.Net into an Integer.
89
+ def value_to_integer(value)
90
+ value.to_s.to_i
91
+ end
92
+
93
+ # Coverts an Integer into an Authorize.Net integer string.
94
+ def integer_to_value(int)
95
+ int.to_s
96
+ end
97
+
98
+ # Converts a key value pair into a HTTP POST parameter. The key is prefixed
99
+ # with key_prefix when being converted to a parameter name.
100
+ def to_param(key, value, key_prefix = API_FIELD_PREFIX)
101
+ key_str = "#{key_prefix}#{key}="
102
+ if value.kind_of?(Array)
103
+ (value.collect do |v|
104
+ key_str + CGI::escape(v.to_s)
105
+ end).join('&')
106
+ else
107
+ key_str + CGI::escape(value.to_s)
108
+ end
109
+ end
110
+
111
+
112
+ # Converts an internal field name (Symbol) into an external field name (Symbol)
113
+ # that can be consumed by the Authorize.Net API.
114
+ def to_external_field(key)
115
+ (API_FIELD_PREFIX + key.to_s).to_sym
116
+ end
117
+
118
+ # Converts an external field name (Symbol) into an internal field name (Symbol). This
119
+ # is the exact inverse of to_external_field. Running to_internal_field(to_external_field(:foo))
120
+ # would return :foo back.
121
+ def to_internal_field(key)
122
+ k_str = key.to_s
123
+ k_str[API_FIELD_PREFIX.length..k_str.length].to_sym
124
+ end
125
+ end
126
+
127
+ # Provides some basic methods used by the various model classes.
128
+ module Model
129
+
130
+ # The constructor for models. Takes any of the supported attributes
131
+ # as key/value pairs.
132
+ def initialize(fields = {})
133
+ fields.each do |k, v|
134
+ method_name = (k.to_s + '=').to_sym
135
+ if self.respond_to?(method_name)
136
+ self.send(method_name, v)
137
+ end
138
+ end
139
+ end
140
+
141
+ def to_a
142
+ [self]
143
+ end
144
+
145
+ #:enddoc:
146
+ protected
147
+
148
+ def handle_multivalue_hashing(obj)
149
+ obj.to_a.collect(&:to_hash)
150
+ end
151
+
152
+ end
153
+
154
+ end
@@ -0,0 +1,19 @@
1
+ module AuthorizeNet::CIM
2
+
3
+ # Models a customer profile.
4
+ class CustomerProfile < AuthorizeNet::Customer
5
+
6
+ include AuthorizeNet::Model
7
+
8
+ attr_accessor :customer_profile_id, :payment_profiles
9
+
10
+ def to_hash
11
+ hash = super
12
+ hash.delete_if {|k, v| v.nil?}
13
+ hash[:payment_profiles] = handle_multivalue_hashing(@payment_profiles)
14
+ hash
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,37 @@
1
+ module AuthorizeNet::CIM
2
+ # Models a payment profile.
3
+ class PaymentProfile
4
+
5
+ module CustomerType
6
+ INDIVIDUAL = 'individual'
7
+ BUSINESS = 'business'
8
+ end
9
+
10
+ include AuthorizeNet::Model
11
+
12
+ attr_accessor :cust_type, :billing_address, :payment_method, :customer_payment_profile_id
13
+
14
+ def cust_type=(type) #:nodoc:
15
+ case type
16
+ when :business
17
+ @cust_type = CustomerType::BUSINESS
18
+ when :individual
19
+ @cust_type = CustomerType::INDIVIDUAL
20
+ else
21
+ @cust_type = type
22
+ end
23
+ end
24
+
25
+ def to_hash
26
+ hash = {
27
+ :cust_type => @cust_type,
28
+ :customer_payment_profile_id => @customer_payment_profile_id
29
+ }
30
+ hash.delete_if {|k, v| v.nil?}
31
+ hash.merge!(@billing_address.to_hash) unless @billing_address.nil?
32
+ hash.merge!(@payment_method.to_hash) unless @payment_method.nil?
33
+ hash
34
+ end
35
+
36
+ end
37
+ end