trustev 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 00973810bcd07e8c4b4c232d0a48bad7b484fb46
4
+ data.tar.gz: 23d4ea284a284cf70c2b865ea6becbf6aed6f7a5
5
+ SHA512:
6
+ metadata.gz: c18f46e7e522fdd882216aa27dbd93dd0f8c0b8d9a7a9ebc19ab55daca5050bca31e9c1e551dc77dd586e6a607a28a984bbedec67aa12eebe5fca7343efdee36
7
+ data.tar.gz: 21fd158dc6f3ab6a2c8e39bbc6b856caa7e35f0bdc36b9acf3bb07a444a53b7034974650022fb157209c9be1695bb399d4c962aa12e0f1f8cb326a79ffd372e2
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in trustev.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jonah Hirsch
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,335 @@
1
+ # Trustev
2
+
3
+ Ruby wrapper for Trustev API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'trustev'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install trustev
20
+
21
+ ## Configuration
22
+ Set the following options
23
+ ```ruby
24
+ # This is your Trustev Site Username (NOTE: different from Reliance Login Username).
25
+ # It is available under the ‘View API Keys’ section of Reliance.
26
+ Trustev.username = 'username'
27
+ # This is your Trustev Site Password (NOTE: different from Reliance Login Password).
28
+ Trustev.password = 'password'
29
+ # This is your Trustev Site Shared Secret, available from Reliance.
30
+ Trustev.shared_secret = '0f0f0f0f'
31
+ #This is your Trustev Site Private Key, available from Reliance.
32
+ Trustev.private_key = 'ffffffff'
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ For more information on the parameters referenced below, see the [trustev API documentation](http://developers.trustev.com/#addtransaction)
38
+
39
+ ### Authentication
40
+
41
+ Authentication is handled automatically. You never have to request an authentication token manually.
42
+
43
+ ### Validation of Digital Signature
44
+
45
+ ```ruby
46
+ # digital_signature = Trustev::DigitalSignature.new(digital_signature, timestamp, session_id, stage_1)
47
+ # digital_signature.valid?
48
+ # or
49
+ # digital_signature.invalid?
50
+ digital_signature = Trustev::DigitalSignature.new('ae5b0c9ea554fed8080457debed0cccf832c183b3fa7794b497f5492e98a74a2',
51
+ 20141028163912,
52
+ 'f39767e2-0cb5-hk97-a296-4619c269d59d',
53
+ '123456.joe@bloggs.com')
54
+ digital_signature.valid? # true
55
+ digital_signature.invalid? # false
56
+ ```
57
+
58
+ ### Transaction
59
+
60
+ #### Create a new transaction
61
+
62
+ Only the following fields are required:
63
+ * transaction_number
64
+ * transaction_data.currency
65
+ * transaction_data.total_transaction_value
66
+ * transaction_data.timestamp
67
+ * customer
68
+ ```ruby
69
+ transaction = Trustev::Transaction.new('1234abcd')
70
+ transaction.create(
71
+ {
72
+ social_network: {
73
+ type: 0,
74
+ id: '12345678'
75
+ },
76
+ transaction_data: {
77
+ currency_code: 'EUR',
78
+ total_delivery: 10.0,
79
+ total_before_tax: 40,
80
+ total_discount: 10,
81
+ total_tax: 10,
82
+ total_transaction_value: 50.00,
83
+ timestamp: 1391449224000,
84
+ address: [
85
+ {
86
+ type: 0,
87
+ first_name: 'Joe',
88
+ last_name: 'Bloggs',
89
+ address_1: '2011',
90
+ address_2: 'Imaginary Way',
91
+ address_3: '',
92
+ city: 'Anycity',
93
+ state: 'AnyState',
94
+ postal_code: '123456',
95
+ country_code: 'US'
96
+ }
97
+ ],
98
+ item: [
99
+ {
100
+ name: 'T-Shirt',
101
+ url: 'T-shirts.com',
102
+ image_url: 'T-shirts.com/Trustev-T-Shirt',
103
+ quantity: 1,
104
+ total_before_tax: 40.0,
105
+ total_discount: 0.0,
106
+ total_tax: 10,
107
+ total_item_value: 50.0
108
+ }
109
+ ]
110
+ },
111
+ customer: {
112
+ first_name: 'John',
113
+ last_name: 'Doe',
114
+ phone_number: '00353861658789',
115
+ date_of_birth: 1403256280325,
116
+ email: [
117
+ {
118
+ is_default: true,
119
+ email_address: "jondoe@mail.com"
120
+ }
121
+ ],
122
+ address: [
123
+ {
124
+ type: 0,
125
+ first_name: 'Joe',
126
+ last_name: 'Bloggs',
127
+ address_1: '2011',
128
+ address_2: 'Imaginary Way',
129
+ address_3: '',
130
+ city: 'Anycity',
131
+ state: 'AnyState',
132
+ postal_code: '123456',
133
+ country_code: 'US',
134
+ is_default: true
135
+ }
136
+ ]
137
+ },
138
+ session_id: 'f39767e2-0cb5-hk97-a296-4619c269d59d'
139
+ }
140
+ )
141
+ ```
142
+
143
+ #### Update an existing transaction
144
+
145
+ This takes the same parameters as `Trustev::transaction.create`
146
+ ```ruby
147
+ transaction = Trustev::Transaction.new('1234abcd')
148
+ transaction.update({...})
149
+ ```
150
+
151
+ #### Set transaction status
152
+
153
+ ```ruby
154
+ # transaction.set_status(status, reason, comment)
155
+ transaction = Trustev::Transaction.new('1234abcd')
156
+ transaction.set_status(3, 2, 'Transaction was refused due to a Trustev Score of 35')
157
+ ```
158
+
159
+ | Status Code | Description |
160
+ |-------------|-------------|
161
+ | 0 | Init |
162
+ | 1 | Placed |
163
+ | 2 | Refunded |
164
+ | 3 | Rejected |
165
+ | 5 | Completed |
166
+ | 8 | Chargeback |
167
+
168
+ | Reason Code | Description |
169
+ |-------------|-------------|
170
+ | 0 | System |
171
+ | 1 | Fraud |
172
+ | 2 | Complaint |
173
+ | 3 | Remorse |
174
+ | 4 | Other |
175
+
176
+ Comment: This allows you to include and extra comment on the status of the transaction
177
+
178
+ See the [trustev API documentation](http://developers.trustev.com/#addtransactionstatus) for up to date codes.
179
+
180
+ #### Add transaction BIN
181
+
182
+ ```ruby
183
+ # transaction.set_bin(bin, transaction_number)
184
+ transaction = Trustev::Transaction.new('1234abcd')
185
+ transaction.set_bin(123456)
186
+ ```
187
+
188
+ ### Social
189
+
190
+ #### Add Social
191
+
192
+ ```ruby
193
+ Trustev::Social.create([
194
+ {
195
+ type: 0,
196
+ id: 780219323,
197
+ short_term_token: 'CAAGEIkkiTM4BAHR9ar4XH4uTqK6JaOF1aIGbCBrsQgocHUh9',
198
+ long_term_token: 'CAAGEIkkiTM4BAJyc0pMxQQAprOrNlMRODaVQgQtcvlNO7Rvab',
199
+ short_term_expiry: 1391448969000,
200
+ long_term_expiry: 1391449878000,
201
+ secret: '84bcd7da0e967139652f7ce90k4c859e'
202
+ }
203
+ ])
204
+ ```
205
+
206
+ | Social Network Type | Name |
207
+ |---------------------|----------|
208
+ | 0 | Facebook |
209
+ | 1 | Twitter |
210
+ | 2 | Linkedin |
211
+ | 3 | Trustev |
212
+
213
+ See the [trustev API documentation](http://developers.trustev.com/#addprofile) for up to types.
214
+
215
+ #### Update Social
216
+
217
+ This is similar `Trustev::Social.create`, but only accepts ONE hash, instead of an array of hashes.
218
+ ```ruby
219
+ Trustev::transaction.update({
220
+ type: 0,
221
+ id: 780219323,
222
+ short_term_token: 'CAAGEIkkiTM4BAHR9ar4XH4uTqK6JaOF1aIGbCBrsQgocHUh9',
223
+ long_term_token: 'CAAGEIkkiTM4BAJyc0pMxQQAprOrNlMRODaVQgQtcvlNO7Rvab',
224
+ short_term_expiry: 1391448969000,
225
+ long_term_expiry: 1391449878000,
226
+ secret: '84bcd7da0e967139652f7ce90k4c859e'
227
+ })
228
+ ```
229
+
230
+ #### Delete Social
231
+ ```ruby
232
+ # Trustev::Social.delete(social_network_type, social_network_id)
233
+ Trustev::Social.delete(0, 780219323)
234
+ ```
235
+
236
+ ### Profile
237
+
238
+ #### Retrieve Raw Scores
239
+ ```ruby
240
+ # profile = Trustev::Profile.new(transaction_number)
241
+ # profile.retrieve_scores
242
+ Trustev::Profile.retrieve('1234abcd')
243
+ profile.retrieve_scores
244
+ ```
245
+
246
+ This returns a hash with the Trustev Score.
247
+
248
+ ###### Sample Response
249
+ ```ruby
250
+ {
251
+ Code: 200,
252
+ Message: "Success",
253
+ Profile: {
254
+ Sources: [{
255
+ Scores: [{
256
+ Confidence : 100,
257
+ Parameter : 0,
258
+ Score : 73
259
+ }],
260
+ Source : 7
261
+ }]
262
+ }
263
+ }
264
+ ```
265
+
266
+ | Response Parameter | Description |
267
+ |----------------------|-----------------------------------------------------------------------------------------------------------------------------------|
268
+ | Code (int) | This will be a basic HTML response code |
269
+ | Message (string) | This will be a response string which should give your some basic information on the status of you response eg. “Success” or “NOK” |
270
+ | Sources (array) | This will be an array of Trustev Scores from different Trustev Sources |
271
+ | Scores (array) | This will be an array of Trustev Scores based on different Score parameters |
272
+ | Confidence (decimal) | This will be a Trustev Confidence which outlines Trustev’s Condfidence in the score it has returned |
273
+ | Parameter (int) | This will be The Trustev parameter which the score is based on |
274
+ | Score (decimal) | This is the Trustev Score |
275
+ | Source (int) | This will be the TrustevProfile Score Source on which the Trustev Scores Array was based on |
276
+
277
+ #### Retrieve Overall Trustev score
278
+ ```ruby
279
+ # profile = Trustev::Profile.new(transaction_number)
280
+ # profile.get_overall_score
281
+ Trustev::Profile.retrieve('1234abcd')
282
+ profile.get_overall_score
283
+ ```
284
+
285
+ This returns the overall Trustev score
286
+
287
+ #### Retrieve A Specific score
288
+ ```ruby
289
+ # profile = Trustev::Profile.new(transaction_number)
290
+ # profile.get_score(source_id, parameter_id)
291
+ Trustev::Profile.retrieve('1234abcd')
292
+ profile.get_score(7, 0)
293
+ ```
294
+
295
+ This returns a score from a specific source and parameter
296
+
297
+ | Score Source | Description |
298
+ |--------------|-------------|
299
+ | 0 | Address |
300
+ | 1 | Behavior |
301
+ | 2 | Device |
302
+ | 3 | Email |
303
+ | 4 | Facebook |
304
+ | 5 | IP |
305
+ | 6 | Transaction |
306
+ | 7 | Trustev |
307
+ | 8 | Velocity |
308
+
309
+ | Parameter Code | Description |
310
+ |----------------|-------------|
311
+ | 0 | Overall |
312
+ | 1 | Billing |
313
+ | 2 | Delivery |
314
+ | 3 | Input |
315
+ | 4 | Domain |
316
+ | 5 | Address |
317
+ | 6 | IP |
318
+ | 7 | Proxy |
319
+ | 8 | VPN |
320
+ | 9 | Value |
321
+ | 10 | Velocity |
322
+ | 11 | Legitimacy |
323
+ | 12 | Pattern |
324
+ | 13 | Hustle |
325
+
326
+ See the [trustev API documentation](http://developers.trustev.com/#getprofile) for up to date response info.
327
+
328
+
329
+ ## Contributing
330
+
331
+ 1. Fork it ( https://github.com/giftcardzen/trustev/fork )
332
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
333
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
334
+ 4. Push to the branch (`git push origin my-new-feature`)
335
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
@@ -0,0 +1,112 @@
1
+ require 'httparty'
2
+ require 'multi_json'
3
+
4
+ require 'trustev/version'
5
+ require 'trustev/authenticate'
6
+ require 'trustev/profile'
7
+ require 'trustev/social'
8
+ require 'trustev/transaction'
9
+ require 'trustev/error'
10
+ require 'trustev/digital_signature'
11
+
12
+ module Trustev
13
+ @@username = nil
14
+ @@password = nil
15
+ @@shared_secret = nil
16
+ @@private_key = nil
17
+ @@api_base = 'https://api.trustev.com/v'
18
+ @@api_version = '1.2'
19
+ @@token = nil
20
+ @@token_expire = nil
21
+
22
+ def self.username=(username)
23
+ @@username = username
24
+ end
25
+
26
+ def self.username
27
+ @@username
28
+ end
29
+
30
+ def self.password=(password)
31
+ @@password = password
32
+ end
33
+
34
+ def self.password
35
+ @@password
36
+ end
37
+
38
+ def self.shared_secret=(shared_secret)
39
+ @@shared_secret = shared_secret
40
+ end
41
+
42
+ def self.shared_secret
43
+ @@shared_secret
44
+ end
45
+
46
+ def self.private_key=(private_key)
47
+ @@private_key = private_key
48
+ end
49
+
50
+ def self.private_key
51
+ @@private_key
52
+ end
53
+
54
+ def self.api_url(url='')
55
+ @@api_base + @@api_version + '/' + url
56
+ end
57
+
58
+ def self.token=(token)
59
+ @@token = token
60
+ end
61
+
62
+ def self.token
63
+ @@token
64
+ end
65
+
66
+ def self.token_expire=(token_expire)
67
+ @@token_expire = token_expire
68
+ end
69
+
70
+ def self.token_expire
71
+ @@token_expire
72
+ end
73
+
74
+ def self.send_request(path, body, method, expect_json=false, requires_token=true)
75
+
76
+ if requires_token && invalid_token?
77
+ Authenticate.retrieve_token
78
+ end
79
+
80
+ raise Error.new('Auth token missing or expired') if requires_token && invalid_token?
81
+
82
+ headers = { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
83
+ headers['X-Authorization'] = "#{@@username} #{@@token}" if requires_token
84
+
85
+ body = { request: body }
86
+
87
+ options = { body: body.to_json, headers: headers}
88
+
89
+ response = HTTParty.post(api_url(path), options) if method == 'POST'
90
+ response = HTTParty.get(api_url(path), options) if method == 'GET'
91
+ response = HTTParty.put(api_url(path), options) if method == 'PUT'
92
+ response = HTTParty.delete(api_url(path), options) if method == 'DELETE'
93
+
94
+ raise Error.new('Bad API response', response.code, response.message) if response.code != 200
95
+
96
+ if expect_json
97
+ begin
98
+ response = MultiJson.load(response.body, symbolize_keys: true)
99
+ rescue MultiJson::DecodeError
100
+ raise Error.new('Invalid API response', response.code, response.message)
101
+ end
102
+ end
103
+
104
+ response
105
+ end
106
+
107
+ private
108
+
109
+ def self.invalid_token?
110
+ @@token.nil? || @@token_expire-600 <= Time.now.to_i
111
+ end
112
+ end