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
@@ -1,4 +1,4 @@
1
1
  module PayTrace
2
2
  # Version number
3
- VERSION = "0.1.23"
3
+ VERSION = "1.0.0"
4
4
  end
data/lib/paytrace.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require "paytrace/version"
2
2
  require "paytrace/configuration"
3
- require "paytrace/credit_card"
4
3
  require "paytrace/customer"
5
4
  require "paytrace/transaction"
6
5
  require "paytrace/email_receipt_request"
@@ -12,6 +11,3 @@ require 'paytrace/exceptions'
12
11
  require 'paytrace/recurring_transaction'
13
12
  require 'paytrace/check_transaction'
14
13
  require 'paytrace/batch_operations'
15
-
16
- module PayTrace
17
- end
data/paytrace.gemspec CHANGED
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "guard", '~> 0'
27
27
  spec.add_development_dependency "guard-minitest", '~> 0'
28
28
  spec.add_development_dependency "ruby_gntp", '~> 0'
29
+ spec.add_development_dependency "simplecov", "~> 0.7.1"
29
30
  end
@@ -0,0 +1,15 @@
1
+ #!/bin/sh
2
+
3
+ ruby test/scripts/run_adjust_amount.rb
4
+ ruby test/scripts/run_change_password.rb
5
+ ruby test/scripts/run_email_request.rb
6
+ ruby test/scripts/run_export_transactions.rb
7
+ ruby test/scripts/run_settle_transaction.rb
8
+ ruby test/scripts/run_attach_signature.rb
9
+ ruby test/scripts/run_check_transactions.rb
10
+ ruby test/scripts/run_export_batches.rb
11
+ ruby test/scripts/run_level3_data.rb
12
+ ruby test/scripts/run_calculate_shipping_costs.rb
13
+ ruby test/scripts/run_create_customer.rb
14
+ ruby test/scripts/run_export_customers.rb
15
+ ruby test/scripts/run_recur_payments_integration.rb
@@ -83,6 +83,14 @@ describe PayTrace::API::Gateway do
83
83
  faraday.verify_stubbed_calls
84
84
  end
85
85
 
86
+ it "includes the last response object" do
87
+ PayTrace::API::Gateway.debug = true
88
+ request = PayTrace::API::Request.new
89
+ gateway = PayTrace::API::Gateway.new
90
+ response = gateway.send_request(request)
91
+ PayTrace::API::Gateway.last_response_object.must_equal response
92
+ end
93
+
86
94
  it "raises an ErrorResponse exception for errors" do
87
95
  PayTrace::API::Gateway.debug = true # to enable mock response
88
96
  PayTrace::API::Gateway.raise_exceptions = true
@@ -24,40 +24,96 @@ describe PayTrace::API::Request do
24
24
  to_url.must_equal "UN~request_test|PSWD~request_password|TERMS~Y|"
25
25
  end
26
26
 
27
- it "can manually set params" do
28
- r = PayTrace::API::Request.new
29
- r.set_param(:billing_name, "Fred Jones")
30
- r.params[:billing_name].must_equal ["Fred Jones"]
31
- end
27
+ describe "#set_param" do
28
+ it "can manually set params" do
29
+ r = PayTrace::API::Request.new
30
+ r.set_param(:billing_name, "Fred Jones")
31
+ r.params[:billing_name].must_equal ["Fred Jones"]
32
+ end
32
33
 
33
- it "can bulk set params" do
34
- params = {billing_name: "Fred Jones", billing_postal_code: 98133}
35
- r = PayTrace::API::Request.new
36
- r.set_params([:billing_name, :billing_postal_code], params)
37
- r.params[:billing_name].must_equal ["Fred Jones"]
38
- r.params[:billing_postal_code].must_equal [98133]
39
- end
34
+ it "invokes set_request on values sent to set_param" do
35
+ request = PayTrace::API::Request.new
40
36
 
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
37
+ mock = MiniTest::Mock.new
38
+ mock.expect(:nil?, false)
39
+ mock.expect(:set_request, nil, [request])
48
40
 
