paytrace 0.1.23 → 1.0.0

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 +4 -4
  2. data/lib/paytrace/address.rb +2 -0
  3. data/lib/paytrace/api/gateway.rb +19 -4
  4. data/lib/paytrace/api/request.rb +72 -28
  5. data/lib/paytrace/api/response.rb +19 -11
  6. data/lib/paytrace/batch_operations.rb +8 -30
  7. data/lib/paytrace/check_transaction.rb +119 -84
  8. data/lib/paytrace/configuration.rb +2 -0
  9. data/lib/paytrace/customer.rb +95 -97
  10. data/lib/paytrace/debug.rb +36 -0
  11. data/lib/paytrace/email_receipt_request.rb +4 -28
  12. data/lib/paytrace/recurring_transaction.rb +20 -67
  13. data/lib/paytrace/transaction.rb +680 -267
  14. data/lib/paytrace/version.rb +1 -1
  15. data/lib/paytrace.rb +0 -4
  16. data/paytrace.gemspec +1 -0
  17. data/run_all_integrations.sh +15 -0
  18. data/test/paytrace/api/gateway_spec.rb +8 -0
  19. data/test/paytrace/api/request_spec.rb +84 -28
  20. data/test/paytrace/api/response_spec.rb +2 -2
  21. data/test/paytrace/batch_operations_spec.rb +5 -5
  22. data/test/paytrace/{check_transactions_spec.rb → check_transaction_spec.rb} +40 -19
  23. data/test/paytrace/customer_spec.rb +86 -110
  24. data/test/paytrace/email_receipt_request_spec.rb +9 -8
  25. data/test/paytrace/level3_data_spec.rb +28 -2
  26. data/test/paytrace/recurring_transaction_spec.rb +8 -16
  27. data/test/paytrace/transaction_spec.rb +300 -330
  28. data/test/scripts/run_adjust_amount.rb +1 -1
  29. data/test/scripts/run_attach_signature.rb +2 -2
  30. data/test/scripts/run_calculate_shipping_costs.rb +2 -3
  31. data/test/scripts/run_change_password.rb +2 -0
  32. data/test/scripts/run_check_transactions.rb +2 -3
  33. data/test/scripts/run_create_customer.rb +16 -23
  34. data/test/scripts/run_email_request.rb +3 -5
  35. data/test/scripts/run_export_batches.rb +6 -3
  36. data/test/scripts/run_export_customers.rb +1 -1
  37. data/test/scripts/run_export_transactions.rb +2 -2
  38. data/test/scripts/run_level3_data.rb +1 -1
  39. data/test/scripts/run_recur_payments_integration.rb +24 -32
  40. data/test/scripts/run_settle_transaction.rb +2 -2
  41. data/test/test_helper.rb +12 -1
  42. metadata +19 -7
  43. data/lib/paytrace/credit_card.rb +0 -32
  44. data/test/paytrace/credit_card_spec.rb +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb8b55937b9c0b2a71ebf27a80842724762b006d
4
- data.tar.gz: 872c601caeb2ebe395d9ff3abc1c64edde62f78b
3
+ metadata.gz: 0c93b4f1327e0d702fb6fb6c45643323f1a98421
4
+ data.tar.gz: 5461e5901af68ce1c0af687eaec7fed77e9165d9
5
5
  SHA512:
6
- metadata.gz: fa3d3191c00543ab32e097a41a2b50fe8ab74eff126c64e288ae9d1b74dc841a7316e44706357ea14baca473673674a0561a59e07f82e913a0ccb264336cd44e
7
- data.tar.gz: 0b32bc57ddec96fa1007f53118cbfc85fd685d804048a9729ae5356868c783e1fd6a692b3072aff36602321a9772c35a4d76ad28b0f02f7ecd7ca18d382ad574
6
+ metadata.gz: f2923d19c3f1d19c60988b228481b0d08fa711f80e4adb9e8ee18de5a22a1d1ff0cf17897f1ac7fb070895184047b7a3d6f9ad6a314aef00ee771d45e694ff26
7
+ data.tar.gz: 07faf40f2999b251eb20ecfdd4a68ecec571efedfa56508fe63fa22f8493a3b745890b1b47bc9b728d3276c0858b8209c06ca15cb17a57c4e45d4ad5dae22af2
@@ -3,6 +3,7 @@ module PayTrace
3
3
  # _Note:_ the "region" parameter can only be defined for shipping addresses, and the
