firstdata 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ff142ec94423c82b435ed073fc80a423d8f0de8
4
+ data.tar.gz: 42f64de83e59ffdf4f649aa1f0469b5e5125c04b
5
+ SHA512:
6
+ metadata.gz: a50b1512c58507c73ccf8779c1999c7afe4c47c7955cb3f549fc8e8e56006d0d5549eac614e4349e4ed275338333cfc480a253af1e9a1e891400cb6041511609
7
+ data.tar.gz: 5bd59400a80eb903d67c5f81fd609df36dfe20f3e438527177b8c59ad5fb0145572de41fc95e17f62516b81e60e55ff6b92509dc0f7a5dabe3b134466cbcd3f2
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ .idea/
3
+ .DS_Store
4
+ /.yardoc
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+ *.bundle
13
+ *.so
14
+ *.o
15
+ *.a
16
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in firstdata.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Nitesh Gupta
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,122 @@
1
+ # Firstdata
2
+
3
+ Lightweight ruby bindings for the Firstdata 'Global Gateway e4' API.
4
+
5
+ Note: This works for v12+ of the API.
6
+ It calculates the HMAC hash according to this
7
+ (https://support.payeezy.com/hc/en-us/articles/203731149-API-Security-HMAC-Hash)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'firstdata'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install firstdata
24
+
25
+ ## Usage
26
+
27
+ Note: It is recommended that you use environment variables to set these values.
28
+
29
+ To set the keys:
30
+
31
+ ```ruby
32
+ Firstdata.gateway_id = # gateway id goes here
33
+ Firstdata.password = # password goes here
34
+ Firstdata.key_id = # key id goes here
35
+ Firstdata.key = # key goes here
36
+ ```
37
+
38
+ To make a transaction:
39
+
40
+ ```ruby
41
+ Firstdata.transact(
42
+ # request hash goes here.
43
+ )
44
+ ```
45
+
46
+ For more information on what to put in the request hash, refer to the
47
+ [API reference guide](https://firstdata.zendesk.com/entries/407571-First-Data-Global-Gateway-e4-Web-Service-API-Reference-Guide) or scroll down for examples.
48
+
49
+ ## Examples
50
+
51
+ Purchase:
52
+
53
+ ```ruby
54
+ Firstdata.transact(
55
+ {
56
+ transaction_type: '00',
57
+ amount: 0,
58
+ cc_expiry: '1020',
59
+ cardholder_name: 'Test Name',
60
+ cc_number: '4111111111111111',
61
+ cvd_code: '1111',
62
+ currency_code: 'USD',
63
+ address: {
64
+ address1: 'Address Line 1',
65
+ city: 'City',
66
+ state: 'MA',
67
+ zip: '02108',
68
+ phone_number: '1111111111',
69
+ phone_type: 'H',
70
+ }
71
+ }
72
+ )
73
+ ```
74
+
75
+ ### Transarmor flow:
76
+
77
+ Pre-Authorization:
78
+
79
+ ```ruby
80
+ res = Firstdata.transact(
81
+ {
82
+ transaction_type: '01',
83
+ amount: 0,
84
+ cc_expiry: '1020',
85
+ cardholder_name: 'Test Name',
86
+ cc_number: '4111111111111111',
87
+ cvd_code: '1111',
88
+ currency_code: 'USD',
89
+ address: {
90
+ address1: 'Address Line 1',
91
+ city: 'City',
92
+ state: 'MA',
93
+ zip: '02108',
94
+ phone_number: '1111111111',
95
+ phone_type: 'H',
96
+ }
97
+ }
98
+ )
99
+ ```
100
+
101
+ Purchase:
102
+ ```ruby
103
+ res2 = Firstdata.transact(
104
+ {
105
+ transaction_type: '00',
106
+ amount: 50,
107
+ credit_card_type: "Visa",
108
+ cc_expiry: '1020',
109
+ cardholder_name: 'Test Name',
110
+ transarmor_token: "#{res['transarmor_token']}",
111
+ }
112
+ )
113
+ ```
114
+
115
+
116
+ ## Contributing
117
+
118
+ 1. Fork it ( https://github.com/[my-github-username]/firstdata/fork )
119
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
120
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
121
+ 4. Push to the branch (`git push origin my-new-feature`)
122
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/firstdata.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'firstdata/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "firstdata"
8
+ spec.version = Firstdata::VERSION
9
+ spec.authors = ["Nitesh Gupta"]
10
+ spec.email = ["niteshvgupta@gmail.com"]
11
+ spec.summary = %q{Gem to wrap First Data's GGE4 API}
12
+ spec.description = %q{}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest"
24
+
25
+ end
@@ -0,0 +1,3 @@
1
+ module Firstdata
2
+ VERSION = "0.0.1"
3
+ end
data/lib/firstdata.rb ADDED
@@ -0,0 +1,84 @@
1
+ # Description: This gem wraps API calls to the First Data Global Gateway E4.
2
+ #
3
+ # After running speed tests, I chose net/http over curb, rest-client, and open-uri.
4
+ #
5
+ # Copyright (c) 2015 Nitesh Gupta
6
+ #
7
+ # MIT License
8
+
9
+ require 'json'
10
+ require 'openssl'
11
+ require 'net/http'
12
+ require 'time'
13
+ require 'base64'
14
+
15
+ require_relative 'firstdata/version'
16
+
17
+ module Firstdata
18
+ @api_url = 'https://api.globalgatewaye4.firstdata.com/transaction/v14'
19
+
20
+ class << self
21
+ attr_accessor :gateway_id, :password, :key_id, :key, :api_url
22
+ end
23
+
24
+ def self.transact(payload)
25
+ body = payload.merge(gateway_id: @gateway_id, password: @password).to_json
26
+ post(set_headers(body), body, api_url)
27
+ end
28
+
29
+ private
30
+
31
+ def self.digest(payload)
32
+ OpenSSL::Digest.new('sha1', payload)
33
+ end
34
+
35
+ def self.gen_hmac(digest, data)
36
+ Base64.strict_encode64(OpenSSL::HMAC.digest(digest, @key, data))
37
+ end
38
+
39
+ def self.concat(*args)
40
+ args.join("\n")
41
+ end
42
+
43
+ def self.urn
44
+ @api_url.split('.com').last
45
+ end
46
+
47
+ def self.set_headers(payload)
48
+ type = 'application/json'
49
+ time = Time.now.utc.iso8601
50
+ content_digest = digest(payload)
51
+ data = concat('POST', type, content_digest.to_s, time, urn)
52
+ hmac = gen_hmac(content_digest, data)
53
+ {
54
+ 'Content-Type' => type,
55
+ 'Accept' => type,
56
+ 'x-gge4-date' => time,
57
+ 'x-gge4-content-sha1' => content_digest.to_s,
58
+ 'Authorization' => "GGE4_API #{@key_id}:#{hmac}"
59
+ }
60
+ end
61
+
62
+ def self.post(headers, body, url)
63
+ uri = URI.parse(url)
64
+ http = Net::HTTP.new(uri.host, uri.port)
65
+ http.use_ssl = true
66
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
67
+ request.body = body
68
+ commit_post(http, request)
69
+ end
70
+
71
+ def self.commit_post(http, request)
72
+ begin
73
+ response = http.request(request)
74
+ JSON.parse response.body
75
+ rescue JSON::ParserError
76
+ handle_error(response)
77
+ end
78
+ end
79
+
80
+ def self.handle_error(e)
81
+ e = e.body if e.body
82
+ { 'Error' => { 'messages' => "#{e.inspect}" } }
83
+ end
84
+ end
@@ -0,0 +1,48 @@
1
+ require '../lib/firstdata.rb'
2
+ require 'minitest/autorun'
3
+
4
+ describe Firstdata do
5
+ it 'can set keys properly' do
6
+ Firstdata.gateway_id = 'gatewayid'
7
+ Firstdata.password = 'password'
8
+ Firstdata.key_id = 'key_id'
9
+ Firstdata.key = 'key'
10
+ Firstdata.gateway_id.must_equal 'gatewayid'
11
+ Firstdata.password.must_equal 'password'
12
+ Firstdata.key_id.must_equal 'key_id'
13
+ Firstdata.key.must_equal 'key'
14
+ end
15
+
16
+ #
17
+ # I've commented out the test below, as you will need to sign up for a test
18
+ # account in order to test transactions.
19
+ #
20
+ # You can sign up for a test account by clicking the link below:
21
+ # https://provisioning.demo.globalgatewaye4.firstdata.com/signup
22
+ #
23
+ # it 'can make a transaction' do
24
+ # Firstdata.gateway_id = 'gateway id goes here'
25
+ # Firstdata.password = 'password goes here'
26
+ # Firstdata.key_id = 'key id goes here'
27
+ # Firstdata.key = 'hmac key goes here'
28
+ # Firstdata.api_url = 'https://api.demo.globalgatewaye4.firstdata.com/transaction/v14'
29
+ # req_body = {
30
+ # transaction_type: '00',
31
+ # amount: 10,
32
+ # cc_expiry: '1020',
33
+ # cardholder_name: 'Random Name',
34
+ # cc_number: '4111111111111111',
35
+ # cvd_code: '1111',
36
+ # currency_code: 'USD',
37
+ # address: {
38
+ # address1: 'Address Line 1',
39
+ # city: 'City',
40
+ # state: 'MA',
41
+ # zip: '02108',
42
+ # phone_number: '1111111111',
43
+ # phone_type: 'H',
44
+ # }
45
+ # }
46
+ # Firstdata.transact(req_body)['transaction_error'].must_equal 0
47
+ # end
48
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: firstdata
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nitesh Gupta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ''
56
+ email:
57
+ - niteshvgupta@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - firstdata.gemspec
68
+ - lib/firstdata.rb
69
+ - lib/firstdata/version.rb
70
+ - test/test_helper.rb
71
+ homepage: ''
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.4.6
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Gem to wrap First Data's GGE4 API
95
+ test_files:
96
+ - test/test_helper.rb