49
- it "raises a validation exception for unknown fields" do
50
- r = PayTrace::API::Request.new
41
+ request.set_param(:billing_name, mock)
42
+ end
43
+
44
+ it "correctly sets a value named :discretionary_data as discretionary data" do
45
+ r = PayTrace::API::Request.new
46
+ r.set_param(:discretionary_data, {hair_color: 'red'})
47
+
48
+ r.params[:discretionary_data].must_equal nil
49
+ r.discretionary_data[:hair_color].must_equal 'red'
50
+ end
51
+
52
+ it "properly appends discretionary data" do
53
+ r = PayTrace::API::Request.new
54
+ r.set_param(:billing_name, "Fred Jones")
55
+ r.set_discretionary(:hair_color, "red")
56
+
57
+ r.to_parms_string.must_equal "UN~#{PayTrace.configuration.user_name}|PSWD~#{PayTrace.configuration.password}|TERMS~Y|" +
58
+ "BNAME~Fred Jones|hair_color~red|"
59
+ end
60
+
61
+ it "raises a validation exception for unknown fields" do
62
+ r = PayTrace::API::Request.new
51
63
 
52
- -> { r.set_param(:foo, "bar") }.must_raise PayTrace::Exceptions::ValidationError
64
+ -> { r.set_param(:foo, "bar") }.must_raise PayTrace::Exceptions::ValidationError
65
+ end
53
66
  end
54
67
 
55
- it "properly appends discretionary data" do
56
- r = PayTrace::API::Request.new
57
- r.set_param(:billing_name, "Fred Jones")
58
- r.set_discretionary(:hair_color, "red")
68
+ describe "#set_params" do
69
+ it "can bulk set params" do
70
+ params = {billing_name: "Fred Jones", billing_postal_code: 98133}
71
+ r = PayTrace::API::Request.new
72
+ r.set_params(params, [:billing_name, :billing_postal_code])
73
+ r.params[:billing_name].must_equal ["Fred Jones"]
74
+ r.params[:billing_postal_code].must_equal [98133]
75
+ end
76
+
77
+ it "can alias parameters in set_params" do
78
+ params = {name: "Ron Jones", postal_code: 98134}
79
+ r = PayTrace::API::Request.new
80
+ r.set_params(params, [[:billing_name, :name], [:billing_postal_code, :postal_code]])
81
+ r.params[:billing_name].must_equal ["Ron Jones"]
82
+ r.params[:billing_postal_code].must_equal [98134]
83
+ end
84
+
85
+ it "attempts to fetch parameter values from an object if supplied" do
86
+ mock = MiniTest::Mock.new
87
+
88
+ mock.expect(:is_a?, false, [Hash])
89
+ mock.expect(:send, "1234 Fake Ave.", [:send, :billing_address])
90
+
91
+ r = PayTrace::API::Request.new
92
+ r.set_params(mock, [:billing_address])
93
+ mock.verify
94
+ r.params[:billing_address].must_equal ["1234 Fake Ave."]
95
+ end
96
+
97
+ it "raises an exception for missing required parameters" do
98
+ params = {}
99
+ r = PayTrace::API::Request.new
100
+
101
+ -> { r.set_params(params, [:billing_name]) }.must_raise PayTrace::Exceptions::ValidationError
102
+ end
59
103
 
60
- r.to_parms_string.must_equal "UN~#{PayTrace.configuration.user_name}|PSWD~#{PayTrace.configuration.password}|TERMS~Y|" +
61
- "BNAME~Fred Jones|hair_color~red|"
104
+ it "raises an exception for extra unrecognized parameters" do
105
+ params = {billing_name: "1234 Fake Blvd."}
106
+ r = PayTrace::API::Request.new
107
+
108
+ -> { r.set_params(params, []) }.must_raise PayTrace::Exceptions::ValidationError
109
+ end
110
+
111
+ it "does not raise an exception for optional parameters" do
112
+ params = {billing_address: "1234 Fake St."}
113
+ r = PayTrace::API::Request.new
114
+
115
+ # MiniTest does not have a "wont_raise" predicate, but an exception is the same as failure...
116
+ r.set_params(params, [], [:billing_address])
117
+ end
62
118
  end
63
119
  end
@@ -5,7 +5,7 @@ describe PayTrace::API::Response do
5
5
  it "parses a successful transaction response" do
6
6
  from_server = "RESPONSE~101. Your transaction was successfully approved.|TRANSACTIONID~93|APPCODE~TAS671|APPMSG~APPROVAL TAS671 - Approved and completed|AVSRESPONSE~0|CSCRESPONSE~|"
7
7
  response = PayTrace::API::Response.new(from_server)