4
4
  # default address type (if unspecified) is billing.
5
5
  class Address
6
+ # :nodoc:
6
7
  attr_accessor :name, :street,:street2,:city,:state, :country,:region,:postal_code,:address_type
7
8
 
8
9
  ATTRIBUTE_MAP = [
@@ -15,6 +16,7 @@ module PayTrace
15
16
  [:postal_code, :postal_code],
16
17
  [:country, :country]
17
18
  ]
19
+ # :doc:
18
20
 
19
21
  # Initialize a new address instance. Parameters are symbolic keys in a hash. They are:
20
22
  # * *:name* -- the name on this address
@@ -14,6 +14,7 @@ module PayTrace
14
14
  @@last_response_object = nil
15
15
  @@next_response = nil
16
16
  @@raise_exceptions = true
17
+ # :doc:
17
18
 
18
19
  # Creates a new gateway object, optionally using a supplied connection object
19
20
  def initialize(connection = nil)
@@ -58,10 +59,24 @@ module PayTrace
58
59
  @@raise_exceptions = raise_exceptions
59
60
  end
60
61
 
62
+ # Helper method to abstract away a common use pattern. Creates a request object, sets parameters, creates a gateway object, sends the request, and returns the response.
63
+ #
64
+ # Arguments:
65
+ #
66
+ # * *param_names* -- the array of parameter names to be set from *arguments*
67
+ # * *arguments* -- the arguments to be set in the request
68
+ def self.send_request(method, params, required = [], optional = [])
69
+ request = Request.new
70
+ request.set_param(:method, method)
71
+ request.set_params(params, required, optional)
72
+ yield request if block_given?
73
+
74
+ gateway = Gateway.new
75
+ gateway.send_request(request)
76
+ end
77
+
61
78
  # Sends a request object
62
- # Params:
63
- # * *:multi_value_response_fields* -- response fields that may have multiple entries for the same key
64
- def send_request(request, multi_value_response_fields = [])
79
+ def send_request(request)
65
80
  @@last_request = request.to_parms_string if @@debug
66
81
  unless (@@debug && @@next_response)
67
82
  res = @connection.post PayTrace.configuration.url, parmlist: request.to_parms_string
@@ -71,7 +86,7 @@ module PayTrace
71
86
  end
72
87
 
73
88
  @@last_response = raw_response
74
- response = PayTrace::API::Response.new(raw_response, multi_value_response_fields)
89
+ response = PayTrace::API::Response.new(raw_response)
75
90
  @@last_response_object = response
76
91
 
77
92
  @@next_response = nil # just to be sure
@@ -57,30 +57,25 @@ module PayTrace
57
57
  end
58
58
 
59
59
  # :nodoc:
60
- def validate_param(k, v)
61
- raise PayTrace::Exceptions::ValidationError.new("Unknown field '#{k}'") unless PayTrace::API.fields.has_key?(k)
60
+ def valid_param?(key, value)
61
+ if key == :discretionary_data
62
+ value.is_a?(Hash) || value.nil? # any discretionary data that's a hash or nil should be passed
63
+ else
64
+ PayTrace::API.fields.has_key?(key) || value.nil? || value.respond_to?(:set_request)
65
+ end
62
66
  end
63
- # :doc:
64
-
65
- # Sets a single request parameters
66
- # * *:key* -- the name of the setting
67
- # * *:value* -- the value of the setting
68
- def set_param(key, value = nil)
69
- validate_param(key, value)
70
-
71
- unless value.nil?
72
- @params[key] ||= []
73
67
 
74
- @params[key] << value
75
- end
68
+ def validate_param!(k, v)
69
+ raise PayTrace::Exceptions::ValidationError.new("Unknown field '#{k}' (value: #{v})") unless valid_param?(k,v)
76
70
  end
71
+ # :doc:
77
72
 
78
73
  # Sets multiple parameters with the same name using the custom delimiter
79
- # * *:param_name* -- the name of the "top level" setting
80
- # * *:items* -- a hash of "second level" settings
74
+ # * *param_name* -- the name of the "top level" setting
75
+ # * *items* -- a hash of "second level" settings
81
76
  def set_multivalue(param_name, items = {})
