payeezy 1.0.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.
- data/.gitignore +22 -0
- data/.idea/.name +1 -0
- data/.idea/compiler.xml +23 -0
- data/.idea/copyright/profiles_settings.xml +3 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/inspectionProfiles/Project_Default.xml +22 -0
- data/.idea/inspectionProfiles/profiles_settings.xml +7 -0
- data/.idea/misc.xml +27 -0
- data/.idea/modules.xml +9 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/.idea/workspace.xml +1017 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/lib/payeezy.rb +107 -0
- data/lib/payeezy/version.rb +3 -0
- data/payeezy.gemspec +28 -0
- data/payeezy.iml +34 -0
- data/spec/payeezy_spec.rb +88 -0
- data/spec/spec_helper.rb +2 -0
- metadata +150 -0
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 TODO: Write your name
|
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,29 @@
|
|
1
|
+
# Payeezy
|
2
|
+
|
3
|
+
Integrate the Payeezy API with this ruby gem
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'payeezy'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install payeezy
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Test cases can be run with 'bundle exec rake spec'
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/payeezy.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'payeezy/version'
|
2
|
+
require 'rest_client'
|
3
|
+
require 'date'
|
4
|
+
require 'json'
|
5
|
+
require 'digest/sha2'
|
6
|
+
require 'base64'
|
7
|
+
require 'securerandom'
|
8
|
+
|
9
|
+
module Payeezy
|
10
|
+
class Transactions
|
11
|
+
def initialize(options = {})
|
12
|
+
@url = options[:url]
|
13
|
+
@apikey = options[:apikey]
|
14
|
+
@apisecret = options[:apisecret]
|
15
|
+
@token = options[:token]
|
16
|
+
end
|
17
|
+
|
18
|
+
def transact(action, payload)
|
19
|
+
commit(action, payload)
|
20
|
+
end
|
21
|
+
|
22
|
+
def generate_hmac(nonce, current_timestamp, payload)
|
23
|
+
message = @apikey + nonce.to_s + current_timestamp.to_s + @token + payload
|
24
|
+
hash = Base64.encode64(bin_to_hex(OpenSSL::HMAC.digest('sha256', @apisecret, message)))
|
25
|
+
end
|
26
|
+
|
27
|
+
def bin_to_hex(s)
|
28
|
+
s.unpack('H*').first
|
29
|
+
end
|
30
|
+
|
31
|
+
def headers(payload)
|
32
|
+
nonce = (SecureRandom.random_number *10000000000)
|
33
|
+
current_timestamp = (Time.now.to_f*1000).to_i
|
34
|
+
{
|
35
|
+
'Content-Type' => 'application/json',
|
36
|
+
'apikey' => @apikey,
|
37
|
+
'token' => @token,
|
38
|
+
'nonce' => nonce,
|
39
|
+
'timestamp' => current_timestamp,
|
40
|
+
'Authorization' => generate_hmac(nonce, current_timestamp, payload)
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def commit(action, params)
|
45
|
+
url = @url
|
46
|
+
if action == :capture || action == :void || action == :refund
|
47
|
+
url = url + '/' + params[:transaction_id]
|
48
|
+
params.delete(:transaction_id)
|
49
|
+
end
|
50
|
+
params[:transaction_type] = action
|
51
|
+
call_rest(url, post_data(params), headers(post_data(params)))
|
52
|
+
end
|
53
|
+
|
54
|
+
def call_rest(url, data, headers)
|
55
|
+
rest_resource = RestClient::Resource.new(url)
|
56
|
+
raw_response = response = {}
|
57
|
+
success = false
|
58
|
+
begin
|
59
|
+
raw_response = rest_resource.post data, headers
|
60
|
+
response = parse(raw_response)
|
61
|
+
success = !response.key?('Error')
|
62
|
+
rescue => e
|
63
|
+
raw_response = e.response
|
64
|
+
response = response_error(raw_response)
|
65
|
+
rescue JSON::ParserError
|
66
|
+
response = json_error(raw_response)
|
67
|
+
end
|
68
|
+
|
69
|
+
response
|
70
|
+
end
|
71
|
+
|
72
|
+
def handle_message(response, success)
|
73
|
+
if success
|
74
|
+
response['transaction_status']
|
75
|
+
elsif (response.key?('Error'))
|
76
|
+
response['Error'].map { |_, messages| messages }.join('. ')
|
77
|
+
else
|
78
|
+
response.inspect
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def response_error(raw_response)
|
83
|
+
begin
|
84
|
+
parse(raw_response)
|
85
|
+
rescue JSON::ParserError
|
86
|
+
json_error(raw_response)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def parse(body)
|
91
|
+
JSON.parse(body)
|
92
|
+
end
|
93
|
+
|
94
|
+
def post_data(params)
|
95
|
+
params.to_json
|
96
|
+
end
|
97
|
+
|
98
|
+
def json_error(raw_response)
|
99
|
+
msg = "Payeezy has returned an invalid response: [#{raw_response.inspect}]"
|
100
|
+
{
|
101
|
+
'Error' => {
|
102
|
+
'messages' => msg
|
103
|
+
}
|
104
|
+
}
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
data/payeezy.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'payeezy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "payeezy"
|
8
|
+
spec.version = Payeezy::VERSION
|
9
|
+
spec.authors = ["Sachin Shetty"]
|
10
|
+
spec.email = ["sachin.shetty@firstdata.com"]
|
11
|
+
spec.summary = %q{Transact with Payeezy}
|
12
|
+
spec.description = %q{See how easy it is to integrate with Payeezy using this gem}
|
13
|
+
spec.homepage = "https://developer.payeezy.com"
|
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.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
|
25
|
+
spec.add_dependency('rest-client', '~> 1.4')
|
26
|
+
spec.add_dependency('json', '~> 1.8.1')
|
27
|
+
|
28
|
+
end
|
data/payeezy.iml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="CompassSettings">
|
4
|
+
<option name="compassSupportEnabled" value="true" />
|
5
|
+
</component>
|
6
|
+
<component name="FacetManager">
|
7
|
+
<facet type="gem" name="Ruby Gem">
|
8
|
+
<configuration>
|
9
|
+
<option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
|
10
|
+
<option name="GEM_APP_TEST_PATH" value="$MODULE_DIR$/test" />
|
11
|
+
<option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
|
12
|
+
</configuration>
|
13
|
+
</facet>
|
14
|
+
</component>
|
15
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
16
|
+
<exclude-output />
|
17
|
+
<content url="file://$MODULE_DIR$">
|
18
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
19
|
+
</content>
|
20
|
+
<orderEntry type="inheritedJdk" />
|
21
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.6.2, ruby-1.9.3-p484) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, ruby-1.9.3-p484) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="json (v1.8.1, ruby-1.9.3-p484) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="mime-types (v1.25.1, ruby-1.9.3-p484) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v10.3.2, ruby-1.9.3-p484) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="rest-client (v1.6.7, ruby-1.9.3-p484) [gem]" level="application" />
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v2.14.1, ruby-1.9.3-p484) [gem]" level="application" />
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v2.14.8, ruby-1.9.3-p484) [gem]" level="application" />
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v2.14.5, ruby-1.9.3-p484) [gem]" level="application" />
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v2.14.6, ruby-1.9.3-p484) [gem]" level="application" />
|
32
|
+
</component>
|
33
|
+
</module>
|
34
|
+
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Sample calls to Payeezy" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
options = {}
|
7
|
+
options[:url] = 'https://api-cert.payeezy.com/v1/transactions'
|
8
|
+
options[:apikey] = 'y6pWAJNyJyjGv66IsVuWnklkKUPFbb0a'
|
9
|
+
options[:apisecret] = '09730a91f4f055dd5d3878099644f2f60bf0a4421485f20af72076bbb0b41e96'
|
10
|
+
options[:token] = 'fdoa-a480ce8951daa73262734cf102641994c1e55e7cdf4c02b6'
|
11
|
+
|
12
|
+
@payeezy = Payeezy::Transactions.new options
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#new" do
|
16
|
+
it 'returns an instance of Payeezy' do
|
17
|
+
@payeezy.should be_an_instance_of Payeezy::Transactions
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "Execute Primary Transactions" do
|
22
|
+
it 'Authorize Transaction' do
|
23
|
+
@primary_response = @payeezy.transact(:authorize,primary_tx_payload)
|
24
|
+
@primary_response['transaction_status'].should == "approved"
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'Purchase Transaction' do
|
28
|
+
@primary_response = @payeezy.transact(:purchase,primary_tx_payload)
|
29
|
+
@primary_response['transaction_status'].should == "approved"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "Execute Secondary Transactions" do
|
34
|
+
it 'Capture Transaction' do
|
35
|
+
@primary_response = @payeezy.transact(:authorize,primary_tx_payload)
|
36
|
+
@primary_response['transaction_status'].should == "approved"
|
37
|
+
@secondary_response = @payeezy.transact(:capture,secondary_tx_payload(@primary_response))
|
38
|
+
@secondary_response['transaction_status'].should == "approved"
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'Void Transaction' do
|
42
|
+
@primary_response = @payeezy.transact(:authorize,primary_tx_payload)
|
43
|
+
@primary_response['transaction_status'].should == "approved"
|
44
|
+
@secondary_response = @payeezy.transact(:void,secondary_tx_payload(@primary_response))
|
45
|
+
@secondary_response['transaction_status'].should == "approved"
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'Refund Transaction' do
|
49
|
+
@primary_response = @payeezy.transact(:purchase,primary_tx_payload)
|
50
|
+
@primary_response['transaction_status'].should == "approved"
|
51
|
+
@secondary_response = @payeezy.transact(:refund,secondary_tx_payload(@primary_response))
|
52
|
+
@secondary_response['transaction_status'].should == "approved"
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
def primary_tx_payload
|
59
|
+
credit_card = {}
|
60
|
+
payload = {}
|
61
|
+
payload[:merchant_ref] = 'Astonishing-Sale'
|
62
|
+
payload[:amount]='1299'
|
63
|
+
payload[:currency_code]='USD'
|
64
|
+
payload[:method]='credit_card'
|
65
|
+
|
66
|
+
credit_card[:type] = 'visa'
|
67
|
+
credit_card[:cardholder_name] = 'John Smith'
|
68
|
+
credit_card[:card_number] = '4788250000028291'
|
69
|
+
credit_card[:exp_date] = '1014'
|
70
|
+
credit_card[:cvv] = '123'
|
71
|
+
payload[:credit_card] = credit_card
|
72
|
+
|
73
|
+
payload
|
74
|
+
end
|
75
|
+
|
76
|
+
def secondary_tx_payload(response)
|
77
|
+
payload = {}
|
78
|
+
payload[:merchant_ref] = 'Astonishing-Sale'
|
79
|
+
payload[:transaction_tag] = response['transaction_tag']
|
80
|
+
payload[:method]=response['method']
|
81
|
+
payload[:amount]=response['amount']
|
82
|
+
payload[:currency_code]=response['currency']
|
83
|
+
payload[:transaction_id] = response['transaction_id']
|
84
|
+
|
85
|
+
payload
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: payeezy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sachin Shetty
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-10-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.6'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.6'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rest-client
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.4'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.4'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: json
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.8.1
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.8.1
|
94
|
+
description: See how easy it is to integrate with Payeezy using this gem
|
95
|
+
email:
|
96
|
+
- sachin.shetty@firstdata.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- .idea/.name
|
103
|
+
- .idea/compiler.xml
|
104
|
+
- .idea/copyright/profiles_settings.xml
|
105
|
+
- .idea/encodings.xml
|
106
|
+
- .idea/inspectionProfiles/Project_Default.xml
|
107
|
+
- .idea/inspectionProfiles/profiles_settings.xml
|
108
|
+
- .idea/misc.xml
|
109
|
+
- .idea/modules.xml
|
110
|
+
- .idea/scopes/scope_settings.xml
|
111
|
+
- .idea/vcs.xml
|
112
|
+
- .idea/workspace.xml
|
113
|
+
- Gemfile
|
114
|
+
- LICENSE.txt
|
115
|
+
- README.md
|
116
|
+
- Rakefile
|
117
|
+
- lib/payeezy.rb
|
118
|
+
- lib/payeezy/version.rb
|
119
|
+
- payeezy.gemspec
|
120
|
+
- payeezy.iml
|
121
|
+
- spec/payeezy_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
123
|
+
homepage: https://developer.payeezy.com
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 1.8.28
|
145
|
+
signing_key:
|
146
|
+
specification_version: 3
|
147
|
+
summary: Transact with Payeezy
|
148
|
+
test_files:
|
149
|
+
- spec/payeezy_spec.rb
|
150
|
+
- spec/spec_helper.rb
|