8
- response.response_code.must_equal "101. Your transaction was successfully approved."
8
+ response.get_response().must_equal "101. Your transaction was successfully approved."
9
9
  end
10
10
 
11
11
  it "parses multiple error responses" do
@@ -24,7 +24,7 @@ describe PayTrace::API::Response do
24
24
  from_server ="ERROR~35. Please provide a valid Credit Card Number.|ERROR~43. Please provide a valid Expiration Month.|"
25
25
  response = PayTrace::API::Response.new(from_server)
26
26
  actual ="35. Please provide a valid Credit Card Number.,43. Please provide a valid Expiration Month.,"
27
- response.response_code.must_equal actual
27
+ response.get_response().must_equal actual
28
28
  end
29
29
 
30
30
 
@@ -10,16 +10,16 @@ describe PayTrace::BatchOperations do
10
10
  PayTrace::API::Gateway.reset_trace()
11
11
  end
12
12
 
13
- describe "exportSingle" do
13
+ describe "export_single" do
14
14
  it "generates the correct request" do
15
15
  PayTrace::API::Gateway.next_response = "RESULT~Ok"
16
- result = PayTrace::BatchOperations.exportSingle()
16
+ result = PayTrace::BatchOperations.export_single()
17
17
  PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::BatchOperations::EXPORT_SINGLE_METHOD)
18
18
  end
19
19
 
20
20
  it "accepts an optional batch number" do
21
21
  PayTrace::API::Gateway.next_response = "RESULT~Ok"
22
- result = PayTrace::BatchOperations.exportSingle(batch_number: 12345)
22
+ result = PayTrace::BatchOperations.export_single(batch_number: 12345)
23
23
  PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::BatchOperations::EXPORT_SINGLE_METHOD) + "BATCHNUMBER~12345|"
24
24
  end
25
25
  end
@@ -27,7 +27,7 @@ describe PayTrace::BatchOperations do
27
27
  describe "exportMultiple" do
28
28
  it "generates the correct request" do
29
29
  PayTrace::API::Gateway.next_response = "RESULT~Ok"
30
- result = PayTrace::BatchOperations.exportMultiple(start_date: "03/01/2014", end_date: "06/01/2014")
30
+ result = PayTrace::BatchOperations.export_multiple(start_date: "03/01/2014", end_date: "06/01/2014")
31
31
  PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::BatchOperations::EXPORT_MULTIPLE_METHOD) +
32
32
  "SDATE~03/01/2014|EDATE~06/01/2014|"
33
33
  end
@@ -36,7 +36,7 @@ describe PayTrace::BatchOperations do
36
36
  describe "exportDetails" do
37
37
  it "generates the correct request" do
38
38
  PayTrace::API::Gateway.next_response = "RESULT~Ok"
39
- result = PayTrace::BatchOperations.exportDetails(batch_number: 12346)
39
+ result = PayTrace::BatchOperations.export_details(batch_number: 12346)
40
40
  PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::BatchOperations::EXPORT_DETAILS_METHOD) + "BATCHNUMBER~12346|"
41
41
  end
42
42
  end
@@ -21,9 +21,8 @@ describe PayTrace::CheckTransaction do
21
21
  account_number: 1234567,
22
22
  routing_number: 1234568
23
23
  }
24
- result = PayTrace::CheckTransaction.process_sale(params)
25
- PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::CheckTransaction::PROCESS_SALE_METHOD) +
26
- "CHECKTYPE~foo|AMOUNT~17.29|DDA~1234567|TR~1234568|"
24
+ result = PayTrace::CheckTransaction.sale(params)
25
+ assert_last_request_equals "METHOD~ProcessCheck|CHECKTYPE~foo|AMOUNT~17.29|DDA~1234567|TR~1234568|"
27
26
  end
28
27
 
29
28
  # UN, PSWD, TERMS, METHOD, CHECKTYPE, AMOUNT, CUSTID
@@ -34,9 +33,8 @@ describe PayTrace::CheckTransaction do
34
33
  amount: 17.28,
35
34
  customer_id: 'MMouse'
36
35
  }
37
- result = PayTrace::CheckTransaction.process_sale(params)
38
- PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::CheckTransaction::PROCESS_SALE_METHOD) +
39
- "CHECKTYPE~bar|AMOUNT~17.28|CUSTID~MMouse|"
36
+ result = PayTrace::CheckTransaction.customer_id_sale(params)
37
+ assert_last_request_equals "METHOD~ProcessCheck|CHECKTYPE~bar|AMOUNT~17.28|CUSTID~MMouse|"
40
38
  end
