paytrace 0.1.7 → 0.1.8

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: 7823d38c4a275aeab478b25d379d7602224cad3d
4
- data.tar.gz: 34e1abb081f2d8b63ab21986b67ac38078e0edc9
3
+ metadata.gz: e13cfd13c9fa4d9c8ec7b4fc6e950bd3b2923a3f
4
+ data.tar.gz: d407555a86e3e4193e9fb38a66eecd47701350c1
5
5
  SHA512:
6
- metadata.gz: 7367901908882b94361f6f2ded694a98bc3a926e26aeb675bc54aa214375a4093842c765f914c6abb052c2d47d0a092e68af914f76f5946dfa78bb538dcecc3e
7
- data.tar.gz: 8c24e2639e2d277709dd27274150ac3749fc2f3516b74d37889d2ad8d038391c0de41965739f594c6993e154ae76613d2713fb60082c67b4b6cf73c1411614b2
6
+ metadata.gz: f3e0613a8cdddcfa3800e120ce48da58353cc6886af2100e5db2922f3cc2503ade41ca24f380e294530d6deb50f5ccce1121c32782056b4916e8a973a1cc07b3
7
+ data.tar.gz: f74214c1513e428e24a7b245693a441d536d4f1ffd24990f7c8f0c473ce9ffe3199818fa0c10b965fbbe60c4f5473eee902715cd92a8ff9d83686973ac8eaf43
@@ -12,11 +12,16 @@ module PayTrace
12
12
  description: "DESCRIPTION",
13
13
  tax_amount: "TAX",
14
14
  return_clr: "RETURNCLR",
15
+ return_bin: "RETURNBIN",
15
16
  enable_partial_authentication: "ENABLEPARTIALAUTH",
16
17
  custom_dba: "CUSTOMDBA",
17
18
  invoice:"INVOICE",
18
19
  transaction_id:"TRANXID",
20
+ transaction_user:"USER",
21
+ search_text:"SEARCHTEXT",
19
22
  check_id:"CHECKID",
23
+ start_date:"SDATE",
24
+ end_date:"EDATE",
20
25
  #credit card
21
26
  card_number: "CC",
22
27
  expiration_year: "EXPYR",
@@ -62,7 +67,10 @@ module PayTrace
62
67
  recur_start: "START",
63
68
  recur_count: "TOTALCOUNT",
64
69
  recur_receipt: "CUSTRECEIPT",
65
- recur_type: "RECURTYPE"
70
+ recur_type: "RECURTYPE",
71
+ # attach signatures
72
+ image_data: "IMAGEDATA",
73
+ image_type: "IMAGETYPE"
66
74
  }
67
75
  end
68
76
  end
@@ -41,7 +41,7 @@ module PayTrace
41
41
  @@raise_exceptions = raise_exceptions
42
42
  end
43
43
 
44
- def send_request(request)
44
+ def send_request(request, multi_value_fields = [])
45
45
  @@last_request = request.to_parms_string if @@debug
46
46
  unless (@@debug && @@next_response)
47
47
  res = @connection.post PayTrace.configuration.url, parmlist: request.to_parms_string
@@ -51,7 +51,7 @@ module PayTrace
51
51
  end
52
52
 
53
53
  @@last_response = raw_response
54
- response = PayTrace::API::Response.new(raw_response)
54
+ response = PayTrace::API::Response.new(raw_response, multi_value_fields)
55
55
  @@last_response_object = response
56
56
 
57
57
  @@next_response = nil # just to be sure
@@ -3,12 +3,13 @@ module PayTrace
3
3
  class Response
4
4
  attr_reader :values, :errors
5
5
 
6
- def initialize(response_string)
6
+ def initialize(response_string, multi_value_fields = [])
7
7
  @field_delim = "|"
8
8
  @value_delim = "~"
9
+ @multi_value_delim = "+"
9
10
  @values = {}
10
11
  @errors = {}
11
- parse_response(response_string)
12
+ parse_response(response_string, multi_value_fields)
12
13
  end
13
14
 
14
15
  def response_code
@@ -19,7 +20,7 @@ module PayTrace
19
20
  @errors.length > 0
20
21
  end
21
22
 
22
- def parse_response(response_string)
23
+ def parse_response(response_string, multi_value_fields = [])
23
24
 
24
25
  if (response_string.include? "ERROR")
25
26
  return parse_errors(response_string)
