paytrace 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae74bece9567072735235bb13c243480933eb2ad
4
- data.tar.gz: f9a82b0cb1cecd8357cef85dc7b103de8dc52f2d
3
+ metadata.gz: dc24d8b07a7ac3d137357a112e9f82722e8cdba9
4
+ data.tar.gz: 6db8dc240022b174b1c519cbbfdf71dc8c4a1f4b
5
5
  SHA512:
6
- metadata.gz: 4093411b2ecb7a0166affcab5ddbc0296de3d594695dabe4f6ca1a9a428ff5fe7bacd473657bd6b1624fe99c08aeac53f4afa38c9eeac1c2902df6a0b9a9df80
7
- data.tar.gz: e163f38094a6034abc1739b6e12d841d7cca74c1a242bad7616831a976345252fc9a045f27085507a859e509045828154f4f2e3ce5ba079b9c34c36af5d5f7c0
6
+ metadata.gz: 7f1cb13b0698362191da90230643f5bb13e3a6e85de366fe4727b3195d2681f74171d6cd629fc0fdf546c0ac5f522763dc22c6480f4fa1143275d7c4a72a84ea
7
+ data.tar.gz: 43e763f160328816280a99dcb8d75701ce6ab827ca5b559c040e8557854df9f627c4710428a3437a49323a880b68b21305e83b864145f4dbd83926d7d82e1d2e
data/README.md CHANGED
@@ -95,7 +95,7 @@ transaction = Transaction.Sale(
95
95
  email:"me@example.com",
96
96
  description:"This is a test",
97
97
  tax_amount:".50",
98
- discretionary_data:"This is some data that is discretionary"
98
+ discretionary_data: {hair_color: "red"}
99
99
  }
100
100
  )
101
101
 
@@ -13,7 +13,6 @@ module PayTrace
13
13
  tax_amount: "TAX",
14
14
  return_clr: "RETURNCLR",
15
15
  enable_partial_authentication: "ENABLEPARTIALAUTH",
16
- discretionary_data: "DISCRETIONARY DATA",
17
16
  custom_dba: "CUSTOMDBA",
18
17
  invoice:"INVOICE",
19
18
  transaction_id:"TRANXID",
@@ -1,8 +1,7 @@
1
1
  module PayTrace
2
2
  module API
3
3
  class Request
4
- TRANSACTION_METHOD = "PROCESSTRANX"
5
- attr_reader :params, :field_delim, :value_delim
4
+ attr_reader :params, :field_delim, :value_delim, :discretionary_data
6
5
 
7
6
  def initialize
8
7
  @field_delim = "|"
@@ -14,12 +13,29 @@ module PayTrace
14
13
  terms: "Y"
15
14
  }
16
15
 
16
+ @discretionary_data = {}
17
17
  end
18
18
 
19
19
  def to_parms_string()
20
- @params.map do |k,v|
20
+ raw_request = @params.map do |k,v|
21
21
  "#{PayTrace::API.fields[k]}#{@value_delim}#{v}"
22
- end.join(@field_delim) << "|"
22
+ end.join(@field_delim) << @field_delim
23
+
24
+ if @discretionary_data.any?
25
+ raw_request << @discretionary_data.map do |k,v|
26
+ "#{k}#{@value_delim}#{v}"
27
+ end.join(@field_delim) << @field_delim
28
+ end
29
+
30
+ raw_request
31
+ end
32
+
33
+ def set_discretionary(k, v = nil)
34
+ if k.is_a?(Hash)
35
+ @discretionary_data = k
36
+ else
37
+ @discretionary_data[k] = v unless v.nil?
38
+ end
23
39
  end
24
40
 
25
41
  def set_param(k, v)
@@ -62,7 +62,11 @@ module PayTrace
62
62
  request.set_param(:customer_password, params[:customer_password])
63
63
  request.set_param(:account_number, params[:account_number])
64
64
  request.set_param(:routing_number, params[:routing_number])
65
- request.set_param(:discretionary_data, params[:discretionary_data])
65
+ if params[:discretionary_data]
66
+ params[:discretionary_data].keys.each do |k|
67
+ request.set_discretionary(k, params[:discretionary_data][k])
68
+ end
69
+ end
66
70
 
67
71
  gateway = PayTrace::API::Gateway.new
68
72
  response = gateway.send_request(request)
@@ -81,7 +81,7 @@ module PayTrace
81
81
  end
82
82
 
83
83
  attr_reader :amount, :credit_card, :type, :customer, :billing_address, :shipping_address,:optional_fields
