trustev 0.3.2 → 0.4.0.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -329
- data/Rakefile +1 -2
- data/lib/trustev.rb +20 -68
- data/lib/trustev/{authenticate.rb → 1.2/authenticate.rb} +0 -0
- data/lib/trustev/{digital_signature.rb → 1.2/digital_signature.rb} +0 -0
- data/lib/trustev/{profile.rb → 1.2/profile.rb} +1 -1
- data/lib/trustev/{social.rb → 1.2/social.rb} +0 -0
- data/lib/trustev/{transaction.rb → 1.2/transaction.rb} +0 -0
- data/lib/trustev/1.2/trustev.rb +66 -0
- data/lib/trustev/2.0/address.rb +41 -0
- data/lib/trustev/2.0/authenticate.rb +40 -0
- data/lib/trustev/2.0/case.rb +45 -0
- data/lib/trustev/2.0/case_attribute.rb +24 -0
- data/lib/trustev/2.0/customer.rb +32 -0
- data/lib/trustev/2.0/customer_address.rb +5 -0
- data/lib/trustev/2.0/decision.rb +17 -0
- data/lib/trustev/2.0/email.rb +35 -0
- data/lib/trustev/2.0/item.rb +34 -0
- data/lib/trustev/2.0/payment.rb +33 -0
- data/lib/trustev/2.0/social.rb +38 -0
- data/lib/trustev/2.0/status.rb +34 -0
- data/lib/trustev/2.0/timestamp.rb +17 -0
- data/lib/trustev/2.0/transaction.rb +30 -0
- data/lib/trustev/2.0/transaction_address.rb +5 -0
- data/lib/trustev/2.0/trustev.rb +51 -0
- data/lib/trustev/error.rb +5 -6
- data/lib/trustev/version.rb +1 -1
- data/test/{authenticate_test.rb → 1.2/authenticate_test.rb} +0 -0
- data/test/{digital_signature_test.rb → 1.2/digital_signature_test.rb} +0 -0
- data/test/{error_test.rb → 1.2/error_test.rb} +3 -3
- data/test/{profile_test.rb → 1.2/profile_test.rb} +0 -0
- data/test/{social_test.rb → 1.2/social_test.rb} +0 -0
- data/test/{test_helper.rb → 1.2/test_helper.rb} +3 -2
- data/test/{transaction_test.rb → 1.2/transaction_test.rb} +0 -0
- data/test/2.0/authenticate_test.rb +13 -0
- data/test/2.0/case_test.rb +31 -0
- data/test/2.0/customer_address_test.rb +35 -0
- data/test/2.0/customer_test.rb +31 -0
- data/test/2.0/decision_test.rb +13 -0
- data/test/2.0/email_test.rb +33 -0
- data/test/2.0/error_test.rb +18 -0
- data/test/2.0/item_test.rb +33 -0
- data/test/2.0/payment_test.rb +33 -0
- data/test/2.0/social_test.rb +33 -0
- data/test/2.0/status_test.rb +27 -0
- data/test/2.0/test_helper.rb +165 -0
- data/test/2.0/transaction_address_Test.rb +35 -0
- data/test/2.0/transaction_test.rb +31 -0
- data/trustev.gemspec +3 -0
- metadata +111 -24
@@ -0,0 +1,17 @@
|
|
1
|
+
module Trustev
|
2
|
+
class Timestamp
|
3
|
+
|
4
|
+
def initialize(timestamp=Time.now.utc)
|
5
|
+
raise Error.new('timestamp must be an instance of Time') unless timestamp.instance_of?(Time)
|
6
|
+
@timestamp = timestamp
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
@timestamp.strftime('%Y-%m-%dT%H:%M:%S.%LZ')
|
11
|
+
end
|
12
|
+
|
13
|
+
def timestamp
|
14
|
+
@timestamp
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Trustev
|
2
|
+
class Transaction < CaseAttribute
|
3
|
+
|
4
|
+
SERVICE_URL = 'transaction'
|
5
|
+
|
6
|
+
def create
|
7
|
+
Trustev.send_request url, build, 'POST'
|
8
|
+
end
|
9
|
+
|
10
|
+
def retrieve
|
11
|
+
Trustev.send_request url, {}, 'GET'
|
12
|
+
end
|
13
|
+
|
14
|
+
def update
|
15
|
+
Trustev.send_request url, build, 'PUT'
|
16
|
+
end
|
17
|
+
|
18
|
+
def build
|
19
|
+
transaction = {
|
20
|
+
TotalTransactionValue: @opts[:total_transaction_value],
|
21
|
+
Currency: @opts[:currency_code],
|
22
|
+
timestamp: @opts[:timestamp],
|
23
|
+
addresses: @opts[:addresses],
|
24
|
+
items: @opts[:items]
|
25
|
+
}
|
26
|
+
transaction[:id] = @opts[:id] unless @opts[:id].nil?
|
27
|
+
transaction
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
require 'trustev/error'
|
3
|
+
|
4
|
+
module Trustev
|
5
|
+
|
6
|
+
@@api_base = 'https://app.trustev.com/api/v'
|
7
|
+
|
8
|
+
STATUS_TYPES = {
|
9
|
+
completed: 0,
|
10
|
+
rejecetd_fraud: 1,
|
11
|
+
rejected_auth_failure: 2,
|
12
|
+
rejected_suspicious: 3,
|
13
|
+
cancelled: 4,
|
14
|
+
chargeback_fraud: 5,
|
15
|
+
chargeback_other: 6,
|
16
|
+
refunded: 7,
|
17
|
+
placed: 8,
|
18
|
+
on_hold_review: 9
|
19
|
+
}
|
20
|
+
|
21
|
+
DECISIONS = {
|
22
|
+
unknown: 0,
|
23
|
+
pass: 1,
|
24
|
+
flag: 2,
|
25
|
+
fail: 3
|
26
|
+
}
|
27
|
+
|
28
|
+
PAYMENT_TYPES = {
|
29
|
+
none: 0,
|
30
|
+
credit_card: 1,
|
31
|
+
debit_card: 2,
|
32
|
+
direct_debit: 3,
|
33
|
+
paypal: 4,
|
34
|
+
bitcoin: 5
|
35
|
+
}
|
36
|
+
|
37
|
+
def self.raise_error(response)
|
38
|
+
error_response = MultiJson.load(response.body, symbolize_keys: true)
|
39
|
+
raise Error.new('Bad API response', response.code, error_response[:Message])
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.invalid_token?
|
43
|
+
now = Time.now
|
44
|
+
timestamp = @@token_expire? @@token_expire.timestamp : 0
|
45
|
+
@@token.nil? || timestamp-600 <= now
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.send_request(path, body, method, _expect_json=false, requires_token=true)
|
49
|
+
Trustev.do_send_request(path, body, method, true, requires_token)
|
50
|
+
end
|
51
|
+
end
|
data/lib/trustev/error.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
module Trustev
|
2
2
|
class Error < StandardError
|
3
3
|
attr_reader :message
|
4
|
-
attr_reader :http_status
|
5
4
|
|
6
5
|
def initialize(message=nil, http_status=nil, trustev_message=nil)
|
7
|
-
|
8
|
-
|
6
|
+
status_string = http_status.nil? ? '' : "(#{http_status}) "
|
7
|
+
trustev_message = "- #{trustev_message}" unless trustev_message.nil?
|
8
|
+
@message = "#{status_string}#{message} #{trustev_message}"
|
9
9
|
|
10
10
|
super(message)
|
11
11
|
end
|
12
12
|
|
13
13
|
def to_s
|
14
|
-
|
15
|
-
"#{status_string}#{@message}"
|
14
|
+
@message
|
16
15
|
end
|
17
16
|
end
|
18
|
-
end
|
17
|
+
end
|
data/lib/trustev/version.rb
CHANGED
File without changes
|
File without changes
|
@@ -5,14 +5,14 @@ describe Trustev::Error do
|
|
5
5
|
describe 'when an error is created' do
|
6
6
|
it 'must convert to a string properly' do
|
7
7
|
error = Trustev::Error.new('Test Message', 404, 'Invalid API Response')
|
8
|
-
error.to_s.must_equal '(
|
8
|
+
error.to_s.must_equal '(404) Test Message - Invalid API Response'
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
describe 'an error without a status code' do
|
13
13
|
it 'should just have messages when converted to a string' do
|
14
14
|
error = Trustev::Error.new('Test Message', nil, 'Invalid API Response')
|
15
|
-
error.to_s.must_equal 'Test Message Invalid API Response'
|
15
|
+
error.to_s.must_equal 'Test Message - Invalid API Response'
|
16
16
|
end
|
17
17
|
end
|
18
|
-
end
|
18
|
+
end
|
File without changes
|
File without changes
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative '../../lib/trustev'
|
2
2
|
require 'minitest/autorun'
|
3
3
|
require 'securerandom'
|
4
4
|
|
@@ -6,6 +6,7 @@ Trustev.username = 'FancyTees'
|
|
6
6
|
Trustev.password = '58dcca6b98a24e5a80b2a3682190da1a'
|
7
7
|
Trustev.shared_secret = '48357fbb820c407f855d72893d3f47ed'
|
8
8
|
Trustev.private_key = '65950d41f8d3ea86dc25aaf893ba15db'
|
9
|
+
Trustev.api_version = '1.2'
|
9
10
|
|
10
11
|
def build_transaction
|
11
12
|
{
|
@@ -77,4 +78,4 @@ def build_transaction
|
|
77
78
|
},
|
78
79
|
session_id: '4cec59b2-37f9-461e-9abc-861267e1a4d7'
|
79
80
|
}
|
80
|
-
end
|
81
|
+
end
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
describe Trustev::Authenticate do
|
4
|
+
|
5
|
+
describe 'when an authentication token is requested' do
|
6
|
+
it 'must set the authentication token' do
|
7
|
+
Trustev::Authenticate.retrieve_token
|
8
|
+
Trustev.token.wont_be_nil
|
9
|
+
Trustev.token_expire.wont_be_nil
|
10
|
+
Trustev.token_expire.instance_of?(Trustev::Timestamp).must_equal true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
describe Trustev::Case do
|
4
|
+
describe 'when creating a case' do
|
5
|
+
it 'must return a valid response' do
|
6
|
+
trustev_case = build_case
|
7
|
+
response = trustev_case.create
|
8
|
+
response[:Id].wont_be_nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'when updating a case' do
|
13
|
+
it 'must return a valid response' do
|
14
|
+
skip 'Intermittently broken at Trustev'
|
15
|
+
trustev_case = build_case
|
16
|
+
response = trustev_case.create
|
17
|
+
case_id = response[:Id]
|
18
|
+
case_number = response[:CaseNumber]
|
19
|
+
trustev_case = Trustev::Case.new(case_id, { case_number: case_number, customer: build_customer.build })
|
20
|
+
response = trustev_case.update
|
21
|
+
response[:Id].must_equal case_id
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'when retrieving a case' do
|
26
|
+
it 'must return a valid response' do
|
27
|
+
case_id = build_case.create[:Id]
|
28
|
+
Trustev::Case.new(case_id).retrieve[:Id].must_equal case_id
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
describe Trustev::CustomerAddress do
|
4
|
+
before do
|
5
|
+
@trustev_case = build_case
|
6
|
+
@case_id = @trustev_case.create[:Id]
|
7
|
+
@customer_address = build_customer_address case_id: @case_id
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'when creating a customer address' do
|
11
|
+
it 'must return a valid response' do
|
12
|
+
create_case_attribute @customer_address
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'when updating a customer address' do
|
17
|
+
it 'must return a valid response' do
|
18
|
+
update_case_attribute @customer_address, self.method(:build_customer_address), @case_id, { first_name: Faker::Name.first_name }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'when retrieving a customer address' do
|
23
|
+
it 'must return a valid response' do
|
24
|
+
customer_address = @trustev_case.retrieve[:Customer][:Addresses][0]
|
25
|
+
to_retrieve = Trustev::CustomerAddress.new(case_id: @case_id, id: customer_address[:Id])
|
26
|
+
to_retrieve.retrieve[:Id].wont_be_nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'when retrieving all customer addresses' do
|
31
|
+
it 'must return a valid response' do
|
32
|
+
retrieve_all_case_attribute Trustev::Social, @case_id
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
describe Trustev::Customer do
|
4
|
+
describe 'when creating a customer' do
|
5
|
+
it 'must return a valid response' do
|
6
|
+
trustev_case = build_case nil, SecureRandom.hex, { customer: nil }
|
7
|
+
case_id = trustev_case.create[:Id]
|
8
|
+
customer = build_customer case_id: case_id
|
9
|
+
customer.create[:Id].wont_be_nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'when updating a customer' do
|
14
|
+
it 'must return a valid response' do
|
15
|
+
trustev_case = build_case
|
16
|
+
case_id = trustev_case.create[:Id]
|
17
|
+
customer = build_customer case_id: case_id, first_name: Faker::Name.first_name
|
18
|
+
customer.update[:Id].wont_be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'when retrieving a customer' do
|
23
|
+
it 'must return a valid response' do
|
24
|
+
trustev_case = build_case.create
|
25
|
+
case_id = trustev_case[:Id]
|
26
|
+
customer_id = trustev_case[:Customer][:Id]
|
27
|
+
customer = Trustev::Customer.new id: customer_id, case_id: case_id
|
28
|
+
customer.retrieve[:Id].wont_be_nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
describe Trustev::Decision do
|
4
|
+
|
5
|
+
describe 'when an decision is requested' do
|
6
|
+
it 'must return the decision' do
|
7
|
+
case_id = build_case(nil, "#{SecureRandom.hex}pass").create[:Id]
|
8
|
+
decision = Trustev::Decision.new case_id
|
9
|
+
response = decision.retrieve
|
10
|
+
response[:Id].wont_be_nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
describe Trustev::Email do
|
4
|
+
before do
|
5
|
+
trustev_case = build_case
|
6
|
+
@case_id = trustev_case.create[:Id]
|
7
|
+
@email = build_email case_id: @case_id
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'when creating an email' do
|
11
|
+
it 'must return a valid response' do
|
12
|
+
create_case_attribute @email
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'when updating an email' do
|
17
|
+
it 'must return a valid response' do
|
18
|
+
update_case_attribute @email, self.method(:build_email), @case_id, { email: Faker::Internet.email }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'when retrieving an email' do
|
23
|
+
it 'must return a valid response' do
|
24
|
+
retrieve_case_attribute @email, Trustev::Email, @case_id
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'when retrieving all emails' do
|
29
|
+
it 'must return a valid response' do
|
30
|
+
retrieve_all_case_attribute Trustev::Email, @case_id
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
describe Trustev::Error do
|
4
|
+
|
5
|
+
describe 'when an error is created' do
|
6
|
+
it 'must convert to a string properly' do
|
7
|
+
error = Trustev::Error.new('Test Message', 404, 'Invalid API Response')
|
8
|
+
error.to_s.must_equal '(404) Test Message - Invalid API Response'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'an error without a status code' do
|
13
|
+
it 'should just have messages when converted to a string' do
|
14
|
+
error = Trustev::Error.new('Test Message', nil, 'Invalid API Response')
|
15
|
+
error.to_s.must_equal 'Test Message - Invalid API Response'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
describe Trustev::Item do
|
4
|
+
before do
|
5
|
+
trustev_case = build_case
|
6
|
+
@case_id = trustev_case.create[:Id]
|
7
|
+
@item = build_item case_id: @case_id
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'when creating an item' do
|
11
|
+
it 'must return a valid response' do
|
12
|
+
create_case_attribute @item
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'when updating an item' do
|
17
|
+
it 'must return a valid response' do
|
18
|
+
update_case_attribute @item, self.method(:build_item), @case_id, { name: Faker::Commerce.product_name }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'when retrieving an item' do
|
23
|
+
it 'must return a valid response' do
|
24
|
+
retrieve_case_attribute @item, Trustev::Item, @case_id
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'when retrieving all items' do
|
29
|
+
it 'must return a valid response' do
|
30
|
+
retrieve_all_case_attribute Trustev::Item, @case_id
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
describe Trustev::Payment do
|
4
|
+
before do
|
5
|
+
trustev_case = build_case
|
6
|
+
@case_id = trustev_case.create[:Id]
|
7
|
+
@payment = build_payment case_id: @case_id
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'when creating a payment' do
|
11
|
+
it 'must return a valid response' do
|
12
|
+
create_case_attribute @payment
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'when updating a payment' do
|
17
|
+
it 'must return a valid response' do
|
18
|
+
update_case_attribute @payment, self.method(:build_payment), @case_id, { bin_number: Faker::Number.number(6) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'when retrieving a payment' do
|
23
|
+
it 'must return a valid response' do
|
24
|
+
retrieve_case_attribute @payment, Trustev::Payment, @case_id
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'when retrieving all payments' do
|
29
|
+
it 'must return a valid response' do
|
30
|
+
retrieve_all_case_attribute Trustev::Payment, @case_id
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
describe Trustev::Social do
|
4
|
+
before do
|
5
|
+
trustev_case = build_case
|
6
|
+
@case_id = trustev_case.create[:Id]
|
7
|
+
@social = build_social case_id: @case_id
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'when creating a social' do
|
11
|
+
it 'must return a valid response' do
|
12
|
+
create_case_attribute @social
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'when updating a social' do
|
17
|
+
it 'must return a valid response' do
|
18
|
+
update_case_attribute @social, self.method(:build_social), @case_id, { social_id: Faker::Number.number(5) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'when retrieving an social' do
|
23
|
+
it 'must return a valid response' do
|
24
|
+
retrieve_case_attribute @social, Trustev::Social, @case_id
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'when retrieving all social' do
|
29
|
+
it 'must return a valid response' do
|
30
|
+
retrieve_all_case_attribute Trustev::Social, @case_id
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|