paytrace 0.0.6 → 0.0.7
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 +4 -4
- data/Guardfile +28 -0
- data/README.md +1 -1
- data/lib/paytrace.rb +2 -0
- data/lib/paytrace/address.rb +16 -2
- data/lib/paytrace/api/fields.rb +15 -2
- data/lib/paytrace/api/gateway.rb +44 -4
- data/lib/paytrace/api/request.rb +4 -3
- data/lib/paytrace/customer.rb +72 -2
- data/lib/paytrace/exceptions.rb +12 -0
- data/lib/paytrace/recurring_transaction.rb +57 -0
- data/lib/paytrace/transaction.rb +22 -44
- data/lib/paytrace/version.rb +1 -1
- data/paytrace.gemspec +2 -0
- data/test/paytrace/address_spec.rb +65 -0
- data/test/paytrace/api/gateway_spec.rb +86 -12
- data/test/paytrace/api/request_spec.rb +8 -2
- data/test/paytrace/customer_spec.rb +186 -0
- data/test/paytrace/exceptions_spec.rb +3 -0
- data/test/paytrace/recurring_transaction_spec.rb +117 -0
- data/test/paytrace/transaction_spec.rb +4 -4
- data/test/scripts/run_create_customer.rb +55 -0
- data/test/scripts/run_email_request.rb +36 -0
- metadata +46 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae74bece9567072735235bb13c243480933eb2ad
|
4
|
+
data.tar.gz: f9a82b0cb1cecd8357cef85dc7b103de8dc52f2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4093411b2ecb7a0166affcab5ddbc0296de3d594695dabe4f6ca1a9a428ff5fe7bacd473657bd6b1624fe99c08aeac53f4afa38c9eeac1c2902df6a0b9a9df80
|
7
|
+
data.tar.gz: e163f38094a6034abc1739b6e12d841d7cca74c1a242bad7616831a976345252fc9a045f27085507a859e509045828154f4f2e3ce5ba079b9c34c36af5d5f7c0
|
data/Guardfile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :minitest do
|
5
|
+
# with Minitest::Unit
|
6
|
+
watch(%r{^test/(.*)\/?test_(.*)\.rb$})
|
7
|
+
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
8
|
+
watch(%r{^test/test_helper\.rb$}) { 'test' }
|
9
|
+
|
10
|
+
# with Minitest::Spec
|
11
|
+
watch(%r{^test/(.*)_spec\.rb$})
|
12
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_spec.rb" }
|
13
|
+
watch(%r{^test/test_helper\.rb$}) { 'test' }
|
14
|
+
|
15
|
+
# Rails 4
|
16
|
+
# watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
|
17
|
+
# watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' }
|
18
|
+
# watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
|
19
|
+
# watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
|
20
|
+
# watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
|
21
|
+
# watch(%r{^test/.+_test\.rb$})
|
22
|
+
# watch(%r{^test/test_helper\.rb$}) { 'test' }
|
23
|
+
|
24
|
+
# Rails < 4
|
25
|
+
# watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
|
26
|
+
# watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" }
|
27
|
+
# watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
|
28
|
+
end
|
data/README.md
CHANGED
data/lib/paytrace.rb
CHANGED
data/lib/paytrace/address.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module PayTrace
|
2
2
|
class Address
|
3
|
-
|
3
|
+
attr_accessor :name, :street,:street2,:city,:state, :country,:region,:postal_code,:address_type
|
4
4
|
|
5
5
|
def initialize(options={})
|
6
6
|
@name = options[:name]
|
@@ -8,9 +8,23 @@ module PayTrace
|
|
8
8
|
@street2 = options[:street2]
|
9
9
|
@city = options[:city]
|
10
10
|
@state = options[:state]
|
11
|
-
@region = options[:region]
|
12
11
|
@country = options[:country]
|
13
12
|
@postal_code = options[:postal_code ]
|
13
|
+
@address_type = options[:address_type] || :billing
|
14
|
+
@region = options[:region] if @address_type == :shipping # special case for shipping addresses
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_request(request)
|
18
|
+
atype_str = address_type.to_s
|
19
|
+
|
20
|
+
request.set_param(:"#{atype_str}_name", name) if name
|
21
|
+
request.set_param(:"#{atype_str}_address", street) if street
|
22
|
+
request.set_param(:"#{atype_str}_address2", street2) if street2
|
23
|
+
request.set_param(:"#{atype_str}_city", city) if city
|
24
|
+
request.set_param(:"#{atype_str}_region", region) if region
|
25
|
+
request.set_param(:"#{atype_str}_state", state) if state
|
26
|
+
request.set_param(:"#{atype_str}_postal_code", postal_code) if postal_code
|
27
|
+
request.set_param(:"#{atype_str}_country", country) if country
|
14
28
|
end
|
15
29
|
end
|
16
30
|
end
|
data/lib/paytrace/api/fields.rb
CHANGED
@@ -43,14 +43,27 @@ module PayTrace
|
|
43
43
|
shipping_country: "SCOUNTRY",
|
44
44
|
#customer
|
45
45
|
customer_id: "CUSTID",
|
46
|
+
new_customer_id: "NEWCUSTID",
|
46
47
|
customer_reference_id:"CUSTREF",
|
48
|
+
customer_password:"CUSTPSWD",
|
49
|
+
customer_fax:"FAX",
|
50
|
+
customer_phone:"PHONE",
|
47
51
|
approval_code:"APPROVAL",
|
48
52
|
#cash advance
|
49
53
|
cash_advance:"CASHADVANCE",
|
50
54
|
id_number:"PHOTOID",
|
51
55
|
id_expiration:"IDEXP",
|
52
|
-
cc_last_4:"LAST4"
|
53
|
-
|
56
|
+
cc_last_4:"LAST4",
|
57
|
+
#bank accounts
|
58
|
+
account_number:"DDA",
|
59
|
+
routing_number:"TR",
|
60
|
+
#recurring transactions
|
61
|
+
recur_id: "RECURID",
|
62
|
+
recur_frequency: "FREQUENCY",
|
63
|
+
recur_start: "START",
|
64
|
+
recur_count: "TOTALCOUNT",
|
65
|
+
recur_receipt: "CUSTRECEIPT",
|
66
|
+
recur_type: "RECURTYPE"
|
54
67
|
}
|
55
68
|
end
|
56
69
|
end
|
data/lib/paytrace/api/gateway.rb
CHANGED
@@ -1,19 +1,59 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
require 'paytrace/api/response'
|
3
|
+
require 'paytrace/exceptions'
|
3
4
|
|
4
5
|
module PayTrace
|
5
6
|
module API
|
6
7
|
class Gateway
|
7
8
|
attr_accessor :connection
|
9
|
+
@@debug = false
|
10
|
+
@@last_request = nil
|
11
|
+
@@last_response = nil
|
12
|
+
@@next_response = nil
|
13
|
+
@@raise_exceptions = true
|
8
14
|
|
9
15
|
def initialize(connection: nil)
|
10
|
-
@connection = connection
|
11
|
-
|
16
|
+
@connection = connection || PayTrace.configuration.connection
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.debug=(enable)
|
20
|
+
@@debug = enable
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.last_request
|
24
|
+
@@last_request
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.last_response
|
28
|
+
@@last_response
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.next_response=(next_response)
|
32
|
+
@@next_response = next_response
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.raise_exceptions=(raise_exceptions)
|
36
|
+
@@raise_exceptions = raise_exceptions
|
12
37
|
end
|
13
38
|
|
14
39
|
def send_request(request)
|
15
|
-
|
16
|
-
|
40
|
+
@@last_request = request.to_parms_string if @@debug
|
41
|
+
unless (@@debug && @@next_response)
|
42
|
+
res = @connection.post PayTrace.configuration.url, parmlist: request.to_parms_string
|
43
|
+
raw_response = res.body
|
44
|
+
else
|
45
|
+
raw_response = @@next_response
|
46
|
+
end
|
47
|
+
|
48
|
+
@@last_response = raw_response
|
49
|
+
response = PayTrace::API::Response.new(raw_response)
|
50
|
+
@@next_response = nil # just to be sure
|
51
|
+
|
52
|
+
if @@raise_exceptions && response.has_errors?
|
53
|
+
raise PayTrace::Exceptions::ErrorResponse.new(response.get_response())
|
54
|
+
else
|
55
|
+
response
|
56
|
+
end
|
17
57
|
end
|
18
58
|
end
|
19
59
|
end
|
data/lib/paytrace/api/request.rb
CHANGED
@@ -18,14 +18,15 @@ module PayTrace
|
|
18
18
|
|
19
19
|
def to_parms_string()
|
20
20
|
@params.map do |k,v|
|
21
|
-
"#{PayTrace::API.fields
|
21
|
+
"#{PayTrace::API.fields[k]}#{@value_delim}#{v}"
|
22
22
|
end.join(@field_delim) << "|"
|
23
23
|
end
|
24
24
|
|
25
25
|
def set_param(k, v)
|
26
|
-
|
27
|
-
end
|
26
|
+
raise PayTrace::Exceptions::ValidationError.new("Unknown field '#{k}'") unless PayTrace::API.fields.has_key?(k)
|
28
27
|
|
28
|
+
@params[k] = v unless v.nil?
|
29
|
+
end
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
data/lib/paytrace/customer.rb
CHANGED
@@ -1,10 +1,80 @@
|
|
1
1
|
module PayTrace
|
2
2
|
class Customer
|
3
|
-
|
3
|
+
attr :id, :customer_id
|
4
4
|
|
5
|
-
|
5
|
+
CREATE_CUSTOMER = "CreateCustomer"
|
6
|
+
UPDATE_CUSTOMER = "UpdateCustomer"
|
7
|
+
DELETE_CUSTOMER = "DeleteCustomer"
|
8
|
+
|
9
|
+
def initialize(customer_id = nil)
|
6
10
|
@customer_id = customer_id
|
7
11
|
end
|
12
|
+
|
13
|
+
def update(params = {})
|
14
|
+
set_request_data(UPDATE_CUSTOMER, params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete
|
18
|
+
request = PayTrace::API::Request.new
|
19
|
+
request.set_param(:method, DELETE_CUSTOMER)
|
20
|
+
request.set_param(:customer_id, @customer_id)
|
21
|
+
gateway = PayTrace::API::Gateway.new
|
22
|
+
gateway.send_request(request)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.delete(customer_id)
|
26
|
+
Customer.new(customer_id).delete
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.from_cc_info(params = {})
|
30
|
+
customer = Customer.new(params[:customer_id])
|
31
|
+
customer.set_request_data(CREATE_CUSTOMER, params)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.from_transaction_id(params = {})
|
35
|
+
customer = Customer.new(params[:customer_id])
|
36
|
+
customer.set_request_data(CREATE_CUSTOMER, params)
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_request_data(method, params)
|
40
|
+
request = PayTrace::API::Request.new
|
41
|
+
request.set_param(:method, method)
|
42
|
+
request.set_param(:customer_id, params[:customer_id])
|
43
|
+
request.set_param(:new_customer_id, params[:new_customer_id])
|
44
|
+
request.set_param(:transaction_id, params[:transaction_id])
|
45
|
+
|
46
|
+
if params[:billing_address]
|
47
|
+
params[:billing_address].name = nil if (method == CREATE_CUSTOMER && params[:transaction_id])
|
48
|
+
params[:billing_address].set_request(request)
|
49
|
+
end
|
50
|
+
params[:shipping_address].set_request(request) if params[:shipping_address]
|
51
|
+
|
52
|
+
|
53
|
+
if params[:credit_card]
|
54
|
+
request.set_param(:card_number, params[:credit_card].card_number)
|
55
|
+
request.set_param(:expiration_month, params[:credit_card].expiration_month)
|
56
|
+
request.set_param(:expiration_year, params[:credit_card].expiration_year)
|
57
|
+
end
|
58
|
+
|
59
|
+
request.set_param(:email, params[:email])
|
60
|
+
request.set_param(:customer_phone, params[:phone])
|
61
|
+
request.set_param(:customer_fax, params[:fax])
|
62
|
+
request.set_param(:customer_password, params[:customer_password])
|
63
|
+
request.set_param(:account_number, params[:account_number])
|
64
|
+
request.set_param(:routing_number, params[:routing_number])
|
65
|
+
request.set_param(:discretionary_data, params[:discretionary_data])
|
66
|
+
|
67
|
+
gateway = PayTrace::API::Gateway.new
|
68
|
+
response = gateway.send_request(request)
|
69
|
+
unless response.has_errors?
|
70
|
+
values = response.values
|
71
|
+
@id = values["CUSTID"]
|
72
|
+
@customer_id = values["CUSTOMERID"]
|
73
|
+
self
|
74
|
+
else
|
75
|
+
nil
|
76
|
+
end
|
77
|
+
end
|
8
78
|
end
|
9
79
|
end
|
10
80
|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'paytrace'
|
2
|
+
|
3
|
+
module PayTrace
|
4
|
+
class RecurringTransaction
|
5
|
+
attr :id
|
6
|
+
CREATE_METHOD = "CreateRecur"
|
7
|
+
DELETE_METHOD = "DeleteRecur"
|
8
|
+
UPDATE_METHOD = "UpdateRecur"
|
9
|
+
|
10
|
+
def self.create(params = {})
|
11
|
+
set_request_data(CREATE_METHOD, params)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.delete(params = {})
|
15
|
+
request = PayTrace::API::Request.new
|
16
|
+
request.set_param(:method, DELETE_METHOD)
|
17
|
+
if params[:recur_id]
|
18
|
+
request.set_param(:recur_id, params[:recur_id])
|
19
|
+
else
|
20
|
+
request.set_param(:customer_id, params[:customer_id])
|
21
|
+
end
|
22
|
+
|
23
|
+
gateway = PayTrace::API::Gateway.new
|
24
|
+
parse_response(gateway.send_request(request))
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.update(params = {})
|
28
|
+
set_request_data(UPDATE_METHOD, params)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.parse_response(response)
|
32
|
+
unless response.has_errors?
|
33
|
+
values = response.values
|
34
|
+
values["RECURID"]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.set_request_data(method, params)
|
39
|
+
request = PayTrace::API::Request.new
|
40
|
+
request.set_param(:method, method)
|
41
|
+
|
42
|
+
request.set_param(:recur_id, params[:recur_id])
|
43
|
+
request.set_param(:customer_id, params[:customer_id])
|
44
|
+
request.set_param(:recur_frequency, params[:recur_frequency])
|
45
|
+
request.set_param(:recur_start, params[:recur_start])
|
46
|
+
request.set_param(:recur_count, params[:recur_count])
|
47
|
+
request.set_param(:amount, params[:amount])
|
48
|
+
request.set_param(:transaction_type, params[:transaction_type])
|
49
|
+
request.set_param(:description, params[:description])
|
50
|
+
request.set_param(:recur_receipt, params[:recur_receipt])
|
51
|
+
request.set_param(:recur_type, params[:recur_type])
|
52
|
+
|
53
|
+
gateway = PayTrace::API::Gateway.new
|
54
|
+
parse_response(gateway.send_request(request))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/paytrace/transaction.rb
CHANGED
@@ -52,7 +52,7 @@ module PayTrace
|
|
52
52
|
def create_transaction(args,type)
|
53
53
|
amount = args.delete(:amount) if args[:amount]
|
54
54
|
cc = CreditCard.new(args.delete(:credit_card)) if args[:credit_card]
|
55
|
-
customer =
|
55
|
+
customer = args.delete(:customer) if args[:customer]
|
56
56
|
|
57
57
|
t = Transaction.new(amount: amount,
|
58
58
|
credit_card: cc,
|
@@ -101,18 +101,22 @@ module PayTrace
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def set_request(request)
|
104
|
-
|
104
|
+
add_credit_card(request, credit_card) if credit_card
|
105
|
+
if customer.is_a?(PayTrace::Customer)
|
106
|
+
request.set_param(:customer_id, customer.id)
|
107
|
+
elsif customer.is_a?(Fixnum)
|
108
|
+
request.set_param(:customer_id, customer)
|
109
|
+
end
|
110
|
+
add_transaction_info(request)
|
111
|
+
add_addresses(request)
|
112
|
+
add_optional_fields(request) if optional_fields
|
105
113
|
end
|
106
114
|
|
107
115
|
private
|
108
|
-
def
|
109
|
-
add_credit_card(request, credit_card) if credit_card
|
110
|
-
add_customer(request, customer) if customer
|
116
|
+
def add_transaction_info(request)
|
111
117
|
request.set_param(:transaction_type, type)
|
112
118
|
request.set_param(:method, TRANSACTION_METHOD)
|
113
119
|
request.set_param(:amount, amount)
|
114
|
-
load_address(request)
|
115
|
-
load_misc_fields(request) if optional_fields
|
116
120
|
end
|
117
121
|
|
118
122
|
def add_credit_card(request, cc)
|
@@ -123,59 +127,33 @@ module PayTrace
|
|
123
127
|
request.set_param(:csc, cc.csc) if cc.csc
|
124
128
|
end
|
125
129
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
request.set_param(k, v)
|
131
|
-
end
|
132
|
-
|
133
|
-
|
134
|
-
end
|
135
|
-
|
136
|
-
def load_address(request)
|
137
|
-
add_shipping_address(request, shipping_address) if shipping_address
|
138
|
-
add_billing_address(request, billing_address) if billing_address
|
130
|
+
def add_optional_fields(request)
|
131
|
+
o = optional_fields
|
132
|
+
o.each do |k,v|
|
133
|
+
request.set_param(k, v)
|
139
134
|
end
|
140
135
|
|
141
|
-
def add_customer(request, c)
|
142
|
-
request.set_param(:customer_id, c.customer_id)
|
143
|
-
end
|
144
136
|
|
145
|
-
|
146
|
-
add_address(request, "shipping",s)
|
147
|
-
end
|
148
|
-
|
149
|
-
def add_billing_address(request, b)
|
150
|
-
add_address(request, "billing",b)
|
151
|
-
end
|
152
|
-
|
153
|
-
def add_address(request, address_type, address)
|
154
|
-
request.set_param(:"#{address_type}_name", address.name) if address.name
|
155
|
-
request.set_param(:"#{address_type}_address", address.street) if address.street
|
156
|
-
request.set_param(:"#{address_type}_address2", address.street2) if address.street2
|
157
|
-
request.set_param(:"#{address_type}_city", address.city) if address.city
|
158
|
-
request.set_param(:"#{address_type}_region", address.region) if address.region
|
159
|
-
request.set_param(:"#{address_type}_state", address.state) if address.state
|
160
|
-
request.set_param(:"#{address_type}_postal_code", address.postal_code) if address.postal_code
|
161
|
-
request.set_param(:"#{address_type}_country", address.country) if address.country
|
162
|
-
end
|
137
|
+
end
|
163
138
|
|
139
|
+
def add_addresses(request)
|
140
|
+
shipping_address.set_request(request) if shipping_address
|
141
|
+
billing_address.set_request(request) if billing_address
|
142
|
+
end
|
164
143
|
|
165
144
|
def include_optional(args)
|
166
145
|
s = nil
|
167
146
|
b = nil
|
168
147
|
|
169
148
|
b = args.delete(:billing_address) if args[:billing_address]
|
170
|
-
@billing_address = PayTrace::Address.new(b) if b
|
149
|
+
@billing_address = PayTrace::Address.new({address_type: :billing}.merge(b)) if b
|
171
150
|
s = args.delete(:shipping_address) if args[:shipping_address]
|
172
|
-
@shipping_address = PayTrace::Address.new(s) if s
|
151
|
+
@shipping_address = PayTrace::Address.new({address_type: :shipping}.merge(s)) if s
|
173
152
|
if args[:address_shipping_same_as_billing]
|
174
153
|
self.set_shipping_same_as_billing
|
175
154
|
end
|
176
155
|
|
177
156
|
@optional_fields = args
|
178
|
-
|
179
157
|
end
|
180
158
|
|
181
159
|
|
data/lib/paytrace/version.rb
CHANGED
data/paytrace.gemspec
CHANGED
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.1"
|
25
25
|
spec.add_development_dependency "mocha", "~> 1.0"
|
26
|
+
spec.add_development_dependency "guard", '~> 0'
|
27
|
+
spec.add_development_dependency "guard-minitest", '~> 0'
|
26
28
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../test_helper.rb')
|
2
|
+
|
3
|
+
describe PayTrace::Address do
|
4
|
+
it "should accept an address type" do
|
5
|
+
a = PayTrace::Address.new({address_type: :shipping})
|
6
|
+
|
7
|
+
a.address_type.must_equal :shipping
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should default to a billing address" do
|
11
|
+
a = PayTrace::Address.new({})
|
12
|
+
|
13
|
+
a.address_type.must_equal :billing
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should skip blank fields" do
|
17
|
+
a = PayTrace::Address.new({foo: :bar, baz: :bat})
|
18
|
+
|
19
|
+
a.name.must_be_nil
|
20
|
+
a.street.must_be_nil
|
21
|
+
a.street2.must_be_nil
|
22
|
+
a.city.must_be_nil
|
23
|
+
a.state.must_be_nil
|
24
|
+
a.country.must_be_nil
|
25
|
+
a.region.must_be_nil
|
26
|
+
a.postal_code.must_be_nil
|
27
|
+
|
28
|
+
# special case: defaults to :billing
|
29
|
+
a.address_type.wont_be_nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should not add arbitrary fields" do
|
33
|
+
a = PayTrace::Address.new({foo: :bar, baz: :bat})
|
34
|
+
|
35
|
+
a.must_respond_to(:address_type)
|
36
|
+
a.wont_respond_to(:foo)
|
37
|
+
a.wont_respond_to(:baz)
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
it "should set the request fields correctly" do
|
42
|
+
r = PayTrace::API::Request.new
|
43
|
+
a = PayTrace::Address.new({
|
44
|
+
name: "John Doe",
|
45
|
+
street: "1234 Main Street",
|
46
|
+
street2: "Apt. B",
|
47
|
+
city: "Shoreline",
|
48
|
+
state: "WA",
|
49
|
+
country: "USA",
|
50
|
+
region: "region??",
|
51
|
+
postal_code: "98133",
|
52
|
+
address_type: :shipping
|
53
|
+
})
|
54
|
+
a.set_request(r)
|
55
|
+
|
56
|
+
r.params[:shipping_name].must_equal "John Doe"
|
57
|
+
r.params[:shipping_address].must_equal "1234 Main Street"
|
58
|
+
r.params[:shipping_address2].must_equal "Apt. B"
|
59
|
+
r.params[:shipping_city].must_equal "Shoreline"
|
60
|
+
r.params[:shipping_state].must_equal "WA"
|
61
|
+
r.params[:shipping_country].must_equal "USA"
|
62
|
+
r.params[:shipping_region].must_equal "region??"
|
63
|
+
r.params[:shipping_postal_code].must_equal "98133"
|
64
|
+
end
|
65
|
+
end
|
@@ -2,26 +2,35 @@ require File.expand_path(File.dirname(__FILE__) + '../../../test_helper.rb')
|
|
2
2
|
require 'paytrace/api/gateway'
|
3
3
|
|
4
4
|
describe PayTrace::API::Gateway do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
attr :connection, :faraday
|
6
|
+
|
7
|
+
def set_mock_configuration
|
8
|
+
PayTrace.configure do |config|
|
9
|
+
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
|
10
|
+
stub.post ("https://paytrace.com/api/default.pay") {[ 200, {}, 'foo' ]}
|
11
|
+
end
|
12
|
+
@faraday = stubs
|
9
13
|
|
10
|
-
|
11
|
-
|
14
|
+
test = Faraday.new do |builder|
|
15
|
+
builder.adapter :test , stubs
|
16
|
+
end
|
17
|
+
config.connection = test
|
18
|
+
@connection = test
|
12
19
|
end
|
20
|
+
end
|
21
|
+
|
22
|
+
before do
|
23
|
+
set_mock_configuration()
|
24
|
+
end
|
13
25
|
|
26
|
+
it "converts a request into a URL to the api specifying the user name and password from configuration" do
|
14
27
|
request = mock()
|
15
28
|
request.stubs(:to_parms_string).returns("foo")
|
16
29
|
|
17
|
-
|
18
|
-
PayTrace::API::Response.stubs(:new).returns(response)
|
19
|
-
|
20
|
-
gateway = PayTrace::API::Gateway.new(connection: test)
|
30
|
+
gateway = PayTrace::API::Gateway.new(connection: connection)
|
21
31
|
r = gateway.send_request request
|
22
32
|
|
23
|
-
|
24
|
-
r.must_equal response
|
33
|
+
faraday.verify_stubbed_calls
|
25
34
|
end
|
26
35
|
|
27
36
|
it "initializes the connection based on the configuration" do
|
@@ -33,4 +42,69 @@ describe PayTrace::API::Gateway do
|
|
33
42
|
gateway.connection.must_equal faraday_connection
|
34
43
|
end
|
35
44
|
|
45
|
+
describe "debug mode" do
|
46
|
+
it "sends a mock response if directed to" do
|
47
|
+
PayTrace::API::Gateway.debug = true
|
48
|
+
|
49
|
+
request = PayTrace::API::Request.new
|
50
|
+
gateway = PayTrace::API::Gateway.new
|
51
|
+
canned_response = "foobar"
|
52
|
+
PayTrace::API::Gateway.next_response = canned_response
|
53
|
+
|
54
|
+
gateway.send_request(request)
|
55
|
+
PayTrace::API::Gateway.last_response.must_equal(canned_response)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "doesn't send the same response twice" do
|
59
|
+
PayTrace::API::Gateway.debug = true
|
60
|
+
|
61
|
+
request = PayTrace::API::Request.new
|
62
|
+
gateway = PayTrace::API::Gateway.new
|
63
|
+
canned_response = "foobar"
|
64
|
+
PayTrace::API::Gateway.next_response = canned_response
|
65
|
+
|
66
|
+
gateway.send_request(request)
|
67
|
+
PayTrace::API::Gateway.last_response.must_equal(canned_response)
|
68
|
+
gateway.send_request(request)
|
69
|
+
PayTrace::API::Gateway.last_response.wont_equal(canned_response)
|
70
|
+
faraday.verify_stubbed_calls
|
71
|
+
end
|
72
|
+
|
73
|
+
it "does not send a mock response unless in debug mode" do
|
74
|
+
PayTrace::API::Gateway.debug = false
|
75
|
+
|
76
|
+
request = PayTrace::API::Request.new
|
77
|
+
gateway = PayTrace::API::Gateway.new
|
78
|
+
canned_response = "foobar"
|
79
|
+
PayTrace::API::Gateway.next_response = canned_response
|
80
|
+
|
81
|
+
gateway.send_request(request)
|
82
|
+
PayTrace::API::Gateway.last_response.wont_equal(canned_response)
|
83
|
+
faraday.verify_stubbed_calls
|
84
|
+
end
|
85
|
+
|
86
|
+
it "raises an ErrorResponse exception for errors" do
|
87
|
+
PayTrace::API::Gateway.debug = true # to enable mock response
|
88
|
+
PayTrace::API::Gateway.raise_exceptions = true
|
89
|
+
|
90
|
+
response = "ERROR~35. Please provide a valid Credit Card Number.|ERROR~43. Please provide a valid Expiration Month.|"
|
91
|
+
PayTrace::API::Gateway.next_response = response
|
92
|
+
|
93
|
+
request = PayTrace::API::Request.new
|
94
|
+
gateway = PayTrace::API::Gateway.new
|
95
|
+
-> { gateway.send_request(request) }.must_raise PayTrace::Exceptions::ErrorResponse
|
96
|
+
end
|
97
|
+
|
98
|
+
it "does not raise an ErrorResponse if raise_exceptions is false" do
|
99
|
+
PayTrace::API::Gateway.debug = true # to enable mock response
|
100
|
+
PayTrace::API::Gateway.raise_exceptions = false
|
101
|
+
|
102
|
+
response = "ERROR~35. Please provide a valid Credit Card Number.|ERROR~43. Please provide a valid Expiration Month.|"
|
103
|
+
PayTrace::API::Gateway.next_response = response
|
104
|
+
|
105
|
+
request = PayTrace::API::Request.new
|
106
|
+
gateway = PayTrace::API::Gateway.new
|
107
|
+
gateway.send_request(request) # if it raises an exception, the test fails; there's no "wont_raise" in minitest
|
108
|
+
end
|
109
|
+
end
|
36
110
|
end
|
@@ -26,7 +26,13 @@ describe PayTrace::API::Request do
|
|
26
26
|
|
27
27
|
it "can manually set params" do
|
28
28
|
r = PayTrace::API::Request.new
|
29
|
-
r.set_param(:
|
30
|
-
r.params[:
|
29
|
+
r.set_param(:billing_name, "Fred Jones")
|
30
|
+
r.params[:billing_name].must_equal "Fred Jones"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "raises a validation exception for unknown fields" do
|
34
|
+
r = PayTrace::API::Request.new
|
35
|
+
|
36
|
+
-> { r.set_param(:foo, "bar") }.must_raise PayTrace::Exceptions::ValidationError
|
31
37
|
end
|
32
38
|
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../test_helper.rb')
|
2
|
+
|
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
|
+
before do
|
9
|
+
PayTrace::API::Gateway.debug = true
|
10
|
+
PayTrace::API::Gateway.next_response = "RESPONSE~ok|CUSTOMERID~12345|CUSTID~john_doe"
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "create customer profile" do
|
14
|
+
# first call path: create from credit card information
|
15
|
+
it "can be created from credit card information" do
|
16
|
+
credit_card = PayTrace::CreditCard.new({card_number: "1234123412341234", expiration_month: 12, expiration_year: 2014})
|
17
|
+
billing_addr = PayTrace::Address.new({name: "Foo Bar", address_type: :billing})
|
18
|
+
|
19
|
+
PayTrace::Customer.from_cc_info({customer_id: "foo_bar", credit_card: credit_card, billing_address: billing_addr})
|
20
|
+
PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~CreateCustomer|CUSTID~foo_bar|BNAME~Foo Bar|CC~1234123412341234|EXPMNTH~12|EXPYR~2014|"
|
21
|
+
end
|
22
|
+
|
23
|
+
# second call path: create from a transaction ID
|
24
|
+
it "can be created from a transaction ID" do
|
25
|
+
PayTrace::Customer.from_transaction_id({customer_id: "foo_bar", transaction_id: 12345678})
|
26
|
+
PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~CreateCustomer|CUSTID~foo_bar|TRANXID~12345678|"
|
27
|
+
end
|
28
|
+
|
29
|
+
# all billing address fields are accepted
|
30
|
+
it "accepts full billing address information" do
|
31
|
+
credit_card = PayTrace::CreditCard.new({card_number: "1234123412341234", expiration_month: 12, expiration_year: 2014})
|
32
|
+
billing_addr = PayTrace::Address.new({
|
33
|
+
name: "Foo Bar",
|
34
|
+
street: "1234 Main Street",
|
35
|
+
street2: "Apartment 1B",
|
36
|
+
city: "Shoreline",
|
37
|
+
state: "WA",
|
38
|
+
country: "USA",
|
39
|
+
postal_code: 98133,
|
40
|
+
address_type: :billing
|
41
|
+
})
|
42
|
+
|
43
|
+
PayTrace::Customer.from_cc_info({customer_id: "foo_bar", credit_card: credit_card, billing_address: billing_addr})
|
44
|
+
PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~CreateCustomer|CUSTID~foo_bar|BNAME~Foo Bar|BADDRESS~1234 Main Street|" +
|
45
|
+
"BADDRESS2~Apartment 1B|BCITY~Shoreline|BSTATE~WA|BZIP~98133|BCOUNTRY~USA|" +
|
46
|
+
"CC~1234123412341234|EXPMNTH~12|EXPYR~2014|"
|
47
|
+
end
|
48
|
+
|
49
|
+
# you can include a shipping address, too
|
50
|
+
it "accepts a shipping address" do
|
51
|
+
shipping_addr = PayTrace::Address.new({
|
52
|
+
name: "Foo Bar",
|
53
|
+
street: "1234 Main Street",
|
54
|
+
street2: "Apartment 1B",
|
55
|
+
city: "Shoreline",
|
56
|
+
state: "WA",
|
57
|
+
region: "Snohomish",
|
58
|
+
country: "USA",
|
59
|
+
postal_code: 98133,
|
60
|
+
address_type: :shipping
|
61
|
+
})
|
62
|
+
|
63
|
+
PayTrace::Customer.from_transaction_id({customer_id: "foo_bar", transaction_id: 12345678, shipping_address: shipping_addr})
|
64
|
+
PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~CreateCustomer|CUSTID~foo_bar|TRANXID~12345678|SNAME~Foo Bar|SADDRESS~1234 Main Street|" +
|
65
|
+
"SADDRESS2~Apartment 1B|SCITY~Shoreline|SCOUNTY~Snohomish|SSTATE~WA|SZIP~98133|SCOUNTRY~USA|"
|
66
|
+
end
|
67
|
+
|
68
|
+
# special case: when creating from transaction ID, the billing name is ignored (no clue why, but it's in the API)
|
69
|
+
it "ignores the billing address name if using a transaction id" do
|
70
|
+
billing_addr = PayTrace::Address.new({
|
71
|
+
name: "Foo Bar",
|
72
|
+
street: "1234 Main Street",
|
73
|
+
street2: "Apartment 1B",
|
74
|
+
city: "Shoreline",
|
75
|
+
state: "WA",
|
76
|
+
region: "region",
|
77
|
+
country: "USA",
|
78
|
+
postal_code: 98133,
|
79
|
+
address_type: :billing
|
80
|
+
})
|
81
|
+
|
82
|
+
PayTrace::Customer.from_transaction_id({customer_id: "foo_bar", transaction_id: 12345678, billing_address: billing_addr})
|
83
|
+
PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~CreateCustomer|CUSTID~foo_bar|TRANXID~12345678|BADDRESS~1234 Main Street|" +
|
84
|
+
"BADDRESS2~Apartment 1B|BCITY~Shoreline|BSTATE~WA|BZIP~98133|BCOUNTRY~USA|"
|
85
|
+
end
|
86
|
+
|
87
|
+
# there are additional fields (email, phone, discretionary data, etc.) that can be sent
|
88
|
+
it "accepts extra customer information" do
|
89
|
+
params = {
|
90
|
+
customer_id: "foo_bar",
|
91
|
+
transaction_id: 12345678,
|
92
|
+
email: "support@paytrace.com",
|
93
|
+
phone: "123-555-1212",
|
94
|
+
fax: "456-555-1212",
|
95
|
+
customer_password: "none_shall_pass",
|
96
|
+
account_number: 123456789,
|
97
|
+
routing_number: 12345678,
|
98
|
+
discretionary_data: "discretionary_data"
|
99
|
+
}
|
100
|
+
|
101
|
+
PayTrace::Customer.from_transaction_id(params)
|
102
|
+
PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~CreateCustomer|CUSTID~foo_bar|TRANXID~12345678|EMAIL~support@paytrace.com|" +
|
103
|
+
"PHONE~123-555-1212|FAX~456-555-1212|CUSTPSWD~none_shall_pass|DDA~123456789|TR~12345678|" +
|
104
|
+
"DISCRETIONARY DATA~discretionary_data|"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "update customer profile" do
|
109
|
+
it "accepts a billing address" do
|
110
|
+
billing_addr = PayTrace::Address.new({
|
111
|
+
name: "Foo Bar",
|
112
|
+
street: "1234 Main Street",
|
113
|
+
street2: "Apartment 1B",
|
114
|
+
city: "Shoreline",
|
115
|
+
state: "WA",
|
116
|
+
region: "region",
|
117
|
+
country: "USA",
|
118
|
+
postal_code: 98133,
|
119
|
+
address_type: :billing
|
120
|
+
})
|
121
|
+
|
122
|
+
c = PayTrace::Customer.new
|
123
|
+
c.update({new_customer_id: "joanie_doe", billing_address: billing_addr})
|
124
|
+
|
125
|
+
PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~UpdateCustomer|NEWCUSTID~joanie_doe|" +
|
126
|
+
"BNAME~Foo Bar|BADDRESS~1234 Main Street|" +
|
127
|
+
"BADDRESS2~Apartment 1B|BCITY~Shoreline|BSTATE~WA|BZIP~98133|BCOUNTRY~USA|"
|
128
|
+
end
|
129
|
+
|
130
|
+
it "accepts a shipping address" do
|
131
|
+
shipping_addr = PayTrace::Address.new({
|
132
|
+
name: "Foo Bar",
|
133
|
+
street: "1234 Main Street",
|
134
|
+
street2: "Apartment 1B",
|
135
|
+
city: "Shoreline",
|
136
|
+
state: "WA",
|
137
|
+
region: "Snohomish",
|
138
|
+
country: "USA",
|
139
|
+
postal_code: 98133,
|
140
|
+
address_type: :shipping
|
141
|
+
})
|
142
|
+
|
143
|
+
c = PayTrace::Customer.new
|
144
|
+
c.update({new_customer_id: "joanie_doe", shipping_address: shipping_addr})
|
145
|
+
|
146
|
+
PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~UpdateCustomer|NEWCUSTID~joanie_doe|" +
|
147
|
+
"SNAME~Foo Bar|SADDRESS~1234 Main Street|SADDRESS2~Apartment 1B|SCITY~Shoreline|SCOUNTY~Snohomish|" +
|
148
|
+
"SSTATE~WA|SZIP~98133|SCOUNTRY~USA|"
|
149
|
+
end
|
150
|
+
|
151
|
+
it "accepts extra customer information" do
|
152
|
+
params = {
|
153
|
+
new_customer_id: "foo_bar",
|
154
|
+
email: "support@paytrace.com",
|
155
|
+
phone: "123-555-1212",
|
156
|
+
fax: "456-555-1212",
|
157
|
+
customer_password: "none_shall_pass",
|
158
|
+
account_number: 123456789,
|
159
|
+
routing_number: 12345678,
|
160
|
+
discretionary_data: "discretionary_data"
|
161
|
+
}
|
162
|
+
|
163
|
+
c = PayTrace::Customer.new
|
164
|
+
c.update(params)
|
165
|
+
|
166
|
+
PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~UpdateCustomer|NEWCUSTID~foo_bar|" +
|
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|"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe "delete customer profile" do
|
173
|
+
it "works with an instantiated Customer object" do
|
174
|
+
c = PayTrace::Customer.new("foo_bar")
|
175
|
+
c.delete
|
176
|
+
|
177
|
+
PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~DeleteCustomer|CUSTID~foo_bar|"
|
178
|
+
end
|
179
|
+
|
180
|
+
it "works with a static class method" do
|
181
|
+
PayTrace::Customer.delete("foob_barb")
|
182
|
+
|
183
|
+
PayTrace::API::Gateway.last_request.must_equal base_url + "METHOD~DeleteCustomer|CUSTID~foob_barb|"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../test_helper.rb')
|
2
|
+
|
3
|
+
describe PayTrace::RecurringTransaction do
|
4
|
+
def base_url(method)
|
5
|
+
"UN~#{PayTrace.configuration.user_name}|PSWD~#{PayTrace.configuration.password}|TERMS~Y|METHOD~#{method}|"
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "create recurrence" do
|
9
|
+
before do
|
10
|
+
PayTrace::API::Gateway.debug = true
|
11
|
+
PayTrace::API::Gateway.next_response = "RESPONSE~ok|RECURID~12345|"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "works" do
|
15
|
+
params = {
|
16
|
+
customer_id: "foo_bar",
|
17
|
+
recur_frequency: "3",
|
18
|
+
recur_start: "4/22/2014",
|
19
|
+
recur_count: 999,
|
20
|
+
amount: 9.99,
|
21
|
+
transaction_type: "sale",
|
22
|
+
description: "Recurring transaction",
|
23
|
+
recur_receipt: "Y",
|
24
|
+
recur_type: "A"
|
25
|
+
}
|
26
|
+
|
27
|
+
recur_id = PayTrace::RecurringTransaction.create(params)
|
28
|
+
PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::RecurringTransaction::CREATE_METHOD) +
|
29
|
+
"CUSTID~foo_bar|FREQUENCY~3|START~4/22/2014|TOTALCOUNT~999|AMOUNT~9.99|TRANXTYPE~sale|DESCRIPTION~Recurring transaction|CUSTRECEIPT~Y|RECURTYPE~A|"
|
30
|
+
|
31
|
+
recur_id.must_equal "12345"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "update recurrence" do
|
36
|
+
before do
|
37
|
+
PayTrace::API::Gateway.debug = true
|
38
|
+
PayTrace::API::Gateway.next_response = "RESPONSE~ok|RECURID~12345|"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "works" do
|
42
|
+
params = {
|
43
|
+
recur_id: 12345,
|
44
|
+
customer_id: "foo_bar",
|
45
|
+
recur_frequency: "3",
|
46
|
+
recur_start: "4/22/2014",
|
47
|
+
recur_count: 999,
|
48
|
+
amount: 9.99,
|
49
|
+
transaction_type: "sale",
|
50
|
+
description: "Recurring transaction",
|
51
|
+
recur_receipt: "Y"
|
52
|
+
}
|
53
|
+
|
54
|
+
recur_id = PayTrace::RecurringTransaction.update(params)
|
55
|
+
PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::RecurringTransaction::UPDATE_METHOD) +
|
56
|
+
"RECURID~12345|CUSTID~foo_bar|FREQUENCY~3|START~4/22/2014|TOTALCOUNT~999|AMOUNT~9.99|TRANXTYPE~sale|" +
|
57
|
+
"DESCRIPTION~Recurring transaction|CUSTRECEIPT~Y|"
|
58
|
+
|
59
|
+
recur_id.must_equal "12345"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "accepts a recur type" do
|
63
|
+
params = {
|
64
|
+
recur_id: 12345,
|
65
|
+
customer_id: "foo_bar",
|
66
|
+
recur_frequency: "3",
|
67
|
+
recur_start: "4/22/2014",
|
68
|
+
recur_count: 999,
|
69
|
+
amount: 9.99,
|
70
|
+
transaction_type: "sale",
|
71
|
+
description: "Recurring transaction",
|
72
|
+
recur_receipt: "Y",
|
73
|
+
recur_type: "A"
|
74
|
+
}
|
75
|
+
|
76
|
+
recur_id = PayTrace::RecurringTransaction.update(params)
|
77
|
+
PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::RecurringTransaction::UPDATE_METHOD) +
|
78
|
+
"RECURID~12345|CUSTID~foo_bar|FREQUENCY~3|START~4/22/2014|TOTALCOUNT~999|AMOUNT~9.99|TRANXTYPE~sale|" +
|
79
|
+
"DESCRIPTION~Recurring transaction|CUSTRECEIPT~Y|RECURTYPE~A|"
|
80
|
+
|
81
|
+
recur_id.must_equal "12345"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "delete recurrence" do
|
86
|
+
before do
|
87
|
+
PayTrace::API::Gateway.debug = true
|
88
|
+
PayTrace::API::Gateway.next_response = "RESPONSE~ok|RECURID~12345|"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "works with a recur ID" do
|
92
|
+
params = {
|
93
|
+
recur_id: 12345
|
94
|
+
}
|
95
|
+
|
96
|
+
recur_id = PayTrace::RecurringTransaction.delete(params)
|
97
|
+
PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::RecurringTransaction::DELETE_METHOD) +
|
98
|
+
"RECURID~12345|"
|
99
|
+
|
100
|
+
recur_id.must_equal "12345"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "works with a customer ID" do
|
104
|
+
params = {
|
105
|
+
customer_id: "foo_bar"
|
106
|
+
}
|
107
|
+
|
108
|
+
recur_id = PayTrace::RecurringTransaction.delete(params)
|
109
|
+
PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::RecurringTransaction::DELETE_METHOD) +
|
110
|
+
"CUSTID~foo_bar|"
|
111
|
+
|
112
|
+
recur_id.must_equal "12345"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
# describe "export single recurrence"
|
116
|
+
# describe "bulk update recurrences"
|
117
|
+
end
|
@@ -52,12 +52,12 @@ describe PayTrace::Transaction do
|
|
52
52
|
it "can run a transaction for a customer" do
|
53
53
|
t = PayTrace::Transaction.sale(
|
54
54
|
{amount: "1.00",
|
55
|
-
|
55
|
+
customer: 123456}
|
56
56
|
)
|
57
57
|
|
58
58
|
t.amount.must_equal "1.00"
|
59
59
|
t.type.must_equal PayTrace::TransactionTypes::SALE
|
60
|
-
t.customer.
|
60
|
+
t.customer.must_equal 123456
|
61
61
|
t.credit_card.must_be_nil
|
62
62
|
t.response.must_equal @response
|
63
63
|
|
@@ -215,14 +215,14 @@ describe PayTrace::Transaction do
|
|
215
215
|
|
216
216
|
it "can use a customer id for processing the transaction" do
|
217
217
|
t = PayTrace::Transaction.new({amount: "12.34",
|
218
|
-
customer:
|
218
|
+
customer: 1234,
|
219
219
|
type: PayTrace::TransactionTypes::SALE
|
220
220
|
}
|
221
221
|
)
|
222
222
|
r = PayTrace::API::Request.new
|
223
223
|
t.set_request(r)
|
224
224
|
|
225
|
-
r.params[:customer_id].must_equal
|
225
|
+
r.params[:customer_id].must_equal 1234
|
226
226
|
r.params[:amount].must_equal "12.34"
|
227
227
|
|
228
228
|
url = r.to_parms_string
|
@@ -0,0 +1,55 @@
|
|
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
|
+
PayTrace.configure do |config|
|
21
|
+
config.user_name = "demo123"
|
22
|
+
config.password = "demo123"
|
23
|
+
config.domain = "stage.paytrace.com"
|
24
|
+
end
|
25
|
+
|
26
|
+
# this should be a valid credit card number (it can be a "sandbox" number, however)
|
27
|
+
cc = PayTrace::CreditCard.new({
|
28
|
+
card_number: "4111111111111111",
|
29
|
+
expiration_month: 12,
|
30
|
+
expiration_year: 2014
|
31
|
+
})
|
32
|
+
ba = PayTrace::Address.new({
|
33
|
+
name: "John Doe",
|
34
|
+
street: "1234 Main Street",
|
35
|
+
street2: "Apartment 1B",
|
36
|
+
city: "Shoreline",
|
37
|
+
state: "WA",
|
38
|
+
country: "US",
|
39
|
+
postal_code: "98133",
|
40
|
+
address_type: :billing
|
41
|
+
})
|
42
|
+
extra = {
|
43
|
+
email: "support@paytrace.com",
|
44
|
+
phone: "206-555-1212",
|
45
|
+
fax: "206-555-1313",
|
46
|
+
password: "foxtrot123",
|
47
|
+
account_number: 123456789,
|
48
|
+
routing_number: 12345678,
|
49
|
+
discretionary_data: "Discretionary data."
|
50
|
+
}
|
51
|
+
|
52
|
+
PayTrace::API::Gateway.set_debug(true)
|
53
|
+
c = PayTrace::Customer.from_cc_info("john_doe", cc, ba, nil, extra)
|
54
|
+
|
55
|
+
dump_response_values(PayTrace::API::Gateway.last_response)
|
@@ -0,0 +1,36 @@
|
|
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
|
+
PayTrace.configure do |config|
|
21
|
+
config.user_name = "demo123"
|
22
|
+
config.password = "demo123"
|
23
|
+
config.domain = "stage.paytrace.com"
|
24
|
+
end
|
25
|
+
|
26
|
+
e = PayTrace::EmailReceiptRequest.new("support@paytrace.com", "CHECK2345", true)
|
27
|
+
r = e.send_request
|
28
|
+
|
29
|
+
# this is for the check auth version
|
30
|
+
dump_response_values(r)
|
31
|
+
|
32
|
+
e = PayTrace::EmailReceiptRequest.new("support@paytrace.com", "TRANS1234", false)
|
33
|
+
r = e.send_request
|
34
|
+
|
35
|
+
# this is for the transaction version
|
36
|
+
dump_response_values(r)
|
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.0.
|
4
|
+
version: 0.0.7
|
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-03
|
11
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
description: Integration with PayTrace Payment Gateway
|
70
98
|
email:
|
71
99
|
- trevor@paytrace.com
|
@@ -76,6 +104,7 @@ files:
|
|
76
104
|
- ".gitignore"
|
77
105
|
- ".ruby-gemset"
|
78
106
|
- Gemfile
|
107
|
+
- Guardfile
|
79
108
|
- LICENSE.txt
|
80
109
|
- README.md
|
81
110
|
- Rakefile
|
@@ -91,17 +120,25 @@ files:
|
|
91
120
|
- lib/paytrace/credit_card.rb
|
92
121
|
- lib/paytrace/customer.rb
|
93
122
|
- lib/paytrace/email_receipt_request.rb
|
123
|
+
- lib/paytrace/exceptions.rb
|
124
|
+
- lib/paytrace/recurring_transaction.rb
|
94
125
|
- lib/paytrace/transaction.rb
|
95
126
|
- lib/paytrace/version.rb
|
96
127
|
- paytrace.gemspec
|
128
|
+
- test/paytrace/address_spec.rb
|
97
129
|
- test/paytrace/api/fields_spec.rb
|
98
130
|
- test/paytrace/api/gateway_spec.rb
|
99
131
|
- test/paytrace/api/request_spec.rb
|
100
132
|
- test/paytrace/api/response_spec.rb
|
101
133
|
- test/paytrace/configuration_spec.rb
|
102
134
|
- test/paytrace/credit_card_spec.rb
|
135
|
+
- test/paytrace/customer_spec.rb
|
103
136
|
- test/paytrace/email_receipt_request_spec.rb
|
137
|
+
- test/paytrace/exceptions_spec.rb
|
138
|
+
- test/paytrace/recurring_transaction_spec.rb
|
104
139
|
- test/paytrace/transaction_spec.rb
|
140
|
+
- test/scripts/run_create_customer.rb
|
141
|
+
- test/scripts/run_email_request.rb
|
105
142
|
- test/test_helper.rb
|
106
143
|
- vagrant-bootstrap.sh
|
107
144
|
homepage: http://github.com/PayTrace/paytrace_ruby
|
@@ -124,17 +161,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
161
|
version: '0'
|
125
162
|
requirements: []
|
126
163
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
164
|
+
rubygems_version: 2.2.2
|
128
165
|
signing_key:
|
129
166
|
specification_version: 4
|
130
167
|
summary: Integration providing access to the transaction processing API for PayTrace
|
131
168
|
test_files:
|
169
|
+
- test/paytrace/address_spec.rb
|
132
170
|
- test/paytrace/api/fields_spec.rb
|
133
171
|
- test/paytrace/api/gateway_spec.rb
|
134
172
|
- test/paytrace/api/request_spec.rb
|
135
173
|
- test/paytrace/api/response_spec.rb
|
136
174
|
- test/paytrace/configuration_spec.rb
|
137
175
|
- test/paytrace/credit_card_spec.rb
|
176
|
+
- test/paytrace/customer_spec.rb
|
138
177
|
- test/paytrace/email_receipt_request_spec.rb
|
178
|
+
- test/paytrace/exceptions_spec.rb
|
179
|
+
- test/paytrace/recurring_transaction_spec.rb
|
139
180
|
- test/paytrace/transaction_spec.rb
|
181
|
+
- test/scripts/run_create_customer.rb
|
182
|
+
- test/scripts/run_email_request.rb
|
140
183
|
- test/test_helper.rb
|