82
77
  result = (items.map do |k,v|
83
- validate_param(k, v)
78
+ validate_param!(k, v)
84
79
  "#{PayTrace::API.fields[k]}#{@multi_value_delim}#{v}"
85
80
  end.join(@multi_field_delim))
86
81
 
@@ -89,9 +84,28 @@ module PayTrace
89
84
  result
90
85
  end
91
86
 
87
+ # Sets a single request parameters
88
+ # * *key* -- the name of the setting
89
+ # * *value* -- the value of the setting
90
+ #
91
+ # _Note:_ you can pass in an object that responds to *set_request* as the *value*, and this will invoke *set_request* on it, with this request object as the parameter. Also, any value named *:discretionary_data* that is set will be set in the discretionary hash, not the regular params hash.
92
+ def set_param(key, value = nil)
93
+ validate_param!(key, value)
94
+
95
+ if value.respond_to?(:set_request)
96
+ value.set_request(self)
97
+ elsif key == :discretionary_data
98
+ set_discretionary(value)
99
+ elsif value != nil
100
+ @params[key] ||= []
101
+
102
+ @params[key] << value
103
+ end
104
+ end
105
+
92
106
  # Sets multiple parameters at once
93
- # * *:keys* -- an array of key names to extract from the params hash
94
- # * *:params* -- the parameters hash to be extracted from
107
+ # * *:params* -- the hash or object to fetch the parameters from
108
+ # * *:required* -- an array of required key names to extract from the params object
95
109
  #
96
110
  # _Note:_ the values in *:keys* can also include arrays of two values (techincally, a tuple). The sub-array contains the name of the field that will be used in the request, and the name of the field in the params. This allows more succinct parameter names; e.g. *:address* instead of *:billing_address*. Example:
97
111
  #
@@ -103,16 +117,46 @@ module PayTrace
103
117
  # :foo,
104
118
  # [:billing_address, :address]
105
119
  # ], params)
106
- def set_params(keys, params)
107
- keys.each do |key|
108
- if key.is_a?(Array)
109
- request_variable = key[0]
110
- arg_name = key[1]
111
- set_param(request_variable, params[arg_name])
112
- else
113
- set_param(key, params[key])
114
- end
120
+ def set_params(params, required = [], optional = [])
121
+ required_remaining, params_remaining = Request.process_param_list(required, params) do |request_variable, arg_name, value|
122
+ set_param(request_variable, value)
123
+ end
124
+
125
+ # if we're missing *required* parameters, fail...
126
+ raise PayTrace::Exceptions::ValidationError.new("Missing the following required parameters: #{required_remaining.to_s}") if required_remaining.any?
127
+
128
+ optional_remaining, params_remaining = Request.process_param_list(optional, params_remaining) do |request_variable, arg_name, value|
129
+ set_param(request_variable, value)
115
130
  end
131
+
132
+ # if we have any EXTRA parameters, fail...
133
+ raise PayTrace::Exceptions::ValidationError.new("The following parameters are unknown: #{params_remaining.to_s}") if params_remaining && params_remaining.any?
134
+ end
135
+
136
+ # takes a list of permitted keys and a params hash, and returns any missing or extra params, optionally
137
+ # calling a supplied block once per key
138
+ def self.process_param_list(key_list, params, &block)
139
+ if params.is_a?(Hash)
140
+ accessor = :[]
141
+ track_params = true
142
+ else
143
+ accessor = :send
144
+ track_params = false
145
+ end
146
+ params_remaining = params.dup if track_params
147
+
148
+ remaining = key_list.dup
149
+ key_list.each do |key|
150
+ request_variable, arg_name = key # de-alias the name, if it's aliased
151
+ arg_name ||= request_variable # just use the same name for both, if not
152
+
153
+ value = params.send(accessor, arg_name) # this allows us to treat hashes and objects the same
154
+ yield request_variable, arg_name, value if block_given?
155
+ remaining.delete(key) if value
156
+ params_remaining.delete(arg_name) if track_params
157
+ end
158
+
159
+ return (remaining.map {|req,arg| arg || req}), (track_params ? params_remaining : nil)
116
160
  end
117
161
  end
118
162
  end
@@ -2,21 +2,18 @@ module PayTrace
2
2
  module API