84
- attr_accessor :response
84
+ attr_accessor :response, :discretionary_data
85
85
 
86
86
  TRANSACTION_METHOD = "PROCESSTRANX"
87
87
 
@@ -92,11 +92,12 @@ module PayTrace
92
92
 
93
93
 
94
94
 
95
- def initialize(amount: nil, credit_card: nil, customer: nil, type: nil, optional: nil )
95
+ def initialize(amount: nil, credit_card: nil, customer: nil, type: nil, optional: nil, discretionary_data: {} )
96
96
  @amount = amount
97
97
  @credit_card = credit_card
98
98
  @type = type
99
99
  @customer = customer
100
+ @discretionary_data = discretionary_data || {}
100
101
  include_optional(optional) if optional
101
102
  end
102
103
 
@@ -110,6 +111,9 @@ module PayTrace
110
111
  add_transaction_info(request)
111
112
  add_addresses(request)
112
113
  add_optional_fields(request) if optional_fields
114
+ if @discretionary_data.any?
115
+ request.set_discretionary(@discretionary_data)
116
+ end
113
117
  end
114
118
 
115
119
  private
@@ -1,3 +1,3 @@
1
1
  module PayTrace
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -35,4 +35,13 @@ describe PayTrace::API::Request do
35
35
 
36
36
  -> { r.set_param(:foo, "bar") }.must_raise PayTrace::Exceptions::ValidationError
37
37
  end
38
+
39
+ it "properly appends discretionary data" do
40
+ r = PayTrace::API::Request.new
41
+ r.set_param(:billing_name, "Fred Jones")
42
+ r.set_discretionary(:hair_color, "red")
43
+
44
+ r.to_parms_string.must_equal "UN~#{PayTrace.configuration.user_name}|PSWD~#{PayTrace.configuration.password}|TERMS~Y|" +
45
+ "BNAME~Fred Jones|hair_color~red|"
46
+ end
38
47
  end
@@ -95,13 +95,13 @@ describe PayTrace::Customer do
95
95
  customer_password: "none_shall_pass",
96
96
  account_number: 123456789,
97
97
  routing_number: 12345678,
98
- discretionary_data: "discretionary_data"
98
+ discretionary_data: {hair_color: "red"}
99
99
  }
100
100
 
101
101
  PayTrace::Customer.from_transaction_id(params)
102
102
  PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~CreateCustomer|CUSTID~foo_bar|TRANXID~12345678|EMAIL~support@paytrace.com|" +
103
103
  "PHONE~123-555-1212|FAX~456-555-1212|CUSTPSWD~none_shall_pass|DDA~123456789|TR~12345678|" +
104
- "DISCRETIONARY DATA~discretionary_data|"
104
+ "hair_color~red|"
105
105
  end
106
106
  end
107
107
 
@@ -157,7 +157,7 @@ describe PayTrace::Customer do
157
157
  customer_password: "none_shall_pass",
158
158
  account_number: 123456789,
159
159
  routing_number: 12345678,
160
- discretionary_data: "discretionary_data"
160
+ discretionary_data: {hair_color: "red"}
161
161
  }
162
162
 
163
163
  c = PayTrace::Customer.new
@@ -165,7 +165,7 @@ describe PayTrace::Customer do
165
165
 
166
166
  PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~UpdateCustomer|NEWCUSTID~foo_bar|" +
167
167
  "EMAIL~support@paytrace.com|PHONE~123-555-1212|FAX~456-555-1212|CUSTPSWD~none_shall_pass|DDA~123456789|" +
168
- "TR~12345678|DISCRETIONARY DATA~discretionary_data|"
168
+ "TR~12345678|hair_color~red|"
169
169
  end
170
170
  end
171
171
 
@@ -275,9 +275,9 @@ describe PayTrace::Transaction do
275
275
  tax_amount: "1.00",
276
276
  return_clr: "Y",
277
277
  enable_partial_authentication:"Y",
278
- discretionary_data:"This is some data that is discretionary",
279
278
  custom_dba:"NewName"
280
- }
279
+ },
280
+ discretionary_data: {hair_color: "red"}
281
281
  )
282
282
 
283
283
  r = PayTrace::API::Request.new
@@ -290,7 +290,7 @@ describe PayTrace::Transaction do
290
290
  url.must_match /\|EMAIL~it@paytrace.com\|/
291
291
  url.must_match /\|RETURNCLR~Y\|/
