eway_rapid 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -0
- data/LICENSE.md +21 -0
- data/README.md +96 -0
- data/Rakefile +14 -0
- data/eway_rapid.gemspec +26 -0
- data/lib/eway_rapid.rb +78 -0
- data/lib/eway_rapid/constants.rb +126 -0
- data/lib/eway_rapid/entities/cancel_authorisation_request.rb +9 -0
- data/lib/eway_rapid/entities/cancel_authorisation_response.rb +34 -0
- data/lib/eway_rapid/entities/capture_payment_request.rb +11 -0
- data/lib/eway_rapid/entities/capture_payment_response.rb +34 -0
- data/lib/eway_rapid/entities/create_access_code_request.rb +35 -0
- data/lib/eway_rapid/entities/create_access_code_response.rb +128 -0
- data/lib/eway_rapid/entities/create_access_code_shared_request.rb +53 -0
- data/lib/eway_rapid/entities/create_access_code_shared_response.rb +40 -0
- data/lib/eway_rapid/entities/create_customer_response.rb +8 -0
- data/lib/eway_rapid/entities/direct_customer_search_request.rb +9 -0
- data/lib/eway_rapid/entities/direct_customer_search_response.rb +23 -0
- data/lib/eway_rapid/entities/direct_payment_request.rb +29 -0
- data/lib/eway_rapid/entities/direct_payment_response.rb +58 -0
- data/lib/eway_rapid/entities/direct_refund_request.rb +26 -0
- data/lib/eway_rapid/entities/direct_refund_response.rb +44 -0
- data/lib/eway_rapid/entities/transaction_search_response.rb +23 -0
- data/lib/eway_rapid/exceptions.rb +51 -0
- data/lib/eway_rapid/message/convert/customer_to_internal_customer.rb +70 -0
- data/lib/eway_rapid/message/convert/direct_payment_to_trans_status.rb +47 -0
- data/lib/eway_rapid/message/convert/direct_refund_to_trans_status.rb +33 -0
- data/lib/eway_rapid/message/convert/internal_customer_to_customer.rb +41 -0
- data/lib/eway_rapid/message/convert/internal_trans_to_trans.rb +62 -0
- data/lib/eway_rapid/message/convert/internal_transaction_to_address.rb +27 -0
- data/lib/eway_rapid/message/convert/internal_transaction_to_status.rb +55 -0
- data/lib/eway_rapid/message/convert/payment_to_payment_details.rb +25 -0
- data/lib/eway_rapid/message/convert/request/refund_to_direct_refund_req.rb +41 -0
- data/lib/eway_rapid/message/convert/request/transaction_to_capture_payment.rb +28 -0
- data/lib/eway_rapid/message/convert/request/transaction_to_create_access_code_request.rb +58 -0
- data/lib/eway_rapid/message/convert/request/transaction_to_create_access_code_shared_request.rb +54 -0
- data/lib/eway_rapid/message/convert/request/transaction_to_direct_payment.rb +45 -0
- data/lib/eway_rapid/message/convert/response/access_code_shared_to_create_cust.rb +23 -0
- data/lib/eway_rapid/message/convert/response/access_code_shared_to_create_trans.rb +28 -0
- data/lib/eway_rapid/message/convert/response/access_code_to_create_cust.rb +24 -0
- data/lib/eway_rapid/message/convert/response/access_code_to_create_trans.rb +27 -0
- data/lib/eway_rapid/message/convert/response/cancel_authorisation_to_refund.rb +37 -0
- data/lib/eway_rapid/message/convert/response/capture_payment_to_create_transaction.rb +43 -0
- data/lib/eway_rapid/message/convert/response/direct_customer_to_query_customer.rb +55 -0
- data/lib/eway_rapid/message/convert/response/direct_payment_to_create_cust.rb +23 -0
- data/lib/eway_rapid/message/convert/response/direct_payment_to_create_trans.rb +32 -0
- data/lib/eway_rapid/message/convert/response/direct_refund_to_refund_response.rb +28 -0
- data/lib/eway_rapid/message/convert/response/search_to_query_trans.rb +30 -0
- data/lib/eway_rapid/message/convert/shipping_details_to_address.rb +35 -0
- data/lib/eway_rapid/message/convert/transaction_shipping_address.rb +37 -0
- data/lib/eway_rapid/message/convert/transaction_to_arr_line_item.rb +14 -0
- data/lib/eway_rapid/message/convert/transaction_to_arr_option.rb +25 -0
- data/lib/eway_rapid/message/convert/transaction_to_payment.rb +29 -0
- data/lib/eway_rapid/message/convert/verification_to_verification_result.rb +33 -0
- data/lib/eway_rapid/message/process/customer_process.rb +255 -0
- data/lib/eway_rapid/message/process/refund_process.rb +76 -0
- data/lib/eway_rapid/message/process/rest_process.rb +87 -0
- data/lib/eway_rapid/message/process/transaction_process.rb +139 -0
- data/lib/eway_rapid/models/enums.rb +126 -0
- data/lib/eway_rapid/models/internal_models.rb +431 -0
- data/lib/eway_rapid/models/models.rb +334 -0
- data/lib/eway_rapid/output/create_transaction_response.rb +24 -0
- data/lib/eway_rapid/output/query_customer_response.rb +25 -0
- data/lib/eway_rapid/output/query_transaction_response.rb +16 -0
- data/lib/eway_rapid/output/refund_response.rb +9 -0
- data/lib/eway_rapid/output/response_output.rb +14 -0
- data/lib/eway_rapid/rapid_client.rb +444 -0
- data/lib/eway_rapid/rapid_logger.rb +40 -0
- data/lib/eway_rapid/resources/err_code_resource_en.yml +237 -0
- data/lib/eway_rapid/resources/rapid-api.yml +4 -0
- data/lib/eway_rapid/version.rb +3 -0
- metadata +201 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
module EwayRapid
|
2
|
+
module Message
|
3
|
+
module RefundProcess
|
4
|
+
|
5
|
+
# Refund message process
|
6
|
+
class RefundMsgProcess
|
7
|
+
include RestProcess
|
8
|
+
|
9
|
+
# @param [Models::Refund] refund
|
10
|
+
# @return [DirectRefundRequest]
|
11
|
+
def self.create_request(refund)
|
12
|
+
converter = Convert::Request::RefundToDirectRefundReq.new
|
13
|
+
converter.do_convert(refund)
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param [DirectRefundRequest] request
|
17
|
+
# @return [String]
|
18
|
+
def self.send_request(url, api_key, password, request)
|
19
|
+
url = url + '/' + request.refund.original_transaction_id.to_s + '/' + Constants::REFUND_SUB_PATH_METHOD
|
20
|
+
url = URI.encode(url)
|
21
|
+
RefundMsgProcess.new.do_post(url, api_key, password, request)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param [String] response
|
25
|
+
# @return [RefundResponse]
|
26
|
+
def self.make_result(response)
|
27
|
+
response = DirectRefundResponse.from_json(response)
|
28
|
+
converter = Convert::Response::DirectRefundToRefundResponse.new
|
29
|
+
converter.do_convert(response)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# cancel authorisation message process
|
34
|
+
class CancelAuthorisationMsgProcess
|
35
|
+
include RestProcess
|
36
|
+
|
37
|
+
# @param [Models::Refund] refund
|
38
|
+
# @return [CancelAuthorisationRequest]
|
39
|
+
def self.create_request(refund)
|
40
|
+
set_refund(refund)
|
41
|
+
request = CancelAuthorisationRequest.new
|
42
|
+
|
43
|
+
# @type [InternalModels::RefundDetails]
|
44
|
+
refund_detail = refund.refund_details
|
45
|
+
unless refund_detail
|
46
|
+
fail 'Refund detail has been null'
|
47
|
+
end
|
48
|
+
request.transaction_id = refund_detail.original_transaction_id
|
49
|
+
request
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.send_request(url, api_key, password, request)
|
53
|
+
CancelAuthorisationMsgProcess.new.do_post(url, api_key, password, request)
|
54
|
+
end
|
55
|
+
|
56
|
+
# @param [String] response
|
57
|
+
# @return [RefundResponse]
|
58
|
+
def self.make_result(response)
|
59
|
+
cancel_response = CancelAuthorisationResponse.from_json(response)
|
60
|
+
converter = Convert::Response::CancelAuthorisationToRefund.new(get_refund)
|
61
|
+
converter.do_convert(cancel_response)
|
62
|
+
end
|
63
|
+
|
64
|
+
# @param [Models::Refund] refund
|
65
|
+
def self.set_refund(refund)
|
66
|
+
@refund = refund
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [Models::Refund]
|
70
|
+
def self.get_refund
|
71
|
+
@refund
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module EwayRapid
|
2
|
+
module Message
|
3
|
+
module RestProcess
|
4
|
+
|
5
|
+
# Call restful web service with post method
|
6
|
+
#
|
7
|
+
# @param [String] url rapid endpoint url
|
8
|
+
# @param [String] api_key rapid api key
|
9
|
+
# @param [String] password rapid password
|
10
|
+
# @param [String] request object to post
|
11
|
+
def do_post(url, api_key, password, request)
|
12
|
+
begin
|
13
|
+
RestClient::Request.execute(
|
14
|
+
:method => :post,
|
15
|
+
:url => url,
|
16
|
+
:user => api_key,
|
17
|
+
:password => password,
|
18
|
+
:payload => request.to_json,
|
19
|
+
:timeout => 9000000,
|
20
|
+
:headers => {
|
21
|
+
:accept => :json,
|
22
|
+
:content_type => :json,
|
23
|
+
:user_agent => get_user_agent
|
24
|
+
}
|
25
|
+
)
|
26
|
+
rescue SocketError => e
|
27
|
+
raise Exceptions::CommunicationFailureException.new(e.to_s)
|
28
|
+
rescue RestClient::Exception => e
|
29
|
+
if e.http_code == 401 || e.http_code == 403 || e.http_code == 404
|
30
|
+
raise Exceptions::AuthenticationFailureException.new(e.to_s)
|
31
|
+
else
|
32
|
+
raise Exceptions::SystemErrorException.new(e.to_s)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Call restful web service with get method
|
38
|
+
#
|
39
|
+
# @param [String] url rapid endpoint url
|
40
|
+
# @param [String] api_key rapid api key
|
41
|
+
# @param [String] password rapid password
|
42
|
+
def do_get(url, api_key, password)
|
43
|
+
begin
|
44
|
+
RestClient::Request.new(
|
45
|
+
:method => :get,
|
46
|
+
:url => url,
|
47
|
+
:user => api_key,
|
48
|
+
:password => password,
|
49
|
+
:headers => {
|
50
|
+
:accept => :json,
|
51
|
+
:content_type => :json,
|
52
|
+
:user_agent => get_user_agent
|
53
|
+
}
|
54
|
+
).execute
|
55
|
+
rescue SocketError => e
|
56
|
+
raise Exceptions::CommunicationFailureException.new(e.to_s)
|
57
|
+
rescue RestClient::Exception => e
|
58
|
+
if e.http_code == 401 || e.http_code == 403 || e.http_code == 404
|
59
|
+
raise Exceptions::AuthenticationFailureException.new(e.to_s)
|
60
|
+
else
|
61
|
+
raise Exceptions::SystemErrorException.new(e.to_s)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def get_user_agent
|
69
|
+
begin
|
70
|
+
property_array = YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'resources', 'rapid-api.yml'))
|
71
|
+
property_array.each do |h|
|
72
|
+
if Constants::RAPID_SDK_USER_AGENT_PARAM == h.keys.first
|
73
|
+
if h[h.keys.first]
|
74
|
+
return "#{h[h.keys.first]} #{EwayRapid::VERSION}"
|
75
|
+
else
|
76
|
+
fail "Rapid endpoint '#{Constants::RAPID_API_RESOURCE}' is invalid."
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
rescue => e
|
81
|
+
@logger.error "Error loading user agent parameter #{e}" if @logger
|
82
|
+
end
|
83
|
+
''
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module EwayRapid
|
2
|
+
module Message
|
3
|
+
module TransactionProcess
|
4
|
+
|
5
|
+
# Create transaction with direct payment message process
|
6
|
+
class TransDirectPaymentMsgProcess
|
7
|
+
include RestProcess
|
8
|
+
|
9
|
+
# @param [Models::Transaction] input
|
10
|
+
# @return [DirectPaymentRequest]
|
11
|
+
def self.create_request(input)
|
12
|
+
req_convert = Convert::Request::TransactionToDirectPayment.new
|
13
|
+
req_convert.do_convert(input)
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param [String] url
|
17
|
+
# @param [String] api_key
|
18
|
+
# @param [String] password
|
19
|
+
# @param [DirectPaymentRequest] request
|
20
|
+
# @return [String]
|
21
|
+
def self.send_request(url, api_key, password, request)
|
22
|
+
TransDirectPaymentMsgProcess.new.do_post(url, api_key, password, request)
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param [String] response
|
26
|
+
# @return [CreateTransactionResponse]
|
27
|
+
def self.make_result(response)
|
28
|
+
direct_payment_response = DirectPaymentResponse.from_json(response)
|
29
|
+
converter = Convert::Response::DirectPaymentToCreateTrans.new
|
30
|
+
converter.do_convert(direct_payment_response)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Create transaction with responsive shared message process
|
35
|
+
class TransResponsiveSharedMsgProcess
|
36
|
+
include RestProcess
|
37
|
+
|
38
|
+
# @param [Models::Transaction] input
|
39
|
+
# @return [CreateAccessCodeSharedRequest]AccessCodeSharedToCreateCust
|
40
|
+
def self.create_request(input)
|
41
|
+
req_convert = Convert::Request::TransactionToCreateAccessCodeSharedRequest.new
|
42
|
+
req_convert.do_convert(input)
|
43
|
+
end
|
44
|
+
|
45
|
+
# @param [String] url
|
46
|
+
# @param [String] api_key
|
47
|
+
# @param [String] password
|
48
|
+
# @param [CreateAccessCodeSharedRequest] request
|
49
|
+
# @return [String]
|
50
|
+
def self.send_request(url, api_key, password, request)
|
51
|
+
TransResponsiveSharedMsgProcess.new.do_post(url, api_key, password, request)
|
52
|
+
end
|
53
|
+
|
54
|
+
# @param [String] response
|
55
|
+
# @return [CreateTransactionResponse]
|
56
|
+
def self.make_result(response)
|
57
|
+
access_code_shared_response = CreateAccessCodeSharedResponse.from_json(response)
|
58
|
+
converter = Convert::Response::AccessCodeSharedToCreateTrans.new
|
59
|
+
converter.do_convert(access_code_shared_response)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Create transaction with transparent redirect method message process
|
64
|
+
class TransTransparentRedirectMsgProcess
|
65
|
+
include RestProcess
|
66
|
+
|
67
|
+
# @param [Models::Transaction] input
|
68
|
+
# @return [CreateAccessCodeRequest]
|
69
|
+
def self.create_request(input)
|
70
|
+
req_convert = Convert::Request::TransactionToCreateAccessCodeRequest.new
|
71
|
+
req_convert.do_convert(input)
|
72
|
+
end
|
73
|
+
|
74
|
+
# @param [String] url
|
75
|
+
# @param [String] api_key
|
76
|
+
# @param [String] password
|
77
|
+
# @param [CreateAccessCodeRequest] request
|
78
|
+
# @return [String]
|
79
|
+
def self.send_request(url, api_key, password, request)
|
80
|
+
TransTransparentRedirectMsgProcess.new.do_post(url, api_key, password, request)
|
81
|
+
end
|
82
|
+
|
83
|
+
# @param [String] response
|
84
|
+
# @return [CreateTransactionResponse]
|
85
|
+
def self.make_result(response)
|
86
|
+
create_access_code_response = CreateAccessCodeResponse.from_json(response)
|
87
|
+
converter = Convert::Response::AccessCodeToCreateTrans.new
|
88
|
+
converter.do_convert(create_access_code_response)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Capture payment message process
|
93
|
+
class CapturePaymentMsgProcess
|
94
|
+
include RestProcess
|
95
|
+
|
96
|
+
# @param [Models::Transaction] input
|
97
|
+
# @return [CapturePaymentRequest]
|
98
|
+
def self.create_request(input)
|
99
|
+
req_convert = Convert::Request::TransactionToCapturePayment.new
|
100
|
+
req_convert.do_convert(input)
|
101
|
+
end
|
102
|
+
|
103
|
+
# @param [String] url
|
104
|
+
# @param [String] api_key
|
105
|
+
# @param [String] password
|
106
|
+
# @param [CapturePaymentRequest] request
|
107
|
+
# @return [String]
|
108
|
+
def self.send_request(url, api_key, password, request)
|
109
|
+
CapturePaymentMsgProcess.new.do_post(url, api_key, password, request)
|
110
|
+
end
|
111
|
+
|
112
|
+
# @param [String] response
|
113
|
+
# @return [CreateTransactionResponse]
|
114
|
+
def self.make_result(response)
|
115
|
+
capture_payment_response = CapturePaymentResponse.from_json(response)
|
116
|
+
converter = Convert::Response::CapturePaymentToCreateTransaction.new
|
117
|
+
converter.do_convert(capture_payment_response)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# Query transaction message process
|
122
|
+
class TransQueryMsgProcess
|
123
|
+
include RestProcess
|
124
|
+
|
125
|
+
def self.process_post_msg(url, api_key, password)
|
126
|
+
TransQueryMsgProcess.new.do_get(url, api_key, password)
|
127
|
+
end
|
128
|
+
|
129
|
+
# @param [String] response
|
130
|
+
# @return [QueryTransactionResponse]
|
131
|
+
def self.make_result(response)
|
132
|
+
transaction_search_resp = TransactionSearchResponse.from_json(response)
|
133
|
+
converter = Convert::Response::SearchToQueryTrans.new
|
134
|
+
converter.do_convert(transaction_search_resp)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
module EwayRapid
|
2
|
+
module Enums
|
3
|
+
|
4
|
+
class BeagleVerifyStatus
|
5
|
+
NOT_VERIFIED = 'NotVerified'
|
6
|
+
ATTEMPTED = 'Attempted'
|
7
|
+
VERIFIED = 'Verified'
|
8
|
+
FAILED = 'Failed'
|
9
|
+
|
10
|
+
# @param [Integer] index
|
11
|
+
# @return [String]
|
12
|
+
def self.calculate_beagle_status(index)
|
13
|
+
case index
|
14
|
+
when 0 then NOT_VERIFIED
|
15
|
+
when 1 then ATTEMPTED
|
16
|
+
when 2 then VERIFIED
|
17
|
+
when 3 then FAILED
|
18
|
+
else
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class FraudAction
|
25
|
+
NOT_CHALLENGED = 'NotChallenged'
|
26
|
+
ALLOW = 'Allow'
|
27
|
+
REVIEW = 'Review'
|
28
|
+
PRE_AUTH = 'PreAuth'
|
29
|
+
PROCESSED = 'Processed'
|
30
|
+
APPROVED = 'Approved'
|
31
|
+
BLOCK = 'Block'
|
32
|
+
end
|
33
|
+
|
34
|
+
class PaymentMethod
|
35
|
+
DIRECT = 'Direct'
|
36
|
+
RESPONSIVE_SHARED = 'ResponsiveShared'
|
37
|
+
TRANSPARENT_REDIRECT = 'TransparentRedirect'
|
38
|
+
WALLET = 'Wallet'
|
39
|
+
AUTHORISATION = 'Authorisation'
|
40
|
+
end
|
41
|
+
|
42
|
+
class RequestMethod
|
43
|
+
PROCESS_PAYMENT = 'ProcessPayment'
|
44
|
+
CREATE_TOKEN_CUSTOMER = 'CreateTokenCustomer'
|
45
|
+
UPDATE_TOKEN_CUSTOMER = 'UpdateTokenCustomer'
|
46
|
+
TOKEN_PAYMENT = 'TokenPayment'
|
47
|
+
AUTHORISE = 'Authorise'
|
48
|
+
end
|
49
|
+
|
50
|
+
class ShippingMethod
|
51
|
+
UNKNOWN = 'Unknown'
|
52
|
+
LOW_COST = 'LowCost'
|
53
|
+
DESIGNATED_BY_CUSTOMER = 'DesignatedByCustomer'
|
54
|
+
INTERNATIONAL = 'International'
|
55
|
+
MILITARY = 'Military'
|
56
|
+
NEXT_DAY = 'NextDay'
|
57
|
+
STORE_PICKUP = 'StorePickup'
|
58
|
+
TWO_DAY_SERVICE = 'TwoDayService'
|
59
|
+
THREE_DAY_SERVICE = 'ThreeDayService'
|
60
|
+
OTHER = 'Other'
|
61
|
+
end
|
62
|
+
|
63
|
+
class TransactionType
|
64
|
+
PURCHASE = 'Purchase'
|
65
|
+
RECURRING = 'Recurring'
|
66
|
+
MOTO = 'MOTO'
|
67
|
+
end
|
68
|
+
|
69
|
+
class TransactionFilter
|
70
|
+
TRANSACTION_ID_INDEX = 1
|
71
|
+
ACCESS_CODE_INDEX = 2
|
72
|
+
INVOICE_NUMBER_INDEX = 3
|
73
|
+
INVOICE_REFERENCE_INDEX = 4
|
74
|
+
|
75
|
+
attr_accessor :transaction_id,
|
76
|
+
:access_code,
|
77
|
+
:invoice_number,
|
78
|
+
:invoice_reference
|
79
|
+
|
80
|
+
# @return [Integer]
|
81
|
+
def calculate_index_of_value
|
82
|
+
index = 0
|
83
|
+
count = 0
|
84
|
+
unless transaction_id.nil?
|
85
|
+
index = TRANSACTION_ID_INDEX
|
86
|
+
count += 1
|
87
|
+
end
|
88
|
+
unless access_code.nil?
|
89
|
+
index = ACCESS_CODE_INDEX
|
90
|
+
count += 1
|
91
|
+
end
|
92
|
+
unless invoice_number.nil?
|
93
|
+
index = INVOICE_NUMBER_INDEX
|
94
|
+
count += 1
|
95
|
+
end
|
96
|
+
unless invoice_reference.nil?
|
97
|
+
index = INVOICE_REFERENCE_INDEX
|
98
|
+
count += 1
|
99
|
+
end
|
100
|
+
if count == 1
|
101
|
+
index
|
102
|
+
else
|
103
|
+
nil
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
class VerifyStatus
|
109
|
+
UNCHECKED = 'unchecked'
|
110
|
+
VALID = 'valid'
|
111
|
+
INVALID = 'invalid'
|
112
|
+
|
113
|
+
# @param [Integer] index
|
114
|
+
# @return [String]
|
115
|
+
def self.calculate_status(index)
|
116
|
+
case index
|
117
|
+
when 0 then UNCHECKED
|
118
|
+
when 1 then VALID
|
119
|
+
when 2 then INVALID
|
120
|
+
else
|
121
|
+
nil
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,431 @@
|
|
1
|
+
module EwayRapid
|
2
|
+
module InternalModels
|
3
|
+
class BeagleVerification
|
4
|
+
attr_accessor :email
|
5
|
+
attr_accessor :phone
|
6
|
+
|
7
|
+
def to_json(options={})
|
8
|
+
hash = {}
|
9
|
+
hash[Constants::EMAIL] = email
|
10
|
+
hash[Constants::PHONE] = phone
|
11
|
+
hash.to_json
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.from_json(json)
|
15
|
+
hash = JSON.parse(json)
|
16
|
+
from_hash(hash)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.from_hash(hash)
|
20
|
+
beagle_verification = self.new
|
21
|
+
beagle_verification.email = hash[Constants::EMAIL]
|
22
|
+
beagle_verification.phone = hash[Constants::PHONE]
|
23
|
+
beagle_verification
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Customer
|
28
|
+
attr_accessor :token_customer_id
|
29
|
+
attr_accessor :reference
|
30
|
+
attr_accessor :title
|
31
|
+
attr_accessor :first_name
|
32
|
+
attr_accessor :last_name
|
33
|
+
attr_accessor :company_name
|
34
|
+
attr_accessor :job_description
|
35
|
+
attr_accessor :street1
|
36
|
+
attr_accessor :street2
|
37
|
+
attr_accessor :city
|
38
|
+
attr_accessor :state
|
39
|
+
attr_accessor :postal_code
|
40
|
+
attr_accessor :country
|
41
|
+
attr_accessor :email
|
42
|
+
attr_accessor :phone
|
43
|
+
attr_accessor :mobile
|
44
|
+
attr_accessor :comments
|
45
|
+
attr_accessor :fax
|
46
|
+
attr_accessor :url
|
47
|
+
attr_accessor :card_number
|
48
|
+
attr_accessor :card_start_month
|
49
|
+
attr_accessor :card_start_year
|
50
|
+
attr_accessor :card_issue_number
|
51
|
+
attr_accessor :card_name
|
52
|
+
attr_accessor :card_expiry_month
|
53
|
+
attr_accessor :card_expiry_year
|
54
|
+
attr_accessor :is_active
|
55
|
+
attr_accessor :card_details
|
56
|
+
attr_accessor :customer_device_ip
|
57
|
+
|
58
|
+
def self.to_hash(customer)
|
59
|
+
hash = {}
|
60
|
+
if customer
|
61
|
+
hash[Constants::TOKEN_CUSTOMER_ID] = customer.token_customer_id if customer.token_customer_id
|
62
|
+
hash[Constants::REFERENCE] = customer.reference if customer.reference
|
63
|
+
hash[Constants::TITLE] = customer.title if customer.title
|
64
|
+
hash[Constants::FIRST_NAME] = customer.first_name if customer.first_name
|
65
|
+
hash[Constants::LAST_NAME] = customer.last_name if customer.last_name
|
66
|
+
hash[Constants::COMPANY_NAME] = customer.company_name if customer.company_name
|
67
|
+
hash[Constants::JOB_DESCRIPTION] = customer.job_description if customer.job_description
|
68
|
+
hash[Constants::STREET1] = customer.street1 if customer.street1
|
69
|
+
hash[Constants::STREET2] = customer.street2 if customer.street2
|
70
|
+
hash[Constants::CITY] = customer.city if customer.city
|
71
|
+
hash[Constants::STATE] = customer.state if customer.state
|
72
|
+
hash[Constants::POSTAL_CODE] = customer.postal_code if customer.postal_code
|
73
|
+
hash[Constants::COUNTRY] = customer.country if customer.country
|
74
|
+
hash[Constants::EMAIL] = customer.email if customer.email
|
75
|
+
hash[Constants::PHONE] = customer.phone if customer.phone
|
76
|
+
hash[Constants::MOBILE] = customer.mobile if customer.mobile
|
77
|
+
hash[Constants::COMMENTS] = customer.comments if customer.comments
|
78
|
+
hash[Constants::FAX] = customer.fax if customer.fax
|
79
|
+
hash[Constants::URL] = customer.url if customer.url
|
80
|
+
hash[Constants::CARD_DETAILS] = Models::CardDetails.to_hash(customer.card_details) if Models::CardDetails.to_hash(customer.card_details)
|
81
|
+
hash[Constants::IS_ACTIVE] = customer.is_active if customer.is_active
|
82
|
+
|
83
|
+
hash[Constants::CARD_NUMBER] = customer.card_number if customer.card_number
|
84
|
+
hash[Constants::CARD_START_MONTH] = customer.card_start_month if customer.card_start_month
|
85
|
+
hash[Constants::CARD_START_YEAR] = customer.card_start_year if customer.card_start_year
|
86
|
+
hash[Constants::CARD_ISSUE_NUMBER] = customer.card_issue_number if customer.card_issue_number
|
87
|
+
hash[Constants::CARD_NAME] = customer.card_name if customer.card_name
|
88
|
+
hash[Constants::CARD_EXPIRY_MONTH] = customer.card_expiry_month if customer.card_expiry_month
|
89
|
+
hash[Constants::CARD_EXPIRY_YEAR] = customer.card_expiry_year if customer.card_expiry_year
|
90
|
+
hash[Constants::CUSTOMER_DEVICE_IP] = customer.customer_device_ip if customer.customer_device_ip
|
91
|
+
end
|
92
|
+
hash
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.from_json(json)
|
96
|
+
hash = JSON.parse(json)
|
97
|
+
from_hash(hash)
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.from_hash(hash)
|
101
|
+
customer = Customer.new
|
102
|
+
customer.token_customer_id = hash[Constants::TOKEN_CUSTOMER_ID]
|
103
|
+
customer.reference = hash[Constants::REFERENCE]
|
104
|
+
customer.title = hash[Constants::TITLE]
|
105
|
+
customer.first_name = hash[Constants::FIRST_NAME]
|
106
|
+
customer.last_name = hash[Constants::LAST_NAME]
|
107
|
+
customer.company_name = hash[Constants::COMPANY_NAME]
|
108
|
+
customer.job_description = hash[Constants::JOB_DESCRIPTION]
|
109
|
+
customer.street1 = hash[Constants::STREET1]
|
110
|
+
customer.street2 = hash[Constants::STREET2]
|
111
|
+
customer.city = hash[Constants::CITY]
|
112
|
+
customer.state = hash[Constants::STATE]
|
113
|
+
customer.postal_code = hash[Constants::POSTAL_CODE]
|
114
|
+
customer.country = hash[Constants::COUNTRY]
|
115
|
+
customer.email = hash[Constants::EMAIL]
|
116
|
+
customer.phone = hash[Constants::PHONE]
|
117
|
+
customer.mobile = hash[Constants::MOBILE]
|
118
|
+
customer.comments = hash[Constants::COMMENTS]
|
119
|
+
customer.fax = hash[Constants::FAX]
|
120
|
+
customer.url = hash[Constants::URL]
|
121
|
+
customer.card_number = hash[Constants::CARD_NUMBER]
|
122
|
+
customer.card_start_month = hash[Constants::CARD_START_MONTH]
|
123
|
+
customer.card_start_year = hash[Constants::CARD_START_YEAR]
|
124
|
+
customer.card_issue_number = hash[Constants::CARD_ISSUE_NUMBER]
|
125
|
+
customer.card_name = hash[Constants::CARD_NAME]
|
126
|
+
customer.card_expiry_month = hash[Constants::CARD_EXPIRY_MONTH]
|
127
|
+
customer.card_expiry_year = hash[Constants::CARD_EXPIRY_YEAR]
|
128
|
+
customer.is_active = hash[Constants::IS_ACTIVE]
|
129
|
+
customer.card_details = Models::CardDetails.from_hash(hash[Constants::CARD_DETAILS])
|
130
|
+
customer.customer_device_ip = hash[Constants::CUSTOMER_DEVICE_IP]
|
131
|
+
customer
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.from_array(array)
|
135
|
+
options = []
|
136
|
+
if array
|
137
|
+
array.each {|option_hash|
|
138
|
+
obj = Customer.from_hash(option_hash)
|
139
|
+
options.push(obj)
|
140
|
+
}
|
141
|
+
end
|
142
|
+
options
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
class Option
|
147
|
+
attr_accessor :value
|
148
|
+
|
149
|
+
def self.to_hash(option)
|
150
|
+
hash = {}
|
151
|
+
if option
|
152
|
+
hash[Constants::VALUE] = option.value if option.value
|
153
|
+
end
|
154
|
+
hash
|
155
|
+
end
|
156
|
+
|
157
|
+
def self.to_array(array)
|
158
|
+
options = []
|
159
|
+
if array
|
160
|
+
array.each {|option_hash|
|
161
|
+
if option_hash
|
162
|
+
obj = Option.to_hash(option_hash)
|
163
|
+
options.push(obj)
|
164
|
+
end
|
165
|
+
}
|
166
|
+
end
|
167
|
+
options
|
168
|
+
end
|
169
|
+
|
170
|
+
def self.from_json(json)
|
171
|
+
hash = JSON.parse(json)
|
172
|
+
from_hash(hash)
|
173
|
+
end
|
174
|
+
|
175
|
+
def self.from_hash(hash)
|
176
|
+
option = Option.new
|
177
|
+
option.value = hash[Constants::VALUE]
|
178
|
+
option
|
179
|
+
end
|
180
|
+
|
181
|
+
def self.from_array(array)
|
182
|
+
options = []
|
183
|
+
array.each {|option_hash|
|
184
|
+
obj = Option.from_hash(option_hash)
|
185
|
+
options.push(obj)
|
186
|
+
}
|
187
|
+
options
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
class Payment
|
192
|
+
attr_accessor :total_amount
|
193
|
+
attr_accessor :invoice_number
|
194
|
+
attr_accessor :invoice_description
|
195
|
+
attr_accessor :invoice_reference
|
196
|
+
attr_accessor :currency_code
|
197
|
+
|
198
|
+
def self.to_hash(payment)
|
199
|
+
hash = {}
|
200
|
+
if payment
|
201
|
+
hash[Constants::TOTAL_AMOUNT] = payment.total_amount if payment.total_amount
|
202
|
+
hash[Constants::INVOICE_NUMBER] = payment.invoice_number if payment.invoice_number
|
203
|
+
hash[Constants::INVOICE_DESCRIPTION] = payment.invoice_description if payment.invoice_description
|
204
|
+
hash[Constants::INVOICE_REFERENCE] = payment.invoice_reference if payment.invoice_reference
|
205
|
+
hash[Constants::CURRENCY_CODE] = payment.currency_code if payment.currency_code
|
206
|
+
end
|
207
|
+
hash
|
208
|
+
end
|
209
|
+
|
210
|
+
def self.from_json(json)
|
211
|
+
hash = JSON.parse(json)
|
212
|
+
from_hash(hash)
|
213
|
+
end
|
214
|
+
|
215
|
+
def self.from_hash(hash)
|
216
|
+
payment = Payment.new
|
217
|
+
payment.total_amount = hash[Constants::TOTAL_AMOUNT]
|
218
|
+
payment.invoice_number = hash[Constants::INVOICE_NUMBER]
|
219
|
+
payment.invoice_description = hash[Constants::INVOICE_DESCRIPTION]
|
220
|
+
payment.invoice_reference = hash[Constants::INVOICE_REFERENCE]
|
221
|
+
payment.currency_code = hash[Constants::CURRENCY_CODE]
|
222
|
+
payment
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
class RefundDetails
|
227
|
+
attr_accessor :original_transaction_id
|
228
|
+
attr_accessor :total_amount
|
229
|
+
attr_accessor :invoice_number
|
230
|
+
attr_accessor :invoice_description
|
231
|
+
attr_accessor :invoice_reference
|
232
|
+
attr_accessor :currency_code
|
233
|
+
|
234
|
+
def self.to_hash(refund_details)
|
235
|
+
hash = {}
|
236
|
+
if refund_details
|
237
|
+
hash[Constants::ORIGINAL_TRANSACTION_ID] = refund_details.original_transaction_id if refund_details.original_transaction_id
|
238
|
+
hash[Constants::TOTAL_AMOUNT] = refund_details.total_amount if refund_details.total_amount
|
239
|
+
hash[Constants::INVOICE_NUMBER] = refund_details.invoice_number if refund_details.invoice_number
|
240
|
+
hash[Constants::INVOICE_DESCRIPTION] = refund_details.invoice_description if refund_details.invoice_description
|
241
|
+
hash[Constants::INVOICE_REFERENCE] = refund_details.invoice_reference if refund_details.invoice_reference
|
242
|
+
hash[Constants::CURRENCY_CODE] = refund_details.currency_code if refund_details.currency_code
|
243
|
+
end
|
244
|
+
hash
|
245
|
+
end
|
246
|
+
|
247
|
+
def self.from_json(json)
|
248
|
+
hash = JSON.parse(json)
|
249
|
+
from_hash(hash)
|
250
|
+
end
|
251
|
+
|
252
|
+
def self.from_hash(hash)
|
253
|
+
refund_details = RefundDetails.new
|
254
|
+
refund_details.original_transaction_id = hash[Constants::ORIGINAL_TRANSACTION_ID]
|
255
|
+
refund_details.total_amount = hash[Constants::TOTAL_AMOUNT]
|
256
|
+
refund_details.invoice_number = hash[Constants::INVOICE_NUMBER]
|
257
|
+
refund_details.invoice_description = hash[Constants::INVOICE_DESCRIPTION]
|
258
|
+
refund_details.invoice_reference = hash[Constants::INVOICE_REFERENCE]
|
259
|
+
refund_details.currency_code = hash[Constants::CURRENCY_CODE]
|
260
|
+
refund_details
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
class ShippingAddress
|
265
|
+
attr_accessor :first_name
|
266
|
+
attr_accessor :last_name
|
267
|
+
attr_accessor :street1
|
268
|
+
attr_accessor :street2
|
269
|
+
attr_accessor :city
|
270
|
+
attr_accessor :state
|
271
|
+
attr_accessor :country
|
272
|
+
attr_accessor :postal_code
|
273
|
+
attr_accessor :email
|
274
|
+
attr_accessor :phone
|
275
|
+
attr_accessor :fax
|
276
|
+
attr_accessor :shipping_method
|
277
|
+
|
278
|
+
def self.to_hash(shipping_address)
|
279
|
+
hash = {}
|
280
|
+
if shipping_address
|
281
|
+
hash[Constants::FIRST_NAME] = shipping_address.first_name if shipping_address.first_name
|
282
|
+
hash[Constants::LAST_NAME] = shipping_address.last_name if shipping_address.last_name
|
283
|
+
hash[Constants::STREET1] = shipping_address.street1 if shipping_address.street1
|
284
|
+
hash[Constants::STREET2] = shipping_address.street2 if shipping_address.street2
|
285
|
+
hash[Constants::CITY] = shipping_address.city if shipping_address.city
|
286
|
+
hash[Constants::STATE] = shipping_address.state if shipping_address.state
|
287
|
+
hash[Constants::COUNTRY] = shipping_address.country if shipping_address.country
|
288
|
+
hash[Constants::POSTAL_CODE] = shipping_address.postal_code if shipping_address.postal_code
|
289
|
+
hash[Constants::EMAIL] = shipping_address.email if shipping_address.email
|
290
|
+
hash[Constants::PHONE] = shipping_address.phone if shipping_address.phone
|
291
|
+
hash[Constants::FAX] = shipping_address.fax if shipping_address.fax
|
292
|
+
hash[Constants::SHIPPING_METHOD] = shipping_address.shipping_method if shipping_address.shipping_method
|
293
|
+
end
|
294
|
+
hash
|
295
|
+
end
|
296
|
+
|
297
|
+
def self.from_json(json)
|
298
|
+
hash = JSON.parse(json)
|
299
|
+
from_hash(hash)
|
300
|
+
end
|
301
|
+
|
302
|
+
def self.from_hash(hash)
|
303
|
+
shipping_address = ShippingAddress.new
|
304
|
+
shipping_address.first_name = hash[Constants::FIRST_NAME]
|
305
|
+
shipping_address.last_name = hash[Constants::LAST_NAME]
|
306
|
+
shipping_address.street1 = hash[Constants::STREET1]
|
307
|
+
shipping_address.street2 = hash[Constants::STREET2]
|
308
|
+
shipping_address.city = hash[Constants::CITY]
|
309
|
+
shipping_address.state = hash[Constants::STATE]
|
310
|
+
shipping_address.country = hash[Constants::COUNTRY]
|
311
|
+
shipping_address.postal_code = hash[Constants::POSTAL_CODE]
|
312
|
+
shipping_address.email = hash[Constants::EMAIL]
|
313
|
+
shipping_address.phone = hash[Constants::PHONE]
|
314
|
+
shipping_address.fax = hash[Constants::FAX]
|
315
|
+
shipping_address.shipping_method = hash[Constants::SHIPPING_METHOD]
|
316
|
+
shipping_address
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
class Transaction
|
321
|
+
attr_accessor :customer_note
|
322
|
+
attr_accessor :authorisation_code
|
323
|
+
attr_accessor :response_code
|
324
|
+
attr_accessor :response_message
|
325
|
+
attr_accessor :invoice_number
|
326
|
+
attr_accessor :invoice_reference
|
327
|
+
attr_accessor :total_amount
|
328
|
+
attr_accessor :transaction_id
|
329
|
+
attr_accessor :transaction_status
|
330
|
+
attr_accessor :token_customer_id
|
331
|
+
attr_accessor :beagle_score
|
332
|
+
attr_accessor :options
|
333
|
+
attr_accessor :verification
|
334
|
+
attr_accessor :customer
|
335
|
+
attr_accessor :shipping_address
|
336
|
+
attr_accessor :beagle_verification
|
337
|
+
attr_accessor :errors
|
338
|
+
|
339
|
+
def to_json(opts={})
|
340
|
+
hash = {}
|
341
|
+
hash[Constants::CUSTOMER_NOTE] = customer_note if customer_note
|
342
|
+
hash[Constants::AUTHORISATION_CODE] = authorisation_code if authorisation_code
|
343
|
+
hash[Constants::RESPONSE_CODE] = response_code if response_code
|
344
|
+
hash[Constants::RESPONSE_MESSAGE] = response_message if response_message
|
345
|
+
hash[Constants::INVOICE_NUMBER] = invoice_number if invoice_number
|
346
|
+
hash[Constants::INVOICE_REFERENCE] = invoice_reference if invoice_reference
|
347
|
+
hash[Constants::TOTAL_AMOUNT] = total_amount if total_amount
|
348
|
+
hash[Constants::TRANSACTION_ID] = transaction_id if transaction_id
|
349
|
+
hash[Constants::TRANSACTION_STATUS] = transaction_status if transaction_status
|
350
|
+
hash[Constants::TOKEN_CUSTOMER_ID] = token_customer_id if token_customer_id
|
351
|
+
hash[Constants::BEAGLE_SCORE] = beagle_score if beagle_score
|
352
|
+
hash[Constants::OPTIONS] = options if options
|
353
|
+
hash[Constants::VERIFICATION] = verification if verification
|
354
|
+
hash[Constants::CUSTOMER] = customer if customer
|
355
|
+
hash[Constants::SHIPPING_ADDRESS] = shipping_address if shipping_address
|
356
|
+
hash[Constants::BEAGLE_VERIFICATION] = beagle_verification if beagle_verification
|
357
|
+
hash[Constants::ERRORS] = errors if errors
|
358
|
+
hash.to_json
|
359
|
+
end
|
360
|
+
|
361
|
+
def self.from_json(json)
|
362
|
+
hash = JSON.parse(json)
|
363
|
+
from_hash(hash)
|
364
|
+
end
|
365
|
+
|
366
|
+
def self.from_hash(hash)
|
367
|
+
transaction = Transaction.new
|
368
|
+
transaction.customer_note = hash[Constants::CUSTOMER_NOTE]
|
369
|
+
transaction.authorisation_code = hash[Constants::AUTHORISATION_CODE]
|
370
|
+
transaction.response_code = hash[Constants::RESPONSE_CODE]
|
371
|
+
transaction.response_message = hash[Constants::RESPONSE_MESSAGE]
|
372
|
+
transaction.invoice_number = hash[Constants::INVOICE_NUMBER]
|
373
|
+
transaction.invoice_reference = hash[Constants::INVOICE_REFERENCE]
|
374
|
+
transaction.total_amount = hash[Constants::TOTAL_AMOUNT]
|
375
|
+
transaction.transaction_id = hash[Constants::TRANSACTION_ID]
|
376
|
+
transaction.transaction_status = hash[Constants::TRANSACTION_STATUS]
|
377
|
+
transaction.token_customer_id = hash[Constants::TOKEN_CUSTOMER_ID]
|
378
|
+
transaction.beagle_score = hash[Constants::BEAGLE_SCORE]
|
379
|
+
transaction.options = Option.from_array(hash[Constants::OPTIONS])
|
380
|
+
transaction.verification = Verification.from_hash(hash[Constants::VERIFICATION])
|
381
|
+
transaction.customer = Customer.from_hash(hash[Constants::CUSTOMER])
|
382
|
+
transaction.shipping_address = ShippingAddress.from_hash(hash[Constants::SHIPPING_ADDRESS])
|
383
|
+
transaction.beagle_verification = BeagleVerification.from_hash(hash[Constants::BEAGLE_VERIFICATION])
|
384
|
+
transaction.errors = hash[Constants::ERRORS]
|
385
|
+
transaction
|
386
|
+
end
|
387
|
+
|
388
|
+
def self.from_array(array)
|
389
|
+
transactions = []
|
390
|
+
array.each {|transaction_hash|
|
391
|
+
obj = from_hash(transaction_hash)
|
392
|
+
transactions.push(obj)
|
393
|
+
}
|
394
|
+
transactions
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
class Verification
|
399
|
+
attr_accessor :cvn
|
400
|
+
attr_accessor :address
|
401
|
+
attr_accessor :email
|
402
|
+
attr_accessor :mobile
|
403
|
+
attr_accessor :phone
|
404
|
+
|
405
|
+
def to_json(options={})
|
406
|
+
hash = {}
|
407
|
+
hash[Constants::CVN] = cvn if cvn
|
408
|
+
hash[Constants::ADDRESS] = address if address
|
409
|
+
hash[Constants::EMAIL] = email if email
|
410
|
+
hash[Constants::MOBILE] = mobile if mobile
|
411
|
+
hash[Constants::PHONE] = phone if phone
|
412
|
+
hash.to_json
|
413
|
+
end
|
414
|
+
|
415
|
+
def self.from_json(json)
|
416
|
+
hash = JSON.parse(json)
|
417
|
+
from_hash(hash)
|
418
|
+
end
|
419
|
+
|
420
|
+
def self.from_hash(hash)
|
421
|
+
verification = Verification.new
|
422
|
+
verification.cvn = hash[Constants::CVN]
|
423
|
+
verification.address = hash[Constants::ADDRESS]
|
424
|
+
verification.email = hash[Constants::EMAIL]
|
425
|
+
verification.mobile = hash[Constants::MOBILE]
|
426
|
+
verification.phone = hash[Constants::PHONE]
|
427
|
+
verification
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|
431
|
+
end
|