payneteasy-payneteasyapi 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gemtest +0 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +18 -0
- data/README.md +54 -0
- data/Rakefile +8 -0
- data/doc/00-basic-tutorial.md +254 -0
- data/doc/01-library-internals.md +6 -0
- data/doc/02-payment-scenarios.md +9 -0
- data/doc/library-internals/00-payment-data.md +162 -0
- data/doc/library-internals/01-payment-processor.md +163 -0
- data/doc/library-internals/02-validator.md +55 -0
- data/doc/library-internals/03-property-accessor.md +76 -0
- data/doc/payment-scenarios/00-sale-transactions.md +90 -0
- data/doc/payment-scenarios/01-preauth-capture-transactions.md +105 -0
- data/doc/payment-scenarios/02-transfer-transactions.md +89 -0
- data/doc/payment-scenarios/03-return-transactions.md +52 -0
- data/doc/payment-scenarios/04-recurrent-transactions.md +110 -0
- data/doc/payment-scenarios/05-payment-form-integration.md +59 -0
- data/doc/payment-scenarios/06-merchant-callbacks.md +29 -0
- data/example/capture.rb +12 -0
- data/example/common/functions.rb +56 -0
- data/lib/paynet_easy/paynet_easy_api/callback/callback_factory.rb +47 -0
- data/lib/paynet_easy/paynet_easy_api/callback/callback_prototype.rb +186 -0
- data/lib/paynet_easy/paynet_easy_api/callback/customer_return_callback.rb +28 -0
- data/lib/paynet_easy/paynet_easy_api/callback/paynet_easy_callback.rb +44 -0
- data/lib/paynet_easy/paynet_easy_api/error/paynet_error.rb +4 -0
- data/lib/paynet_easy/paynet_easy_api/error/request_error.rb +6 -0
- data/lib/paynet_easy/paynet_easy_api/error/response_error.rb +6 -0
- data/lib/paynet_easy/paynet_easy_api/error/validation_error.rb +6 -0
- data/lib/paynet_easy/paynet_easy_api/payment_data/billing_address.rb +41 -0
- data/lib/paynet_easy/paynet_easy_api/payment_data/credit_card.rb +32 -0
- data/lib/paynet_easy/paynet_easy_api/payment_data/customer.rb +35 -0
- data/lib/paynet_easy/paynet_easy_api/payment_data/data.rb +13 -0
- data/lib/paynet_easy/paynet_easy_api/payment_data/payment.rb +190 -0
- data/lib/paynet_easy/paynet_easy_api/payment_data/payment_transaction.rb +188 -0
- data/lib/paynet_easy/paynet_easy_api/payment_data/query_config.rb +95 -0
- data/lib/paynet_easy/paynet_easy_api/payment_data/recurrent_card.rb +40 -0
- data/lib/paynet_easy/paynet_easy_api/payment_processor.rb +251 -0
- data/lib/paynet_easy/paynet_easy_api/paynet_easy_api.rb +26 -0
- data/lib/paynet_easy/paynet_easy_api/query/capture_query.rb +30 -0
- data/lib/paynet_easy/paynet_easy_api/query/create_card_ref_query.rb +78 -0
- data/lib/paynet_easy/paynet_easy_api/query/get_card_info_query.rb +49 -0
- data/lib/paynet_easy/paynet_easy_api/query/make_rebill_query.rb +37 -0
- data/lib/paynet_easy/paynet_easy_api/query/preauth_form_query.rb +10 -0
- data/lib/paynet_easy/paynet_easy_api/query/preauth_query.rb +10 -0
- data/lib/paynet_easy/paynet_easy_api/query/prototype/payment_form_query.rb +69 -0
- data/lib/paynet_easy/paynet_easy_api/query/prototype/payment_query.rb +71 -0
- data/lib/paynet_easy/paynet_easy_api/query/prototype/query.rb +302 -0
- data/lib/paynet_easy/paynet_easy_api/query/query_factory.rb +19 -0
- data/lib/paynet_easy/paynet_easy_api/query/return_query.rb +46 -0
- data/lib/paynet_easy/paynet_easy_api/query/sale_form_query.rb +10 -0
- data/lib/paynet_easy/paynet_easy_api/query/sale_query.rb +53 -0
- data/lib/paynet_easy/paynet_easy_api/query/status_query.rb +50 -0
- data/lib/paynet_easy/paynet_easy_api/query/transfer_by_ref_query.rb +41 -0
- data/lib/paynet_easy/paynet_easy_api/query/transfer_form_query.rb +10 -0
- data/lib/paynet_easy/paynet_easy_api/transport/callback_response.rb +21 -0
- data/lib/paynet_easy/paynet_easy_api/transport/gateway_client.rb +91 -0
- data/lib/paynet_easy/paynet_easy_api/transport/request.rb +20 -0
- data/lib/paynet_easy/paynet_easy_api/transport/response.rb +136 -0
- data/lib/paynet_easy/paynet_easy_api/util/property_accessor.rb +60 -0
- data/lib/paynet_easy/paynet_easy_api/util/string.rb +9 -0
- data/lib/paynet_easy/paynet_easy_api/util/validator.rb +110 -0
- data/payneteasy-payneteasyapi.gemspec +16 -0
- data/test/paynet_easy/paynet_easy_api/callback/callback_factory_test.rb +22 -0
- data/test/paynet_easy/paynet_easy_api/callback/callback_test_prototype.rb +168 -0
- data/test/paynet_easy/paynet_easy_api/callback/customer_return_callback_test.rb +95 -0
- data/test/paynet_easy/paynet_easy_api/callback/paynet_easy_callback_test.rb +101 -0
- data/test/paynet_easy/paynet_easy_api/fake.rb +71 -0
- data/test/paynet_easy/paynet_easy_api/payment_processor_test.rb +255 -0
- data/test/paynet_easy/paynet_easy_api/query/capture_query_test.rb +48 -0
- data/test/paynet_easy/paynet_easy_api/query/create_card_ref_query_test.rb +116 -0
- data/test/paynet_easy/paynet_easy_api/query/get_card_info_query_test.rb +116 -0
- data/test/paynet_easy/paynet_easy_api/query/make_rebill_query_test.rb +59 -0
- data/test/paynet_easy/paynet_easy_api/query/prototype/payment_query_test_prototype.rb +117 -0
- data/test/paynet_easy/paynet_easy_api/query/prototype/query_test_prototype.rb +190 -0
- data/test/paynet_easy/paynet_easy_api/query/prototype/sync_query_test_prototype.rb +88 -0
- data/test/paynet_easy/paynet_easy_api/query/query_factory_test.rb +21 -0
- data/test/paynet_easy/paynet_easy_api/query/return_query_test.rb +58 -0
- data/test/paynet_easy/paynet_easy_api/query/sale_form_query_test.rb +96 -0
- data/test/paynet_easy/paynet_easy_api/query/sale_query_test.rb +78 -0
- data/test/paynet_easy/paynet_easy_api/query/status_query_test.rb +81 -0
- data/test/paynet_easy/paynet_easy_api/query/transfer_by_ref_query_test.rb +63 -0
- data/test/paynet_easy/paynet_easy_api/transport/gateway_client_test.rb +22 -0
- data/test/paynet_easy/paynet_easy_api/transport/response_test.rb +26 -0
- data/test/paynet_easy/paynet_easy_api/util/property_accessor_test.rb +52 -0
- data/test/paynet_easy/paynet_easy_api/util/validator_test.rb +42 -0
- metadata +204 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
require 'payment_data/payment_transaction'
|
|
2
|
+
require 'query/query_factory'
|
|
3
|
+
require 'query/prototype/query'
|
|
4
|
+
require 'callback/callback_factory'
|
|
5
|
+
require 'callback/callback_prototype'
|
|
6
|
+
require 'transport/gateway_client'
|
|
7
|
+
require 'transport/request'
|
|
8
|
+
require 'transport/response'
|
|
9
|
+
require 'transport/callback_response'
|
|
10
|
+
|
|
11
|
+
module PaynetEasy::PaynetEasyApi
|
|
12
|
+
class PaymentProcessor
|
|
13
|
+
include PaynetEasy::PaynetEasyApi::PaymentData
|
|
14
|
+
include PaynetEasy::PaynetEasyApi::Transport
|
|
15
|
+
include PaynetEasy::PaynetEasyApi::Query
|
|
16
|
+
include PaynetEasy::PaynetEasyApi::Callback
|
|
17
|
+
|
|
18
|
+
# Payment changed and should be saved
|
|
19
|
+
HANDLER_SAVE_CHANGES = 'save_payment'
|
|
20
|
+
|
|
21
|
+
# Payment status not changed and should be updated
|
|
22
|
+
HANDLER_STATUS_UPDATE = 'status_update'
|
|
23
|
+
|
|
24
|
+
# Html received and should be displayed
|
|
25
|
+
HANDLER_SHOW_HTML = 'show_html'
|
|
26
|
+
|
|
27
|
+
# Redirect url received, customer should be to it
|
|
28
|
+
HANDLER_REDIRECT = 'redirect'
|
|
29
|
+
|
|
30
|
+
# Payment processing ended
|
|
31
|
+
HANDLER_FINISH_PROCESSING = 'finish_processing'
|
|
32
|
+
|
|
33
|
+
# Exception handle needed
|
|
34
|
+
HANDLER_CATCH_EXCEPTION = 'catch_exception'
|
|
35
|
+
|
|
36
|
+
# Allowed handlers list
|
|
37
|
+
@@allowed_handlers =
|
|
38
|
+
[
|
|
39
|
+
HANDLER_SAVE_CHANGES,
|
|
40
|
+
HANDLER_STATUS_UPDATE,
|
|
41
|
+
HANDLER_SHOW_HTML,
|
|
42
|
+
HANDLER_REDIRECT,
|
|
43
|
+
HANDLER_FINISH_PROCESSING,
|
|
44
|
+
HANDLER_CATCH_EXCEPTION
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
attr_accessor :gateway_client
|
|
48
|
+
attr_accessor :query_factory
|
|
49
|
+
attr_accessor :callback_factory
|
|
50
|
+
|
|
51
|
+
def initialize(handlers = {})
|
|
52
|
+
@handlers = {}
|
|
53
|
+
set_handlers handlers
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Executes payment API query
|
|
57
|
+
#
|
|
58
|
+
# @param query_name [String] Payment API query name
|
|
59
|
+
# @param payment_transaction [PaymentTransaction] Payment transaction for processing
|
|
60
|
+
#
|
|
61
|
+
# @return [Response] Query response
|
|
62
|
+
def execute_query(query_name, payment_transaction)
|
|
63
|
+
query = query(query_name)
|
|
64
|
+
|
|
65
|
+
begin
|
|
66
|
+
request = query.create_request payment_transaction
|
|
67
|
+
response = make_request request
|
|
68
|
+
query.process_response payment_transaction, response
|
|
69
|
+
rescue Exception => error
|
|
70
|
+
handle_exception error, payment_transaction, response
|
|
71
|
+
return
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
handle_query_result payment_transaction, response
|
|
75
|
+
|
|
76
|
+
response
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Executes payment gateway processor for customer return from payment form or 3D-auth
|
|
80
|
+
#
|
|
81
|
+
# @param callback_response [CallbackResponse] Callback object with data from payment gateway
|
|
82
|
+
# @param payment_transaction [PaymentTransaction] Payment transaction for processing
|
|
83
|
+
#
|
|
84
|
+
# @return [CallbackResponse] Validated payment gateway callback
|
|
85
|
+
def process_customer_return(callback_response, payment_transaction)
|
|
86
|
+
callback_response.type = 'customer_return'
|
|
87
|
+
process_paynet_easy_callback callback_response, payment_transaction
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Executes payment gateway processor for PaynetEasy payment callback
|
|
91
|
+
#
|
|
92
|
+
# @param callback_response [CallbackResponse] Callback object with data from payment gateway
|
|
93
|
+
# @param payment_transaction [PaymentTransaction] Payment transaction for processing
|
|
94
|
+
#
|
|
95
|
+
# @return [CallbackResponse] Validated payment gateway callback
|
|
96
|
+
def process_paynet_easy_callback(callback_response, payment_transaction)
|
|
97
|
+
begin
|
|
98
|
+
callback(callback_response.type).process_callback(payment_transaction, callback_response)
|
|
99
|
+
rescue Exception => error
|
|
100
|
+
handle_exception error, payment_transaction, callback_response
|
|
101
|
+
return
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
handle_query_result payment_transaction, callback_response
|
|
105
|
+
|
|
106
|
+
callback_response
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Create API query object by API query method
|
|
110
|
+
#
|
|
111
|
+
# @param api_query_name [String] API query method
|
|
112
|
+
#
|
|
113
|
+
# @return [Prototype::Query] API query object
|
|
114
|
+
def query(api_query_name)
|
|
115
|
+
query_factory.query api_query_name
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Create API callback processor by callback response
|
|
119
|
+
#
|
|
120
|
+
# @param callback_type [String] Callback response type
|
|
121
|
+
#
|
|
122
|
+
# @return [CallbackPrototype] Callback processor
|
|
123
|
+
def callback(callback_type)
|
|
124
|
+
callback_factory.callback callback_type
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Make request to the PaynetEasy gateway
|
|
128
|
+
#
|
|
129
|
+
# @param request [Request] Request data
|
|
130
|
+
#
|
|
131
|
+
# @return [Response] Response data
|
|
132
|
+
def make_request(request)
|
|
133
|
+
gateway_client.make_request request
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Set handler callback for processing action.
|
|
137
|
+
#
|
|
138
|
+
# @param handler_name [String] Handler name
|
|
139
|
+
# @param handler_callback [Proc] Handler callback
|
|
140
|
+
def set_handler(handler_name, &handler_callback)
|
|
141
|
+
check_handler_name handler_name
|
|
142
|
+
|
|
143
|
+
@handlers[handler_name] = handler_callback
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Set handlers. Handlers array must follow new format:
|
|
147
|
+
# {<handlerName>:String => <handlerCallback>:Proc}
|
|
148
|
+
#
|
|
149
|
+
# @param handlers [Hash] Handlers callbacks
|
|
150
|
+
def set_handlers(handlers = {})
|
|
151
|
+
handlers.each {|handler_name, handler_callback| set_handler handler_name, &handler_callback}
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# Remove handler for processing action
|
|
155
|
+
#
|
|
156
|
+
# @param handler_name [String] Handler name
|
|
157
|
+
def remove_handler(handler_name)
|
|
158
|
+
check_handler_name handler_name
|
|
159
|
+
|
|
160
|
+
@handlers.delete handler_name
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# Remove all handlers
|
|
164
|
+
def remove_handlers
|
|
165
|
+
@handlers = {}
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def gateway_client
|
|
169
|
+
@gateway_client ||= GatewayClient.new
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def query_factory
|
|
173
|
+
@query_factory ||= QueryFactory.new
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def callback_factory
|
|
177
|
+
@callback_factory ||= CallbackFactory.new
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
protected
|
|
181
|
+
|
|
182
|
+
# Handle query result.
|
|
183
|
+
# Method calls handlers for:
|
|
184
|
+
# - HANDLER_SAVE_CHANGES always
|
|
185
|
+
# - HANDLER_STATUS_UPDATE if needed payment transaction status update
|
|
186
|
+
# - HANDLER_SHOW_HTML if needed to show response html
|
|
187
|
+
# - HANDLER_REDIRECT if needed to redirect to response URL
|
|
188
|
+
# - HANDLER_FINISH_PROCESSING if not additional action needed
|
|
189
|
+
#
|
|
190
|
+
# @param payment_transaction [PaymentTransaction] Payment transaction
|
|
191
|
+
# @param response [Response] Query result
|
|
192
|
+
def handle_query_result(payment_transaction, response)
|
|
193
|
+
call_handler HANDLER_SAVE_CHANGES, payment_transaction, response
|
|
194
|
+
|
|
195
|
+
case true
|
|
196
|
+
when response.redirect_needed?
|
|
197
|
+
call_handler HANDLER_REDIRECT, response, payment_transaction
|
|
198
|
+
when response.show_html_needed?
|
|
199
|
+
call_handler HANDLER_SHOW_HTML, response, payment_transaction
|
|
200
|
+
when response.status_update_needed?
|
|
201
|
+
call_handler HANDLER_STATUS_UPDATE, response, payment_transaction
|
|
202
|
+
else
|
|
203
|
+
call_handler HANDLER_FINISH_PROCESSING, payment_transaction, response
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
# Handle raised exception. If configured self::HANDLER_CATCH_EXCEPTION, handler will be called,
|
|
208
|
+
# if not - exception will be raised again.
|
|
209
|
+
#
|
|
210
|
+
# @param error [Exception]
|
|
211
|
+
# @param payment_transaction [PaymentTransaction]
|
|
212
|
+
# @param response [Response]
|
|
213
|
+
def handle_exception(error, payment_transaction, response = nil)
|
|
214
|
+
call_handler HANDLER_SAVE_CHANGES, payment_transaction, response
|
|
215
|
+
|
|
216
|
+
raise error unless has_handler? HANDLER_CATCH_EXCEPTION
|
|
217
|
+
|
|
218
|
+
call_handler HANDLER_CATCH_EXCEPTION, error, payment_transaction, response
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
# Executes handler callback.
|
|
222
|
+
# Method receives at least one parameter - handler name,
|
|
223
|
+
# all other parameters will be passed to handler callback.
|
|
224
|
+
#
|
|
225
|
+
# @param handler_name [String] Handler name
|
|
226
|
+
# @param args [Array] Handler parameters
|
|
227
|
+
def call_handler(handler_name, *args)
|
|
228
|
+
check_handler_name handler_name
|
|
229
|
+
|
|
230
|
+
@handlers[handler_name].(*args) if has_handler? handler_name
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
# Check if handler name is allowed
|
|
234
|
+
#
|
|
235
|
+
# @param handler_name [String] Handler name
|
|
236
|
+
def check_handler_name(handler_name)
|
|
237
|
+
unless @@allowed_handlers.include? handler_name
|
|
238
|
+
raise RuntimeError, "Unknown handler name: '#{handler_name}'"
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
# True if processor has handler callback for given handler name
|
|
243
|
+
#
|
|
244
|
+
# @param handler_name [String] Handler name
|
|
245
|
+
#
|
|
246
|
+
# @return [TrueClass|FalseClass] Check result
|
|
247
|
+
def has_handler?(handler_name)
|
|
248
|
+
@handlers.key? handler_name
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module PaynetEasy
|
|
2
|
+
module PaynetEasyApi
|
|
3
|
+
module PaymentData
|
|
4
|
+
end
|
|
5
|
+
module Callback
|
|
6
|
+
end
|
|
7
|
+
module Query
|
|
8
|
+
module Prototype
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
module Transport
|
|
12
|
+
end
|
|
13
|
+
module Util
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
require 'payment_processor'
|
|
19
|
+
require 'payment_data/query_config'
|
|
20
|
+
require 'payment_data/payment_transaction'
|
|
21
|
+
require 'payment_data/payment'
|
|
22
|
+
require 'payment_data/billing_address'
|
|
23
|
+
require 'payment_data/customer'
|
|
24
|
+
require 'payment_data/credit_card'
|
|
25
|
+
require 'payment_data/recurrent_card'
|
|
26
|
+
require 'transport/callback_response'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'query/prototype/payment_query'
|
|
2
|
+
require 'payment_data/payment'
|
|
3
|
+
require 'util/validator'
|
|
4
|
+
|
|
5
|
+
module PaynetEasy::PaynetEasyApi::Query
|
|
6
|
+
class CaptureQuery < Prototype::PaymentQuery
|
|
7
|
+
include PaynetEasy::PaynetEasyApi::PaymentData
|
|
8
|
+
include PaynetEasy::PaynetEasyApi::Util
|
|
9
|
+
|
|
10
|
+
@request_fields_definition =
|
|
11
|
+
[
|
|
12
|
+
# mandatory
|
|
13
|
+
['client_orderid', 'payment.client_id', true, Validator::ID],
|
|
14
|
+
['orderid', 'payment.paynet_id', true, Validator::ID],
|
|
15
|
+
['login', 'query_config.login', true, Validator::MEDIUM_STRING]
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
@signature_definition =
|
|
19
|
+
[
|
|
20
|
+
'query_config.login',
|
|
21
|
+
'payment.client_id',
|
|
22
|
+
'payment.paynet_id',
|
|
23
|
+
'payment.amount_in_cents',
|
|
24
|
+
'payment.currency',
|
|
25
|
+
'query_config.signing_key'
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
@payment_status = Payment::STATUS_CAPTURE
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require 'query/prototype/query'
|
|
2
|
+
require 'util/validator'
|
|
3
|
+
require 'error/validation_error'
|
|
4
|
+
|
|
5
|
+
module PaynetEasy::PaynetEasyApi::Query
|
|
6
|
+
class CreateCardRefQuery < Prototype::Query
|
|
7
|
+
include PaynetEasy::PaynetEasyApi::PaymentData
|
|
8
|
+
include PaynetEasy::PaynetEasyApi::Util
|
|
9
|
+
include PaynetEasy::PaynetEasyApi::Error
|
|
10
|
+
|
|
11
|
+
@request_fields_definition =
|
|
12
|
+
[
|
|
13
|
+
# mandatory
|
|
14
|
+
['client_orderid', 'payment.client_id', true, Validator::ID],
|
|
15
|
+
['orderid', 'payment.paynet_id', true, Validator::ID],
|
|
16
|
+
['login', 'query_config.login', true, Validator::MEDIUM_STRING]
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
@signature_definition =
|
|
20
|
+
[
|
|
21
|
+
'query_config.login',
|
|
22
|
+
'payment.client_id',
|
|
23
|
+
'payment.paynet_id',
|
|
24
|
+
'query_config.signing_key'
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
@response_fields_definition =
|
|
28
|
+
[
|
|
29
|
+
'type',
|
|
30
|
+
'status',
|
|
31
|
+
'card-ref-id',
|
|
32
|
+
'serial-number'
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
@success_response_type = 'create-card-ref-response'
|
|
36
|
+
|
|
37
|
+
protected
|
|
38
|
+
|
|
39
|
+
# @param payment_transaction [PaymentTransaction] Payment transaction for validation
|
|
40
|
+
def validate_payment_transaction(payment_transaction)
|
|
41
|
+
check_payment_transaction_status payment_transaction
|
|
42
|
+
super payment_transaction
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# @param payment_transaction [PaymentTransaction] Payment transaction
|
|
46
|
+
# @param response [Response] Response for validating
|
|
47
|
+
def validate_response_on_success(payment_transaction, response)
|
|
48
|
+
check_payment_transaction_status payment_transaction
|
|
49
|
+
super payment_transaction, response
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# @param payment_transaction [PaymentTransaction] Payment transaction
|
|
53
|
+
# @param response [Response] Response for validating
|
|
54
|
+
def validate_response_on_error(payment_transaction, response)
|
|
55
|
+
check_payment_transaction_status payment_transaction
|
|
56
|
+
super payment_transaction, response
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# @param payment_transaction [PaymentTransaction] Payment transaction
|
|
60
|
+
# @param response [Response] Response for payment transaction updating
|
|
61
|
+
def update_payment_transaction_on_success(payment_transaction, response)
|
|
62
|
+
payment_transaction.payment.recurrent_card_from.paynet_id = response.card_paynet_id
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Check, if payment transaction is finished and payment is not new.
|
|
66
|
+
#
|
|
67
|
+
# @param payment_transaction [PaymentTransaction] Payment transaction for validation
|
|
68
|
+
def check_payment_transaction_status(payment_transaction)
|
|
69
|
+
unless payment_transaction.finished?
|
|
70
|
+
raise ValidationError, 'Only finished payment transaction can be used for create-card-ref-id'
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
unless payment_transaction.payment.paid?
|
|
74
|
+
raise ValidationError, "Can not use new payment for create-card-ref-id. Execute 'sale' or 'preauth' query first"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'query/prototype/query'
|
|
2
|
+
require 'util/validator'
|
|
3
|
+
|
|
4
|
+
module PaynetEasy::PaynetEasyApi::Query
|
|
5
|
+
class GetCardInfoQuery < Prototype::Query
|
|
6
|
+
include PaynetEasy::PaynetEasyApi::Util
|
|
7
|
+
|
|
8
|
+
@request_fields_definition =
|
|
9
|
+
[
|
|
10
|
+
# mandatory
|
|
11
|
+
['cardrefid', 'payment.recurrent_card_from.paynet_id', true, Validator::ID],
|
|
12
|
+
['login', 'query_config.login', true, Validator::MEDIUM_STRING]
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
@signature_definition =
|
|
16
|
+
[
|
|
17
|
+
'query_config.login',
|
|
18
|
+
'payment.recurrent_card_from.paynet_id',
|
|
19
|
+
'query_config.signing_key'
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
@response_fields_definition =
|
|
23
|
+
[
|
|
24
|
+
'type',
|
|
25
|
+
'card-printed-name',
|
|
26
|
+
'expire-year',
|
|
27
|
+
'expire-month',
|
|
28
|
+
'bin',
|
|
29
|
+
'last-four-digits',
|
|
30
|
+
'serial-number'
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
@success_response_type = 'get-card-info-response'
|
|
34
|
+
|
|
35
|
+
protected
|
|
36
|
+
|
|
37
|
+
# @param payment_transaction [PaymentTransaction] Payment transaction
|
|
38
|
+
# @param response [Response] Response for payment transaction updating
|
|
39
|
+
def update_payment_transaction_on_success(payment_transaction, response)
|
|
40
|
+
recurrent_card = payment_transaction.payment.recurrent_card_from
|
|
41
|
+
|
|
42
|
+
recurrent_card.card_printed_name = response['card-printed-name']
|
|
43
|
+
recurrent_card.expire_year = response['expire-year']
|
|
44
|
+
recurrent_card.expire_month = response['expire-month']
|
|
45
|
+
recurrent_card.bin = response['bin']
|
|
46
|
+
recurrent_card.last_four_digits = response['last-four-digits']
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'query/prototype/payment_query'
|
|
2
|
+
require 'payment_data/payment'
|
|
3
|
+
require 'util/validator'
|
|
4
|
+
|
|
5
|
+
module PaynetEasy::PaynetEasyApi::Query
|
|
6
|
+
class MakeRebillQuery < Prototype::PaymentQuery
|
|
7
|
+
include PaynetEasy::PaynetEasyApi::PaymentData
|
|
8
|
+
include PaynetEasy::PaynetEasyApi::Util
|
|
9
|
+
|
|
10
|
+
@request_fields_definition =
|
|
11
|
+
[
|
|
12
|
+
# mandatory
|
|
13
|
+
['client_orderid', 'payment.client_id', true, Validator::ID],
|
|
14
|
+
['order_desc', 'payment.description', true, Validator::LONG_STRING],
|
|
15
|
+
['amount', 'payment.amount', true, Validator::AMOUNT],
|
|
16
|
+
['currency', 'payment.currency', true, Validator::CURRENCY],
|
|
17
|
+
['ipaddress', 'payment.customer.ip_address', true, Validator::IP],
|
|
18
|
+
['cardrefid', 'payment.recurrent_card_from.paynet_id', true, Validator::ID],
|
|
19
|
+
['login', 'query_config.login', true, Validator::MEDIUM_STRING],
|
|
20
|
+
# optional
|
|
21
|
+
['comment', 'payment.comment', false, Validator::MEDIUM_STRING],
|
|
22
|
+
['cvv2', 'payment.recurrent_card_from.cvv2', false, Validator::CVV2],
|
|
23
|
+
['server_callback_url', 'query_config.callback_url', false, Validator::URL]
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
@signature_definition =
|
|
27
|
+
[
|
|
28
|
+
'query_config.end_point',
|
|
29
|
+
'payment.client_id',
|
|
30
|
+
'payment.amount_in_cents',
|
|
31
|
+
'payment.recurrent_card_from.paynet_id',
|
|
32
|
+
'query_config.signing_key'
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
@payment_status = Payment::STATUS_CAPTURE
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'query/prototype/payment_form_query'
|
|
2
|
+
require 'payment_data/payment'
|
|
3
|
+
|
|
4
|
+
module PaynetEasy::PaynetEasyApi::Query
|
|
5
|
+
class PreauthFormQuery < Prototype::PaymentFormQuery
|
|
6
|
+
include PaynetEasy::PaynetEasyApi::PaymentData
|
|
7
|
+
|
|
8
|
+
@payment_status = Payment::STATUS_PREAUTH
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'query/prototype/payment_query'
|
|
2
|
+
require 'util/validator'
|
|
3
|
+
require 'transport/response'
|
|
4
|
+
|
|
5
|
+
module PaynetEasy::PaynetEasyApi::Query::Prototype
|
|
6
|
+
class PaymentFormQuery < PaymentQuery
|
|
7
|
+
include PaynetEasy::PaynetEasyApi::Util
|
|
8
|
+
include PaynetEasy::PaynetEasyApi::Transport
|
|
9
|
+
|
|
10
|
+
@request_fields_definition =
|
|
11
|
+
[
|
|
12
|
+
# mandatory
|
|
13
|
+
['client_orderid', 'payment.client_id', true, Validator::ID],
|
|
14
|
+
['order_desc', 'payment.description', true, Validator::LONG_STRING],
|
|
15
|
+
['amount', 'payment.amount', true, Validator::AMOUNT],
|
|
16
|
+
['currency', 'payment.currency', true, Validator::CURRENCY],
|
|
17
|
+
['address1', 'payment.billing_address.first_line', true, Validator::MEDIUM_STRING],
|
|
18
|
+
['city', 'payment.billing_address.city', true, Validator::MEDIUM_STRING],
|
|
19
|
+
['zip_code', 'payment.billing_address.zip_code', true, Validator::ZIP_CODE],
|
|
20
|
+
['country', 'payment.billing_address.country', true, Validator::COUNTRY],
|
|
21
|
+
['phone', 'payment.billing_address.phone', true, Validator::PHONE],
|
|
22
|
+
['ipaddress', 'payment.customer.ip_address', true, Validator::IP],
|
|
23
|
+
['email', 'payment.customer.email', true, Validator::EMAIL],
|
|
24
|
+
['redirect_url', 'query_config.redirect_url', true, Validator::URL],
|
|
25
|
+
# optional
|
|
26
|
+
['first_name', 'payment.customer.first_name', false, Validator::MEDIUM_STRING],
|
|
27
|
+
['last_name', 'payment.customer.last_name', false, Validator::MEDIUM_STRING],
|
|
28
|
+
['ssn', 'payment.customer.ssn', false, Validator::SSN],
|
|
29
|
+
['birthday', 'payment.customer.birthday', false, Validator::DATE],
|
|
30
|
+
['state', 'payment.billing_address.state', false, Validator::COUNTRY],
|
|
31
|
+
['cell_phone', 'payment.billing_address.cell_phone', false, Validator::PHONE],
|
|
32
|
+
['site_url', 'query_config.site_url', false, Validator::URL],
|
|
33
|
+
['server_callback_url', 'query_config.callback_url', false, Validator::URL]
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
@signature_definition =
|
|
37
|
+
[
|
|
38
|
+
'query_config.end_point',
|
|
39
|
+
'payment.client_id',
|
|
40
|
+
'payment.amount_in_cents',
|
|
41
|
+
'payment.customer.email',
|
|
42
|
+
'query_config.signing_key'
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
@response_fields_definition =
|
|
46
|
+
[
|
|
47
|
+
'type',
|
|
48
|
+
'status',
|
|
49
|
+
'paynet-order-id',
|
|
50
|
+
'merchant-order-id',
|
|
51
|
+
'serial-number',
|
|
52
|
+
'redirect-url'
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
@success_response_type = 'async-form-response'
|
|
56
|
+
|
|
57
|
+
protected
|
|
58
|
+
|
|
59
|
+
# @param payment_transaction [PaymentTransaction] Payment transaction
|
|
60
|
+
# @param response [Response] Response for payment transaction updating
|
|
61
|
+
def update_payment_transaction_on_success(payment_transaction, response)
|
|
62
|
+
super payment_transaction, response
|
|
63
|
+
|
|
64
|
+
if response.has_redirect_url?
|
|
65
|
+
response.needed_action = Response::NEEDED_REDIRECT
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'query/prototype/query'
|
|
2
|
+
require 'error/validation_error'
|
|
3
|
+
|
|
4
|
+
module PaynetEasy::PaynetEasyApi::Query::Prototype
|
|
5
|
+
class PaymentQuery < Query
|
|
6
|
+
# Status for payment, when it is processing by this query
|
|
7
|
+
@payment_status = ''
|
|
8
|
+
|
|
9
|
+
@response_fields_definition =
|
|
10
|
+
[
|
|
11
|
+
'type',
|
|
12
|
+
'status',
|
|
13
|
+
'paynet-order-id',
|
|
14
|
+
'merchant-order-id',
|
|
15
|
+
'serial-number'
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
@success_response_type = 'async-response'
|
|
19
|
+
|
|
20
|
+
class << self;
|
|
21
|
+
protected
|
|
22
|
+
|
|
23
|
+
# @return [String]
|
|
24
|
+
def payment_status
|
|
25
|
+
@payment_status
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# @param payment_transaction [PaymentTransaction]
|
|
30
|
+
#
|
|
31
|
+
# @return [Request]
|
|
32
|
+
def create_request(payment_transaction)
|
|
33
|
+
request = super payment_transaction
|
|
34
|
+
|
|
35
|
+
payment_transaction.payment.status = payment_status
|
|
36
|
+
payment_transaction.processor_type = PaymentTransaction::PROCESSOR_QUERY
|
|
37
|
+
payment_transaction.processor_name = @api_method
|
|
38
|
+
payment_transaction.status = PaymentTransaction::STATUS_PROCESSING
|
|
39
|
+
|
|
40
|
+
request
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
protected
|
|
44
|
+
|
|
45
|
+
# @param payment_transaction [PaymentTransaction]
|
|
46
|
+
def validate_payment_transaction(payment_transaction)
|
|
47
|
+
if payment_transaction.payment.has_processing_transaction?
|
|
48
|
+
raise ValidationError, 'Payment can not has processing payment transaction'
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
unless payment_transaction.new?
|
|
52
|
+
raise ValidationError, 'Payment transaction must be new'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
super payment_transaction
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def validate_query_definition
|
|
59
|
+
super
|
|
60
|
+
|
|
61
|
+
unless payment_status
|
|
62
|
+
raise RuntimeError, 'You must configure @payment_status'
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# @return [String]
|
|
67
|
+
def payment_status
|
|
68
|
+
self.class.instance_variable_get :@payment_status
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|