cardgate 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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +14 -0
- data/cardgate.gemspec +27 -0
- data/lib/cardgate.rb +17 -0
- data/lib/cardgate/callback.rb +42 -0
- data/lib/cardgate/constants.rb +4 -0
- data/lib/cardgate/creditcard/creditcard.rb +1 -0
- data/lib/cardgate/creditcard/refund.rb +27 -0
- data/lib/cardgate/exception.rb +6 -0
- data/lib/cardgate/gateway.rb +37 -0
- data/lib/cardgate/ideal/ideal.rb +4 -0
- data/lib/cardgate/ideal/issuer.rb +24 -0
- data/lib/cardgate/ideal/issuers.rb +36 -0
- data/lib/cardgate/ideal/payment.rb +25 -0
- data/lib/cardgate/ideal/refund.rb +17 -0
- data/lib/cardgate/payment.rb +90 -0
- data/lib/cardgate/refund.rb +60 -0
- data/lib/cardgate/response.rb +19 -0
- data/lib/cardgate/transaction.rb +32 -0
- data/lib/cardgate/transactions.rb +24 -0
- data/lib/cardgate/version.rb +3 -0
- data/lib/deep_merge.rb +27 -0
- data/test/callback_test.rb +93 -0
- data/test/creditcard/refund_test.rb +16 -0
- data/test/fixtures.rb +15 -0
- data/test/gateway_test.rb +48 -0
- data/test/ideal/issuer_test.rb +21 -0
- data/test/ideal/issuers_test.rb +48 -0
- data/test/ideal/payment_test.rb +108 -0
- data/test/ideal/refund_test.rb +57 -0
- data/test/payment_test.rb +50 -0
- data/test/response_test.rb +38 -0
- data/test/test_helper.rb +17 -0
- data/test/transaction_test.rb +29 -0
- data/test/transactions_test.rb +66 -0
- metadata +165 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: daed47a0e6496785bc3b54917a82d8c08b1809e2
|
4
|
+
data.tar.gz: 00ed2d0e426b7b18d677b45cc48c757b713cc8ba
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b1abf8bfcc18486173646f117a20c85c4caa68c0a5426211e509d13b1c5e7fda39a9774db44def8b822ad0bf917b2e267737d2500dfe050823df3eea3aeb88bd
|
7
|
+
data.tar.gz: 198ec6d118ba005eb80b65be016eed04ea3212ed48cbcfcfe564e8af716a0530704973875eacc3dcbcc6636f87e255082a74d195f582519294822701c0d62d87
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Youri van der Lans
|
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,39 @@
|
|
1
|
+
# Cardgate
|
2
|
+
|
3
|
+
This gem is a client for the Cardgate REST API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'cardgate'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install cardgate
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
To configure this gem on rails, add the following initializer.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
unless Rails.env.production?
|
25
|
+
Cardgate::Gateway.environment = :test
|
26
|
+
end
|
27
|
+
|
28
|
+
Cardgate::Gateway.merchant = ''
|
29
|
+
Cardgate::Gateway.api_key = ''
|
30
|
+
Cardgate::Gateway.request_logger = true # or false if you want to disable request logging
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( http://github.com/yourivdlans/cardgate/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
task default: :test
|
6
|
+
|
7
|
+
desc 'Run Cardgate unit tests.'
|
8
|
+
Rake::TestTask.new(:test) do |t|
|
9
|
+
t.libs << 'lib'
|
10
|
+
t.libs << 'test'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
t.warning = false
|
14
|
+
end
|
data/cardgate.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cardgate/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cardgate"
|
8
|
+
spec.version = Cardgate::VERSION
|
9
|
+
spec.authors = ["Youri van der Lans"]
|
10
|
+
spec.email = ["youri@itflows.nl"]
|
11
|
+
spec.summary = "Cardgate REST API client"
|
12
|
+
spec.description = "Provides an easy way to communicate with the cardgate REST API"
|
13
|
+
spec.homepage = "https://github.com/yourivdlans/cardgate"
|
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.5"
|
22
|
+
spec.add_development_dependency "rake", "~> 0"
|
23
|
+
spec.add_development_dependency "mocha", "~> 0"
|
24
|
+
|
25
|
+
spec.add_dependency "faraday", "~> 0.8"
|
26
|
+
spec.add_dependency "faraday_middleware", "~> 0.9"
|
27
|
+
end
|
data/lib/cardgate.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
if !defined?(Rails)
|
2
|
+
require 'deep_merge'
|
3
|
+
end
|
4
|
+
|
5
|
+
require 'cardgate/callback'
|
6
|
+
require 'cardgate/constants'
|
7
|
+
require 'cardgate/exception'
|
8
|
+
require 'cardgate/gateway'
|
9
|
+
require 'cardgate/response'
|
10
|
+
require 'cardgate/transaction'
|
11
|
+
require 'cardgate/transactions'
|
12
|
+
require 'cardgate/payment'
|
13
|
+
require 'cardgate/refund'
|
14
|
+
require 'cardgate/version'
|
15
|
+
|
16
|
+
require 'cardgate/creditcard/creditcard'
|
17
|
+
require 'cardgate/ideal/ideal'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Cardgate
|
2
|
+
|
3
|
+
class Callback
|
4
|
+
|
5
|
+
attr_accessor :is_test, :transaction_id, :currency, :amount, :ref, :status, :hash_key, :hash
|
6
|
+
|
7
|
+
def initialize(attributes = {})
|
8
|
+
attributes.each do |k,v|
|
9
|
+
send("#{k}=", v)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def valid?
|
14
|
+
hash_elements = [ @transaction_id, @currency, @amount, @ref, @status, @hash_key ]
|
15
|
+
hash_elements.unshift 'TEST' if @is_test.to_i == 1
|
16
|
+
|
17
|
+
Digest::MD5.hexdigest(hash_elements.join) == @hash
|
18
|
+
end
|
19
|
+
|
20
|
+
def response
|
21
|
+
"#{@transaction_id}.#{@status}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def successful?
|
25
|
+
[200, 210].include?(@status.to_i)
|
26
|
+
end
|
27
|
+
|
28
|
+
def failed?
|
29
|
+
[300, 301].include?(@status.to_i)
|
30
|
+
end
|
31
|
+
|
32
|
+
def recurring_failed?
|
33
|
+
@status.to_i == 310
|
34
|
+
end
|
35
|
+
|
36
|
+
def refund?
|
37
|
+
@status.to_i == 400
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'cardgate/creditcard/refund'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Cardgate
|
2
|
+
|
3
|
+
module Creditcard
|
4
|
+
|
5
|
+
class Refund < Cardgate::Refund
|
6
|
+
|
7
|
+
attr_accessor :descriptor
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def provider
|
12
|
+
'creditcard'
|
13
|
+
end
|
14
|
+
|
15
|
+
def refund_params
|
16
|
+
{
|
17
|
+
refund: {
|
18
|
+
descriptor: @descriptor
|
19
|
+
}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
|
3
|
+
module Cardgate
|
4
|
+
|
5
|
+
class Gateway
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :environment, :merchant, :api_key, :request_logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.is_test_environment?
|
12
|
+
self.environment == :test
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.request_url
|
16
|
+
if self.is_test_environment?
|
17
|
+
Cardgate::TEST_URL
|
18
|
+
else
|
19
|
+
Cardgate::LIVE_URL
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.connection
|
24
|
+
raise Cardgate::Exception, 'Merchant and/or API key not set' if !self.merchant || !self.api_key
|
25
|
+
|
26
|
+
Faraday.new(url: self.request_url, ssl: { verify: !is_test_environment? } ) do |faraday|
|
27
|
+
faraday.request :json
|
28
|
+
faraday.response :json
|
29
|
+
faraday.response :logger if request_logger == true
|
30
|
+
faraday.adapter Faraday.default_adapter
|
31
|
+
faraday.basic_auth self.merchant, self.api_key
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Cardgate
|
2
|
+
|
3
|
+
module Ideal
|
4
|
+
|
5
|
+
class Issuer
|
6
|
+
|
7
|
+
attr_accessor :id, :name, :list
|
8
|
+
|
9
|
+
def initialize(id, name, list)
|
10
|
+
@id = id
|
11
|
+
@name = name
|
12
|
+
@list = list
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def ==(o)
|
17
|
+
o.class == self.class && o.id == id
|
18
|
+
end
|
19
|
+
alias_method :eql?, :==
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Cardgate
|
2
|
+
|
3
|
+
module Ideal
|
4
|
+
|
5
|
+
class Issuers
|
6
|
+
|
7
|
+
def self.list
|
8
|
+
find_all_from_api
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def self.find_all_from_api
|
14
|
+
result = Cardgate::Gateway.connection.get do |req|
|
15
|
+
req.url '/rest/v1/ideal/issuers/'
|
16
|
+
req.headers['Accept'] = 'application/json'
|
17
|
+
end
|
18
|
+
|
19
|
+
response = Cardgate::Response.new(result)
|
20
|
+
|
21
|
+
issuers = response.body['issuers']
|
22
|
+
|
23
|
+
if !issuers.empty?
|
24
|
+
issuers.map do |issuer|
|
25
|
+
Cardgate::Ideal::Issuer.new(issuer['id'], issuer['name'], issuer['list'])
|
26
|
+
end
|
27
|
+
else
|
28
|
+
[]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Cardgate
|
2
|
+
|
3
|
+
module Ideal
|
4
|
+
|
5
|
+
class Payment < Cardgate::Payment
|
6
|
+
|
7
|
+
attr_accessor :issuer_id
|
8
|
+
|
9
|
+
def provider
|
10
|
+
'ideal'
|
11
|
+
end
|
12
|
+
|
13
|
+
def payment_params
|
14
|
+
{
|
15
|
+
payment: {
|
16
|
+
issuer_id: @issuer_id
|
17
|
+
}
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Cardgate
|
2
|
+
|
3
|
+
class Payment
|
4
|
+
|
5
|
+
attr_accessor :site_id, :return_url, :control_url, :ref, :amount, :currency,
|
6
|
+
:language, :ip_address, :first_name, :last_name, :company_name,
|
7
|
+
:address, :city, :state, :postal_code, :country_code, :phone_number, :email,
|
8
|
+
:description, :provider
|
9
|
+
|
10
|
+
def initialize(attributes = {})
|
11
|
+
attributes.each do |k,v|
|
12
|
+
send("#{k}=", v)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def default_params
|
17
|
+
default_params = {
|
18
|
+
payment: {
|
19
|
+
site_id: @site_id,
|
20
|
+
currency: @currency,
|
21
|
+
ref: @ref,
|
22
|
+
return_url: @return_url,
|
23
|
+
control_url: @control_url,
|
24
|
+
currency: @currency,
|
25
|
+
language: @language,
|
26
|
+
ip_address: @ip_address,
|
27
|
+
description: @description,
|
28
|
+
amount: @amount
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
customer_fields = %w(first_name last_name company_name address city state postal_code country_code phone_number email)
|
33
|
+
|
34
|
+
customer_fields.each do |field|
|
35
|
+
var = instance_variable_get("@#{field}")
|
36
|
+
|
37
|
+
if !var.nil? && !var.empty?
|
38
|
+
default_params[:payment][:customer] = {} if default_params[:payment][:customer].nil?
|
39
|
+
default_params[:payment][:customer][field.to_sym] = var
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
return default_params
|
44
|
+
end
|
45
|
+
|
46
|
+
def initiate
|
47
|
+
@response ||= response
|
48
|
+
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def payment_url
|
53
|
+
@response.body['payment']['issuer_auth_url']
|
54
|
+
end
|
55
|
+
|
56
|
+
def transaction_id
|
57
|
+
@response.body['payment']['transaction_id']
|
58
|
+
end
|
59
|
+
|
60
|
+
def params
|
61
|
+
default_params.deep_merge!(payment_params)
|
62
|
+
end
|
63
|
+
|
64
|
+
def payment_params
|
65
|
+
{}
|
66
|
+
end
|
67
|
+
|
68
|
+
def api_payment_endpoint
|
69
|
+
"/rest/v1/#{provider}/payment/"
|
70
|
+
end
|
71
|
+
|
72
|
+
def provider
|
73
|
+
@provider or raise Cardgate::Exception.new('Provider not set for Payment')
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def response
|
79
|
+
result = Cardgate::Gateway.connection.post do |req|
|
80
|
+
req.url api_payment_endpoint
|
81
|
+
req.headers['Accept'] = 'application/json'
|
82
|
+
req.body = params
|
83
|
+
end
|
84
|
+
|
85
|
+
Cardgate::Response.new(result)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|