datacash 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +9 -0
- data/datacash.gemspec +34 -0
- data/lib/datacash.rb +51 -0
- data/lib/datacash/client.rb +61 -0
- data/lib/datacash/exceptions.rb +3 -0
- data/lib/datacash/request/amount.rb +14 -0
- data/lib/datacash/request/authentication.rb +7 -0
- data/lib/datacash/request/base.rb +37 -0
- data/lib/datacash/request/browser.rb +11 -0
- data/lib/datacash/request/card.rb +9 -0
- data/lib/datacash/request/card_transaction.rb +11 -0
- data/lib/datacash/request/cv2avs.rb +7 -0
- data/lib/datacash/request/historic_transaction.rb +8 -0
- data/lib/datacash/request/hps_transaction.rb +8 -0
- data/lib/datacash/request/request.rb +19 -0
- data/lib/datacash/request/thirdman.rb +23 -0
- data/lib/datacash/request/three_d_secure.rb +12 -0
- data/lib/datacash/request/transaction.rb +12 -0
- data/lib/datacash/request/transaction_details.rb +11 -0
- data/lib/datacash/response/auth_attempts.rb +7 -0
- data/lib/datacash/response/base.rb +33 -0
- data/lib/datacash/response/card.rb +7 -0
- data/lib/datacash/response/hps_transaction.rb +12 -0
- data/lib/datacash/response/query_transaction_result.rb +9 -0
- data/lib/datacash/response/response.rb +11 -0
- data/lib/datacash/session.rb +175 -0
- data/lib/datacash/version.rb +3 -0
- data/spec/datacash/client_spec.rb +124 -0
- data/spec/datacash/request/amount_spec.rb +27 -0
- data/spec/datacash/request/authentication_spec.rb +12 -0
- data/spec/datacash/request/browser_spec.rb +18 -0
- data/spec/datacash/request/card_spec.rb +24 -0
- data/spec/datacash/request/card_transaction_spec.rb +28 -0
- data/spec/datacash/request/cv2avs_spec.rb +12 -0
- data/spec/datacash/request/historic_transaction_spec.rb +16 -0
- data/spec/datacash/request/hps_transaction_spec.rb +16 -0
- data/spec/datacash/request/request_spec.rb +58 -0
- data/spec/datacash/request/thirdman_spec.rb +12 -0
- data/spec/datacash/request/three_d_secure_spec.rb +17 -0
- data/spec/datacash/request/transaction_details_spec.rb +36 -0
- data/spec/datacash/request/transaction_spec.rb +24 -0
- data/spec/datacash/response/response_spec.rb +48 -0
- data/spec/datacash/response_spec.rb +48 -0
- data/spec/spec_helper.rb +20 -0
- metadata +265 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fcc6b1f0993e561e5b5e93d37d6e4cef4445bc8e
|
4
|
+
data.tar.gz: 133a4c6c605c49911cc3e02d644d2c80503a0dc2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c06d551c2beedc9015f32c8e761d8e220c176eb02c7a4c6e58cdf9a4ec3595b73a8983dc2636c125bed7b94bb755cdc8781493d695a171711e06feb29855601
|
7
|
+
data.tar.gz: b93e1fad07c9ebc94de5017339acdcc9e53b40f0ca59eae483ccd1418697cbd88feab2166a92acbef1a993a3c4981331058e8053e9399a281c0115a532b976a7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Robert Williams, Richard Grundy
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Datacash
|
2
|
+
|
3
|
+
This is an unofficial library!
|
4
|
+
|
5
|
+
DataCash, a MasterCard Company, is an international provider of credit /
|
6
|
+
debit card processing and industry leading fraud / risk management solutions.
|
7
|
+
|
8
|
+
This library provides an idiomatic interface to the DataCash gateway. I would
|
9
|
+
highly recommend reading the DataCash Developers Guide which is available in the
|
10
|
+
[Developers Area](https://testserver.datacash.com/software/download.cgi). You will
|
11
|
+
will need a [test login](https://testserver.datacash.com/software/integration.shtml)
|
12
|
+
to be able to download the developers guide and to play with the gateway.
|
13
|
+
|
14
|
+
## Configuration
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
# Gemfile
|
18
|
+
gem 'datacash'
|
19
|
+
|
20
|
+
# config/initializers/datacash.rb
|
21
|
+
Datacash.configure do |config|
|
22
|
+
config.client = "123456"
|
23
|
+
config.password = "password1234"
|
24
|
+
config.environment = :live || :test
|
25
|
+
end
|
26
|
+
# or
|
27
|
+
Datacash.configuration.client = "123456"
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
You can play with the library using the console. Run ```rake console```
|
33
|
+
then configure using the method above.
|
34
|
+
|
35
|
+
### Query
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
reference = "3403410491041490149314"
|
39
|
+
Datacash::Client.new.query(reference) # => Datacash::Response::Response
|
40
|
+
```
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/datacash.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'datacash/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "datacash"
|
8
|
+
spec.version = Datacash::VERSION
|
9
|
+
spec.authors = ["Robert Williams", "Richard Grundy"]
|
10
|
+
spec.email = ["rob@r-williams.com", "richguk@gmail.com"]
|
11
|
+
spec.description = "This library provides an idiomatic interface to the DataCash gateway."
|
12
|
+
spec.summary = "This library provides an idiomatic interface to the DataCash gateway."
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "builder"
|
22
|
+
spec.add_dependency "hashie"
|
23
|
+
spec.add_dependency "activesupport"
|
24
|
+
spec.add_dependency "multi_xml", "~> 0.5.3"
|
25
|
+
spec.add_dependency "rest-client", "~> 1.6"
|
26
|
+
spec.add_dependency 'gem_config'
|
27
|
+
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
30
|
+
spec.add_development_dependency "rake"
|
31
|
+
spec.add_development_dependency "rspec"
|
32
|
+
spec.add_development_dependency "pry"
|
33
|
+
spec.add_development_dependency "webmock"
|
34
|
+
end
|
data/lib/datacash.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
require 'gem_config'
|
4
|
+
require 'rest_client'
|
5
|
+
require 'builder'
|
6
|
+
require 'multi_xml'
|
7
|
+
require 'hashie'
|
8
|
+
require 'active_support/core_ext/hash/conversions'
|
9
|
+
require 'hashie/extensions/structure'
|
10
|
+
|
11
|
+
require 'datacash/exceptions'
|
12
|
+
|
13
|
+
module Datacash
|
14
|
+
include GemConfig::Base
|
15
|
+
|
16
|
+
TIME_FORMAT = '%Y%m%d %H:%M:%S'
|
17
|
+
|
18
|
+
with_configuration do
|
19
|
+
has :client, classes: String
|
20
|
+
has :password, classes: String
|
21
|
+
has :environment, values: [:test, :live], default: :test
|
22
|
+
end
|
23
|
+
|
24
|
+
autoload :Client, 'datacash/client'
|
25
|
+
|
26
|
+
module Request
|
27
|
+
autoload :Amount, 'datacash/request/amount'
|
28
|
+
autoload :Authentication, 'datacash/request/authentication'
|
29
|
+
autoload :Base, 'datacash/request/base'
|
30
|
+
autoload :Browser, 'datacash/request/browser'
|
31
|
+
autoload :Card, 'datacash/request/card'
|
32
|
+
autoload :Cv2Avs, 'datacash/request/cv2avs'
|
33
|
+
autoload :CardTransaction, 'datacash/request/card_transaction'
|
34
|
+
autoload :HistoricTransaction, 'datacash/request/historic_transaction'
|
35
|
+
autoload :HpsTransaction, 'datacash/request/hps_transaction'
|
36
|
+
autoload :Request, 'datacash/request/request'
|
37
|
+
autoload :ThreeDSecure, 'datacash/request/three_d_secure'
|
38
|
+
autoload :Transaction, 'datacash/request/transaction'
|
39
|
+
autoload :TransactionDetails, 'datacash/request/transaction_details'
|
40
|
+
autoload :Thirdman, 'datacash/request/thirdman'
|
41
|
+
end
|
42
|
+
|
43
|
+
module Response
|
44
|
+
autoload :AuthAttempts, 'datacash/response/auth_attempts'
|
45
|
+
autoload :Base, 'datacash/response/base'
|
46
|
+
autoload :Card, 'datacash/response/card'
|
47
|
+
autoload :HpsTransaction, 'datacash/response/hps_transaction'
|
48
|
+
autoload :QueryTransactionResult, 'datacash/response/query_transaction_result'
|
49
|
+
autoload :Response, 'datacash/response/response'
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Datacash
|
2
|
+
class Client
|
3
|
+
|
4
|
+
ENDPOINTS = {
|
5
|
+
live: "https://mars.transaction.datacash.com/Transaction",
|
6
|
+
test: "https://accreditation.datacash.com/Transaction/cnp_a"
|
7
|
+
}.freeze
|
8
|
+
|
9
|
+
def initialize(options={})
|
10
|
+
@client = options.fetch(:client, Datacash.configuration.client)
|
11
|
+
@password = options.fetch(:password, Datacash.configuration.password)
|
12
|
+
@environment = options.fetch(:environment, Datacash.configuration.environment)
|
13
|
+
@rest_client = options.fetch(:rest_client, RestClient)
|
14
|
+
end
|
15
|
+
|
16
|
+
def post(request)
|
17
|
+
prepare_request(request)
|
18
|
+
|
19
|
+
handle_response do
|
20
|
+
rest_client.post(
|
21
|
+
endpoint,
|
22
|
+
request.to_xml,
|
23
|
+
content_type: :xml,
|
24
|
+
accept: :xml
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def query(datacash_reference)
|
30
|
+
request = Request::Request.new(transaction: {
|
31
|
+
historic_transaction: {
|
32
|
+
method: "query", reference: datacash_reference
|
33
|
+
}
|
34
|
+
})
|
35
|
+
post(request)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
attr_reader :rest_client, :environment, :client, :password
|
40
|
+
|
41
|
+
def parse_response_to_hash(response)
|
42
|
+
MultiXml.parse(response, :symbolize_keys => true)[:Response]
|
43
|
+
end
|
44
|
+
|
45
|
+
def endpoint
|
46
|
+
ENDPOINTS[environment]
|
47
|
+
end
|
48
|
+
|
49
|
+
def prepare_request(request)
|
50
|
+
request.add_authentication(client: client, password: password)
|
51
|
+
end
|
52
|
+
|
53
|
+
def handle_response(&block)
|
54
|
+
response = Response::Response.new(parse_response_to_hash(yield))
|
55
|
+
if response.reason =~ /invalid client\/pass/i
|
56
|
+
raise AuthenticationError, response
|
57
|
+
end
|
58
|
+
response
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Datacash
|
2
|
+
module Request
|
3
|
+
class Amount < Base
|
4
|
+
root 'amount'
|
5
|
+
|
6
|
+
key :amount, default: '0.00'
|
7
|
+
|
8
|
+
def to_xml(options={})
|
9
|
+
xml = options[:builder] ||= Builder::XmlMarkup.new
|
10
|
+
xml.tag!(self.class.root, self[:amount], currency: self[:currency])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Datacash
|
2
|
+
module Request
|
3
|
+
class Base < Hash
|
4
|
+
include Hashie::Extensions::Coercion
|
5
|
+
include Hashie::Extensions::MergeInitializer
|
6
|
+
|
7
|
+
def initialize(*args)
|
8
|
+
self.class.keys.each do |key, options|
|
9
|
+
self[key] = options.fetch(:default, nil)
|
10
|
+
end
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.keys
|
15
|
+
@keys ||= {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.key(key, options={})
|
19
|
+
keys[key] = options
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.root(name=nil)
|
23
|
+
@root = name if name
|
24
|
+
@root
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_xml(options = {})
|
28
|
+
super(options.merge(
|
29
|
+
root: self.class.root,
|
30
|
+
skip_types: true,
|
31
|
+
indent: 0,
|
32
|
+
dasherize: false
|
33
|
+
))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Datacash
|
2
|
+
module Request
|
3
|
+
class Request < Base
|
4
|
+
root "Request"
|
5
|
+
|
6
|
+
coerce_key :authentication, Authentication
|
7
|
+
coerce_key :transaction, Transaction
|
8
|
+
|
9
|
+
key :authentication, default: Authentication.new
|
10
|
+
key :transaction, default: Transaction.new
|
11
|
+
|
12
|
+
def add_authentication(options = {})
|
13
|
+
self[:authentication] ||= {}
|
14
|
+
self[:authentication][:client] = options.fetch(:client)
|
15
|
+
self[:authentication][:password] = options.fetch(:password)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Datacash
|
2
|
+
module Request
|
3
|
+
class Thirdman < Base
|
4
|
+
root "The3rdMan"
|
5
|
+
|
6
|
+
class CustomerInformation < Base
|
7
|
+
root "CustomerInformation"
|
8
|
+
end
|
9
|
+
|
10
|
+
class DeliveryAddress < Base
|
11
|
+
root "DeliveryAddress"
|
12
|
+
end
|
13
|
+
|
14
|
+
class BillingAddress < Base
|
15
|
+
root "BillingAddress"
|
16
|
+
end
|
17
|
+
|
18
|
+
coerce_key :customer_information, CustomerInformation
|
19
|
+
coerce_key :delivery_address, DeliveryAddress
|
20
|
+
coerce_key :billing_address, BillingAddress
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|