@@ -28,7 +29,12 @@ module PayTrace
28
29
  pairs = response_string.split(@field_delim)
29
30
  pairs.each do |p|
30
31
  k,v = p.split(@value_delim)
31
- @values[k] = v
32
+ if multi_value_fields.include?(k)
33
+ @values[k] ||= []
34
+ @values[k] << Hash[v.split(@multi_value_delim).map {|pair| pair.split('=')}]
35
+ else
36
+ @values[k] = v
37
+ end
32
38
  end
33
39
  end
34
40
 
@@ -1,6 +1,8 @@
1
1
  require 'paytrace/api/request'
2
2
  require 'paytrace/api/gateway'
3
3
  require 'paytrace/address'
4
+ require 'base64'
5
+
4
6
  module PayTrace
5
7
  module TransactionOperations
6
8
  def sale(args)
@@ -83,14 +85,14 @@ module PayTrace
83
85
  attr_accessor :response, :discretionary_data
84
86
 
85
87
  TRANSACTION_METHOD = "PROCESSTRANX"
86
-
88
+ EXPORT_TRANSACTIONS_METHOD = "ExportTranx"
89
+ EXPORT_TRANSACTIONS_RESPONSE = "TRANSACTIONRECORD"
90
+ ATTACH_SIGNATURE_METHOD = "AttachSignature"
87
91
 
88
92
  def set_shipping_same_as_billing()
89
93
  @shipping_address = @billing_address
90
94
  end
91
95
 
92
-
93
-
94
96
  def initialize(params = {})
95
97
  @amount = params[:amount]
96
98
  @credit_card = params[:credit_card]
@@ -115,6 +117,41 @@ module PayTrace
115
117
  end
116
118
  end
117
119
 
120
+ def self.export(params = {})
121
+ request = PayTrace::API::Request.new
122
+ request.set_param(:method, EXPORT_TRANSACTIONS_METHOD)
123
+ request.set_param(:transaction_id, params[:transaction_id])
124
+ request.set_param(:start_date, params[:start_date])
125
+ request.set_param(:end_date, params[:end_date])
126
+ request.set_param(:transaction_type, params[:transaction_type])
127
+ request.set_param(:customer_id, params[:customer_id])
128
+ request.set_param(:transaction_user, params[:transaction_user])
129
+ request.set_param(:return_bin, params[:return_bin])
130
+ request.set_param(:search_text, params[:search_test])
131
+
132
+ gateway = PayTrace::API::Gateway.new
133
+ response = gateway.send_request(request, [EXPORT_TRANSACTIONS_RESPONSE])
134
+
135
+ unless response.has_errors?
136
+ response.values[EXPORT_TRANSACTIONS_RESPONSE]
137
+ end
138
+ end
139
+
140
+ def self.attach_signature(params = {})
141
+ request = PayTrace::API::Request.new
142
+ request.set_param(:method, ATTACH_SIGNATURE_METHOD)
143
+ request.set_param(:image_data, params[:image_data])
144
+ request.set_param(:image_type, params[:image_type])
145
+ if params.has_key?(:image_file)
146
+ File.open(params[:image_file], 'rb') do |file|
147
+ request.set_param(:image_data, Base64.encode64(file.read))
148
+ end
149
+ end
150
+
151
+ gateway = PayTrace::API::Gateway.new
152
+ gateway.send_request(request)
153
+ end
154
+
118
155
  private
119
156
  def add_transaction_info(request)
120
157
  request.set_param(:transaction_type, type)
@@ -1,3 +1,3 @@
1
1
  module PayTrace
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -1,6 +1,30 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '../../test_helper.rb')
2
2
 
3
3
  describe PayTrace::Transaction do