41
39
 
42
40
 
@@ -73,7 +71,7 @@ describe PayTrace::CheckTransaction do
73
71
  shipping_address: sa
74
72
  }
75
73
 
76
- result = PayTrace::CheckTransaction.process_sale(params)
74
+ result = PayTrace::CheckTransaction.customer_id_sale(params)
77
75
  PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::CheckTransaction::PROCESS_SALE_METHOD) +
78
76
  "CHECKTYPE~baz|AMOUNT~17.29|CUSTID~DDuck|BNAME~John Doe|BADDRESS~1234 Main Street|BADDRESS2~Apartment 1B|BCITY~Shoreline|BSTATE~WA|BZIP~98133|BCOUNTRY~US|SNAME~Jane Doe|SADDRESS~1235 Moon Street|SADDRESS2~Apartment 2C|SCITY~Shortline|SSTATE~WA|SZIP~98134|SCOUNTRY~US|"
79
77
  end
@@ -83,6 +81,7 @@ describe PayTrace::CheckTransaction do
83
81
  PayTrace::API::Gateway.next_response = "RESULT~Ok"
84
82
 
85
83
  params = {
84
+ check_type: 'foo',
86
85
  email: 'foo@bar.com',
87
86
  description: 'You bought something with a check, yo!',
88
87
  invoice: '12345',
@@ -91,10 +90,9 @@ describe PayTrace::CheckTransaction do
91
90
  tax_amount: 2.11,
92
91
  customer_reference_id: '1234AB'
93
92
  }
94
- result = PayTrace::CheckTransaction.process_sale(params)
93
+ result = PayTrace::CheckTransaction.customer_id_sale(params)
95
94
 
96
- PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::CheckTransaction::PROCESS_SALE_METHOD) +
97
- "AMOUNT~17.27|CUSTID~YosemiteSam|EMAIL~foo@bar.com|INVOICE~12345|DESCRIPTION~You bought something with a check, yo!|TAX~2.11|CUSTREF~1234AB|"
95
+ assert_last_request_equals "METHOD~ProcessCheck|CHECKTYPE~foo|AMOUNT~17.27|CUSTID~YosemiteSam|EMAIL~foo@bar.com|INVOICE~12345|DESCRIPTION~You bought something with a check, yo!|TAX~2.11|CUSTREF~1234AB|"
98
96
  end
99
97
 
100
98
  it "accepts discretionary data" do
@@ -107,10 +105,9 @@ describe PayTrace::CheckTransaction do
107
105
  routing_number: 1234568,
108
106
  discretionary_data: {hair_color: :red}
109
107
  }
110
- result = PayTrace::CheckTransaction.process_sale(params)
108
+ result = PayTrace::CheckTransaction.sale(params)
111
109
 
112
- PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::CheckTransaction::PROCESS_SALE_METHOD) +
113
- "CHECKTYPE~foo|AMOUNT~17.29|DDA~1234567|TR~1234568|hair_color~red|"
110
+ assert_last_request_equals "METHOD~ProcessCheck|CHECKTYPE~foo|AMOUNT~17.29|DDA~1234567|TR~1234568|hair_color~red|"
114
111
  end
115
112
  end
116
113
 
@@ -125,10 +122,10 @@ describe PayTrace::CheckTransaction do
125
122
  routing_number: 1234568,
126
123
  discretionary_data: {hair_color: :red}
127
124
  }
128
- result = PayTrace::CheckTransaction.process_hold(params)
125
+ result = PayTrace::CheckTransaction.hold(params)
129
126
 
130
127
  PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::CheckTransaction::PROCESS_SALE_METHOD) +
131
- "AMOUNT~17.29|DDA~1234567|TR~1234568|CHECKTYPE~Hold|hair_color~red|"
128
+ "CHECKTYPE~Hold|AMOUNT~17.29|DDA~1234567|TR~1234568|hair_color~red|"
132
129
  end
133
130
 
134
131
  describe "refund transactions" do
@@ -136,12 +133,36 @@ describe PayTrace::CheckTransaction do
136
133
  PayTrace::API::Gateway.next_response = "RESULT~Ok"