292
292
  url.must_match /\|ENABLEPARTIALAUTH~Y\|/
293
- url.must_match /\|DISCRETIONARY DATA~This is some data that is discretionary\|/
293
+ url.must_match /\|hair_color~red\|/
294
294
  url.must_match /\|CUSTOMDBA~NewName\|/
295
295
  end
296
296
 
@@ -0,0 +1,90 @@
1
+ require 'paytrace'
2
+
3
+ # see: http://help.paytrace.com/api-email-receipt for details
4
+
5
+ #
6
+ # Helper that loops through the response values and dumps them out
7
+ #
8
+ def dump_response_values(response)
9
+ if(response.has_errors?)
10
+ response.errors.each do |key, value|
11
+ puts "#{key.ljust(20)}#{value}"
12
+ end
13
+ else
14
+ response.values.each do |key, value|
15
+ puts "#{key.ljust(20)}#{value}"
16
+ end
17
+ end
18
+ end
19
+
20
+ def log(msg)
21
+ puts ">>>>>> #{msg}"
22
+ end
23
+
24
+ PayTrace.configure do |config|
25
+ config.user_name = "demo123"
26
+ config.password = "demo123"
27
+ config.domain = "stage.paytrace.com"
28
+ end
29
+
30
+ # this should be a valid credit card number (it can be a "sandbox" number, however)
31
+ cc = PayTrace::CreditCard.new({
32
+ card_number: "4111111111111111",
33
+ expiration_month: 12,
34
+ expiration_year: 2014
35
+ })
36
+ ba = PayTrace::Address.new({
37
+ name: "John Doe",
38
+ street: "1234 Main Street",
39
+ street2: "Apartment 1B",
40
+ city: "Shoreline",
41
+ state: "WA",
42
+ country: "US",
43
+ postal_code: "98133",
44
+ address_type: :billing
45
+ })
46
+ extra = {
47
+ email: "support@paytrace.com",
48
+ phone: "206-555-1212",
49
+ fax: "206-555-1313",
50
+ password: "foxtrot123",
51
+ account_number: 123456789,
52
+ routing_number: 12345678,
53
+ discretionary_data: "Discretionary data."
54
+ }
55
+
56
+ PayTrace::API::Gateway.debug = true
57
+
58
+ begin
59
+ log "Attempting to remove existing customer 'john_doe'..."
60
+ c = PayTrace::Customer.new("john_doe")
61
+ c.delete()
62
+ rescue PayTrace::Exceptions::ErrorResponse
63
+ log "No such cusomter... continuing..."
64
+ end
65
+
66
+ log "Creating customer john_doe..."
67
+ c = PayTrace::Customer.from_cc_info({customer_id: "john_doe", credit_card: cc, billing_address: ba}.merge(extra))
68
+ log "Customer ID: #{c.id}"
69
+ dump_response_values(PayTrace::API::Gateway.last_response)
70
+
71
+ log "Creating recurrence for john_doe..."
72
+ params = {
73
+ customer_id: "john_doe",
74
+ recur_frequency: "3",
75
+ recur_start: "4/22/2016",
76
+ recur_count: 999,
77
+ amount: 9.99,
78
+ transaction_type: "sale",
79
+ description: "Recurring transaction",
80
+ recur_receipt: "Y",
81
+ recur_type: "A"
82
+ }
83
+ recur_id = PayTrace::RecurringTransaction.create(params)
84
+ puts ">>>>>>> Recurrence ID: #{recur_id}"
85
+
86
+ log "Deleting recurrence #{recur_id}..."
87
+ PayTrace::RecurringTransaction.delete({recur_id: recur_id})
88
+
89
+ log "Deleting customer 'john_doe'..."
90
+ c.delete()
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paytrace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trevor Redfern
@@ -139,6 +139,7 @@ files:
139
139
  - test/paytrace/transaction_spec.rb
140
140
  - test/scripts/run_create_customer.rb
141
141
  - test/scripts/run_email_request.rb
142
+ - test/scripts/run_recur_payments_integration.rb
142
143
  - test/test_helper.rb
143
144
  - vagrant-bootstrap.sh
144
145
  homepage: http://github.com/PayTrace/paytrace_ruby
@@ -180,4 +181,5 @@ test_files:
180
181
  - test/paytrace/transaction_spec.rb
181
182
  - test/scripts/run_create_customer.rb
182
183
  - test/scripts/run_email_request.rb
184
+ - test/scripts/run_recur_payments_integration.rb
183
185
  - test/test_helper.rb