4
+ it "exports transaction(s)" do
5
+ PayTrace::API::Gateway.debug = true
6
+ PayTrace::API::Gateway.next_response = "TRANSACTIONRECORD~TRANXID=1143"
7
+ records = PayTrace::Transaction.export({transaction_id: 1143})
8
+ records.must_be_instance_of Array
9
+ records.count.must_equal 1
10
+ records[0].must_be_instance_of Hash
11
+ records[0]["TRANXID"].must_equal "1143"
12
+ end
13
+
14
+ it "successfully attaches base-64 encoded signatures to transactions" do
15
+ PayTrace::API::Gateway.debug = true
16
+ PayTrace::API::Gateway.next_response = "RESPONSE~172. The signature image was successfully attached to Transaction ID 13192003.|"
17
+ result = PayTrace::Transaction.attach_signature({transaction_id: 13192003, image_data: "foo", image_type: "png"})
18
+ result.has_errors?.must_equal false
19
+ end
20
+
21
+ it "successfully attaches image files to transactions" do
22
+ PayTrace::API::Gateway.debug = true
23
+ PayTrace::API::Gateway.next_response = "RESPONSE~172. The signature image was successfully attached to Transaction ID 13192003.|"
24
+ result = PayTrace::Transaction.attach_signature({transaction_id: 13192003, image_file: __FILE__, image_type: "png"})
25
+ result.has_errors?.must_equal false
26
+ end
27
+
4
28
  describe "create sales transactions" do
5
29
  before do
6
30
  @response = mock()
@@ -0,0 +1,50 @@
1
+ $:<< "./lib"
2
+
3
+ require "paytrace"
4
+
5
+ # see: http://help.paytrace.com/api-email-receipt for details
6
+
7
+ #
8
+ # Helper that loops through the response values and dumps them out
9
+ #
10
+ def dump_transaction
11
+ puts "[REQUEST] #{PayTrace::API::Gateway.last_request}"
12
+ response = PayTrace::API::Gateway.last_response_object
13
+ if(response.has_errors?)
14
+ response.errors.each do |key, value|
15
+ puts "[RESPONSE] ERROR: #{key.ljust(20)}#{value}"
16
+ end
17
+ else
18
+ response.values.each do |key, value|
19
+ puts "[RESPONSE] #{key.ljust(20)}#{value}"
20
+ end
21
+ end
22
+ end
23
+
24
+ def log(msg)
25
+ puts ">>>>>> #{msg}"
26
+ end
27
+
28
+ def trace(&block)
29
+ PayTrace::API::Gateway.debug = true
30
+
31
+ begin
32
+ yield
33
+ rescue Exception => e
34
+ raise
35
+ else
36
+ dump_transaction
37
+ end
38
+ end
39
+
40
+ PayTrace.configure do |config|
41
+ config.user_name = "demo123"
42
+ config.password = "demo123"
43
+ config.domain = "stage.paytrace.com"
44
+ end
45
+
46
+ PayTrace::API::Gateway.debug = true
47
+
48
+ trace {
49
+ PayTrace::Transaction.attach_signature({image_file: File.expand_path('smiley_face.png', File.dirname(__FILE__)), image_type: "PNG"})
50
+ }
@@ -0,0 +1,54 @@
1
+ $:<< "./lib"
2
+
3
+ require "paytrace"
4
+
5
+ # see: http://help.paytrace.com/api-email-receipt for details
6
+
7
+ #
8
+ # Helper that loops through the response values and dumps them out
9
+ #
10
+ def dump_transaction
11
+ puts "[REQUEST] #{PayTrace::API::Gateway.last_request}"
12
+ response = PayTrace::API::Gateway.last_response_object
13
+ if(response.has_errors?)
14
+ response.errors.each do |key, value|
15
+ puts "[RESPONSE] ERROR: #{key.ljust(20)}#{value}"
16
+ end
17
+ else
18
+ response.values.each do |key, value|
19
+ puts "[RESPONSE] #{key.ljust(20)}#{value}"
20
+ end
21
+ end
22
+ end
23
+
24
+ def log(msg)
25
+ puts ">>>>>> #{msg}"
26
+ end
27
+
28
+ def trace(&block)
29
+ PayTrace::API::Gateway.debug = true
30
+
31
+ begin
32
+ yield
33
+ rescue Exception => e
34
+ raise
35
+ else
36
+ dump_transaction
37
+ end
38
+ end
39
+
40
+ PayTrace.configure do |config|
41
+ config.user_name = "demo123"
42
+ config.password = "demo123"
43
+ config.domain = "stage.paytrace.com"
44
+ end
45
+
46
+ PayTrace::API::Gateway.debug = true
47
+
48
+ params = {
49
+ start_date: "04/01/2014",
50
+ end_date: "05/31/2014",
51
+ transaction_id: 1143
52
+ }
53
+
54
+ trace { puts PayTrace::Transaction.export(params) }
@@ -20,7 +20,7 @@ def dump_transaction
20
20
  end
21
21
 
22
22
  def log(msg)