137
134
  params = {
138
135
  check_type: 'foo',
139
- check_id: 12345678
136
+ amount: 19.99,
137
+ routing_number: 325081403,
138
+ account_number: 1234567890
139
+ }
140
+ result = PayTrace::CheckTransaction.refund(params)
141
+
142
+ assert_last_request_equals "METHOD~ProcessCheck|CHECKTYPE~Refund|AMOUNT~19.99|DDA~1234567890|TR~325081403|"
143
+ end
144
+
145
+ it "accepts a customer ID" do
146
+ PayTrace::API::Gateway.next_response = "RESULT~Ok"
147
+ params = {
148
+ check_type: 'foo',
149
+ amount: 19.99,
150
+ customer_id: 1234
151
+ }
152
+ result = PayTrace::CheckTransaction.refund_by_customer_id(params)
153
+
154
+ assert_last_request_equals "METHOD~ProcessCheck|CHECKTYPE~Refund|AMOUNT~19.99|CUSTID~1234|"
155
+ end
156
+
157
+ it "accepts a check ID" do
158
+ PayTrace::API::Gateway.next_response = "RESULT~Ok"
159
+ params = {
160
+ check_type: 'foo',
161
+ check_id: 1235
140
162
  }
141
- result = PayTrace::CheckTransaction.process_refund(params)
163
+ result = PayTrace::CheckTransaction.refund_existing_check_id(params)
142
164
 
143
- PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::CheckTransaction::PROCESS_SALE_METHOD) +
144
- "CHECKID~12345678|CHECKTYPE~Refund|"
165
+ assert_last_request_equals "METHOD~ProcessCheck|CHECKTYPE~Refund|CHECKID~1235|"
145
166
  end
146
167
  end
147
168
 
@@ -1,10 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '../../test_helper.rb')
2
2
 
3
3
  describe PayTrace::Customer do
4
- def base_url
5
- "UN~#{PayTrace.configuration.user_name}|PSWD~#{PayTrace.configuration.password}|TERMS~Y|"
6
- end
7
-
8
4
  before do
9
5
  PayTrace::API::Gateway.debug = true
10
6
  PayTrace::API::Gateway.next_response = "RESPONSE~ok|CUSTOMERID~12345|CUSTID~john_doe"
@@ -15,7 +11,7 @@ describe PayTrace::Customer do
15
11
  PayTrace::API::Gateway.next_response = "CUSTOMERRECORD~CUSTID=741356+CUSTOMERID=741356+CC=************5454+EXPMNTH=12+EXPYR=17+SNAME=+SADDRESS=+SADDRESS2=+SCITY=+SCOUNTY=+SSTATE=+SZIP=+SCOUNTRY=US+BNAME=DUMMY1+BADDRESS=+BADDRESS2=+BCITY=+BSTATE=+BZIP=+BCOUNTRY=US+EMAIL=+PHONE=+FAX=+WHEN=2/7/2014 5:02:08 PM+USER=demo123+IP=131.191.89.5+DDA=123412341234+TR=051000017+hair_color=+|"
16
12
  records = PayTrace::Customer.export()
17
13
 
18
- PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~ExportCustomers|"
14
+ assert_last_request_equals "METHOD~ExportCustomers|"
19
15
  records.count.must_equal 1
20
16
  records.must_be_instance_of Array
21
17
  records[0].must_be_instance_of Hash
@@ -26,7 +22,7 @@ describe PayTrace::Customer do
26
22
  PayTrace::API::Gateway.next_response = "CUSTOMERRECORD~CUSTID=12345+BNAME=John Doe+LASTTRANX=01/01/2014+LASTCHECK=02/01/2014+WHEN=03/01/2014"
27
23
  records = PayTrace::Customer.export_inactive({days_inactive: 30})
28
24
 
29
- PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~ExportInactiveCustomers|DAYS~30|"
25
+ assert_last_request_equals "METHOD~ExportInactiveCustomers|DAYS~30|"
30
26
  records.count.must_equal 1
31
27
  records.must_be_instance_of Array
32
28
  records[0].must_be_instance_of Hash
@@ -38,75 +34,63 @@ describe PayTrace::Customer do
38
34
  describe "create customer profile" do
39
35
  # first call path: create from credit card information
40
36
  it "can be created from credit card information" do
