judopay 2.1.0 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +24 -23
- data/.rspec +1 -1
- data/.rubocop.yml +54 -51
- data/.travis.yml +6 -6
- data/CHANGELOG.md +17 -17
- data/Gemfile +4 -4
- data/LICENSE +21 -21
- data/README.md +96 -94
- data/Rakefile +22 -22
- data/judopay.gemspec +38 -38
- data/lib/certs/digicert_sha256_ca.pem +49 -49
- data/lib/certs/rapidssl_ca.crt +63 -63
- data/lib/faraday/judo_mashify.rb +11 -11
- data/lib/faraday/raise_http_exception.rb +19 -19
- data/lib/judopay.rb +70 -70
- data/lib/judopay/api.rb +10 -10
- data/lib/judopay/connection.rb +77 -77
- data/lib/judopay/core_ext/hash.rb +29 -29
- data/lib/judopay/core_ext/string.rb +32 -32
- data/lib/judopay/error.rb +117 -115
- data/lib/judopay/mash.rb +11 -11
- data/lib/judopay/model.rb +134 -134
- data/lib/judopay/models/android_payment.rb +26 -26
- data/lib/judopay/models/android_preauth.rb +8 -8
- data/lib/judopay/models/apple_payment.rb +26 -26
- data/lib/judopay/models/apple_preauth.rb +9 -9
- data/lib/judopay/models/card_address.rb +11 -11
- data/lib/judopay/models/card_payment.rb +33 -33
- data/lib/judopay/models/card_preauth.rb +11 -11
- data/lib/judopay/models/collection.rb +16 -16
- data/lib/judopay/models/encrypt_details.rb +18 -0
- data/lib/judopay/models/inner/pk_payment.rb +17 -17
- data/lib/judopay/models/inner/pk_payment_token.rb +13 -13
- data/lib/judopay/models/inner/transmitted_field.rb +39 -39
- data/lib/judopay/models/inner/wallet.rb +30 -30
- data/lib/judopay/models/market/collection.rb +10 -10
- data/lib/judopay/models/market/payment.rb +10 -10
- data/lib/judopay/models/market/preauth.rb +10 -10
- data/lib/judopay/models/market/refund.rb +10 -10
- data/lib/judopay/models/market/transaction.rb +10 -10
- data/lib/judopay/models/one_use_token_payment.rb +29 -0
- data/lib/judopay/models/payment.rb +8 -8
- data/lib/judopay/models/preauth.rb +8 -8
- data/lib/judopay/models/refund.rb +16 -16
- data/lib/judopay/models/register_card.rb +27 -27
- data/lib/judopay/models/save_card.rb +24 -25
- data/lib/judopay/models/token_payment.rb +30 -30
- data/lib/judopay/models/token_preauth.rb +10 -10
- data/lib/judopay/models/transaction.rb +8 -8
- data/lib/judopay/models/void.rb +19 -19
- data/lib/judopay/models/web_payments/payment.rb +28 -28
- data/lib/judopay/models/web_payments/preauth.rb +10 -10
- data/lib/judopay/models/web_payments/transaction.rb +19 -19
- data/lib/judopay/models/web_payments/web_payment_operation.rb +8 -8
- data/lib/judopay/null_logger.rb +9 -11
- data/lib/judopay/request.rb +50 -50
- data/lib/judopay/response.rb +7 -7
- data/lib/judopay/serializer.rb +27 -27
- data/lib/judopay/version.rb +4 -4
- data/spec/factories.rb +227 -208
- data/spec/faraday/response_spec.rb +27 -27
- data/spec/fixtures/card_payments/create.json +21 -21
- data/spec/fixtures/card_payments/create_3dsecure.json +7 -7
- data/spec/fixtures/card_payments/create_bad_request.json +12 -12
- data/spec/fixtures/card_payments/create_declined.json +23 -23
- data/spec/fixtures/card_payments/validate.json +4 -4
- data/spec/fixtures/token_payments/create.json +21 -21
- data/spec/fixtures/transactions/all.json +237 -237
- data/spec/fixtures/transactions/android_payment.json +26 -26
- data/spec/fixtures/transactions/apple_payment.json +26 -26
- data/spec/fixtures/transactions/find.json +22 -22
- data/spec/fixtures/transactions/find_not_found.json +4 -4
- data/spec/fixtures/transactions/register_card.json +28 -28
- data/spec/fixtures/transactions/save_card.json +27 -27
- data/spec/fixtures/transactions/void.json +26 -26
- data/spec/fixtures/web_payments/payments/create.json +3 -3
- data/spec/fixtures/web_payments/payments/find.json +38 -38
- data/spec/judopay/android_payment_spec.rb +74 -74
- data/spec/judopay/apple_payment_spec.rb +80 -80
- data/spec/judopay/card_address_spec.rb +10 -10
- data/spec/judopay/card_payment_spec.rb +51 -63
- data/spec/judopay/card_preauth_spec.rb +35 -35
- data/spec/judopay/collection_spec.rb +26 -26
- data/spec/judopay/core_ext/hash_spec.rb +24 -24
- data/spec/judopay/core_ext/string_spec.rb +16 -16
- data/spec/judopay/error_spec.rb +70 -70
- data/spec/judopay/judopay_spec.rb +19 -19
- data/spec/judopay/market/collection_spec.rb +26 -26
- data/spec/judopay/market/payment_spec.rb +14 -14
- data/spec/judopay/market/preauth_spec.rb +14 -14
- data/spec/judopay/market/refund_spec.rb +26 -26
- data/spec/judopay/market/transaction_spec.rb +14 -14
- data/spec/judopay/payment_spec.rb +14 -14
- data/spec/judopay/preauth_spec.rb +14 -14
- data/spec/judopay/refund_spec.rb +26 -26
- data/spec/judopay/register_card_spec.rb +24 -24
- data/spec/judopay/save_card_spec.rb +23 -23
- data/spec/judopay/token_payment_spec.rb +22 -22
- data/spec/judopay/token_preauth_spec.rb +22 -22
- data/spec/judopay/transaction_spec.rb +51 -51
- data/spec/judopay/void_spec.rb +24 -24
- data/spec/judopay/web_payments/payment_spec.rb +16 -16
- data/spec/judopay/web_payments/preauth_spec.rb +16 -16
- data/spec/judopay/web_payments/transaction_spec.rb +15 -15
- data/spec/spec_helper.rb +41 -41
- data/test/additions_payment_test.rb +30 -0
- data/test/authentication_test.rb +23 -23
- data/test/base/integration_base.rb +20 -20
- data/test/base/payments_tests.rb +47 -47
- data/test/base/token_payment_tests.rb +98 -98
- data/test/card_details_test.rb +21 -21
- data/test/configuration_test.rb +35 -35
- data/test/helper/assertion_helper.rb +29 -29
- data/test/payment_test.rb +10 -10
- data/test/preauth_test.rb +10 -10
- data/test/register_card_test.rb +42 -42
- data/test/save_card_test.rb +23 -0
- data/test/token_payment_test.rb +10 -10
- data/test/token_preauth_test.rb +10 -10
- data/test/void_test.rb +45 -45
- metadata +18 -12
@@ -1,15 +1,15 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require_relative '../../../lib/judopay/models/web_payments/transaction'
|
3
|
-
|
4
|
-
describe Judopay::WebPayments::Transaction do
|
5
|
-
it 'should give details of a single web transaction given a valid reference' do
|
6
|
-
reference = '4gcBAAMAGAASAAAADA66kRor6ofknGqU3A6i-759FprFGPH3ecVcW5ChMQK0f3pLBQ'
|
7
|
-
stub_get('/webpayments/' + reference).
|
8
|
-
to_return(:status => 200,
|
9
|
-
:body => lambda { |_request| fixture('web_payments/payments/find.json') })
|
10
|
-
|
11
|
-
payment = Judopay::WebPayments::Transaction.find(reference)
|
12
|
-
expect(payment).to be_a(Hash)
|
13
|
-
expect(payment.reference).to eq(reference)
|
14
|
-
end
|
15
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../../lib/judopay/models/web_payments/transaction'
|
3
|
+
|
4
|
+
describe Judopay::WebPayments::Transaction do
|
5
|
+
it 'should give details of a single web transaction given a valid reference' do
|
6
|
+
reference = '4gcBAAMAGAASAAAADA66kRor6ofknGqU3A6i-759FprFGPH3ecVcW5ChMQK0f3pLBQ'
|
7
|
+
stub_get('/webpayments/' + reference).
|
8
|
+
to_return(:status => 200,
|
9
|
+
:body => lambda { |_request| fixture('web_payments/payments/find.json') })
|
10
|
+
|
11
|
+
payment = Judopay::WebPayments::Transaction.find(reference)
|
12
|
+
expect(payment).to be_a(Hash)
|
13
|
+
expect(payment.reference).to eq(reference)
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
require_relative '../lib/judopay'
|
2
|
-
require 'i18n'
|
3
|
-
|
4
|
-
require '
|
5
|
-
require 'factories'
|
6
|
-
require 'webmock/rspec'
|
7
|
-
|
8
|
-
# Added to counter deprecation warning
|
9
|
-
I18n.enforce_available_locales = true
|
10
|
-
|
11
|
-
RSpec.configure do |config|
|
12
|
-
config.include
|
13
|
-
config.include WebMock::API
|
14
|
-
|
15
|
-
config.expect_with :rspec do |c|
|
16
|
-
c.syntax = [:expect, :should]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# Mock configuration
|
21
|
-
Judopay.configure do |config|
|
22
|
-
config.judo_id = 'id'
|
23
|
-
config.api_token = 'token'
|
24
|
-
config.api_secret = 'secret'
|
25
|
-
end
|
26
|
-
|
27
|
-
def stub_get(path)
|
28
|
-
stub_request(:get, /judopay/i)
|
29
|
-
end
|
30
|
-
|
31
|
-
def stub_post(path)
|
32
|
-
stub_request(:post, /judopay/i)
|
33
|
-
end
|
34
|
-
|
35
|
-
def fixture_path
|
36
|
-
File.expand_path('../fixtures', __FILE__)
|
37
|
-
end
|
38
|
-
|
39
|
-
def fixture(file)
|
40
|
-
File.new(fixture_path + '/' + file)
|
41
|
-
end
|
1
|
+
require_relative '../lib/judopay'
|
2
|
+
require 'i18n'
|
3
|
+
|
4
|
+
require 'factory_bot'
|
5
|
+
require 'factories'
|
6
|
+
require 'webmock/rspec'
|
7
|
+
|
8
|
+
# Added to counter deprecation warning
|
9
|
+
I18n.enforce_available_locales = true
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.include FactoryBot::Syntax::Methods
|
13
|
+
config.include WebMock::API
|
14
|
+
|
15
|
+
config.expect_with :rspec do |c|
|
16
|
+
c.syntax = [:expect, :should]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Mock configuration
|
21
|
+
Judopay.configure do |config|
|
22
|
+
config.judo_id = 'id'
|
23
|
+
config.api_token = 'token'
|
24
|
+
config.api_secret = 'secret'
|
25
|
+
end
|
26
|
+
|
27
|
+
def stub_get(path)
|
28
|
+
stub_request(:get, /judopay/i)
|
29
|
+
end
|
30
|
+
|
31
|
+
def stub_post(path)
|
32
|
+
stub_request(:post, /judopay/i)
|
33
|
+
end
|
34
|
+
|
35
|
+
def fixture_path
|
36
|
+
File.expand_path('../fixtures', __FILE__)
|
37
|
+
end
|
38
|
+
|
39
|
+
def fixture(file)
|
40
|
+
File.new(fixture_path + '/' + file)
|
41
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'base/integration_base'
|
2
|
+
|
3
|
+
class AdditionsPaymentTest < IntegrationBase
|
4
|
+
def test_one_use_token_payment
|
5
|
+
generated_token = generate_and_validate_token
|
6
|
+
successfully_use_one_use_token(generated_token)
|
7
|
+
cannot_reuse_one_use_token(generated_token)
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_and_validate_token
|
11
|
+
encryption = build(:encrypt_details, {}).create
|
12
|
+
assert_not_nil(encryption)
|
13
|
+
generated_token = encryption['oneUseToken']
|
14
|
+
assert_not_nil(generated_token)
|
15
|
+
generated_token
|
16
|
+
end
|
17
|
+
|
18
|
+
def successfully_use_one_use_token(generated_token)
|
19
|
+
encrypted_payment = build(:one_use_token_payment, :one_use_token => generated_token).create
|
20
|
+
assert_not_nil(encrypted_payment)
|
21
|
+
assert_equal('Success', encrypted_payment['result'])
|
22
|
+
end
|
23
|
+
|
24
|
+
def cannot_reuse_one_use_token(generated_token)
|
25
|
+
second_encrypted_payment = build(:one_use_token_payment, :one_use_token => generated_token)
|
26
|
+
assert_raise(Judopay::APIError.new('The one time token is not valid. It could have expired. Please try again')) do
|
27
|
+
second_encrypted_payment.create
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/test/authentication_test.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class AuthenticationTest < IntegrationBase
|
4
|
-
def test_payment_with_invalid_judo_id
|
5
|
-
payment = build(:card_payment, :judo_id => 123)
|
6
|
-
|
7
|
-
AssertionHelper.api_exception_with_errors(1, 1) { payment.create }
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_payment_with_invalid_token
|
11
|
-
Judopay.configuration.api_token = 'Bad_token'
|
12
|
-
payment = build(:card_payment)
|
13
|
-
|
14
|
-
AssertionHelper.api_exception_with_errors(0, 403, 403, 1) { payment.create }
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_payment_with_invalid_secret
|
18
|
-
Judopay.configuration.api_secret = 'Bad_secret'
|
19
|
-
payment = build(:card_payment)
|
20
|
-
|
21
|
-
AssertionHelper.api_exception_with_errors(0, 403, 403, 1) { payment.create }
|
22
|
-
end
|
23
|
-
end
|
1
|
+
require_relative 'base/integration_base'
|
2
|
+
|
3
|
+
class AuthenticationTest < IntegrationBase
|
4
|
+
def test_payment_with_invalid_judo_id
|
5
|
+
payment = build(:card_payment, :judo_id => 123)
|
6
|
+
|
7
|
+
AssertionHelper.api_exception_with_errors(1, 1) { payment.create }
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_payment_with_invalid_token
|
11
|
+
Judopay.configuration.api_token = 'Bad_token'
|
12
|
+
payment = build(:card_payment)
|
13
|
+
|
14
|
+
AssertionHelper.api_exception_with_errors(0, 403, 403, 1) { payment.create }
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_payment_with_invalid_secret
|
18
|
+
Judopay.configuration.api_secret = 'Bad_secret'
|
19
|
+
payment = build(:card_payment)
|
20
|
+
|
21
|
+
AssertionHelper.api_exception_with_errors(0, 403, 403, 1) { payment.create }
|
22
|
+
end
|
23
|
+
end
|
@@ -1,20 +1,20 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'judopay'
|
3
|
-
require 'judopay/error'
|
4
|
-
require '
|
5
|
-
require_relative '../../spec/factories'
|
6
|
-
require_relative '../helper/assertion_helper'
|
7
|
-
|
8
|
-
class IntegrationBase < Test::Unit::TestCase
|
9
|
-
include
|
10
|
-
include TestHelpers
|
11
|
-
|
12
|
-
def setup
|
13
|
-
Judopay.configure do |config|
|
14
|
-
config.judo_id = ENV['JUDO_API_ID']
|
15
|
-
config.api_token = ENV['JUDO_API_TOKEN']
|
16
|
-
config.api_secret = ENV['JUDO_API_SECRET']
|
17
|
-
config.use_production = false
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
1
|
+
require 'test/unit'
|
2
|
+
require 'judopay'
|
3
|
+
require 'judopay/error'
|
4
|
+
require 'factory_bot'
|
5
|
+
require_relative '../../spec/factories'
|
6
|
+
require_relative '../helper/assertion_helper'
|
7
|
+
|
8
|
+
class IntegrationBase < Test::Unit::TestCase
|
9
|
+
include FactoryBot::Syntax::Methods
|
10
|
+
include TestHelpers
|
11
|
+
|
12
|
+
def setup
|
13
|
+
Judopay.configure do |config|
|
14
|
+
config.judo_id = ENV['JUDO_API_ID']
|
15
|
+
config.api_token = ENV['JUDO_API_TOKEN']
|
16
|
+
config.api_secret = ENV['JUDO_API_SECRET']
|
17
|
+
config.use_production = false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/test/base/payments_tests.rb
CHANGED
@@ -1,47 +1,47 @@
|
|
1
|
-
require_relative '../base/integration_base'
|
2
|
-
require_relative '../helper/assertion_helper'
|
3
|
-
|
4
|
-
module PaymentTests
|
5
|
-
def test_valid_payment
|
6
|
-
result = get_model.create
|
7
|
-
|
8
|
-
TestHelpers::AssertionHelper.assert_successful_payment(result)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_declined_payment
|
12
|
-
result = get_model(:declined).create
|
13
|
-
|
14
|
-
TestHelpers::AssertionHelper.assert_declined_payment(result)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_payment_with_negative_amount
|
18
|
-
TestHelpers::AssertionHelper.api_exception_with_errors(1, 1) { get_model(:amount => -1.0).create }
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_payment_with_zero_amount
|
22
|
-
TestHelpers::AssertionHelper.api_exception_with_errors(1, 1) { get_model(:amount => 0).create }
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_payment_without_currency
|
26
|
-
assert_raise(Judopay::ValidationError.new("Missing required fields\nField errors:\ncurrency: can't be blank")) do
|
27
|
-
get_model(:currency => nil).create
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_payment_with_unknown_currency
|
32
|
-
TestHelpers::AssertionHelper.api_exception_with_errors(2, 1) { get_model(:currency => 'ZZZ').create }
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_payment_without_reference
|
36
|
-
assert_raise(Judopay::ValidationError.new("Missing required fields\nField errors:\nyour_consumer_reference: can't be blank")) do
|
37
|
-
get_model(:your_consumer_reference => nil).create
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_duplicate_payment
|
42
|
-
model = get_model
|
43
|
-
TestHelpers::AssertionHelper.assert_successful_payment(model.create)
|
44
|
-
|
45
|
-
TestHelpers::AssertionHelper.api_exception_with_errors(1, 86, 409, 4) { model.create }
|
46
|
-
end
|
47
|
-
end
|
1
|
+
require_relative '../base/integration_base'
|
2
|
+
require_relative '../helper/assertion_helper'
|
3
|
+
|
4
|
+
module PaymentTests
|
5
|
+
def test_valid_payment
|
6
|
+
result = get_model.create
|
7
|
+
|
8
|
+
TestHelpers::AssertionHelper.assert_successful_payment(result)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_declined_payment
|
12
|
+
result = get_model(:declined).create
|
13
|
+
|
14
|
+
TestHelpers::AssertionHelper.assert_declined_payment(result)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_payment_with_negative_amount
|
18
|
+
TestHelpers::AssertionHelper.api_exception_with_errors(1, 1) { get_model(:amount => -1.0).create }
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_payment_with_zero_amount
|
22
|
+
TestHelpers::AssertionHelper.api_exception_with_errors(1, 1) { get_model(:amount => 0).create }
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_payment_without_currency
|
26
|
+
assert_raise(Judopay::ValidationError.new("Missing required fields\nField errors:\ncurrency: can't be blank")) do
|
27
|
+
get_model(:currency => nil).create
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_payment_with_unknown_currency
|
32
|
+
TestHelpers::AssertionHelper.api_exception_with_errors(2, 1) { get_model(:currency => 'ZZZ').create }
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_payment_without_reference
|
36
|
+
assert_raise(Judopay::ValidationError.new("Missing required fields\nField errors:\nyour_consumer_reference: can't be blank")) do
|
37
|
+
get_model(:your_consumer_reference => nil).create
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_duplicate_payment
|
42
|
+
model = get_model
|
43
|
+
TestHelpers::AssertionHelper.assert_successful_payment(model.create)
|
44
|
+
|
45
|
+
TestHelpers::AssertionHelper.api_exception_with_errors(1, 86, 409, 4) { model.create }
|
46
|
+
end
|
47
|
+
end
|
@@ -1,98 +1,98 @@
|
|
1
|
-
require_relative '../base/integration_base'
|
2
|
-
require_relative '../helper/assertion_helper'
|
3
|
-
|
4
|
-
module TokenPaymentTests
|
5
|
-
def setup
|
6
|
-
super
|
7
|
-
payment = build(:card_payment)
|
8
|
-
result = payment.create
|
9
|
-
|
10
|
-
TestHelpers::AssertionHelper.assert_successful_payment(result)
|
11
|
-
|
12
|
-
@card_token = result['cardDetails']['cardToken']
|
13
|
-
@consumer_token = result['consumer']['consumerToken']
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_valid_token_payment
|
17
|
-
response = get_model.create
|
18
|
-
|
19
|
-
TestHelpers::AssertionHelper.assert_successful_payment(response)
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_declined_token_payment
|
23
|
-
response = get_model(:cv2 => '666').create
|
24
|
-
|
25
|
-
TestHelpers::AssertionHelper.assert_declined_payment(response)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_token_payment_without_token
|
29
|
-
assert_raise(Judopay::ValidationError.new("Missing required fields\nField errors:\ncard_token: can't be blank")) do
|
30
|
-
get_model(:card_token => nil).create
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_token_payment_without_cv2_and_without_token
|
35
|
-
assert_raise(Judopay::ValidationError.new("Missing required fields\nField errors:\ncard_token: can't be blank")) do
|
36
|
-
get_model(:card_token => nil, :cv2 => nil).create
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_payment_with_negative_amount
|
41
|
-
TestHelpers::AssertionHelper.api_exception_with_errors(1, 1) { get_model(:amount => -1.0).create }
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_payment_with_zero_amount
|
45
|
-
TestHelpers::AssertionHelper.api_exception_with_errors(1, 1) { get_model(:amount => 0).create }
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_payment_without_currency
|
49
|
-
response = get_model(:currency => nil).create
|
50
|
-
TestHelpers::AssertionHelper.assert_successful_payment(response)
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_payment_with_unknown_currency
|
54
|
-
TestHelpers::AssertionHelper.api_exception_with_errors(2, 1) { get_model(:currency => 'ZZZ').create }
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_payment_without_reference
|
58
|
-
assert_raise(Judopay::ValidationError.new("Missing required fields\nField errors:\nyour_consumer_reference: can't be blank")) do
|
59
|
-
get_model(:your_consumer_reference => nil).create
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_declined_token_payment_without_cv2
|
64
|
-
response = get_model(:cv2 => nil).create
|
65
|
-
|
66
|
-
TestHelpers::AssertionHelper.assert_declined_payment(response)
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_token_payment_without_cv2_and_with_negative_amount
|
70
|
-
TestHelpers::AssertionHelper.api_exception_with_errors(1, 1) { get_model(:amount => -1, :cv2 => nil).create }
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_token_payment_without_cv2_and_with_zero_amount
|
74
|
-
TestHelpers::AssertionHelper.api_exception_with_errors(1, 1) { get_model(:amount => 0, :cv2 => nil).create }
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_token_payment_without_cv2_and_without_currency
|
78
|
-
response = get_model(:cv2 => nil, :currency => nil).create
|
79
|
-
TestHelpers::AssertionHelper.assert_declined_payment(response)
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_token_payment_without_cv2_and_with_unknown_currency
|
83
|
-
TestHelpers::AssertionHelper.api_exception_with_errors(2, 1) { get_model(:cv2 => nil, :currency => 'ZZZ').create }
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_token_payment_without_cv2_and_without_reference
|
87
|
-
assert_raise(Judopay::ValidationError.new("Missing required fields\nField errors:\nyour_consumer_reference: can't be blank")) do
|
88
|
-
get_model(:your_consumer_reference => nil, :cv2 => nil).create
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_duplicate_payment
|
93
|
-
model = get_model
|
94
|
-
TestHelpers::AssertionHelper.assert_successful_payment(model.create)
|
95
|
-
|
96
|
-
TestHelpers::AssertionHelper.api_exception_with_errors(1, 86, 409, 4) { model.create }
|
97
|
-
end
|
98
|
-
end
|
1
|
+
require_relative '../base/integration_base'
|
2
|
+
require_relative '../helper/assertion_helper'
|
3
|
+
|
4
|
+
module TokenPaymentTests
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
payment = build(:card_payment)
|
8
|
+
result = payment.create
|
9
|
+
|
10
|
+
TestHelpers::AssertionHelper.assert_successful_payment(result)
|
11
|
+
|
12
|
+
@card_token = result['cardDetails']['cardToken']
|
13
|
+
@consumer_token = result['consumer']['consumerToken']
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_valid_token_payment
|
17
|
+
response = get_model.create
|
18
|
+
|
19
|
+
TestHelpers::AssertionHelper.assert_successful_payment(response)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_declined_token_payment
|
23
|
+
response = get_model(:cv2 => '666').create
|
24
|
+
|
25
|
+
TestHelpers::AssertionHelper.assert_declined_payment(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_token_payment_without_token
|
29
|
+
assert_raise(Judopay::ValidationError.new("Missing required fields\nField errors:\ncard_token: can't be blank")) do
|
30
|
+
get_model(:card_token => nil).create
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_token_payment_without_cv2_and_without_token
|
35
|
+
assert_raise(Judopay::ValidationError.new("Missing required fields\nField errors:\ncard_token: can't be blank")) do
|
36
|
+
get_model(:card_token => nil, :cv2 => nil).create
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_payment_with_negative_amount
|
41
|
+
TestHelpers::AssertionHelper.api_exception_with_errors(1, 1) { get_model(:amount => -1.0).create }
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_payment_with_zero_amount
|
45
|
+
TestHelpers::AssertionHelper.api_exception_with_errors(1, 1) { get_model(:amount => 0).create }
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_payment_without_currency
|
49
|
+
response = get_model(:currency => nil).create
|
50
|
+
TestHelpers::AssertionHelper.assert_successful_payment(response)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_payment_with_unknown_currency
|
54
|
+
TestHelpers::AssertionHelper.api_exception_with_errors(2, 1) { get_model(:currency => 'ZZZ').create }
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_payment_without_reference
|
58
|
+
assert_raise(Judopay::ValidationError.new("Missing required fields\nField errors:\nyour_consumer_reference: can't be blank")) do
|
59
|
+
get_model(:your_consumer_reference => nil).create
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_declined_token_payment_without_cv2
|
64
|
+
response = get_model(:cv2 => nil).create
|
65
|
+
|
66
|
+
TestHelpers::AssertionHelper.assert_declined_payment(response)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_token_payment_without_cv2_and_with_negative_amount
|
70
|
+
TestHelpers::AssertionHelper.api_exception_with_errors(1, 1) { get_model(:amount => -1, :cv2 => nil).create }
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_token_payment_without_cv2_and_with_zero_amount
|
74
|
+
TestHelpers::AssertionHelper.api_exception_with_errors(1, 1) { get_model(:amount => 0, :cv2 => nil).create }
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_token_payment_without_cv2_and_without_currency
|
78
|
+
response = get_model(:cv2 => nil, :currency => nil).create
|
79
|
+
TestHelpers::AssertionHelper.assert_declined_payment(response)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_token_payment_without_cv2_and_with_unknown_currency
|
83
|
+
TestHelpers::AssertionHelper.api_exception_with_errors(2, 1) { get_model(:cv2 => nil, :currency => 'ZZZ').create }
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_token_payment_without_cv2_and_without_reference
|
87
|
+
assert_raise(Judopay::ValidationError.new("Missing required fields\nField errors:\nyour_consumer_reference: can't be blank")) do
|
88
|
+
get_model(:your_consumer_reference => nil, :cv2 => nil).create
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_duplicate_payment
|
93
|
+
model = get_model
|
94
|
+
TestHelpers::AssertionHelper.assert_successful_payment(model.create)
|
95
|
+
|
96
|
+
TestHelpers::AssertionHelper.api_exception_with_errors(1, 86, 409, 4) { model.create }
|
97
|
+
end
|
98
|
+
end
|