3
3
  # An object representing an API response from sending a PayTrace::API::Request with a PayTrace::API::Gateway object
4
4
  class Response
5
+ # :nodoc:
5
6
  attr_reader :values, :errors
7
+ # :doc
6
8
 
7
9
  # Called by the PayTrace::API::Gateway object to initialize a response
8
- def initialize(response_string, multi_value_fields = [])
10
+ def initialize(response_string)
9
11
  @field_delim = "|"
10
12
  @value_delim = "~"
11
13
  @multi_value_delim = "+"
12
14
  @values = {}
13
15
  @errors = {}
14
- parse_response(response_string, multi_value_fields)
15
- end
16
-
17
- # Returns the response code(s) received
18
- def response_code
19
- get_response
16
+ parse_response(response_string)
20
17
  end
21
18
 
22
19
  # Returns true if the response contained any error codes
@@ -24,8 +21,19 @@ module PayTrace
24
21
  @errors.length > 0
25
22
  end
26
23
 
24
+ # given a field name, splits the data in that value into an array of record hashes
25
+ def parse_records(field_name)
26
+ records = []
27
+
28
+ [@values[field_name]].flatten.each do |raw_record|
29
+ records << Hash[raw_record.split(@multi_value_delim).map {|pair| pair.split('=')}]
30
+ end
31
+
32
+ records
33
+ end
34
+
27
35
  # Called by the initialize method
28
- def parse_response(response_string, multi_value_fields = [])
36
+ def parse_response(response_string)
29
37
 
30
38
  if (response_string.include? "ERROR")
31
39
  return parse_errors(response_string)
@@ -34,9 +42,9 @@ module PayTrace
34
42
  pairs = response_string.split(@field_delim)
35
43
  pairs.each do |p|
36
44
  k,v = p.split(@value_delim)
37
- if multi_value_fields.include?(k)
38
- @values[k] ||= []
39
- @values[k] << Hash[v.split(@multi_value_delim).map {|pair| pair.split('=')}]
45
+ if @values.has_key?(k)
46
+ @values[k] = [@values[k]] unless @values[k].is_a?(Array)
47
+ @values[k] << v
40
48
  else
41
49
  @values[k] = v
42
50
  end
@@ -1,9 +1,11 @@
1
1
  module PayTrace
2
2
  # This class serves as a container for batch processing methods
3
3
  class BatchOperations
4
+ # :nodoc:
4
5
  EXPORT_SINGLE_METHOD = "ExportBatch"
5
6
  EXPORT_MULTIPLE_METHOD = "ExportBatches"
6
7
  EXPORT_DETAILS_METHOD = "ExportBatchDetails"
8
+ # :doc:
7
9
 
8
10
  # See http://help.paytrace.com/api-export-single-batch
9
11
  #
@@ -12,16 +14,8 @@ module PayTrace
12
14
  # Optional parameters hash:
13
15
  #
14
16
  # * *:batch_number* -- number of the batch of transactions you wish to export
15
- def self.exportSingle(params = {})
16
- request = PayTrace::API::Request.new
17
- request.set_param(:method, EXPORT_SINGLE_METHOD)
18
- request.set_param(:batch_number, params[:batch_number])
19
-
20
- gateway = PayTrace::API::Gateway.new
21
- response = gateway.send_request(request)
22
- unless response.has_errors?
23
- response.values
24
- end
17
+ def self.export_single(params = {})
18
+ PayTrace::API::Gateway.send_request(EXPORT_SINGLE_METHOD, params, [], [:batch_number])
25
19
  end
26
20
 
27
21
  # See http://help.paytrace.com/api-export-batches
@@ -30,16 +24,8 @@ module PayTrace
30
24
  #
31
25
  # * *:start_date* -- indicates when to start searching for transactions to export. Must be a valid date formatted as MM/DD/YYYY
32
26
  # * *:end_date* -- indicates when to end searching for transactions to export. Must be a valid date formatted as MM/DD/YYYY
33
- def self.exportMultiple(params = {})
34
- request = PayTrace::API::Request.new
35
- request.set_param(:method, EXPORT_MULTIPLE_METHOD)
36
- request.set_params([:start_date, :end_date], params)
37
-
38
- gateway = PayTrace::API::Gateway.new
39
- response = gateway.send_request(request)
40
- unless response.has_errors?
41
- response.values
42
- end
27
+ def self.export_multiple(params = {})
28
+ PayTrace::API::Gateway.send_request(EXPORT_MULTIPLE_METHOD, params, [:start_date, :end_date])
43
29
  end
