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,116 @@
|
|
|
1
|
+
require_relative './prototype/sync_query_test_prototype'
|
|
2
|
+
require 'query/get_card_info_query'
|
|
3
|
+
require 'payment_data/recurrent_card'
|
|
4
|
+
|
|
5
|
+
module PaynetEasy::PaynetEasyApi::Query
|
|
6
|
+
class GetCardInfoQueryTest < Test::Unit::TestCase
|
|
7
|
+
include Prototype::SyncQueryTestPrototype
|
|
8
|
+
|
|
9
|
+
def test_create_request
|
|
10
|
+
[
|
|
11
|
+
create_control_code(
|
|
12
|
+
LOGIN,
|
|
13
|
+
RECURRENT_CARD_FROM_ID,
|
|
14
|
+
SIGNING_KEY
|
|
15
|
+
)
|
|
16
|
+
].each do |control_code|
|
|
17
|
+
assert_create_request control_code
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_process_response_approved
|
|
22
|
+
[
|
|
23
|
+
{
|
|
24
|
+
'type' => success_type,
|
|
25
|
+
'paynet-order-id' => PAYNET_ID,
|
|
26
|
+
'merchant-order-id' => CLIENT_ID,
|
|
27
|
+
'serial-number' => '_',
|
|
28
|
+
'card-printed-name' => 'Vasya Pupkin',
|
|
29
|
+
'expire-month' => '12',
|
|
30
|
+
'expire-year' => '14',
|
|
31
|
+
'bin' => '4485',
|
|
32
|
+
'last-four-digits' => '9130'
|
|
33
|
+
}
|
|
34
|
+
].each do |response|
|
|
35
|
+
assert_process_response_approved response
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def assert_process_response_approved(response)
|
|
40
|
+
payment_transaction = payment_transaction()
|
|
41
|
+
recurrent_card = payment_transaction.payment.recurrent_card_from
|
|
42
|
+
response_object = Response.new response
|
|
43
|
+
|
|
44
|
+
query.process_response payment_transaction, response_object
|
|
45
|
+
|
|
46
|
+
assert_equal response_object['card-printed-name'], recurrent_card.card_printed_name
|
|
47
|
+
assert_equal response_object['expire-year'], recurrent_card.expire_year
|
|
48
|
+
assert_equal response_object['expire-month'], recurrent_card.expire_month
|
|
49
|
+
assert_equal response_object['bin'], recurrent_card.bin
|
|
50
|
+
assert_equal response_object['last-four-digits'], recurrent_card.last_four_digits
|
|
51
|
+
|
|
52
|
+
[payment_transaction, response]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_process_error_response_with_invalid_id
|
|
56
|
+
response = Response.new(
|
|
57
|
+
{
|
|
58
|
+
'type' => 'error',
|
|
59
|
+
'client_orderid' => 'invalid',
|
|
60
|
+
'card-printed-name' => 'Vasya Pupkin',
|
|
61
|
+
'expire-month' => '12',
|
|
62
|
+
'expire-year' => '14',
|
|
63
|
+
'bin' => '4485',
|
|
64
|
+
'last-four-digits' => '9130'
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
assert_raise ValidationError, "Response client_id 'invalid' does not match Payment client_id" do
|
|
68
|
+
query.process_response payment_transaction, response
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def test_process_success_response_with_invalid_id
|
|
73
|
+
response = Response.new(
|
|
74
|
+
{
|
|
75
|
+
'type' => success_type,
|
|
76
|
+
'paynet-order-id' => '_',
|
|
77
|
+
'merchant-order-id' => '_',
|
|
78
|
+
'serial-number' => '_',
|
|
79
|
+
'card-ref-id' => '_',
|
|
80
|
+
'redirect-url' => '_',
|
|
81
|
+
'client_orderid' => 'invalid',
|
|
82
|
+
'card-printed-name' => 'Vasya Pupkin',
|
|
83
|
+
'expire-month' => '12',
|
|
84
|
+
'expire-year' => '14',
|
|
85
|
+
'bin' => '4485',
|
|
86
|
+
'last-four-digits' => '9130'
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
assert_raise ValidationError, "Response client_id '_' does not match Payment client_id" do
|
|
90
|
+
query.process_response payment_transaction, response
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
protected
|
|
95
|
+
|
|
96
|
+
def payment
|
|
97
|
+
Payment.new(
|
|
98
|
+
{
|
|
99
|
+
'client_id' => CLIENT_ID,
|
|
100
|
+
'paynet_id' => PAYNET_ID,
|
|
101
|
+
'recurrent_card_from' => RecurrentCard.new(
|
|
102
|
+
{
|
|
103
|
+
'paynet_id' => RECURRENT_CARD_FROM_ID
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def success_type
|
|
109
|
+
'get-card-info-response'
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def query
|
|
113
|
+
GetCardInfoQuery.new '_'
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require_relative './prototype/payment_query_test_prototype'
|
|
2
|
+
require 'query/make_rebill_query'
|
|
3
|
+
require 'payment_data/customer'
|
|
4
|
+
require 'payment_data/recurrent_card'
|
|
5
|
+
|
|
6
|
+
module PaynetEasy::PaynetEasyApi::Query
|
|
7
|
+
class MakeRebillQueryTest < Test::Unit::TestCase
|
|
8
|
+
include Prototype::PaymentQueryTestPrototype
|
|
9
|
+
|
|
10
|
+
def test_create_request
|
|
11
|
+
[
|
|
12
|
+
create_control_code(
|
|
13
|
+
END_POINT,
|
|
14
|
+
CLIENT_ID,
|
|
15
|
+
'99', # amount
|
|
16
|
+
RECURRENT_CARD_FROM_ID,
|
|
17
|
+
SIGNING_KEY
|
|
18
|
+
)
|
|
19
|
+
].each do |control_code|
|
|
20
|
+
assert_create_request control_code
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
protected
|
|
25
|
+
|
|
26
|
+
# @return [Payment]
|
|
27
|
+
def payment
|
|
28
|
+
Payment.new(
|
|
29
|
+
{
|
|
30
|
+
'client_id' => CLIENT_ID,
|
|
31
|
+
'paynet_id' => PAYNET_ID,
|
|
32
|
+
'description' => 'This is test payment',
|
|
33
|
+
'amount' => 0.99,
|
|
34
|
+
'currency' => 'USD',
|
|
35
|
+
'customer' => Customer.new(
|
|
36
|
+
{
|
|
37
|
+
'ip_address' => '127.0.0.1',
|
|
38
|
+
}),
|
|
39
|
+
'recurrent_card_from' => RecurrentCard.new(
|
|
40
|
+
{
|
|
41
|
+
'paynet_id' => RECURRENT_CARD_FROM_ID,
|
|
42
|
+
'cvv2' => 123
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def payment_status
|
|
48
|
+
Payment::STATUS_CAPTURE
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def api_method
|
|
52
|
+
'make-rebill'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def query
|
|
56
|
+
MakeRebillQuery.new api_method
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
require_relative './query_test_prototype'
|
|
2
|
+
|
|
3
|
+
module PaynetEasy::PaynetEasyApi::Query::Prototype
|
|
4
|
+
module PaymentQueryTestPrototype
|
|
5
|
+
include QueryTestPrototype
|
|
6
|
+
|
|
7
|
+
alias :query_test_assert_create_request :assert_create_request
|
|
8
|
+
|
|
9
|
+
def assert_create_request(control_code)
|
|
10
|
+
payment_transaction, request = query_test_assert_create_request control_code
|
|
11
|
+
payment = payment_transaction.payment
|
|
12
|
+
|
|
13
|
+
assert_true payment.has_processing_transaction?
|
|
14
|
+
assert_equal payment_status, payment.status
|
|
15
|
+
assert_equal PaymentTransaction::PROCESSOR_QUERY, payment_transaction.processor_type
|
|
16
|
+
assert_equal api_method, payment_transaction.processor_name
|
|
17
|
+
|
|
18
|
+
[payment_transaction, request]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_create_request_with_processing_payment
|
|
22
|
+
payment_transaction = payment_transaction()
|
|
23
|
+
payment_transaction.status = PaymentTransaction::STATUS_PROCESSING
|
|
24
|
+
|
|
25
|
+
assert_raise ValidationError, 'Payment can not has processing payment transaction' do
|
|
26
|
+
query.create_request payment_transaction
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_create_request_with_finished_transaction
|
|
31
|
+
payment_transaction = payment_transaction()
|
|
32
|
+
payment_transaction.status = PaymentTransaction::STATUS_APPROVED
|
|
33
|
+
|
|
34
|
+
assert_raise ValidationError, 'Payment transaction must be new' do
|
|
35
|
+
query.create_request payment_transaction
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_process_response_processing
|
|
40
|
+
[
|
|
41
|
+
{
|
|
42
|
+
'type' => success_type,
|
|
43
|
+
'paynet-order-id' => PAYNET_ID,
|
|
44
|
+
'merchant-order-id' => CLIENT_ID,
|
|
45
|
+
'serial-number' => '_'
|
|
46
|
+
}
|
|
47
|
+
].each do |response|
|
|
48
|
+
assert_process_response_processing response
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def assert_process_response_processing(response)
|
|
53
|
+
payment_transaction = payment_transaction()
|
|
54
|
+
response_object = Response.new response
|
|
55
|
+
|
|
56
|
+
query.process_response payment_transaction, response_object
|
|
57
|
+
|
|
58
|
+
assert_equal PAYNET_ID, payment_transaction.payment.paynet_id
|
|
59
|
+
assert_true payment_transaction.processing?
|
|
60
|
+
assert_false payment_transaction.finished?
|
|
61
|
+
assert_false payment_transaction.has_errors?
|
|
62
|
+
|
|
63
|
+
[payment_transaction, response_object]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_process_response_error
|
|
67
|
+
[
|
|
68
|
+
{
|
|
69
|
+
'type' => 'validation-error',
|
|
70
|
+
'serial-number' => '_',
|
|
71
|
+
'error-message' => 'validation-error message',
|
|
72
|
+
'error-code' => 1
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
'type' => 'error',
|
|
76
|
+
'error-message' => 'test type error message',
|
|
77
|
+
'error-code' => 5
|
|
78
|
+
}
|
|
79
|
+
].each do |response|
|
|
80
|
+
assert_process_response_error response
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_validate_client_id_with_different_types
|
|
85
|
+
payment_transaction = payment_transaction()
|
|
86
|
+
payment_transaction.payment.client_id = 123
|
|
87
|
+
|
|
88
|
+
response = Response.new(
|
|
89
|
+
{
|
|
90
|
+
'type' => success_type,
|
|
91
|
+
'status' => 'approved',
|
|
92
|
+
'paynet-order-id' => PAYNET_ID,
|
|
93
|
+
'merchant-order-id' => '123',
|
|
94
|
+
'serial-number' => '_',
|
|
95
|
+
'redirect-url' => 'http://example.com'
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
query.process_response payment_transaction, response
|
|
99
|
+
|
|
100
|
+
assert_true payment_transaction.approved?
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
protected
|
|
104
|
+
|
|
105
|
+
def success_type
|
|
106
|
+
'async-response'
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def api_method
|
|
110
|
+
raise NotImplementedError, 'You must return query api method from this method'
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def payment_status
|
|
114
|
+
raise NotImplementedError, 'You must return query payment status from this method'
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'digest/sha1'
|
|
3
|
+
require 'paynet_easy_api'
|
|
4
|
+
require 'query/prototype/query'
|
|
5
|
+
require 'payment_data/payment_transaction'
|
|
6
|
+
require 'payment_data/payment'
|
|
7
|
+
require 'payment_data/query_config'
|
|
8
|
+
require 'transport/response'
|
|
9
|
+
require 'error/validation_error'
|
|
10
|
+
require 'error/paynet_error'
|
|
11
|
+
|
|
12
|
+
module PaynetEasy::PaynetEasyApi::Query::Prototype
|
|
13
|
+
module QueryTestPrototype
|
|
14
|
+
include PaynetEasy::PaynetEasyApi::PaymentData
|
|
15
|
+
include PaynetEasy::PaynetEasyApi::Transport
|
|
16
|
+
include PaynetEasy::PaynetEasyApi::Error
|
|
17
|
+
|
|
18
|
+
LOGIN = 'test-login'
|
|
19
|
+
END_POINT = 789
|
|
20
|
+
SIGNING_KEY = 'D5F82EC1-8575-4482-AD89-97X6X0X20X22'
|
|
21
|
+
CLIENT_ID = 'CLIENT-112233'
|
|
22
|
+
PAYNET_ID = 'PAYNET-112233'
|
|
23
|
+
|
|
24
|
+
RECURRENT_CARD_FROM_ID = '5588943'
|
|
25
|
+
RECURRENT_CARD_TO_ID = '5588978'
|
|
26
|
+
|
|
27
|
+
def test_create_request
|
|
28
|
+
raise NotImplementedError
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def assert_create_request(control_code)
|
|
32
|
+
payment_transaction = payment_transaction()
|
|
33
|
+
|
|
34
|
+
request = query.create_request payment_transaction
|
|
35
|
+
request_fields = request.request_fields
|
|
36
|
+
|
|
37
|
+
assert_not_nil request.api_method
|
|
38
|
+
assert_not_nil request.end_point
|
|
39
|
+
assert_not_nil request_fields['control']
|
|
40
|
+
assert_equal control_code, request_fields['control']
|
|
41
|
+
assert_false payment_transaction.has_errors?
|
|
42
|
+
|
|
43
|
+
[payment_transaction, request]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_create_request_with_empty_fields
|
|
47
|
+
payment_transaction = PaymentTransaction.new(
|
|
48
|
+
{
|
|
49
|
+
'payment' => Payment.new(
|
|
50
|
+
{
|
|
51
|
+
'status' => Payment::STATUS_CAPTURE
|
|
52
|
+
}),
|
|
53
|
+
'query_config' => query_config
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
query = query()
|
|
57
|
+
|
|
58
|
+
assert_raise ValidationError, 'Some required fields missed or empty in Payment' do
|
|
59
|
+
query.create_request payment_transaction
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_create_request_with_invalid_fields
|
|
64
|
+
payment_transaction = payment_transaction()
|
|
65
|
+
payment_transaction.payment.client_id = '123456789012345678901234567890'
|
|
66
|
+
payment_transaction.query_config.login = '123456789012345678901234567890123456789012345678901234567890'
|
|
67
|
+
|
|
68
|
+
assert_raise ValidationError, 'Some fields invalid in Payment' do
|
|
69
|
+
query.create_request payment_transaction
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_process_response_error
|
|
74
|
+
raise NotImplementedError
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def assert_process_response_error(response)
|
|
78
|
+
payment_transaction = payment_transaction()
|
|
79
|
+
response_object = Response.new response
|
|
80
|
+
|
|
81
|
+
begin
|
|
82
|
+
query.process_response payment_transaction, response_object
|
|
83
|
+
rescue PaynetError => error
|
|
84
|
+
assert_true payment_transaction.error?
|
|
85
|
+
assert_true payment_transaction.finished?
|
|
86
|
+
assert_true payment_transaction.has_errors?
|
|
87
|
+
assert_equal response_object.error_message, error.message
|
|
88
|
+
|
|
89
|
+
return [payment_transaction, response_object]
|
|
90
|
+
else
|
|
91
|
+
flunk 'Exception must be raised'
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def test_process_success_response_with_invalid_type
|
|
96
|
+
response = Response.new 'type' => 'invalid'
|
|
97
|
+
|
|
98
|
+
assert_raise ValidationError, "Response type 'invalid' does not match success response type" do
|
|
99
|
+
query.process_response payment_transaction, response
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def test_process_success_response_with_empty_fields
|
|
104
|
+
response = Response.new 'type' => success_type
|
|
105
|
+
|
|
106
|
+
assert_raise ValidationError, 'Some required fields missed or empty in Response' do
|
|
107
|
+
query.process_response payment_transaction, response
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def test_process_response_with_invalid_id
|
|
112
|
+
response = Response.new(
|
|
113
|
+
{
|
|
114
|
+
'type' => success_type,
|
|
115
|
+
'paynet-order-id' => '_',
|
|
116
|
+
'merchant-order-id' => '_',
|
|
117
|
+
'serial-number' => '_',
|
|
118
|
+
'card-ref-id' => '_',
|
|
119
|
+
'redirect-url' => '_',
|
|
120
|
+
'client_orderid' => 'invalid'
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
assert_raise ValidationError, "Response client_id '_' does not match Payment client_id" do
|
|
124
|
+
query.process_response payment_transaction, response
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def test_process_error_response_without_type
|
|
129
|
+
response = Response.new 'status' => 'error'
|
|
130
|
+
|
|
131
|
+
assert_raise ValidationError, 'Unknown response type' do
|
|
132
|
+
query.process_response payment_transaction, response
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def test_process_error_response_with_invalid_id
|
|
137
|
+
response = Response.new 'type' => 'error', 'client_orderid' => 'invalid'
|
|
138
|
+
|
|
139
|
+
assert_raise ValidationError, "Response client_id 'invalid' does not match Payment client_id" do
|
|
140
|
+
query.process_response payment_transaction, response
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
protected
|
|
145
|
+
|
|
146
|
+
# @return [String]
|
|
147
|
+
def success_type
|
|
148
|
+
raise NotImplementedError, 'You must return success type for query response form this method'
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# @return [Query]
|
|
152
|
+
def query
|
|
153
|
+
raise NotImplementedError, 'You must implement query creation in this method'
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# @return [PaymentTransaction]
|
|
157
|
+
def payment_transaction
|
|
158
|
+
payment_transaction = PaymentTransaction.new({}, true)
|
|
159
|
+
|
|
160
|
+
payment_transaction.payment = payment()
|
|
161
|
+
payment_transaction.query_config = query_config()
|
|
162
|
+
|
|
163
|
+
payment_transaction
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# @return [Payment]
|
|
167
|
+
def payment
|
|
168
|
+
raise NotImplementedError
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# @return [QueryConfig]
|
|
172
|
+
def query_config
|
|
173
|
+
QueryConfig.new(
|
|
174
|
+
{
|
|
175
|
+
'login' => LOGIN,
|
|
176
|
+
'end_point' => END_POINT,
|
|
177
|
+
'signing_key' => SIGNING_KEY,
|
|
178
|
+
'site_url' => 'http://example.com',
|
|
179
|
+
'gateway_url_sandbox' => 'https://example.com/sandbox_url',
|
|
180
|
+
'redirect_url' => 'https://example.com/redirect_url',
|
|
181
|
+
'callback_url' => 'https://example.com/callback_url'
|
|
182
|
+
})
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# Create sha1 hash sum from all method arguments
|
|
186
|
+
def create_control_code(*args)
|
|
187
|
+
Digest::SHA1.hexdigest(args.join(''))
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require_relative './query_test_prototype'
|
|
2
|
+
|
|
3
|
+
module PaynetEasy::PaynetEasyApi::Query::Prototype
|
|
4
|
+
module SyncQueryTestPrototype
|
|
5
|
+
include QueryTestPrototype
|
|
6
|
+
|
|
7
|
+
def test_process_response_approved
|
|
8
|
+
raise NotImplementedError
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def assert_process_response_approved(response)
|
|
12
|
+
payment_transaction = payment_transaction()
|
|
13
|
+
response_object = Response.new response
|
|
14
|
+
|
|
15
|
+
query.process_response payment_transaction, response_object
|
|
16
|
+
|
|
17
|
+
assert_true payment_transaction.approved?
|
|
18
|
+
assert_true payment_transaction.finished?
|
|
19
|
+
assert_false payment_transaction.has_errors?
|
|
20
|
+
|
|
21
|
+
[payment_transaction, response_object]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_process_response_declined
|
|
25
|
+
[
|
|
26
|
+
{
|
|
27
|
+
'type' => success_type,
|
|
28
|
+
'status' => 'filtered',
|
|
29
|
+
'paynet-order-id' => PAYNET_ID,
|
|
30
|
+
'merchant-order-id' => CLIENT_ID,
|
|
31
|
+
'serial-number' => '_',
|
|
32
|
+
'error-message' => 'test filtered message',
|
|
33
|
+
'error-code' => 8876
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
'type' => success_type,
|
|
37
|
+
'status' => 'declined',
|
|
38
|
+
'paynet-order-id' => PAYNET_ID,
|
|
39
|
+
'merchant-order-id' => CLIENT_ID,
|
|
40
|
+
'serial-number' => '_',
|
|
41
|
+
'error-message' => 'test error message',
|
|
42
|
+
'error-code' => 578
|
|
43
|
+
}
|
|
44
|
+
].each do |response|
|
|
45
|
+
assert_process_response_declined response
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def assert_process_response_declined(response)
|
|
50
|
+
payment_transaction = payment_transaction()
|
|
51
|
+
response_object = Response.new response
|
|
52
|
+
|
|
53
|
+
query.process_response payment_transaction, response_object
|
|
54
|
+
|
|
55
|
+
assert_true payment_transaction.declined?
|
|
56
|
+
assert_true payment_transaction.finished?
|
|
57
|
+
assert_true payment_transaction.has_errors?
|
|
58
|
+
|
|
59
|
+
[payment_transaction, response_object]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_process_response_error
|
|
63
|
+
[
|
|
64
|
+
{
|
|
65
|
+
'type' => success_type,
|
|
66
|
+
'status' => 'error',
|
|
67
|
+
'paynet-order-id' => PAYNET_ID,
|
|
68
|
+
'merchant-order-id' => CLIENT_ID,
|
|
69
|
+
'serial-number' => '_',
|
|
70
|
+
'error-message' => 'status error message',
|
|
71
|
+
'error-code' => 24
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
'type' => 'validation-error',
|
|
75
|
+
'error-message' => 'validation error message',
|
|
76
|
+
'error-code' => 1
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
'type' => 'error',
|
|
80
|
+
'error-message' => 'immediate error message',
|
|
81
|
+
'error-code' => 1
|
|
82
|
+
}
|
|
83
|
+
].each do |response|
|
|
84
|
+
assert_process_response_error response
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'paynet_easy_api'
|
|
3
|
+
require 'query/query_factory'
|
|
4
|
+
require 'query/create_card_ref_query'
|
|
5
|
+
require 'query/return_query'
|
|
6
|
+
|
|
7
|
+
module PaynetEasy::PaynetEasyApi::Query
|
|
8
|
+
class QueryFactoryTest < Test::Unit::TestCase
|
|
9
|
+
def setup
|
|
10
|
+
@object = QueryFactory.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_query
|
|
14
|
+
query = @object.query 'create-card-ref'
|
|
15
|
+
assert_instance_of CreateCardRefQuery, query
|
|
16
|
+
|
|
17
|
+
query = @object.query 'return'
|
|
18
|
+
assert_instance_of ReturnQuery, query
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require_relative './prototype/payment_query_test_prototype'
|
|
2
|
+
require 'query/return_query'
|
|
3
|
+
|
|
4
|
+
module PaynetEasy::PaynetEasyApi::Query
|
|
5
|
+
class ReturnQueryTest < Test::Unit::TestCase
|
|
6
|
+
include Prototype::PaymentQueryTestPrototype
|
|
7
|
+
|
|
8
|
+
def test_create_request
|
|
9
|
+
[
|
|
10
|
+
create_control_code(
|
|
11
|
+
LOGIN,
|
|
12
|
+
CLIENT_ID,
|
|
13
|
+
PAYNET_ID,
|
|
14
|
+
9910,
|
|
15
|
+
'EUR',
|
|
16
|
+
SIGNING_KEY
|
|
17
|
+
)
|
|
18
|
+
].each do |control_code|
|
|
19
|
+
assert_create_request control_code
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_create_request_with_finished_transaction
|
|
24
|
+
payment_transaction = payment_transaction()
|
|
25
|
+
payment_transaction.payment.status = Payment::STATUS_RETURN
|
|
26
|
+
|
|
27
|
+
assert_raise ValidationError, 'Payment must be paid up to return funds' do
|
|
28
|
+
query.create_request payment_transaction
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
protected
|
|
33
|
+
|
|
34
|
+
def payment
|
|
35
|
+
Payment.new(
|
|
36
|
+
{
|
|
37
|
+
'client_id' => CLIENT_ID,
|
|
38
|
+
'paynet_id' => PAYNET_ID,
|
|
39
|
+
'amount' => 99.1,
|
|
40
|
+
'currency' => 'EUR',
|
|
41
|
+
'comment' => 'cancel payment',
|
|
42
|
+
'status' => Payment::STATUS_CAPTURE
|
|
43
|
+
})
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def payment_status
|
|
47
|
+
Payment::STATUS_RETURN
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def api_method
|
|
51
|
+
'return'
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def query
|
|
55
|
+
ReturnQuery.new api_method
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|