41
- credit_card = PayTrace::CreditCard.new({card_number: "1234123412341234", expiration_month: 12, expiration_year: 2014})
42
- billing_addr = PayTrace::Address.new({name: "Foo Bar", address_type: :billing})
43
-
44
- PayTrace::Customer.from_cc_info({customer_id: "foo_bar", credit_card: credit_card, billing_address: billing_addr})
45
- PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~CreateCustomer|CUSTID~foo_bar|BNAME~Foo Bar|CC~1234123412341234|EXPMNTH~12|EXPYR~2014|"
37
+ params = {
38
+ customer_id: "foo_bar",
39
+ billing_name: "Foo Bar",
40
+ card_number: "1234123412341234",
41
+ expiration_month: 12,
42
+ expiration_year: 2014
43
+ }
44
+ PayTrace::Customer.from_cc_info(params)
45
+ assert_last_request_equals "METHOD~CreateCustomer|CUSTID~foo_bar|BNAME~Foo Bar|CC~1234123412341234|EXPMNTH~12|EXPYR~2014|"
46
46
  end
47
47
 
48
48
  # second call path: create from a transaction ID
49
49
  it "can be created from a transaction ID" do
50
50
  PayTrace::Customer.from_transaction_id({customer_id: "foo_bar", transaction_id: 12345678})
51
- PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~CreateCustomer|CUSTID~foo_bar|TRANXID~12345678|"
51
+ assert_last_request_equals "METHOD~CreateCustomer|CUSTID~foo_bar|TRANXID~12345678|"
52
52
  end
53
53
 
54
54
  # all billing address fields are accepted
55
55
  it "accepts full billing address information" do
56
- credit_card = PayTrace::CreditCard.new({card_number: "1234123412341234", expiration_month: 12, expiration_year: 2014})
57
- billing_addr = PayTrace::Address.new({
58
- name: "Foo Bar",
59
- street: "1234 Main Street",
60
- street2: "Apartment 1B",
61
- city: "Shoreline",
62
- state: "WA",
63
- country: "USA",
64
- postal_code: 98133,
65
- address_type: :billing
66
- })
67
-
68
- PayTrace::Customer.from_cc_info({customer_id: "foo_bar", credit_card: credit_card, billing_address: billing_addr})
69
- PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~CreateCustomer|CUSTID~foo_bar|BNAME~Foo Bar|BADDRESS~1234 Main Street|" +
56
+ params = {
57
+ customer_id: "foo_bar",
58
+ billing_name: "Foo Bar",
59
+ billing_address: "1234 Main Street",
60
+ billing_address2: "Apartment 1B",
61
+ billing_city: "Shoreline",
62
+ billing_state: "WA",
63
+ billing_country: "USA",
64
+ billing_postal_code: 98133,
65
+ card_number: "1234123412341234",
66
+ expiration_month: 12,
67
+ expiration_year: 2014
68
+ }
69
+
70
+ PayTrace::Customer.from_cc_info(params)
71
+ assert_last_request_equals "METHOD~CreateCustomer|CUSTID~foo_bar|BNAME~Foo Bar|BADDRESS~1234 Main Street|" +
70
72
  "BADDRESS2~Apartment 1B|BCITY~Shoreline|BSTATE~WA|BZIP~98133|BCOUNTRY~USA|" +
71
73
  "CC~1234123412341234|EXPMNTH~12|EXPYR~2014|"
72
74
  end
73
75
 
74
76
  # you can include a shipping address, too
75
77
  it "accepts a shipping address" do
76
- shipping_addr = PayTrace::Address.new({
77
- name: "Foo Bar",
78
- street: "1234 Main Street",
79
- street2: "Apartment 1B",
80
- city: "Shoreline",
81
- state: "WA",
82
- region: "Snohomish",
83
- country: "USA",
84
- postal_code: 98133,
85
- address_type: :shipping
86
- })
87
-
88
- PayTrace::Customer.from_transaction_id({customer_id: "foo_bar", transaction_id: 12345678, shipping_address: shipping_addr})
89
- PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~CreateCustomer|CUSTID~foo_bar|TRANXID~12345678|SNAME~Foo Bar|SADDRESS~1234 Main Street|" +
90
- "SADDRESS2~Apartment 1B|SCITY~Shoreline|SCOUNTY~Snohomish|SSTATE~WA|SZIP~98133|SCOUNTRY~USA|"
91
- end
78
+ params = {
79
+ customer_id: "foo_bar",
80
+ transaction_id: 12345678,
81
+ shipping_name: "Foo Bar",
82
+ shipping_address: "1234 Main Street",
83
+ shipping_address2: "Apartment 1B",
84
+ shipping_city: "Shoreline",
85
+ shipping_state: "WA",
86
+ shipping_region: "Snohomish",
87
+ shipping_country: "USA",
88
+ shipping_postal_code: 98133
89
+ }
92
90
 