44
30
 
45
31
  # See http://help.paytrace.com/api-export-batch-details
@@ -47,16 +33,8 @@ module PayTrace
47
33
  # Exports transaction details of a given batch. Required parameters hash:
48
34
  #
49
35
  # * *:batch_number* -- number of the batch of transactions you wish to export
50
- def self.exportDetails(params = {})
51
- request = PayTrace::API::Request.new
52
- request.set_param(:method, EXPORT_DETAILS_METHOD)
53
- request.set_param(:batch_number, params[:batch_number])
54
-
55
- gateway = PayTrace::API::Gateway.new
56
- response = gateway.send_request(request)
57
- unless response.has_errors?
58
- response.values
59
- end
36
+ def self.export_details(params = {})
37
+ PayTrace::API::Gateway.send_request(EXPORT_DETAILS_METHOD, params, [:batch_number])
60
38
  end
61
39
  end
62
40
  end
@@ -1,73 +1,139 @@
1
1
  module PayTrace
2
2
  # Provides a number of helper methods to process check transactions
3
3
  class CheckTransaction
4
+ # :nodoc:
4
5
  PROCESS_SALE_METHOD = "ProcessCheck"
5
6
  MANAGE_CHECK_METHOD = "ManageCheck"
6
7
 
7
- # Process a transaction as a sale. Parameters are passed by symbol name in a hash.
8
- # _Note:_ either supply a customer ID *or* an account/routing number. Although passing in
9
- # both sets of data will not raise an error, the backend API will ignore the account/routing
10
- # number if the customer ID is supplied
8
+ # parameters used by several methods
9
+ COMMON_PARAMETERS = [
10
+ :check_type,
11
+ :amount, :customer_id, :account_number, :routing_number,
12
+ :email, :invoice, :description, :tax_amount, :customer_reference_id, :billing_address, :shipping_address, :discretionary_data,
13
+ :test_flag
14
+ ]
15
+
16
+ BILLING_AND_SHIPPING_ADDRESS_FIELDS = [
17
+ :billing_name,
18
+ :billing_address,
19
+ :billing_address2,
20
+ :billing_city,
21
+ :billing_state,
22
+ :billing_postal_code,
23
+ :billing_country,
24
+ :shipping_name,
25
+ :shipping_address,
26
+ :shipping_address2,
27
+ :shipping_city,
28
+ :shipping_state,
29
+ :shipping_postal_code,
30
+ :shipping_region,
31
+ :shipping_country
32
+ ]
33
+
34
+ SALE_OPTIONAL_PARAMETERS = BILLING_AND_SHIPPING_ADDRESS_FIELDS + [
35
+ :email,
36
+ :invoice,
37
+ :description,
38
+ :tax_amount,
39
+ :customer_reference_id,
40
+ :discretionary_data
41
+ ]
42
+ # :doc:
43
+
44
+ # See http://help.paytrace.com/api-processing-a-check-sale
45
+ #
46
+ # Process a transaction as a sale by checking account number and routing number.
11
47
  #
12
- # The parameters are:
48
+ # Required parameters:
49
+ #
13
50
  # * *:check_type* -- the check transaction type; typically "Sale"
14
51
  # * *:amount* -- the amount of the check
15
- # * *:customer_id* -- the customer ID for the check
16
52
  # * *:account_anumber* -- the checking account number
17
53
  # * *:routing_number* -- the checking account routing number