23
- puts ">>>>>> #{msg}"
23
+ puts ">>>>>> #{msg}"
24
24
  end
25
25
 
26
26
  def trace(&block)
@@ -53,7 +53,11 @@ ba = PayTrace::Address.new({
53
53
  postal_code: "98133",
54
54
  address_type: :billing
55
55
  })
56
- extra = {
56
+
57
+ params = {
58
+ customer_id: "john_doe",
59
+ credit_card: cc,
60
+ billing_address: ba,
57
61
  email: "support@paytrace.com",
58
62
  phone: "206-555-1212",
59
63
  fax: "206-555-1313",
@@ -68,6 +72,7 @@ PayTrace::API::Gateway.debug = true
68
72
  begin
69
73
  log "Attempting to remove existing customer 'john_doe'..."
70
74
  c = PayTrace::Customer.new("john_doe")
75
+ # delete customer "john_doe" if he already exists
71
76
  trace { c.delete() }
72
77
  rescue PayTrace::Exceptions::ErrorResponse
73
78
  log "No such cusomter... continuing..."
@@ -76,7 +81,9 @@ end
76
81
  log "Creating customer john_doe..."
77
82
  begin
78
83
  trace do
79
- c = PayTrace::Customer.from_cc_info({customer_id: "john_doe", credit_card: cc, billing_address: ba}.merge(extra))
84
+ ################
85
+ # create "john_doe" profile from credit card information and a billing address. Also include extra information such as email, phone, and fax
86
+ c = PayTrace::Customer.from_cc_info(params)
80
87
  log "Customer ID: #{c.id}"
81
88
  end
82
89
  rescue
@@ -102,6 +109,8 @@ params = {
102
109
  }
103
110
 
104
111
  trace do
112
+ ################
113
+ # create a recurring payment for "john_doe" of $9.99 every month starting on 4/22/2016, running indefinitely. Send a receipt.
105
114
  recur_id = PayTrace::RecurringTransaction.create(params)
106
115
  log "Recurrence ID: #{recur_id}"
107
116
  end
@@ -109,6 +118,8 @@ end
109
118
  begin
110
119
  log "Exporting recurring transaction..."
111
120
  trace do
121
+ ################
122
+ # export any scheduled recurring transactions for "john_doe" to a RecurringTransaction object...
112
123
  exported = PayTrace::RecurringTransaction.export_scheduled({customer_id: "john_doe"})
113
124
  log "Exported transaction:\n#{exported.inspect}"
114
125
  end
@@ -117,7 +128,11 @@ rescue
117
128
  end
118
129
 
119
130
  log "Deleting recurrences for 'john_doe'..."
131
+ ################
132
+ # delete any scheduled recurring transactions for "john_doe"
120
133
  trace { PayTrace::RecurringTransaction.delete({customer_id: "john_doe"}) }
121
134
 
122
135
  log "Deleting customer 'john_doe'..."
136
+ ################
137
+ # delete "john doe"
123
138
  trace { c.delete() }
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.7
4
+ version: 0.1.8
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-04-04 00:00:00.000000000 Z
11
+ date: 2014-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -137,9 +137,12 @@ files:
137
137
  - test/paytrace/exceptions_spec.rb
138
138
  - test/paytrace/recurring_transaction_spec.rb
139
139
  - test/paytrace/transaction_spec.rb
140
+ - test/scripts/run_attach_signature.rb
140
141
  - test/scripts/run_create_customer.rb
141
142
  - test/scripts/run_email_request.rb
143
+ - test/scripts/run_export_transactions.rb
142
144
  - test/scripts/run_recur_payments_integration.rb
145
+ - test/scripts/smiley_face.png
143
146
  - test/test_helper.rb
144
147
  - vagrant-bootstrap.sh
145
148
  homepage: http://github.com/PayTrace/paytrace_ruby
@@ -179,7 +182,10 @@ test_files:
179
182
  - test/paytrace/exceptions_spec.rb
180
183
  - test/paytrace/recurring_transaction_spec.rb
181
184
  - test/paytrace/transaction_spec.rb
185
+ - test/scripts/run_attach_signature.rb
182
186
  - test/scripts/run_create_customer.rb
183
187
  - test/scripts/run_email_request.rb
188
+ - test/scripts/run_export_transactions.rb
184
189
  - test/scripts/run_recur_payments_integration.rb
190
+ - test/scripts/smiley_face.png
185
191
  - test/test_helper.rb