paytrace 0.1.19 → 0.1.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/paytrace/address.rb +16 -0
- data/lib/paytrace/api/fields.rb +3 -0
- data/lib/paytrace/api/gateway.rb +13 -0
- data/lib/paytrace/api/request.rb +28 -9
- data/lib/paytrace/api/response.rb +1 -0
- data/lib/paytrace/check_transaction.rb +31 -0
- data/lib/paytrace/configuration.rb +17 -0
- data/lib/paytrace/credit_card.rb +19 -1
- data/lib/paytrace/customer.rb +68 -24
- data/lib/paytrace/debug.rb +10 -0
- data/lib/paytrace/email_receipt_request.rb +11 -0
- data/lib/paytrace/exceptions.rb +4 -0
- data/lib/paytrace/recurring_transaction.rb +43 -0
- data/lib/paytrace/transaction.rb +156 -76
- data/lib/paytrace/version.rb +2 -1
- data/test/paytrace/transaction_spec.rb +1 -32
- data/test/scripts/run_check_transactions.rb +59 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c5e82942b71219987900a9ece01e48f70b44833
|
4
|
+
data.tar.gz: 8bb191238ff8bbf79bcc5afcf2011d1e0578d353
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f374f6d857de369ec8554404108057191b71e4a9d04f4b9c23f247eafdd25124fdfa9f5e659acf91f11b18463352df8e7b6340db2fbc35ee718e4662fa593a18
|
7
|
+
data.tar.gz: 2b9ec845d6a698605509144cf7aae2fa3b25ba62a802ad95d6036943de2b5009412af076e3efe21bf8b5f636edb097f96507efa36c9569adbbff622f40aab073
|
data/lib/paytrace/address.rb
CHANGED
@@ -1,7 +1,20 @@
|
|
1
1
|
module PayTrace
|
2
|
+
# Abstracts an address -- two types are possible, shipping and billing.
|
3
|
+
# _Note:_ the "region" parameter can only be defined for shipping addresses, and the
|
4
|
+
# default address type (if unspecified) is billing.
|
2
5
|
class Address
|
3
6
|
attr_accessor :name, :street,:street2,:city,:state, :country,:region,:postal_code,:address_type
|
4
7
|
|
8
|
+
# Initialize a new address instance. Parameters are symbolic keys in a hash. They are:
|
9
|
+
# * *:name* -- the name on this address
|
10
|
+
# * *:street* -- the street address
|
11
|
+
# * *:street2* -- an optional second line of street address (apartment, suite, etc.)
|
12
|
+
# * *:city* -- the city
|
13
|
+
# * *:state* -- the state
|
14
|
+
# * *:country* -- the country
|
15
|
+
# * *:postal_code* -- the postal/zip code
|
16
|
+
# * *:address_type* -- either :billing or :shipping
|
17
|
+
# * *:region* -- the region (often county); note, only used for shipping addresses, ignored for billing addresses
|
5
18
|
def initialize(options={})
|
6
19
|
@name = options[:name]
|
7
20
|
@street = options[:street]
|
@@ -14,6 +27,9 @@ module PayTrace
|
|
14
27
|
@region = options[:region] if @address_type == :shipping # special case for shipping addresses
|
15
28
|
end
|
16
29
|
|
30
|
+
# Applies the address parameters to a request object for proper formatting to the API
|
31
|
+
# Parameters:
|
32
|
+
# * *request* -- the request object to apply this address to
|
17
33
|
def set_request(request)
|
18
34
|
atype_str = address_type.to_s
|
19
35
|
|
data/lib/paytrace/api/fields.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module PayTrace
|
2
2
|
module API
|
3
|
+
# Friendly names for API methods and parameters
|
3
4
|
def self.fields
|
4
5
|
{
|
5
6
|
amount: "AMOUNT",
|
@@ -52,6 +53,7 @@ module PayTrace
|
|
52
53
|
check_id:"CHECKID",
|
53
54
|
start_date:"SDATE",
|
54
55
|
end_date:"EDATE",
|
56
|
+
store_forward_date:"STRFWDDATE",
|
55
57
|
#credit card
|
56
58
|
card_number: "CC",
|
57
59
|
expiration_year: "EXPYR",
|
@@ -100,6 +102,7 @@ module PayTrace
|
|
100
102
|
recur_count: "TOTALCOUNT",
|
101
103
|
recur_receipt: "CUSTRECEIPT",
|
102
104
|
recur_type: "RECURTYPE",
|
105
|
+
recur_next: "NEXT",
|
103
106
|
# attach signatures
|
104
107
|
image_data: "IMAGEDATA",
|
105
108
|
image_type: "IMAGETYPE",
|
data/lib/paytrace/api/gateway.rb
CHANGED
@@ -4,7 +4,9 @@ require 'paytrace/exceptions'
|
|
4
4
|
|
5
5
|
module PayTrace
|
6
6
|
module API
|
7
|
+
# Helper for sending requests
|
7
8
|
class Gateway
|
9
|
+
# :nodoc:
|
8
10
|
attr_accessor :connection
|
9
11
|
@@debug = false
|
10
12
|
@@last_request = nil
|
@@ -13,14 +15,17 @@ module PayTrace
|
|
13
15
|
@@next_response = nil
|
14
16
|
@@raise_exceptions = true
|
15
17
|
|
18
|
+
# Creates a new gateway object, optionally using a supplied connection object
|
16
19
|
def initialize(connection = nil)
|
17
20
|
@connection = connection || PayTrace.configuration.connection
|
18
21
|
end
|
19
22
|
|
23
|
+
# Sets or clears a debug flag to enable testing
|
20
24
|
def self.debug=(enable)
|
21
25
|
@@debug = enable
|
22
26
|
end
|
23
27
|
|
28
|
+
# Clears debug data
|
24
29
|
def self.reset_trace
|
25
30
|
@@last_request = nil
|
26
31
|
@@last_response = nil
|
@@ -28,26 +33,34 @@ module PayTrace
|
|
28
33
|
@@next_response = nil
|
29
34
|
end
|
30
35
|
|
36
|
+
# Returns the last request sent (as raw text)
|
31
37
|
def self.last_request
|
32
38
|
@@last_request
|
33
39
|
end
|
34
40
|
|
41
|
+
# Returns the last response received (as raw text)
|
35
42
|
def self.last_response
|
36
43
|
@@last_response
|
37
44
|
end
|
38
45
|
|
46
|
+
# Returns the last response object received
|
39
47
|
def self.last_response_object
|
40
48
|
@@last_response_object
|
41
49
|
end
|
42
50
|
|
51
|
+
# Use this to set the raw text of the next response; only used when debug is true
|
43
52
|
def self.next_response=(next_response)
|
44
53
|
@@next_response = next_response
|
45
54
|
end
|
46
55
|
|
56
|
+
# Sets or clears a flag to raise exceptions on receiving server errors
|
47
57
|
def self.raise_exceptions=(raise_exceptions)
|
48
58
|
@@raise_exceptions = raise_exceptions
|
49
59
|
end
|
50
60
|
|
61
|
+
# Sends a request object
|
62
|
+
# Params:
|
63
|
+
# * *:multi_value_response_fields* -- response fields that may have multiple entries for the same key
|
51
64
|
def send_request(request, multi_value_response_fields = [])
|
52
65
|
@@last_request = request.to_parms_string if @@debug
|
53
66
|
unless (@@debug && @@next_response)
|
data/lib/paytrace/api/request.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
module PayTrace
|
2
2
|
module API
|
3
|
+
# An object representing an API request to be sent using a PayTrace::API::Gateway object
|
3
4
|
class Request
|
5
|
+
# :nodoc:
|
4
6
|
attr_reader :params, :field_delim, :value_delim, :discretionary_data
|
7
|
+
# :doc:
|
5
8
|
|
9
|
+
# Initializes a new Request object
|
6
10
|
def initialize
|
7
11
|
@field_delim = "|"
|
8
12
|
@multi_field_delim = "+"
|
@@ -18,6 +22,7 @@ module PayTrace
|
|
18
22
|
@discretionary_data = {}
|
19
23
|
end
|
20
24
|
|
25
|
+
# Returns the formatted URL that this request will send
|
21
26
|
def to_parms_string()
|
22
27
|
raw_request = @params.map do |k,items|
|
23
28
|
items.map do |item|
|
@@ -34,28 +39,39 @@ module PayTrace
|
|
34
39
|
raw_request
|
35
40
|
end
|
36
41
|
|
37
|
-
|
38
|
-
|
39
|
-
|
42
|
+
# Sets discretionary data keys and values
|
43
|
+
# * *:key* -- the name of the setting
|
44
|
+
# * *:value* -- the value of the setting
|
45
|
+
def set_discretionary(key, value = nil)
|
46
|
+
if key.is_a?(Hash)
|
47
|
+
@discretionary_data = key
|
40
48
|
else
|
41
|
-
@discretionary_data[
|
49
|
+
@discretionary_data[key] = value unless value.nil?
|
42
50
|
end
|
43
51
|
end
|
44
52
|
|
53
|
+
# :nodoc:
|
45
54
|
def validate_param(k, v)
|
46
55
|
raise PayTrace::Exceptions::ValidationError.new("Unknown field '#{k}'") unless PayTrace::API.fields.has_key?(k)
|
47
56
|
end
|
57
|
+
# :doc:
|
48
58
|
|
49
|
-
|
50
|
-
|
59
|
+
# Sets a single request parameters
|
60
|
+
# * *:key* -- the name of the setting
|
61
|
+
# * *:value* -- the value of the setting
|
62
|
+
def set_param(key, value = nil)
|
63
|
+
validate_param(key, value)
|
51
64
|
|
52
|
-
unless
|
53
|
-
@params[
|
65
|
+
unless value.nil?
|
66
|
+
@params[key] ||= []
|
54
67
|
|
55
|
-
@params[
|
68
|
+
@params[key] << value
|
56
69
|
end
|
57
70
|
end
|
58
71
|
|
72
|
+
# Sets multiple parameters with the same name using the custom delimiter
|
73
|
+
# * *:param_name* -- the name of the "top level" setting
|
74
|
+
# * *:items* -- a hash of "second level" settings
|
59
75
|
def set_multivalue(param_name, items = {})
|
60
76
|
result = (items.map do |k,v|
|
61
77
|
validate_param(k, v)
|
@@ -67,6 +83,9 @@ module PayTrace
|
|
67
83
|
result
|
68
84
|
end
|
69
85
|
|
86
|
+
# Sets multiple parameters at once
|
87
|
+
# * *:keys* -- an array of key names to extract from the params hash
|
88
|
+
# * *:params* -- the parameters hash to be extracted from
|
70
89
|
def set_params(keys, params)
|
71
90
|
keys.each do |key|
|
72
91
|
set_param(key, params[key])
|
@@ -1,8 +1,28 @@
|
|
1
1
|
module PayTrace
|
2
|
+
# Provides a number of helper methods to process check transactions
|
2
3
|
class CheckTransaction
|
3
4
|
PROCESS_SALE_METHOD = "ProcessCheck"
|
4
5
|
MANAGE_CHECK_METHOD = "ManageCheck"
|
5
6
|
|
7
|
+
# Process a transaction as a sale. Parameters are passed by symbol name in a hash.
|
8
|
+
# _Note:_ either supply a customer ID *or* an account/routing number. Although passing in
|
9
|
+
# both sets of data will not raise an error, the backend API will ignore the account/routing
|
10
|
+
# number if the customer ID is supplied
|
11
|
+
#
|
12
|
+
# The parameters are:
|
13
|
+
# * *:check_type* -- the check transaction type; typically "Sale"
|
14
|
+
# * *:amount* -- the amount of the check
|
15
|
+
# * *:customer_id* -- the customer ID for the check
|
16
|
+
# * *:account_anumber* -- the checking account number
|
17
|
+
# * *:routing_number* -- the checking account routing number
|
18
|
+
# * *:email* -- the customer's email
|
19
|
+
# * *:invoice* -- an invoice number to apply to the sale
|
20
|
+
# * *:description* -- a free text description of the sale
|
21
|
+
# * *:tax_amount* -- the tax amount for the sale
|
22
|
+
# * *:customer_reference_id* -- an optional customer reference number
|
23
|
+
# * *:discretionary_data* -- any discretionary data to be applied
|
24
|
+
# * *:shipping_address* -- a shipping address object; see PayTrace::Address
|
25
|
+
# * *:billing_address* -- a billing address object; see PayTrace::Address
|
6
26
|
def self.process_sale(params = {})
|
7
27
|
request = PayTrace::API::Request.new
|
8
28
|
request.set_param(:method, PROCESS_SALE_METHOD)
|
@@ -15,6 +35,9 @@ module PayTrace
|
|
15
35
|
end
|
16
36
|
end
|
17
37
|
|
38
|
+
# Process a transaction as a hold. Parameters are passed by symbol name in a hash.
|
39
|
+
# _Note:_ the parameters for this method are identical to process_sale; this is simply
|
40
|
+
# a convenience method. The :check_type is automatically set to "Hold"
|
18
41
|
def self.process_hold(params = {})
|
19
42
|
request = PayTrace::API::Request.new
|
20
43
|
request.set_param(:method, PROCESS_SALE_METHOD)
|
@@ -29,6 +52,9 @@ module PayTrace
|
|
29
52
|
end
|
30
53
|
end
|
31
54
|
|
55
|
+
# Process a transaction as a refund. Parameters are passed by symbol name in a hash.
|
56
|
+
# _Note:_ the parameters for this method are identical to process_sale; this is simply
|
57
|
+
# a convenience method. The :check_type is automatically set to "Hold"
|
32
58
|
def self.process_refund(params = {})
|
33
59
|
request = PayTrace::API::Request.new
|
34
60
|
request.set_param(:method, PROCESS_SALE_METHOD)
|
@@ -44,6 +70,10 @@ module PayTrace
|
|
44
70
|
end
|
45
71
|
end
|
46
72
|
|
73
|
+
# Manage an existing check, setting a new check type if necessary. Params are passed by symbol
|
74
|
+
# name in a hash. They are:
|
75
|
+
# * *:check_type* -- the (new) type of this check (e.g. "Sale", "Hold", "Refund", etc.)
|
76
|
+
# * *:check_id* -- the id of the check to manage
|
47
77
|
def self.manage_check(params = {})
|
48
78
|
request = PayTrace::API::Request.new
|
49
79
|
request.set_param(:method, MANAGE_CHECK_METHOD)
|
@@ -56,6 +86,7 @@ module PayTrace
|
|
56
86
|
end
|
57
87
|
end
|
58
88
|
|
89
|
+
# Helper method called by the framework. Do not call directly.
|
59
90
|
def self.add_common_parameters(params = {}, request)
|
60
91
|
request.set_params([
|
61
92
|
:check_type,
|
@@ -1,15 +1,28 @@
|
|
1
1
|
module PayTrace
|
2
|
+
# Contains necessary configuration to access the API server; notably the user name, password, and URL information
|
2
3
|
class Configuration
|
3
4
|
attr_accessor :user_name, :password, :connection, :domain, :path
|
4
5
|
|
5
6
|
RESET_PASSWORD_METHOD = "UpdatePassword"
|
6
7
|
|
8
|
+
# Default initializer. Do not call directly; instead use the PayTrace.configure method
|
9
|
+
# Example:
|
10
|
+
# PayTrace.configure do |config|
|
11
|
+
# config.user_name = "demo123"
|
12
|
+
# config.password = "password"
|
13
|
+
# config.domain = "stage.paytrace.com"
|
14
|
+
# config.path = "api/default.pay"
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# _Note:_ sane defaults are provided for the domain and path; typically you only need to supply the user name and password.
|
7
18
|
def initialize
|
8
19
|
@domain = "paytrace.com"
|
9
20
|
@connection = Faraday.new
|
10
21
|
@path = "api/default.pay"
|
11
22
|
end
|
12
23
|
|
24
|
+
# Updates the API password. Parameters are passed in a hash. They are:
|
25
|
+
# * *:new_password* -- the new password to use
|
13
26
|
def update_password(params)
|
14
27
|
request = PayTrace::API::Request.new
|
15
28
|
request.set_param(:method, RESET_PASSWORD_METHOD)
|
@@ -27,15 +40,19 @@ module PayTrace
|
|
27
40
|
response
|
28
41
|
end
|
29
42
|
|
43
|
+
# Returns the API URL, based off the domain and path configured.
|
30
44
|
def url
|
31
45
|
"https://#{@domain}/#{@path}"
|
32
46
|
end
|
33
47
|
end
|
34
48
|
|
49
|
+
# Returns the singleton Configuration object
|
35
50
|
def self.configuration
|
36
51
|
@configuration ||= Configuration.new
|
37
52
|
end
|
38
53
|
|
54
|
+
# Allows setting configuration properties via a yield block.
|
55
|
+
# :yields: a Configuration object.
|
39
56
|
def self.configure
|
40
57
|
yield(configuration) if block_given?
|
41
58
|
end
|
data/lib/paytrace/credit_card.rb
CHANGED
@@ -1,14 +1,32 @@
|
|
1
1
|
module PayTrace
|
2
|
+
# Contains credit card information, including possible swipe data.
|
2
3
|
class CreditCard
|
3
4
|
attr_accessor :card_number, :expiration_month, :expiration_year, :swipe, :csc
|
4
5
|
|
6
|
+
# Initialize instance; possible options are:
|
7
|
+
# * *:card_number* -- the credit card number
|
8
|
+
# * *:expiration_month* -- the expiration month of the card
|
9
|
+
# * *:expiration_year* -- the expiration year of the card
|
10
|
+
# * *:csc* -- the CSC code
|
11
|
+
# * *:swipe* -- swipe data, if present
|
12
|
+
# All parameters are passed in a hash, with symbols for key names.
|
5
13
|
def initialize(options={})
|
6
|
-
|
7
14
|
@card_number = options[:card_number]
|
8
15
|
@expiration_month = options[:expiration_month]
|
9
16
|
@expiration_year = options[:expiration_year]
|
10
17
|
@swipe = options[:swipe]
|
11
18
|
@csc = options[:csc]
|
12
19
|
end
|
20
|
+
|
21
|
+
# :nodoc:
|
22
|
+
# Internal helper method; not meant to be called directly.
|
23
|
+
def set_request_data(request = nil)
|
24
|
+
request ||= PayTrace::API::Request.new
|
25
|
+
request.set_param(:card_number, card_number) if card_number
|
26
|
+
request.set_param(:expiration_month, expiration_month) if expiration_month
|
27
|
+
request.set_param(:expiration_year, expiration_year) if expiration_year
|
28
|
+
request.set_param(:swipe, swipe) if swipe
|
29
|
+
request.set_param(:csc, csc) if csc
|
30
|
+
end
|
13
31
|
end
|
14
32
|
end
|
data/lib/paytrace/customer.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module PayTrace
|
2
|
+
# Abstracts the idea of a merchant's customer. Also provides numerous helper methods to aid in managing customers.
|
2
3
|
class Customer
|
3
4
|
attr :id, :customer_id
|
4
5
|
|
6
|
+
# :nodoc:
|
5
7
|
CREATE_CUSTOMER = "CreateCustomer"
|
6
8
|
UPDATE_CUSTOMER = "UpdateCustomer"
|
7
9
|
DELETE_CUSTOMER = "DeleteCustomer"
|
@@ -9,14 +11,23 @@ module PayTrace
|
|
9
11
|
EXPORT_INACTIVE_CUSTOMERS = "ExportInactiveCustomers"
|
10
12
|
EXPORT_CUSTOMERS_RESPONSE = "CUSTOMERRECORD"
|
11
13
|
|
14
|
+
# :doc:
|
15
|
+
# Initializer. Only param is:
|
16
|
+
# *customer_id* -- the merchant-generated customer ID, if present
|
12
17
|
def initialize(customer_id = nil)
|
13
18
|
@customer_id = customer_id
|
14
19
|
end
|
15
20
|
|
21
|
+
# See http://help.paytrace.com/api-update-customer-profile
|
22
|
+
# Updates the customer's information from parameters hash. See the self.from_cc_info and self.from_transaction_id for
|
23
|
+
# information on the permitted parameters. Immediately updates the profile.
|
16
24
|
def update(params = {})
|
17
|
-
|
25
|
+
send_request(UPDATE_CUSTOMER, params)
|
18
26
|
end
|
19
27
|
|
28
|
+
# See http://help.paytrace.com/api-delete-customer-profile
|
29
|
+
# Sends a request to the server to delete a given customer. No parameters; the customer ID is assumed to be set on
|
30
|
+
# this object.
|
20
31
|
def delete
|
21
32
|
request = PayTrace::API::Request.new
|
22
33
|
request.set_param(:method, DELETE_CUSTOMER)
|
@@ -25,6 +36,12 @@ module PayTrace
|
|
25
36
|
gateway.send_request(request)
|
26
37
|
end
|
27
38
|
|
39
|
+
# See http://help.paytrace.com/api-exporting-customer-profiles for more information.
|
40
|
+
# Exports a customer's (or multiple customers') profile information. Params:
|
41
|
+
# * *:customer_id* -- the customer ID to export
|
42
|
+
# * *:email* -- the email of the customer to export
|
43
|
+
# * *:transaction_user* -- the user name of the PayTrace user who created or processed the customer or transaction you are trying to export
|
44
|
+
# * *:return_bin* -- if set to "Y", card numbers from ExportTranx and ExportCustomers requests will include the first 6 and last 4 digits of the card number
|
28
45
|
def self.export(params = {})
|
29
46
|
# CUSTID, EMAIL, USER, RETURNBIN
|
30
47
|
request = PayTrace::API::Request.new
|
@@ -41,6 +58,9 @@ module PayTrace
|
|
41
58
|
end
|
42
59
|
end
|
43
60
|
|
61
|
+
# See http://help.paytrace.com/api-exporting-inactive-customers
|
62
|
+
# Exports the profiles of customers who have been inactive for a certain length of time. Params:
|
63
|
+
# *:days_inactive* -- the number of days of inactivity to search for
|
44
64
|
def self.export_inactive(params = {})
|
45
65
|
request = PayTrace::API::Request.new
|
46
66
|
request.set_param(:method, EXPORT_INACTIVE_CUSTOMERS)
|
@@ -53,38 +73,73 @@ module PayTrace
|
|
53
73
|
end
|
54
74
|
end
|
55
75
|
|
76
|
+
# See http://help.paytrace.com/api-delete-customer-profile
|
77
|
+
# Performs the same functionality as Customer.delete, but saves a step by not requiring the user to instantiate a new Customer object first. Params:
|
78
|
+
# *customer_id* -- the merchant-assigned customer ID of the profile to delete
|
56
79
|
def self.delete(customer_id)
|
57
80
|
Customer.new(customer_id).delete
|
58
81
|
end
|
59
82
|
|
83
|
+
# See http://help.paytrace.com/api-create-customer-profile
|
84
|
+
# Creates a new customer profile from credit card information. Params:
|
85
|
+
# *:customer_id* -- customer ID to use
|
86
|
+
# *:billing_address* -- a PayTrace::Address object; at minimum the billing name must be filled out
|
87
|
+
# *:credit_card* -- a PayTrace::CreditCard object
|
88
|
+
# *:shipping_address* -- a PayTrace::Address object representing the shipping address
|
89
|
+
# *:email* -- the customer's email address
|
90
|
+
# *:customer_phone* -- the customer's phone number
|
91
|
+
# *:customer_fax* -- the customer's fax number
|
92
|
+
# *:customer_password* -- password that customer uses to log into customer profile in shopping cart. Only required if you are using the PayTrace shopping cart.
|
93
|
+
# *:account_number* -- a checking account number to use for the customer
|
94
|
+
# *:routing_number* -- a bank routing number to use
|
95
|
+
# *:discretionary_data* -- discretionay data (if any) for the customer, expressed as a hash
|
60
96
|
def self.from_cc_info(params = {})
|
61
97
|
customer = Customer.new(params[:customer_id])
|
62
|
-
customer.
|
98
|
+
customer.send_request(CREATE_CUSTOMER, params)
|
63
99
|
end
|
64
100
|
|
101
|
+
# See http://help.paytrace.com/api-create-customer-profile
|
102
|
+
# Creates a new customer profile from credit card information. Params are the same as from_cc_info, with the exception that *:transaction_id* is used to reference a previous sale transaction instead of a credit card.
|
65
103
|
def self.from_transaction_id(params = {})
|
66
104
|
customer = Customer.new(params[:customer_id])
|
67
|
-
customer.
|
105
|
+
customer.send_request(CREATE_CUSTOMER, params)
|
68
106
|
end
|
69
107
|
|
70
|
-
|
71
|
-
|
108
|
+
# :nodoc:
|
109
|
+
# Internal helper method; not meant to be called directly.
|
110
|
+
def send_request(method, params)
|
111
|
+
request ||= PayTrace::API::Request.new
|
72
112
|
request.set_param(:method, method)
|
113
|
+
if params[:billing_address]
|
114
|
+
params[:billing_address].name = nil if (method == CREATE_CUSTOMER && params[:transaction_id])
|
115
|
+
end
|
116
|
+
set_request_data(params, request)
|
117
|
+
|
118
|
+
gateway = PayTrace::API::Gateway.new
|
119
|
+
response = gateway.send_request(request)
|
120
|
+
unless response.has_errors?
|
121
|
+
values = response.values
|
122
|
+
@id = values["CUSTID"]
|
123
|
+
@customer_id = values["CUSTOMERID"]
|
124
|
+
self
|
125
|
+
else
|
126
|
+
nil
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# :nodoc:
|
131
|
+
# Internal helper method; not meant to be called directly.
|
132
|
+
def set_request_data(params, request = nil)
|
133
|
+
request ||= PayTrace::API::Request.new
|
73
134
|
request.set_param(:customer_id, params[:customer_id])
|
74
135
|
request.set_param(:new_customer_id, params[:new_customer_id])
|
75
136
|
request.set_param(:transaction_id, params[:transaction_id])
|
76
137
|
|
77
|
-
if params[:billing_address]
|
78
|
-
params[:billing_address].name = nil if (method == CREATE_CUSTOMER && params[:transaction_id])
|
79
|
-
params[:billing_address].set_request(request)
|
80
|
-
end
|
138
|
+
params[:billing_address].set_request(request) if params[:billing_address]
|
81
139
|
params[:shipping_address].set_request(request) if params[:shipping_address]
|
82
|
-
|
83
140
|
|
84
141
|
if params[:credit_card]
|
85
|
-
|
86
|
-
request.set_param(:expiration_month, params[:credit_card].expiration_month)
|
87
|
-
request.set_param(:expiration_year, params[:credit_card].expiration_year)
|
142
|
+
params[:credit_card].set_request_data(request)
|
88
143
|
end
|
89
144
|
|
90
145
|
request.set_param(:email, params[:email])
|
@@ -98,17 +153,6 @@ module PayTrace
|
|
98
153
|
request.set_discretionary(k, params[:discretionary_data][k])
|
99
154
|
end
|
100
155
|
end
|
101
|
-
|
102
|
-
gateway = PayTrace::API::Gateway.new
|
103
|
-
response = gateway.send_request(request)
|
104
|
-
unless response.has_errors?
|
105
|
-
values = response.values
|
106
|
-
@id = values["CUSTID"]
|
107
|
-
@customer_id = values["CUSTOMERID"]
|
108
|
-
self
|
109
|
-
else
|
110
|
-
nil
|
111
|
-
end
|
112
156
|
end
|
113
157
|
end
|
114
158
|
end
|
data/lib/paytrace/debug.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'paytrace'
|
2
2
|
|
3
3
|
module PayTrace
|
4
|
+
# Useful helper methods for debugging.
|
4
5
|
module Debug
|
5
6
|
#
|
6
7
|
# Helper that loops through the response values and dumps them out
|
@@ -19,10 +20,17 @@ module PayTrace
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
23
|
+
# Formatted output for a text message.
|
22
24
|
def self.log(msg)
|
23
25
|
puts ">>>>>> #{msg}"
|
24
26
|
end
|
25
27
|
|
28
|
+
# Helper method to dump a request response pair. Usage:
|
29
|
+
# Usage:
|
30
|
+
# PayTrace::Debug.trace do
|
31
|
+
# # code the intiates a request/response pair
|
32
|
+
# end
|
33
|
+
# _Note:_ also includes exception handling to ensure responses are dumped even if an exception occurs
|
26
34
|
def self.trace(&block)
|
27
35
|
PayTrace::API::Gateway.debug = true
|
28
36
|
|
@@ -37,6 +45,8 @@ module PayTrace
|
|
37
45
|
end
|
38
46
|
end
|
39
47
|
|
48
|
+
# Helper method to configure a default test environment. Accepts *username*, *password*, and *domain* parameters.
|
49
|
+
# domain defaults to "stage.paytrace.com" and the username/password default to the credentials for the sandbox account
|
40
50
|
def self.configure_test(un = "demo123", pw = "demo123", domain = "stage.paytrace.com")
|
41
51
|
PayTrace.configure do |config|
|
42
52
|
config.user_name = un
|
@@ -1,8 +1,16 @@
|
|
1
1
|
module PayTrace
|
2
|
+
# Methods to request an email receipt for a transaction
|
2
3
|
class EmailReceiptRequest
|
4
|
+
# :nodoc:
|
3
5
|
TRANSACTION_METHOD = "EmailReceipt"
|
4
6
|
attr_accessor :email, :transaction_id, :check_id
|
7
|
+
# :doc:
|
5
8
|
|
9
|
+
# Initializer. Params:
|
10
|
+
# *:email* -- the email address to send the receipt to
|
11
|
+
# *:transaction_id* -- the transaction ID of the transaction to email
|
12
|
+
# *:check_id* -- the check ID of the transaction to email
|
13
|
+
# _Note:_ only use *:transaction_id* _or_ *:check_id* -- not both.
|
6
14
|
def initialize(params = {})
|
7
15
|
email, id, id_is_check_id = false
|
8
16
|
@email = params[:email]
|
@@ -10,6 +18,7 @@ module PayTrace
|
|
10
18
|
@check_id = params[:check_id]
|
11
19
|
end
|
12
20
|
|
21
|
+
# :nodoc:
|
13
22
|
def set_request(request = nil)
|
14
23
|
request ||= PayTrace::API::Request.new
|
15
24
|
request.set_param(:method, TRANSACTION_METHOD)
|
@@ -19,7 +28,9 @@ module PayTrace
|
|
19
28
|
|
20
29
|
request
|
21
30
|
end
|
31
|
+
# :doc:
|
22
32
|
|
33
|
+
# Sends the request for the transaction. Accepts an existing request object, or creates one if needed.
|
23
34
|
def send_request(request = nil)
|
24
35
|
request ||= set_request
|
25
36
|
|
data/lib/paytrace/exceptions.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
module PayTrace
|
2
|
+
# Container module for custom PayTrace exceptions
|
2
3
|
module Exceptions
|
4
|
+
# Base PayTrace exception object
|
3
5
|
class Base < RuntimeError
|
4
6
|
end
|
5
7
|
|
8
|
+
# Raised when an unknown field is sent, or an incorrect value is used
|
6
9
|
class ValidationError < Base
|
7
10
|
end
|
8
11
|
|
12
|
+
# Raised by default when an error response is returned from the server
|
9
13
|
class ErrorResponse < Base
|
10
14
|
end
|
11
15
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'paytrace'
|
2
2
|
|
3
3
|
module PayTrace
|
4
|
+
# Manages recurring transactions
|
4
5
|
class RecurringTransaction
|
6
|
+
# :nodoc:
|
5
7
|
attr :id, :amount, :customer_id, :next, :total_count, :current_count, :repeat, :description
|
6
8
|
|
7
9
|
CREATE_METHOD = "CreateRecur"
|
@@ -26,18 +28,44 @@ module PayTrace
|
|
26
28
|
"<RecurringTransaction:#{@id},customer id:#{@customer_id},amount: #{@amount},next: #{@next}>"
|
27
29
|
end
|
28
30
|
|
31
|
+
# :doc:
|
32
|
+
|
33
|
+
# See http://help.paytrace.com/api-exporting-recurring-transactions
|
34
|
+
# Exports recurring transactions by recurrence ID or customer ID. Params:
|
35
|
+
# * *:recur_id* -- a recurrence ID to export
|
36
|
+
# * *:customer_id* -- a customer ID to export
|
37
|
+
# _Note:_ only supply a recurrence ID _or_ a customer ID, not both.
|
29
38
|
def self.export_scheduled(params = {})
|
30
39
|
parse_response(set_request_data(EXPORT_SCHEDULED_METHOD, params))
|
31
40
|
end
|
32
41
|
|
42
|
+
# See http://help.paytrace.com/api-exporting-a-recurring-transaction
|
43
|
+
# Exports the single most recent recurring transaction for a given customer ID, Params:
|
44
|
+
# * *:customer_id* -- the customer ID to be exported for
|
33
45
|
def self.export_approved(params = {})
|
34
46
|
set_request_data(EXPORT_APPROVED_METHOD, params)
|
35
47
|
end
|
36
48
|
|
49
|
+
# See http://help.paytrace.com/api-create-recurring-transaction
|
50
|
+
# Creates a recurring transaction. Params:
|
51
|
+
# * *:customer_id* -- the customer ID for which the recurrence should be created
|
52
|
+
# * *:recur_frequency* -- the frequency of the recurrence; this must be 1 for annually, 8 for semi-annually, A for trimesterly, 2 for quarterly, 9 for bi-monthly, , 3 for monthly, 4 for bi-weekly, 7 for 1st and 15th, 5 for weekly, or 6 for daily
|
53
|
+
# * *:recur_start* -- date of the first recurrence
|
54
|
+
# * *:recur_count* -- the total number of times the recurring transaction should be processed. Use 999 if the recurring transaction should be processed indefinitely
|
55
|
+
# * *:amount* -- the amount of the recurrence
|
56
|
+
# * *:transaction_type* -- the transaction type of the recurrence; typically "Sale"
|
57
|
+
# * *:description* -- an optional description of the recurrence
|
58
|
+
# * *:recur_receipt* -- "Y" to send a receipt to the customer at each recurrence; default is "N"
|
59
|
+
# * *:recur_type* -- default value is "C" which represents credit card number. Alternative is "A" which represents an ACH/check transaction
|
37
60
|
def self.create(params = {})
|
38
61
|
parse_response(set_request_data(CREATE_METHOD, params))
|
39
62
|
end
|
40
63
|
|
64
|
+
# See http://help.paytrace.com/api-deleting-a-recurring-transaction
|
65
|
+
# Deletes recurring transactions by recurrence ID or customer ID. Params:
|
66
|
+
# * *:recur_id* -- a recurrence ID to export
|
67
|
+
# * *:customer_id* -- a customer ID to export
|
68
|
+
# _Note:_ only supply a recurrence ID _or_ a customer ID, not both.
|
41
69
|
def self.delete(params = {})
|
42
70
|
request = PayTrace::API::Request.new
|
43
71
|
request.set_param(:method, DELETE_METHOD)
|
@@ -51,10 +79,23 @@ module PayTrace
|
|
51
79
|
parse_response(gateway.send_request(request))
|
52
80
|
end
|
53
81
|
|
82
|
+
# See http://help.paytrace.com/api-update-recurring-transaction
|
83
|
+
# Updates parameters of an existing recurrence. Params:
|
84
|
+
# * *:recur_id* -- a recurrence ID to update
|
85
|
+
# * *:customer_id* -- the customer ID for which the recurrence should be created
|
86
|
+
# * *:recur_frequency* -- the frequency of the recurrence; this must be 1 for annually, 8 for semi-annually, A for trimesterly, 2 for quarterly, 9 for bi-monthly, 3 for monthly, 4 for bi-weekly, 7 for 1st and 15th, 5 for weekly, or 6 for daily
|
87
|
+
# * *:recur_next* -- the date of the next recurrence
|
88
|
+
# * *:recur_count* -- the total number of times the recurring transaction should be processed. Use 999 if the recurring transaction should be processed indefinitely
|
89
|
+
# * *:amount* -- the amount of the recurrence
|
90
|
+
# * *:transaction_type* -- the transaction type of the recurrence; typically "Sale"
|
91
|
+
# * *:description* -- an optional description of the recurrence
|
92
|
+
# * *:recur_receipt* -- "Y" to send a receipt to the customer at each recurrence; default is "N"
|
93
|
+
# * *:recur_type* -- default value is "C" which represents credit card number. Alternative is "A" which represents an ACH/check transaction; _note:_ only use for check/ACH recurrences
|
54
94
|
def self.update(params = {})
|
55
95
|
parse_response(set_request_data(UPDATE_METHOD, params))
|
56
96
|
end
|
57
97
|
|
98
|
+
# :nodoc:
|
58
99
|
def self.parse_response(response)
|
59
100
|
unless response.has_errors?
|
60
101
|
values = response.values
|
@@ -75,6 +116,7 @@ module PayTrace
|
|
75
116
|
request.set_param(:customer_id, params[:customer_id])
|
76
117
|
request.set_param(:recur_frequency, params[:recur_frequency])
|
77
118
|
request.set_param(:recur_start, params[:recur_start])
|
119
|
+
request.set_param(:recur_next, params[:recur_next])
|
78
120
|
request.set_param(:recur_count, params[:recur_count])
|
79
121
|
request.set_param(:amount, params[:amount])
|
80
122
|
request.set_param(:transaction_type, params[:transaction_type])
|
@@ -85,5 +127,6 @@ module PayTrace
|
|
85
127
|
gateway = PayTrace::API::Gateway.new
|
86
128
|
gateway.send_request(request)
|
87
129
|
end
|
130
|
+
# :doc:
|
88
131
|
end
|
89
132
|
end
|
data/lib/paytrace/transaction.rb
CHANGED
@@ -4,101 +4,175 @@ require 'paytrace/address'
|
|
4
4
|
require 'base64'
|
5
5
|
|
6
6
|
module PayTrace
|
7
|
-
|
8
|
-
|
7
|
+
# Manages transaction-related functionality
|
8
|
+
class Transaction
|
9
|
+
# :nodoc:
|
10
|
+
attr_reader :amount, :credit_card, :type, :customer, :billing_address, :shipping_address,:optional_fields
|
11
|
+
attr_accessor :response, :discretionary_data
|
12
|
+
|
13
|
+
TRANSACTION_METHOD = "PROCESSTRANX"
|
14
|
+
EXPORT_TRANSACTIONS_METHOD = "ExportTranx"
|
15
|
+
EXPORT_TRANSACTIONS_RESPONSE = "TRANSACTIONRECORD"
|
16
|
+
ATTACH_SIGNATURE_METHOD = "AttachSignature"
|
17
|
+
CALCULATE_SHIPPING_COST = "CalculateShipping"
|
18
|
+
CALCULATE_SHIPPING_COST_RESPONSE = "SHIPPINGRECORD"
|
19
|
+
LEVEL_3_VISA_METHOD = "Level3Visa"
|
20
|
+
LEVEL_3_MC_METHOD = "Level3MCRD"
|
21
|
+
SETTLE_TRANSACTION_METHOD = "SettleTranx"
|
22
|
+
ADJUST_AMOUNT_METHOD = "AdjustAmount"
|
23
|
+
|
24
|
+
# :doc:
|
25
|
+
|
26
|
+
# See http://help.paytrace.com/api-sale
|
27
|
+
# Creates a sale transaction. Params (in hash format):
|
28
|
+
# * *:amount* -- the amount of the transaction
|
29
|
+
# Depending upon the type of sale, the following additional parameters may be present:
|
30
|
+
# * *:credit_card* -- a PayTrace::CreditCard object (key entered sale)
|
31
|
+
# * *:customer* -- a PayTrace::Customer object (for additional customer data; customer ID token or referenced transaction sale). _Note:_ for discretionary data, the best way to include it is by adding it to the PayTrace::Customer object.
|
32
|
+
# * *:optional* -- optional fields hash, kept inside the parameters
|
33
|
+
# _Note:_ the following parameters are kept in the optional fields hash
|
34
|
+
# * *:swipe* -- credit card swipe data (card swiped sales)
|
35
|
+
# * *:customer_id* -- a PayTrace customer ID (customer ID token sale)
|
36
|
+
# * *:transaction_id* -- a transaction ID (referenced transaction sale)
|
37
|
+
# * *:csc* -- credit card security code (customer ID token or referenced transaction sale)
|
38
|
+
# * *:invoice* -- an internal invoice number (customer ID token or referenced transaction sale)
|
39
|
+
# * *:description* -- a description of the sale (customer ID token or referenced transaction sale)
|
40
|
+
# * *:tax_amount* -- the amount of tax on the sale (customer ID token or referenced transaction sale)
|
41
|
+
# * *:customer_reference_id* -- a customer reference ID (customer ID token or referenced transaction sale)
|
42
|
+
# * *:return_clr* -- if set to "Y", card level results will be returned w/ the response. Card level results include whether or not the card is a consumer, purchasing, check, rewards, etc. account. Card level results are only returned with requests to process sales or authorizations through accounts on the TSYS/Vital, Heartland, Global, Paymentech, and Trident networks.(customer ID token sale)
|
43
|
+
# * *:custom_dba* -- optional value that is sent to the cardholder’s issuer and overrides the business name stored in PayTrace. Custom DBA values are only used with requests to process sales or authorizations through accounts on the TSYS/Vital, Heartland, and Trident networks (customer ID token sale)
|
44
|
+
# * *:enable_partial_authentication* -- flag that must be set to ‘Y’ in order to support partial authorization and balance amounts in transaction responses (customer ID token sale)
|
45
|
+
def self.sale(args)
|
9
46
|
create_transaction(args,TransactionTypes::SALE)
|
10
47
|
end
|
11
48
|
|
12
|
-
|
49
|
+
# See http://help.paytrace.com/api-authorizations
|
50
|
+
# Performs an authorization transaction. Params (in hash format):
|
51
|
+
# * *:amount* -- the amount of the transaction
|
52
|
+
# Depending upon the type of authorization, the following additional parameters may be present:
|
53
|
+
# * *:credit_card* -- a PayTrace::CreditCard object (standard authorization)
|
54
|
+
# * *:customer* -- a PayTrace::Customer object (for additional customer data; customer ID token or referenced transaction sale). _Note:_ for discretionary data, the best way to include it is by adding it to the PayTrace::Customer object.
|
55
|
+
# * *:optional* -- optional fields hash, kept inside the parameters
|
56
|
+
# _Note:_ the following parameters are kept in the optional fields hash
|
57
|
+
# * *:customer_id* -- a PayTrace customer ID (customer ID token auth)
|
58
|
+
# * *:transaction_id* -- a transaction ID (referenced transaction sale)
|
59
|
+
# * *:csc* -- credit card security code (customer ID token or referenced transaction auth)
|
60
|
+
# * *:invoice* -- an internal invoice number (customer ID token or referenced transaction auth)
|
61
|
+
# * *:description* -- a description of the auth (customer ID token or referenced transaction auth)
|
62
|
+
# * *:tax_amount* -- the amount of tax on the auth (customer ID token or referenced transaction auth)
|
63
|
+
# * *:customer_reference_id* -- a customer reference ID (customer ID token or referenced transaction auth)
|
64
|
+
# * *:return_clr* -- if set to "Y", card level results will be returned w/ the response. Card level results include whether or not the card is a consumer, purchasing, check, rewards, etc. account. Card level results are only returned with requests to process auths or authorizations through accounts on the TSYS/Vital, Heartland, Global, Paymentech, and Trident networks.(customer ID token auth)
|
65
|
+
# * *:custom_dba* -- optional value that is sent to the cardholder’s issuer and overrides the business name stored in PayTrace. Custom DBA values are only used with requests to process auths or authorizations through accounts on the TSYS/Vital, Heartland, and Trident networks (customer ID token auth)
|
66
|
+
# * *:enable_partial_authentication* -- flag that must be set to ‘Y’ in order to support partial authorization and balance amounts in transaction responses (customer ID token auth)
|
67
|
+
def self.authorization(args)
|
13
68
|
create_transaction(args,TransactionTypes::Authorization)
|
14
69
|
end
|
15
70
|
|
16
|
-
|
71
|
+
# See http://help.paytrace.com/api-refunds
|
72
|
+
# Note that the parameters and transaction types are the same as for self.sale
|
73
|
+
def self.refund(args)
|
17
74
|
create_transaction(args,TransactionTypes::Refund)
|
18
75
|
end
|
19
76
|
|
20
|
-
|
77
|
+
# See http://help.paytrace.com/api-void
|
78
|
+
# Performs a void request. Parameters are:
|
79
|
+
# * *transaction_id* -- (_Note:_ this is _not_ in a hash!) the transaction ID to void
|
80
|
+
def self.void(transaction_id)
|
21
81
|
params = {transaction_id: transaction_id}
|
22
82
|
t = Transaction.new({type: TransactionTypes::Void,
|
23
83
|
optional:params})
|
24
|
-
t.response = send_request
|
84
|
+
t.response = t.send_request
|
25
85
|
t
|
26
86
|
end
|
27
87
|
|
28
|
-
|
88
|
+
# See http://help.paytrace.com/api-forced-sale
|
89
|
+
# Performs a forced approval sale. Params are:
|
90
|
+
# *approval_code* -- (_Note:_ this is _not_ in a hash!) the approval code obtained external to the PayTrace system
|
91
|
+
# *args* -- the argument hash, see the arguments for self.sale
|
92
|
+
def self.forced_sale(approval_code,args)
|
29
93
|
args[:approval_code] = approval_code
|
30
94
|
create_transaction(args,TransactionTypes::ForcedSale)
|
31
95
|
end
|
32
96
|
|
33
|
-
|
97
|
+
# See http://help.paytrace.com/api-capture
|
98
|
+
# Capturing a transaction updates an approved authorization to a pending settlement status that will initiate a transfer of funds. Processing a capture through the PayTrace API may only be accomplished by providing the transaction ID of the unsettled transaction that should be settled. Params are:
|
99
|
+
# * *transaction_id* -- the transaction ID to be captured
|
100
|
+
def self.capture(transaction_id)
|
34
101
|
t = Transaction.new({transaction_id: transaction_id, type: TransactionTypes::Capture,
|
35
102
|
optional:params})
|
36
|
-
t.response = send_request
|
103
|
+
t.response = t.send_request
|
37
104
|
t
|
38
105
|
end
|
39
106
|
|
40
|
-
|
107
|
+
# See http://help.paytrace.com/api-cash-advance
|
108
|
+
# Processing a Cash Advance transaction is similar to processing a Sale, however Cash Advances are special transactions that result in cash disbursements to the card holder. Consequently, additional information is required to process Cash Advances. Cash Advances should always be swiped unless your card reader is not able to reader the card’s magnetic stripe. Additionally, your PayTrace account must be specially configured to process this type of transaction. Params are:
|
109
|
+
# * *:amount* -- the amount of the cash advance
|
110
|
+
# Depending upon the type of cash advance, the following additional parameters may be present:
|
111
|
+
# * *:credit_card* -- a PayTrace::CreditCard object (key entered cash advances)
|
112
|
+
# * *:optional* -- optional fields hash, kept inside the parameters
|
113
|
+
# _Note:_ the following parameters are kept in the optional fields hash
|
114
|
+
# * *:swipe* -- swipe data provided with the cash advance (swiped cash advances)
|
115
|
+
# * *:cash_advance* -- (swiped cash advances) When set to "Y", this attribute causes a Sale transaction to be processed as a cash advance where cash is given to the customer as opposed to a product or service. Please note that Cash Advances may only be processed on accounts that are set up on the TSYS/Vital network and are configured to process Cash Advances. Also, only swiped/card present Sales may include the CashAdvance parameter
|
116
|
+
# * *:id_number* -- the card holder’s drivers license number or other form of photo ID
|
117
|
+
# * *:id_expiration* -- the expiration date of the card holder’s photo ID. MM/DD/YYYY
|
118
|
+
# * *:cc_last_4* -- the last 4 digits of the card number as it appears on the face of the card
|
119
|
+
# * *:billing_address* -- a billing address provided with the cash advance
|
120
|
+
# * *:shipping_address* -- a shipping address provided with the cash advance (key entered cash advances)
|
121
|
+
# * *:csc* -- credit card security code (key entered cash advances)
|
122
|
+
# * *:invoice* -- an internal invoice number (key entered cash advances)
|
123
|
+
# * *:description* -- a description of the auth (key entered cash advances)
|
124
|
+
# * *:tax_amount* -- the amount of tax on the auth (key entered cash advances)
|
125
|
+
# * *:customer_reference_id* -- a customer reference ID (key entered cash advances)
|
126
|
+
def self.cash_advance(args)
|
41
127
|
args[:cash_advance] = "Y"
|
42
128
|
|
43
129
|
create_transaction(args,TransactionTypes::SALE)
|
44
130
|
end
|
45
131
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
132
|
+
# See http://help.paytrace.com/api-store-and-forward
|
133
|
+
# Processing a store & forward through the PayTrace API will request that the transaction is stored for future authorization for specified amount. Please note that the authorization of the store & forward may be scheduled by provided a StrFwdDate value or manually via the Virtual Terminal. *Note that swiped account numbers and CSC values are not stored. Only the card number and expiration dates are stored from the swipe.*
|
134
|
+
# All versions of store and forward may include the following parameters:
|
135
|
+
# * *:amount* -- the amount of the store and forward
|
136
|
+
# * *:optional* -- optional fields hash, kept inside the parameters
|
137
|
+
# The swiped card version takes the following parameters:
|
138
|
+
# * *:swipe* -- swipe data provided with the store and forward (in optional parameters hash)
|
139
|
+
# The key entered version takes the following parameters:
|
140
|
+
# * *:credit_card* -- additional credit card data
|
141
|
+
# The customer ID (token) version takes the following parameters:
|
142
|
+
# * *:customer_id* -- the customer ID (in optional parameters hash)
|
143
|
+
# * *:customer* -- a PayTrace::Customer object for additional customer details
|
144
|
+
# * *:csc* -- credit card security code (in optional parameters hash)
|
145
|
+
# * *:invoice* -- an internal invoice number (in optional parameters hash)
|
146
|
+
# * *:description* -- a description of the auth (in optional parameters hash)
|
147
|
+
# * *:tax_amount* -- the amount of tax on the auth (in optional parameters hash)
|
148
|
+
# * *:customer_reference_id* -- a customer reference ID (in optional parameters hash)
|
149
|
+
# * *:return_clr* -- if set to "Y", card level results will be returned w/ the response. Card level results include whether or not the card is a consumer, purchasing, check, rewards, etc. account. Card level results are only returned with requests to process auths or authorizations through accounts on the TSYS/Vital, Heartland, Global, Paymentech, and Trident networks.(in optional parameters hash)
|
150
|
+
# * *:custom_dba* -- optional value that is sent to the cardholder’s issuer and overrides the business name stored in PayTrace. Custom DBA values are only used with requests to process auths or authorizations through accounts on the TSYS/Vital, Heartland, and Trident networks (in optional parameters hash)
|
151
|
+
# * *:enable_partial_authentication* -- flag that must be set to ‘Y’ in order to support partial authorization and balance amounts in transaction responses (in optional parameters hash)
|
152
|
+
# * *:store_forward_date* -- optional future date when the transaction should be authorized and settled. Only applicable if the TranxType is STR/FWD (in optional parameters hash)
|
153
|
+
def self.store_forward(amount,credit_card,args={})
|
154
|
+
args[:amount] = amount
|
155
|
+
args[:credit_card] = credit_card
|
156
|
+
create_transaction(args,TransactionTypes::StoreForward)
|
50
157
|
end
|
51
158
|
|
52
|
-
|
53
|
-
def create_transaction(args,type)
|
159
|
+
# :nodoc:
|
160
|
+
def self.create_transaction(args,type)
|
54
161
|
amount = args.delete(:amount) if args[:amount]
|
55
162
|
cc = CreditCard.new(args.delete(:credit_card)) if args[:credit_card]
|
56
163
|
customer = args.delete(:customer) if args[:customer]
|
57
164
|
|
58
|
-
t = Transaction.new({
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
165
|
+
t = Transaction.new({
|
166
|
+
amount: amount,
|
167
|
+
credit_card: cc,
|
168
|
+
customer: customer,
|
169
|
+
type: type,
|
170
|
+
optional:args})
|
171
|
+
t.send_request
|
63
172
|
|
64
|
-
t.response = send_request(t)
|
65
173
|
t
|
66
174
|
end
|
67
175
|
|
68
|
-
private
|
69
|
-
def send_request(t)
|
70
|
-
request = PayTrace::API::Request.new
|
71
|
-
t.set_request(request)
|
72
|
-
|
73
|
-
gateway = PayTrace::API::Gateway.new
|
74
|
-
gateway.send_request(request)
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
class Transaction
|
80
|
-
class << self
|
81
|
-
include TransactionOperations
|
82
|
-
end
|
83
|
-
|
84
|
-
attr_reader :amount, :credit_card, :type, :customer, :billing_address, :shipping_address,:optional_fields
|
85
|
-
attr_accessor :response, :discretionary_data
|
86
|
-
|
87
|
-
TRANSACTION_METHOD = "PROCESSTRANX"
|
88
|
-
EXPORT_TRANSACTIONS_METHOD = "ExportTranx"
|
89
|
-
EXPORT_TRANSACTIONS_RESPONSE = "TRANSACTIONRECORD"
|
90
|
-
ATTACH_SIGNATURE_METHOD = "AttachSignature"
|
91
|
-
CALCULATE_SHIPPING_COST = "CalculateShipping"
|
92
|
-
CALCULATE_SHIPPING_COST_RESPONSE = "SHIPPINGRECORD"
|
93
|
-
LEVEL_3_VISA_METHOD = "Level3Visa"
|
94
|
-
LEVEL_3_MC_METHOD = "Level3MCRD"
|
95
|
-
SETTLE_TRANSACTION_METHOD = "SettleTranx"
|
96
|
-
ADJUST_AMOUNT_METHOD = "AdjustAmount"
|
97
|
-
|
98
|
-
def set_shipping_same_as_billing()
|
99
|
-
@shipping_address = @billing_address
|
100
|
-
end
|
101
|
-
|
102
176
|
def initialize(params = {})
|
103
177
|
@amount = params[:amount]
|
104
178
|
@credit_card = params[:credit_card]
|
@@ -111,7 +185,7 @@ module PayTrace
|
|
111
185
|
def set_request(request)
|
112
186
|
add_credit_card(request, credit_card) if credit_card
|
113
187
|
if customer.is_a?(PayTrace::Customer)
|
114
|
-
|
188
|
+
customer.set_request_data(request)
|
115
189
|
elsif customer.is_a?(Fixnum)
|
116
190
|
request.set_param(:customer_id, customer)
|
117
191
|
end
|
@@ -122,18 +196,21 @@ module PayTrace
|
|
122
196
|
request.set_discretionary(@discretionary_data)
|
123
197
|
end
|
124
198
|
end
|
199
|
+
# :doc:
|
200
|
+
|
125
201
|
|
126
202
|
def self.export(params = {})
|
127
203
|
request = PayTrace::API::Request.new
|
128
204
|
request.set_param(:method, EXPORT_TRANSACTIONS_METHOD)
|
129
|
-
request.
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
205
|
+
request.set_params([
|
206
|
+
:transaction_id,
|
207
|
+
:start_date,
|
208
|
+
:end_date,
|
209
|
+
:transaction_type,
|
210
|
+
:customer_id,
|
211
|
+
:transaction_user,
|
212
|
+
:return_bin,
|
213
|
+
:search_text], params)
|
137
214
|
|
138
215
|
gateway = PayTrace::API::Gateway.new
|
139
216
|
response = gateway.send_request(request, [EXPORT_TRANSACTIONS_RESPONSE])
|
@@ -146,9 +223,9 @@ module PayTrace
|
|
146
223
|
def self.attach_signature(params = {})
|
147
224
|
request = PayTrace::API::Request.new
|
148
225
|
request.set_param(:method, ATTACH_SIGNATURE_METHOD)
|
149
|
-
request.
|
150
|
-
|
151
|
-
|
226
|
+
request.set_params([:transaction_id,
|
227
|
+
:image_data,
|
228
|
+
:image_type], params)
|
152
229
|
if params.has_key?(:image_file)
|
153
230
|
File.open(params[:image_file], 'rb') do |file|
|
154
231
|
request.set_param(:image_data, Base64.encode64(file.read))
|
@@ -250,7 +327,6 @@ module PayTrace
|
|
250
327
|
gateway.send_request(request)
|
251
328
|
end
|
252
329
|
|
253
|
-
private
|
254
330
|
def add_transaction_info(request)
|
255
331
|
request.set_param(:transaction_type, type)
|
256
332
|
request.set_param(:method, TRANSACTION_METHOD)
|
@@ -258,11 +334,7 @@ module PayTrace
|
|
258
334
|
end
|
259
335
|
|
260
336
|
def add_credit_card(request, cc)
|
261
|
-
|
262
|
-
request.set_param(:expiration_month, cc.expiration_month) if cc.expiration_month
|
263
|
-
request.set_param(:expiration_year, cc.expiration_year) if cc.expiration_year
|
264
|
-
request.set_param(:swipe, cc.swipe) if cc.swipe
|
265
|
-
request.set_param(:csc, cc.csc) if cc.csc
|
337
|
+
cc.set_request_data(request)
|
266
338
|
end
|
267
339
|
|
268
340
|
def add_optional_fields(request)
|
@@ -288,13 +360,21 @@ module PayTrace
|
|
288
360
|
s = args.delete(:shipping_address) if args[:shipping_address]
|
289
361
|
@shipping_address = PayTrace::Address.new({address_type: :shipping}.merge(s)) if s
|
290
362
|
if args[:address_shipping_same_as_billing]
|
291
|
-
|
363
|
+
@shipping_address = @billing_address
|
292
364
|
end
|
293
365
|
|
294
|
-
|
366
|
+
if args.any?
|
367
|
+
@optional_fields = args
|
368
|
+
end
|
295
369
|
end
|
296
370
|
|
371
|
+
def send_request
|
372
|
+
request = PayTrace::API::Request.new
|
373
|
+
self.set_request(request)
|
297
374
|
|
375
|
+
gateway = PayTrace::API::Gateway.new
|
376
|
+
gateway.send_request(request)
|
377
|
+
end
|
298
378
|
end
|
299
379
|
|
300
380
|
module TransactionTypes
|
data/lib/paytrace/version.rb
CHANGED
@@ -8,6 +8,7 @@ describe PayTrace::Transaction do
|
|
8
8
|
before do
|
9
9
|
PayTrace::API::Gateway.debug = true
|
10
10
|
PayTrace::API::Gateway.reset_trace()
|
11
|
+
PayTrace::API::Gateway.next_response = "RESPONSE~ok|"
|
11
12
|
end
|
12
13
|
|
13
14
|
it "exports transaction(s)" do
|
@@ -78,10 +79,6 @@ describe PayTrace::Transaction do
|
|
78
79
|
end
|
79
80
|
|
80
81
|
describe "create sales transactions" do
|
81
|
-
before do
|
82
|
-
@response = mock()
|
83
|
-
PayTrace::API::Gateway.any_instance.expects(:send_request).returns(@response)
|
84
|
-
end
|
85
82
|
it "can create a Payment Authorization" do
|
86
83
|
t = PayTrace::Transaction.authorization(
|
87
84
|
{ amount:"1242.32",
|
@@ -122,7 +119,6 @@ describe PayTrace::Transaction do
|
|
122
119
|
t.credit_card.card_number.must_equal "1234123412341234"
|
123
120
|
t.credit_card.expiration_month.must_equal 10
|
124
121
|
t.credit_card.expiration_year.must_equal 24
|
125
|
-
t.response.must_equal @response
|
126
122
|
end
|
127
123
|
|
128
124
|
it "can run a transaction for a customer" do
|
@@ -135,8 +131,6 @@ describe PayTrace::Transaction do
|
|
135
131
|
t.type.must_equal PayTrace::TransactionTypes::SALE
|
136
132
|
t.customer.must_equal 123456
|
137
133
|
t.credit_card.must_be_nil
|
138
|
-
t.response.must_equal @response
|
139
|
-
|
140
134
|
end
|
141
135
|
|
142
136
|
it "can run a cash advance" do
|
@@ -220,25 +214,6 @@ describe PayTrace::Transaction do
|
|
220
214
|
b.country.must_equal "USA"
|
221
215
|
b.postal_code.must_equal "98107"
|
222
216
|
end
|
223
|
-
|
224
|
-
it "will return the same address if set to billing shipping same address" do
|
225
|
-
address = {
|
226
|
-
street: "1234 happy lane",
|
227
|
-
street2: "suit 234",
|
228
|
-
city:"Seattle",
|
229
|
-
state:"WA",
|
230
|
-
country:"USA",
|
231
|
-
postal_code:"98107"
|
232
|
-
}
|
233
|
-
|
234
|
-
t = PayTrace::Transaction.new({
|
235
|
-
optional: { billing_address: address
|
236
|
-
} })
|
237
|
-
t.set_shipping_same_as_billing
|
238
|
-
|
239
|
-
t.shipping_address.must_equal t.billing_address
|
240
|
-
end
|
241
|
-
|
242
217
|
end
|
243
218
|
|
244
219
|
it "can be set to void a transaction" do
|
@@ -255,16 +230,10 @@ describe PayTrace::Transaction do
|
|
255
230
|
end
|
256
231
|
|
257
232
|
it "can create a forced sale" do
|
258
|
-
@response = mock()
|
259
|
-
PayTrace::API::Gateway.any_instance.expects(:send_request).returns(@response)
|
260
233
|
t = PayTrace::Transaction.forced_sale("111",{})
|
261
234
|
|
262
235
|
t.optional_fields[:approval_code].must_equal "111"
|
263
236
|
t.type.must_equal PayTrace::TransactionTypes::ForcedSale
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
237
|
end
|
269
238
|
|
270
239
|
|
@@ -3,11 +3,15 @@ $:<< "./lib" # uncomment this to run against a Git clone instead of an installed
|
|
3
3
|
require "paytrace"
|
4
4
|
require "paytrace/debug"
|
5
5
|
|
6
|
+
# see: http://help.paytrace.com/api-processing-a-check-sale
|
7
|
+
|
6
8
|
# change this as needed to reflect the username, password, and test host you're testing against
|
7
9
|
PayTrace::Debug.configure_test("demo123", "demo123", "stage.paytrace.com")
|
8
10
|
|
9
|
-
#
|
11
|
+
# setting this to false keeps the framework from throwing an exception and halting the integration test at the first error
|
12
|
+
PayTrace::API::Gateway.raise_exceptions = false
|
10
13
|
|
14
|
+
# process sale transaction -- replace with valid customer ID to see it succeed.
|
11
15
|
PayTrace::Debug.trace do
|
12
16
|
params = {
|
13
17
|
check_type: "Sale",
|
@@ -18,4 +22,58 @@ PayTrace::Debug.trace do
|
|
18
22
|
}
|
19
23
|
|
20
24
|
PayTrace::CheckTransaction::process_sale(params)
|
25
|
+
end
|
26
|
+
|
27
|
+
# process manage check -- this is invalid data, you can replace with a valid check number
|
28
|
+
# for the login to see it succeed.
|
29
|
+
PayTrace::Debug.trace do
|
30
|
+
params = {
|
31
|
+
check_type: "Hold",
|
32
|
+
check_id: 1234
|
33
|
+
}
|
34
|
+
|
35
|
+
PayTrace::CheckTransaction::manage_check(params)
|
36
|
+
end
|
37
|
+
|
38
|
+
# process a check refund -- replace this with a valid customer ID and amount to see it succeed
|
39
|
+
PayTrace::Debug.trace do
|
40
|
+
ba = PayTrace::Address.new({
|
41
|
+
name: "John Doe",
|
42
|
+
street: "1234 Main Street",
|
43
|
+
street2: "Apartment 1B",
|
44
|
+
city: "Shoreline",
|
45
|
+
state: "WA",
|
46
|
+
country: "US",
|
47
|
+
postal_code: "98133",
|
48
|
+
address_type: :billing
|
49
|
+
})
|
50
|
+
|
51
|
+
sa = PayTrace::Address.new({
|
52
|
+
name: "Jane Doe",
|
53
|
+
street: "1235 Moon Street",
|
54
|
+
street2: "Apartment 2C",
|
55
|
+
city: "Shortline",
|
56
|
+
state: "WA",
|
57
|
+
country: "US",
|
58
|
+
postal_code: "98134",
|
59
|
+
address_type: :shipping
|
60
|
+
})
|
61
|
+
|
62
|
+
params = {
|
63
|
+
check_type: "Refund",
|
64
|
+
amount: 15.99,
|
65
|
+
customer_id: "MMouse",
|
66
|
+
billing_address: ba,
|
67
|
+
shipping_address: sa,
|
68
|
+
email: "tom@paytrace.com",
|
69
|
+
invoice: "abc1234",
|
70
|
+
description: "accidental billing",
|
71
|
+
tax: 2.99,
|
72
|
+
customer_reference_id: '1234AB',
|
73
|
+
discretionary_data: {
|
74
|
+
hair_color: :red
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
PayTrace::CheckTransaction::process_refund(params)
|
21
79
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paytrace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trevor Redfern
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
176
|
version: '0'
|
177
177
|
requirements: []
|
178
178
|
rubyforge_project:
|
179
|
-
rubygems_version: 2.2.
|
179
|
+
rubygems_version: 2.2.2
|
180
180
|
signing_key:
|
181
181
|
specification_version: 4
|
182
182
|
summary: Integration providing access to the transaction processing API for PayTrace
|