paytrace 0.1.21 → 0.1.23

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 151f729f1e86c8a9dd7f218afe022017af0c9c5f
4
- data.tar.gz: 8e5bae858b0e4825466d61fd8084f56d94b43dd5
3
+ metadata.gz: eb8b55937b9c0b2a71ebf27a80842724762b006d
4
+ data.tar.gz: 872c601caeb2ebe395d9ff3abc1c64edde62f78b
5
5
  SHA512:
6
- metadata.gz: 7c704b30039685e4f063bb4906ce383d3a14805ef5aafc0fd533b94b63b5771d3e42eff7e9b4bcf1d928e558512a91334eef0c98d0e00558217fda368859e25e
7
- data.tar.gz: d3b6bbdd08257974328db8713cdfc62d94880bd4c3cb0f193af3ea10f9f514f052e33de7424c22cb1f080ef9afae69ddb669e45dd34e885868c24fb2ff8897d2
6
+ metadata.gz: fa3d3191c00543ab32e097a41a2b50fe8ab74eff126c64e288ae9d1b74dc841a7316e44706357ea14baca473673674a0561a59e07f82e913a0ccb264336cd44e
7
+ data.tar.gz: 0b32bc57ddec96fa1007f53118cbfc85fd685d804048a9729ae5356868c783e1fd6a692b3072aff36602321a9772c35a4d76ad28b0f02f7ecd7ca18d382ad574
@@ -11,6 +11,7 @@ require 'paytrace/api/response'
11
11
  require 'paytrace/exceptions'
12
12
  require 'paytrace/recurring_transaction'
13
13
  require 'paytrace/check_transaction'
14
+ require 'paytrace/batch_operations'
14
15
 
15
16
  module PayTrace
16
17
  end
@@ -5,6 +5,17 @@ module PayTrace
5
5
  class Address
6
6
  attr_accessor :name, :street,:street2,:city,:state, :country,:region,:postal_code,:address_type
7
7
 
8
+ ATTRIBUTE_MAP = [
9
+ [:name, :name],
10
+ [:address, :street],
11
+ [:address2, :street2],
12
+ [:city, :city],
13
+ [:region, :region],
14
+ [:state, :state],
15
+ [:postal_code, :postal_code],
16
+ [:country, :country]
17
+ ]
18
+
8
19
  # Initialize a new address instance. Parameters are symbolic keys in a hash. They are:
9
20
  # * *:name* -- the name on this address
10
21
  # * *:street* -- the street address
@@ -31,16 +42,12 @@ module PayTrace
31
42
  # Parameters:
32
43
  # * *request* -- the request object to apply this address to
33
44
  def set_request(request)
34
- atype_str = address_type.to_s
35
-
36
- request.set_param(:"#{atype_str}_name", name) if name
37
- request.set_param(:"#{atype_str}_address", street) if street
38
- request.set_param(:"#{atype_str}_address2", street2) if street2
39
- request.set_param(:"#{atype_str}_city", city) if city
40
- request.set_param(:"#{atype_str}_region", region) if region
41
- request.set_param(:"#{atype_str}_state", state) if state
42
- request.set_param(:"#{atype_str}_postal_code", postal_code) if postal_code
43
- request.set_param(:"#{atype_str}_country", country) if country
45
+ ATTRIBUTE_MAP.each do |request_name, attribute_name|
46
+ unless request_name == :region && address_type == :billing # special case
47
+ # this is ugly, but it saves us from subclassing just to change field names in a predictable way...
48
+ request.set_param("#{address_type.to_s}_#{request_name}".to_sym, self.send(attribute_name))
49
+ end
50
+ end
44
51
  end
45
52
  end
46
53
  end
@@ -110,6 +110,8 @@ module PayTrace
110
110
  source_state: "SOURCESTATE",
111
111
  shipping_weight: "WEIGHT",
112
112
  shippers: "SHIPPERS",
113
+ # batch opterations
114
+ batch_number: "BATCHNUMBER",
113
115
  # test flag
114
116
  test_flag: "TEST"
115
117
  }
@@ -42,10 +42,16 @@ module PayTrace
42
42
  # Sets discretionary data keys and values
43
43
  # * *:key* -- the name of the setting
44
44
  # * *:value* -- the value of the setting