93
- # special case: when creating from transaction ID, the billing name is ignored (no clue why, but it's in the API)
94
- it "ignores the billing address name if using a transaction id" do
95
- billing_addr = PayTrace::Address.new({
96
- name: "Foo Bar",
97
- street: "1234 Main Street",
98
- street2: "Apartment 1B",
99
- city: "Shoreline",
100
- state: "WA",
101
- region: "region",
102
- country: "USA",
103
- postal_code: 98133,
104
- address_type: :billing
105
- })
106
-
107
- PayTrace::Customer.from_transaction_id({customer_id: "foo_bar", transaction_id: 12345678, billing_address: billing_addr})
108
- PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~CreateCustomer|CUSTID~foo_bar|TRANXID~12345678|BADDRESS~1234 Main Street|" +
109
- "BADDRESS2~Apartment 1B|BCITY~Shoreline|BSTATE~WA|BZIP~98133|BCOUNTRY~USA|"
91
+ PayTrace::Customer.from_transaction_id(params)
92
+ assert_last_request_equals "METHOD~CreateCustomer|CUSTID~foo_bar|TRANXID~12345678|SNAME~Foo Bar|SADDRESS~1234 Main Street|" +
93
+ "SADDRESS2~Apartment 1B|SCITY~Shoreline|SCOUNTY~Snohomish|SSTATE~WA|SZIP~98133|SCOUNTRY~USA|"
110
94
  end
111
95
 
112
96
  # there are additional fields (email, phone, discretionary data, etc.) that can be sent
@@ -115,8 +99,8 @@ describe PayTrace::Customer do
115
99
  customer_id: "foo_bar",
116
100
  transaction_id: 12345678,
117
101
  email: "support@paytrace.com",
118
- phone: "123-555-1212",
119
- fax: "456-555-1212",
102
+ customer_phone: "123-555-1212",
103
+ customer_fax: "456-555-1212",
120
104
  customer_password: "none_shall_pass",
121
105
  account_number: 123456789,
122
106
  routing_number: 12345678,
@@ -124,7 +108,7 @@ describe PayTrace::Customer do
124
108
  }
125
109
 
126
110
  PayTrace::Customer.from_transaction_id(params)
127
- PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~CreateCustomer|CUSTID~foo_bar|TRANXID~12345678|EMAIL~support@paytrace.com|" +
111
+ assert_last_request_equals "METHOD~CreateCustomer|CUSTID~foo_bar|TRANXID~12345678|EMAIL~support@paytrace.com|" +
128
112
  "PHONE~123-555-1212|FAX~456-555-1212|CUSTPSWD~none_shall_pass|DDA~123456789|TR~12345678|" +
129
113
  "hair_color~red|"
130
114
  end
@@ -132,80 +116,72 @@ describe PayTrace::Customer do
132
116
 
133
117
  describe "update customer profile" do
134
118
  it "accepts a billing address" do
135
- billing_addr = PayTrace::Address.new({
136
- name: "Foo Bar",
137
- street: "1234 Main Street",
138
- street2: "Apartment 1B",
139
- city: "Shoreline",
140
- state: "WA",
141
- region: "region",
142
- country: "USA",
143
- postal_code: 98133,
144
- address_type: :billing
145
- })
146
-
147
- c = PayTrace::Customer.new
148
- c.update({new_customer_id: "joanie_doe", billing_address: billing_addr})
149
-
150
- PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~UpdateCustomer|NEWCUSTID~joanie_doe|" +
119
+ params = {
120
+ customer_id: "john doe",
121
+ new_customer_id: "joanie_doe",
122
+ billing_name: "Foo Bar",
123
+ billing_address: "1234 Main Street",
124
+ billing_address2: "Apartment 1B",
125
+ billing_city: "Shoreline",
126
+ billing_state: "WA",
127
+ billing_country: "USA",
128
+ billing_postal_code: 98133
129
+ }
130
+
131
+ PayTrace::Customer.update(params)
132
+
133
+ assert_last_request_equals "METHOD~UpdateCustomer|CUSTID~john doe|" +
151
134
  "BNAME~Foo Bar|BADDRESS~1234 Main Street|" +
152
- "BADDRESS2~Apartment 1B|BCITY~Shoreline|BSTATE~WA|BZIP~98133|BCOUNTRY~USA|"
135
+ "BADDRESS2~Apartment 1B|BCITY~Shoreline|BSTATE~WA|BZIP~98133|BCOUNTRY~USA|NEWCUSTID~joanie_doe|"
153
136
  end
154
137
 
155
138
  it "accepts a shipping address" do
156
- shipping_addr = PayTrace::Address.new({
157
- name: "Foo Bar",
158
- street: "1234 Main Street",
159
- street2: "Apartment 1B",
160
- city: "Shoreline",
161
- state: "WA",
162
- region: "Snohomish",
163
- country: "USA",
164
- postal_code: 98133,
165
- address_type: :shipping
166
- })
167
-
168
- c = PayTrace::Customer.new
169
- c.update({new_customer_id: "joanie_doe", shipping_address: shipping_addr})
170
-
171
- PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~UpdateCustomer|NEWCUSTID~joanie_doe|" +
139
+ params = {
140
+ customer_id: "john doe",
141
+ new_customer_id: "joanie_doe",
142
+ shipping_name: "Foo Bar",
143
+ shipping_address: "1234 Main Street",
144
+ shipping_address2: "Apartment 1B",
145
+ shipping_city: "Shoreline",
146
+ shipping_state: "WA",
147
+ shipping_region: "Snohomish",
148
+ shipping_country: "USA",
149
+ shipping_postal_code: 98133
150
+ }
151
+
152
+ PayTrace::Customer.update(params)
153
+
154
+ assert_last_request_equals "METHOD~UpdateCustomer|CUSTID~john doe|" +
172
155
  "SNAME~Foo Bar|SADDRESS~1234 Main Street|SADDRESS2~Apartment 1B|SCITY~Shoreline|SCOUNTY~Snohomish|" +
173
- "SSTATE~WA|SZIP~98133|SCOUNTRY~USA|"
156
+ "SSTATE~WA|SZIP~98133|SCOUNTRY~USA|NEWCUSTID~joanie_doe|"
174
157
  end
175
158
 
176
159
  it "accepts extra customer information" do
177
160
  params = {
161
+ customer_id: "bar_foo",
178
162
  new_customer_id: "foo_bar",
179
163
  email: "support@paytrace.com",
180
- phone: "123-555-1212",
181
- fax: "456-555-1212",
164
+ customer_phone: "123-555-1212",
165
+ customer_fax: "456-555-1212",
182
166
  customer_password: "none_shall_pass",
183
167
  account_number: 123456789,
184
168
  routing_number: 12345678,
185
169
  discretionary_data: {hair_color: "red"}
186
170
  }
187
171
 
188
- c = PayTrace::Customer.new
189
- c.update(params)
172
+ PayTrace::Customer.update(params)
190
173
 
191
- PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~UpdateCustomer|NEWCUSTID~foo_bar|" +
174
+ assert_last_request_equals "METHOD~UpdateCustomer|CUSTID~bar_foo|" +
192
175
  "EMAIL~support@paytrace.com|PHONE~123-555-1212|FAX~456-555-1212|CUSTPSWD~none_shall_pass|DDA~123456789|" +
193
- "TR~12345678|hair_color~red|"
176
+ "TR~12345678|NEWCUSTID~foo_bar|hair_color~red|"
194
177
  end
195
178
  end
196
179
 
197
180
  describe "delete customer profile" do
198
- it "works with an instantiated Customer object" do
199
- c = PayTrace::Customer.new("foo_bar")
200
- c.delete
201
-
202
- PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~DeleteCustomer|CUSTID~foo_bar|"
203
- end
204
-
205
181
  it "works with a static class method" do
206
182
  PayTrace::Customer.delete("foob_barb")
207
183
 
208
- PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~DeleteCustomer|CUSTID~foob_barb|"
184
+ assert_last_request_equals "METHOD~DeleteCustomer|CUSTID~foob_barb|"
209
185
  end
210
186
  end
211
187
  end