18
- # * *:email* -- the customer's email
19
- # * *:invoice* -- an invoice number to apply to the sale
20
- # * *:description* -- a free text description of the sale
21
- # * *:tax_amount* -- the tax amount for the sale
22
- # * *:customer_reference_id* -- an optional customer reference number
23
- # * *:discretionary_data* -- any discretionary data to be applied
24
- # * *:shipping_address* -- a shipping address object; see PayTrace::Address
25
- # * *:billing_address* -- a billing address object; see PayTrace::Address
26
- def self.process_sale(params = {})
27
- request = PayTrace::API::Request.new
28
- request.set_param(:method, PROCESS_SALE_METHOD)
29
- self.add_common_parameters(params, request)
30
-
31
- gateway = PayTrace::API::Gateway.new
32
- response = gateway.send_request(request)
33
- unless response.has_errors?
34
- response.values
35
- end
54
+ #
55
+ # Optional parameters:
56
+ #
57
+ # * *:billing_name* -- the billing name for this transaction
58
+ # * *:billing_address* -- the billing street address for this transaction
59
+ # * *:billing_address2* -- the billing street address second line (e.g., apartment, suite) for this transaction
60
+ # * *:billing_city* -- the billing city for this transaction
61
+ # * *:billing_state* -- the billing state for this transaction
62
+ # * *:billing_postal_code* -- the billing zip code for this transaction
63
+ # * *:billing_country* -- the billing country for this transaction
64
+ # * *:shipping_name* -- the shipping name for this transaction
65
+ # * *:shipping_address* -- the shipping street address for this transaction
66
+ # * *:shipping_address2* -- the shipping street address second line (e.g., apartment, suite) for this transaction
67
+ # * *:shipping_city* -- the shipping city for this transaction
68
+ # * *:shipping_state* -- the shipping state for this transaction
69
+ # * *:shipping_postal_code* -- the shipping zip code for this transaction
70
+ # * *:shipping_region* -- the shipping region (e.g. county) for this transaction
71
+ # * *:shipping_country* -- the shipping country for this transaction
72
+ # * *:email* -- the customer email for this transaction
73
+ # * *:invoice* -- an internal invoice number (customer ID token or referenced transaction sale)
74
+ # * *:description* -- a description of the sale (customer ID token or referenced transaction sale)
75
+ # * *:tax_amount* -- the amount of tax on the sale (customer ID token or referenced transaction sale)
76
+ # * *:customer_reference_id* -- a customer reference ID (customer ID token or referenced transaction sale)
77
+ # * *:discretionary_data* -- a hash of optional discretionary data to attach to this transaction
78
+ def self.sale(params = {})
79
+ PayTrace::API::Gateway.send_request(PROCESS_SALE_METHOD, params, [:check_type, :amount, :routing_number, :account_number], SALE_OPTIONAL_PARAMETERS)
80
+ end
81
+
82
+ # See http://help.paytrace.com/api-processing-a-check-sale
83
+ #
84
+ # Process a transaction as a sale by checking account number and routing number.
85
+ #
86
+ # Required parameters:
87
+ #
88
+ # * *:check_type* -- the check transaction type; typically "Sale"
89
+ # * *:amount* -- the amount of the check
90
+ # * *:customer_id -- the customer ID to reference for this sale
91
+ #
92
+ # Optional parameters are the same as for sale
93
+ def self.customer_id_sale(params = {})
94
+ PayTrace::API::Gateway.send_request(PROCESS_SALE_METHOD, params, [:check_type, :amount, :customer_id], SALE_OPTIONAL_PARAMETERS)
36
95
  end
37
96
 
38
97
  # Process a transaction as a hold. Parameters are passed by symbol name in a hash.
39
- # _Note:_ the parameters for this method are identical to process_sale; this is simply
98
+ # _Note:_ the parameters for this method are identical to sale; this is simply
40
99
  # a convenience method. The :check_type is automatically set to "Hold"
41
- def self.process_hold(params = {})
42
- request = PayTrace::API::Request.new
43
- request.set_param(:method, PROCESS_SALE_METHOD)
44
- params.delete(:check_type) # make sure we don't duplicate this
45
- self.add_common_parameters(params, request)
46
- request.set_param(:check_type, "Hold")
47
-
48
- gateway = PayTrace::API::Gateway.new
49
- response = gateway.send_request(request)
50
- unless response.has_errors?
51
- response.values
52
- end
100
+ def self.hold(params = {})
101
+ params = params.dup
102
+ params[:check_type] = "Hold"
103
+
104
+ PayTrace::API::Gateway.send_request(PROCESS_SALE_METHOD, params, [], COMMON_PARAMETERS)
53
105
  end
54
106
 
107
+
108
+
55
109
  # Process a transaction as a refund. Parameters are passed by symbol name in a hash.