45
+ #
46
+ # _Note:_ you can bulk-set discretionary data by simply passing in a hash as the "key"
45
47
  def set_discretionary(key, value = nil)
46
48
  if key.is_a?(Hash)
47
- @discretionary_data = key
48
- else
49
+ ddata_hash = key
50
+ ddata_hash.keys.each do |inner_key|
51
+ inner_value = ddata_hash[inner_key]
52
+ @discretionary_data[inner_key] = inner_value unless inner_value.nil?
53
+ end
54
+ elsif key.is_a?(Symbol)
49
55
  @discretionary_data[key] = value unless value.nil?
50
56
  end
51
57
  end
@@ -86,9 +92,26 @@ module PayTrace
86
92
  # Sets multiple parameters at once
87
93
  # * *:keys* -- an array of key names to extract from the params hash
88
94
  # * *:params* -- the parameters hash to be extracted from
95
+ #
96
+ # _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
+ #
98
+ # #
99
+ # # note the nested array; this will send the field :billing_address,
100
+ # # but uses the argument :address as the argument name
101
+ # #
102
+ # set_params([
103
+ # :foo,
104
+ # [:billing_address, :address]
105
+ # ], params)
89
106
  def set_params(keys, params)
90
107
  keys.each do |key|
91
- set_param(key, params[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
92
115
  end
93
116
  end
94
117
  end
@@ -0,0 +1,62 @@
1
+ module PayTrace
2
+ # This class serves as a container for batch processing methods
3
+ class BatchOperations
4
+ EXPORT_SINGLE_METHOD = "ExportBatch"
5
+ EXPORT_MULTIPLE_METHOD = "ExportBatches"
6
+ EXPORT_DETAILS_METHOD = "ExportBatchDetails"
7
+
8
+ # See http://help.paytrace.com/api-export-single-batch
9
+ #
10
+ # Verifying batch details is sometimes necessary for your application to be able to determine deposit and transaction sums. The ExportBatch method is useful for extracting a summary of a specific batch or currently pending settlement break-down by card and transaction type.
11
+ #
12
+ # Optional parameters hash:
13
+ #
14
+ # * *: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
25
+ end
26
+
27
+ # See http://help.paytrace.com/api-export-batches
28
+ #
29
+ # Exports summary information about multiple batches over a given date range. Required parameters:
30
+ #
31
+ # * *:start_date* -- indicates when to start searching for transactions to export. Must be a valid date formatted as MM/DD/YYYY
32
+ # * *: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
43
+ end
44
+
45
+ # See http://help.paytrace.com/api-export-batch-details
46
+ #
47
+ # Exports transaction details of a given batch. Required parameters hash:
48
+ #
49
+ # * *: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
60
+ end
61
+ end
62
+ end
@@ -131,28 +131,23 @@ module PayTrace
131
131
  # Internal helper method; not meant to be called directly.
132
132
  def set_request_data(params, request = nil)
133
133
  request ||= PayTrace::API::Request.new
134
- request.set_param(:customer_id, params[:customer_id])
135
- request.set_param(:new_customer_id, params[:new_customer_id])
136
- request.set_param(:transaction_id, params[:transaction_id])
134
+ request.set_params([
135
+ :customer_id,
136
+ :new_customer_id,
137
+ :transaction_id,
138
+ :email,
139
+ [:customer_phone, :phone],
140
+ [:customer_fax, :fax],
141
+ :customer_password,
142
+ :account_number,
143
+ :routing_number
144
+ ], params)
137
145
 
138
146
  params[:billing_address].set_request(request) if params[:billing_address]
139
147
  params[:shipping_address].set_request(request) if params[:shipping_address]
148
+ params[:credit_card].set_request_data(request) if params[:credit_card]
140
149
 
141
- if params[:credit_card]
142
- params[:credit_card].set_request_data(request)
143
- end
144
-
145
- request.set_param(:email, params[:email])
146
- request.set_param(:customer_phone, params[:phone])
147
- request.set_param(:customer_fax, params[:fax])
148
- request.set_param(:customer_password, params[:customer_password])
149
- request.set_param(:account_number, params[:account_number])
150
- request.set_param(:routing_number, params[:routing_number])
151
- if params[:discretionary_data]
152
- params[:discretionary_data].keys.each do |k|
153
- request.set_discretionary(k, params[:discretionary_data][k])
154
- end
155
- end
150
+ request.set_discretionary(params[:discretionary_data])
156
151
  end
157
152
  end
158
153
  end
@@ -112,17 +112,19 @@ module PayTrace
112
112
  request = PayTrace::API::Request.new
113
113
  request.set_param(:method, method)
114
114
 
115
- request.set_param(:recur_id, params[:recur_id])
116
- request.set_param(:customer_id, params[:customer_id])
117
- request.set_param(:recur_frequency, params[:recur_frequency])
118
- request.set_param(:recur_start, params[:recur_start])
119
- request.set_param(:recur_next, params[:recur_next])
120
- request.set_param(:recur_count, params[:recur_count])
121
- request.set_param(:amount, params[:amount])
122
- request.set_param(:transaction_type, params[:transaction_type])
123
- request.set_param(:description, params[:description])
124
- request.set_param(:recur_receipt, params[:recur_receipt])
125
- request.set_param(:recur_type, params[:recur_type])
115
+ request.set_params([
116
+ :recur_id,
117
+ :customer_id,
118
+ :recur_frequency,
119
+ :recur_start,
120
+ :recur_next,
121
+ :recur_count,
122
+ :amount,
123
+ :transaction_type,
124
+ :description,
125
+ :recur_receipt,
126
+ :recur_type
127
+ ], params)
126
128
 
127
129
  gateway = PayTrace::API::Gateway.new
128
130
  gateway.send_request(request)
@@ -1,4 +1,4 @@
1
1
  module PayTrace
2
2
  # Version number
3
- VERSION = "0.1.21"
3
+ VERSION = "0.1.23"
4
4
  end
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "mocha", "~> 1.0"
26
26
  spec.add_development_dependency "guard", '~> 0'
27
27
  spec.add_development_dependency "guard-minitest", '~> 0'
28
+ spec.add_development_dependency "ruby_gntp", '~> 0'
28
29
  end
@@ -38,6 +38,14 @@ describe PayTrace::API::Request do
38
38
  r.params[:billing_postal_code].must_equal [98133]
39
39
  end
40
40
 
41
+ it "can alias parameters in set_params" do
42
+ params = {name: "Ron Jones", postal_code: 98134}
43
+ r = PayTrace::API::Request.new
44
+ r.set_params([[:billing_name, :name], [:billing_postal_code, :postal_code]], params)
45
+ r.params[:billing_name].must_equal ["Ron Jones"]
46
+ r.params[:billing_postal_code].must_equal [98134]
47
+ end
48
+
41
49
  it "raises a validation exception for unknown fields" do
42
50
  r = PayTrace::API::Request.new
43
51
 
@@ -0,0 +1,43 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../test_helper.rb')
2
+
3
+ describe PayTrace::BatchOperations do
4
+ def base_url(method)
5
+ "UN~#{PayTrace.configuration.user_name}|PSWD~#{PayTrace.configuration.password}|TERMS~Y|METHOD~#{method}|"
6
+ end
7
+
8
+ before do
9
+ PayTrace::API::Gateway.debug = true
10
+ PayTrace::API::Gateway.reset_trace()
11
+ end
12
+
13
+ describe "exportSingle" do
14
+ it "generates the correct request" do
15
+ PayTrace::API::Gateway.next_response = "RESULT~Ok"
16
+ result = PayTrace::BatchOperations.exportSingle()
17
+ PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::BatchOperations::EXPORT_SINGLE_METHOD)
18
+ end
19
+
20
+ it "accepts an optional batch number" do
21
+ PayTrace::API::Gateway.next_response = "RESULT~Ok"
22
+ result = PayTrace::BatchOperations.exportSingle(batch_number: 12345)
23
+ PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::BatchOperations::EXPORT_SINGLE_METHOD) + "BATCHNUMBER~12345|"
24
+ end
25
+ end
26
+
27
+ describe "exportMultiple" do
28
+ it "generates the correct request" do
29
+ PayTrace::API::Gateway.next_response = "RESULT~Ok"
30
+ result = PayTrace::BatchOperations.exportMultiple(start_date: "03/01/2014", end_date: "06/01/2014")
31
+ PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::BatchOperations::EXPORT_MULTIPLE_METHOD) +
32
+ "SDATE~03/01/2014|EDATE~06/01/2014|"
33
+ end
34
+ end
35
+
36
+ describe "exportDetails" do
37
+ it "generates the correct request" do
38
+ PayTrace::API::Gateway.next_response = "RESULT~Ok"
39
+ result = PayTrace::BatchOperations.exportDetails(batch_number: 12346)
40
+ PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::BatchOperations::EXPORT_DETAILS_METHOD) + "BATCHNUMBER~12346|"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,32 @@
1
+ $:<< "./lib" # uncomment this to run against a Git clone instead of an installed gem
2
+
3
+ require "paytrace"
4
+ require "paytrace/debug"
5
+
6
+ # change this as needed to reflect the username, password, and test host you're testing against
7
+ PayTrace::Debug.configure_test("demo123", "demo123", "stage.paytrace.com")
8
+
9
+ # export summary info of a single batch (by batch number in this case, otherwise chooses latest batch)
10
+ PayTrace::Debug.trace do
11
+ params = {
12
+ batch_number: 413
13
+ }
14
+ result = PayTrace::BatchOperations.exportSingle(params)
15
+ end
16
+
17
+ # export batches by date range
18
+ PayTrace::Debug.trace do
19
+ params = {
20
+ start_date: "01/01/2014",
21
+ end_date: "05/01/2014"
22
+ }
23
+ result = PayTrace::BatchOperations.exportMultiple(params)
24
+ end
25
+
26
+ # export batch transaction details
27
+ PayTrace::Debug.trace do
28
+ params = {
29
+ batch_number: 413
30
+ }
31
+ result = PayTrace::BatchOperations.exportDetails(params)
32
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paytrace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trevor Redfern
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-07 00:00:00.000000000 Z
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: ruby_gntp
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Integration with PayTrace Payment Gateway
98
112
  email:
99
113
  - trevor@paytrace.com
@@ -116,6 +130,7 @@ files:
116
130
  - lib/paytrace/api/gateway.rb
117
131
  - lib/paytrace/api/request.rb
118
132
  - lib/paytrace/api/response.rb
133
+ - lib/paytrace/batch_operations.rb
119
134
  - lib/paytrace/check_transaction.rb
120
135
  - lib/paytrace/configuration.rb
121
136
  - lib/paytrace/credit_card.rb
@@ -132,6 +147,7 @@ files:
132
147
  - test/paytrace/api/gateway_spec.rb
133
148
  - test/paytrace/api/request_spec.rb
134
149
  - test/paytrace/api/response_spec.rb
150
+ - test/paytrace/batch_operations_spec.rb
135
151
  - test/paytrace/check_transactions_spec.rb
136
152
  - test/paytrace/configuration_spec.rb
137
153
  - test/paytrace/credit_card_spec.rb
@@ -148,6 +164,7 @@ files:
148
164
  - test/scripts/run_check_transactions.rb
149
165
  - test/scripts/run_create_customer.rb
150
166
  - test/scripts/run_email_request.rb
167
+ - test/scripts/run_export_batches.rb
151
168
  - test/scripts/run_export_customers.rb
152
169
  - test/scripts/run_export_transactions.rb
153
170
  - test/scripts/run_level3_data.rb
@@ -186,6 +203,7 @@ test_files:
186
203
  - test/paytrace/api/gateway_spec.rb
187
204
  - test/paytrace/api/request_spec.rb
188
205
  - test/paytrace/api/response_spec.rb
206
+ - test/paytrace/batch_operations_spec.rb
189
207
  - test/paytrace/check_transactions_spec.rb
190
208
  - test/paytrace/configuration_spec.rb
191
209
  - test/paytrace/credit_card_spec.rb
@@ -202,6 +220,7 @@ test_files:
202
220
  - test/scripts/run_check_transactions.rb
203
221
  - test/scripts/run_create_customer.rb
204
222
  - test/scripts/run_email_request.rb
223
+ - test/scripts/run_export_batches.rb
205
224
  - test/scripts/run_export_customers.rb
206
225
  - test/scripts/run_export_transactions.rb
207
226
  - test/scripts/run_level3_data.rb