56
- # _Note:_ the parameters for this method are identical to process_sale; this is simply
57
- # a convenience method. The :check_type is automatically set to "Hold"
58
- def self.process_refund(params = {})
59
- request = PayTrace::API::Request.new
60
- request.set_param(:method, PROCESS_SALE_METHOD)
61
- params.delete(:check_type) # make sure we don't duplicate this
62
- self.add_common_parameters(params, request)
63
- request.set_param(:check_id, params[:check_id])
64
- request.set_param(:check_type, "Refund")
65
-
66
- gateway = PayTrace::API::Gateway.new
67
- response = gateway.send_request(request)
68
- unless response.has_errors?
69
- response.values
70
- end
110
+ # _Note:_ the parameters for this method are identical to sale; this is simply
111
+ # a convenience method. The :check_type is automatically set to "Refund"
112
+ def self.refund(params = {})
113
+ params = params.dup
114
+ params[:check_type] = "Refund"
115
+
116
+ PayTrace::API::Gateway.send_request(PROCESS_SALE_METHOD, params, [:check_type, :amount, :routing_number, :account_number])
117
+ end
118
+
119
+ # Process a transaction as a refund. Parameters are passed by symbol name in a hash.
120
+ # _Note:_ the parameters for this method are identical to sale; this is simply
121
+ # a convenience method. The :check_type is automatically set to "Refund"
122
+ def self.refund_by_customer_id(params = {})
123
+ params = params.dup
124
+ params[:check_type] = "Refund"
125
+
126
+ PayTrace::API::Gateway.send_request(PROCESS_SALE_METHOD, params, [:check_type, :amount, :customer_id])
127
+ end
128
+
129
+ # Process a transaction as a refund. Parameters are passed by symbol name in a hash.
130
+ # _Note:_ the parameters for this method are identical to sale; this is simply
131
+ # a convenience method. The :check_type is automatically set to "Refund"
132
+ def self.refund_existing_check_id(params = {})
133
+ params = params.dup
134
+ params[:check_type] = "Refund"
135
+
136
+ PayTrace::API::Gateway.send_request(PROCESS_SALE_METHOD, params, [:check_type, :check_id])
71
137
  end
72
138
 
73
139
  # Manage an existing check, setting a new check type if necessary. Params are passed by symbol
@@ -75,38 +141,7 @@ module PayTrace
75
141
  # * *:check_type* -- the (new) type of this check (e.g. "Sale", "Hold", "Refund", etc.)
76
142
  # * *:check_id* -- the id of the check to manage
77
143
  def self.manage_check(params = {})
78
- request = PayTrace::API::Request.new
79
- request.set_param(:method, MANAGE_CHECK_METHOD)
80
- request.set_params([:check_type, :check_id], params)
81
-
82
- gateway = PayTrace::API::Gateway.new
83
- response = gateway.send_request(request)
84
- unless response.has_errors?
85
- response.values
86
- end
87
- end
88
-
89
- # Helper method called by the framework. Do not call directly.
90
- def self.add_common_parameters(params = {}, request)
91
- request.set_params([
92
- :check_type,
93
- :amount, :customer_id, :account_number, :routing_number,
94
- :email, :invoice, :description, :tax_amount, :customer_reference_id, :test_flag
95
- ], params)
96
-
97
- if params[:discretionary_data]
98
- params[:discretionary_data].keys.each do |k|
99
- request.set_discretionary(k, params[:discretionary_data][k])
100
- end
101
- end
102
-
103
- if params.has_key?(:billing_address)
104
- params[:billing_address].set_request(request)
105
- end
106
-
107
- if params.has_key?(:shipping_address)
108
- params[:shipping_address].set_request(request)
109
- end
144
+ PayTrace::API::Gateway.send_request(MANAGE_CHECK_METHOD, params, [:check_type, :check_id])
110
145
  end
111
146
  end
112
147
  end
@@ -1,9 +1,11 @@
1
1
  module PayTrace
2
2
  # Contains necessary configuration to access the API server; notably the user name, password, and URL information
3
3
  class Configuration
4
+ # :nodoc:
4
5
  attr_accessor :user_name, :password, :connection, :domain, :path
5
6
 
6
7
  RESET_PASSWORD_METHOD = "UpdatePassword"
8
+ # :doc:
7
9
 
8
10
  # Default initializer. Do not call directly; instead use the PayTrace.configure method
9
11
  # Example: