csob_payment_gateway 0.0.2
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/Gemfile +4 -0
- data/config/config.yml +37 -0
- data/csob_payment_gateway.gemspec +20 -0
- data/init.rb +1 -0
- data/lib/csob_payment_gateway/config.rb +62 -0
- data/lib/csob_payment_gateway/crypt.rb +44 -0
- data/lib/csob_payment_gateway/models/base_payment.rb +117 -0
- data/lib/csob_payment_gateway/railtie.rb +7 -0
- data/lib/csob_payment_gateway/version.rb +3 -0
- data/lib/csob_payment_gateway.rb +6 -0
- data/readme.md +6 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 403cf49dddae580ab50a773d92c143c27b704cab
|
4
|
+
data.tar.gz: 278571c90ebaf0198ba2c86971a42b7137dd5361
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f3d4edc4fef4762d6f12852890b0eca1c37fbae7f617ec8b310594fbca20b30af0e57d72ecf6e152fb963edf8d21e615f0723aa991f323b24db59778ffbf94b
|
7
|
+
data.tar.gz: 58af0a91aa44abd3bb12e07b14676b2f163d1dcd024165a9753cad551790a1c62e20c0e1f1089de638f91b2c68aa1b52a10c678a2eeb953db3087026585a9d57
|
data/Gemfile
ADDED
data/config/config.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
base:
|
2
|
+
test:
|
3
|
+
gateway_url: "https://iapi.iplatebnibrana.csob.cz/api/v1.5"
|
4
|
+
public_key: "mips_iplatebnibrana.csob.cz.pub"
|
5
|
+
merchant_id: "MERCHANTID"
|
6
|
+
currency: "USD"
|
7
|
+
return_method_post: true
|
8
|
+
close_payment: false
|
9
|
+
keys_directory: "private"
|
10
|
+
production:
|
11
|
+
gateway_url: "https://api.platebnibrana.csob.cz/api/v1.5"
|
12
|
+
public_key: "mips_iplatebnibrana.csob.cz.pub"
|
13
|
+
merchant_id: "MERCHANTID"
|
14
|
+
currency: "USD"
|
15
|
+
return_method_post: true
|
16
|
+
close_payment: false
|
17
|
+
keys_directory: "private"
|
18
|
+
urls:
|
19
|
+
init: "/payment/init/"
|
20
|
+
process: "/payment/process/"
|
21
|
+
status: "/payment/status/"
|
22
|
+
close: "/payment/close/"
|
23
|
+
reverse: "/payment/reverse/"
|
24
|
+
refund: "/payment/refund/"
|
25
|
+
echo: "/echo/"
|
26
|
+
customer_info: "/customer/info/"
|
27
|
+
statuses:
|
28
|
+
requested: 1
|
29
|
+
pending: 2
|
30
|
+
canceled: 3
|
31
|
+
approved: 4
|
32
|
+
reversed: 5
|
33
|
+
declined: 6
|
34
|
+
to_clearing: 7
|
35
|
+
cleared: 8
|
36
|
+
refund_requested: 9
|
37
|
+
refunded: 10
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "csob_payment_gateway/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'csob_payment_gateway'
|
6
|
+
s.version = CsobPaymentGateway::VERSION
|
7
|
+
s.date = '2016-02-12'
|
8
|
+
s.summary = "Ruby implementation of CSOB PaymentGateway"
|
9
|
+
s.description = "Gem for integration CSOB PaymentGateway in Ruby"
|
10
|
+
s.authors = ["Jiří Kratochvíl"]
|
11
|
+
s.email = 'me@kratochviljiri.cz'
|
12
|
+
|
13
|
+
s.add_dependency("rest-client", "~> 1.8")
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.homepage = 'http://rubygems.org/gems/csob_payment_gateway'
|
17
|
+
s.license = 'MIT'
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'csob_payment_gateway'
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module CsobPaymentGateway
|
4
|
+
BASE_PATH = File.expand_path("../../../", __FILE__)
|
5
|
+
|
6
|
+
def self.configure
|
7
|
+
yield configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configuration
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure_from_yaml(path)
|
15
|
+
yaml = YAML.load_file(path)
|
16
|
+
return unless yaml
|
17
|
+
|
18
|
+
configuration.merchant_id = yaml["merchant_id"]
|
19
|
+
configuration.gateway_url = yaml["gateway_url"]
|
20
|
+
configuration.return_url = yaml["return_url"]
|
21
|
+
configuration.public_key = yaml["public_key"]
|
22
|
+
configuration.private_key = yaml["private_key"]
|
23
|
+
configuration.currency = yaml["currency"]
|
24
|
+
configuration.return_method_post = yaml["return_method_post"]
|
25
|
+
configuration.close_payment = yaml["close_payment"]
|
26
|
+
configuration.keys_directory = yaml["keys_directory"]
|
27
|
+
|
28
|
+
configuration
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.configure_from_rails
|
32
|
+
path = ::Rails.root.join("config", "csob.yml")
|
33
|
+
configure_from_yaml(path) if File.exists?(path)
|
34
|
+
|
35
|
+
env = if defined?(::Rails) && ::Rails.respond_to?(:env)
|
36
|
+
::Rails.env.to_sym
|
37
|
+
elsif defined?(::RAILS_ENV)
|
38
|
+
::RAILS_ENV.to_sym
|
39
|
+
end
|
40
|
+
configuration.environment ||= (env == :production) ? :production : :test
|
41
|
+
|
42
|
+
warn "CSOB Payment Gateway wasnt properly configured." if CsobPaymentGateway.configuration.merchant_id.blank?
|
43
|
+
configuration
|
44
|
+
end
|
45
|
+
|
46
|
+
class Configuration
|
47
|
+
attr_accessor :environment, :merchant_id, :return_url, :gateway_url, :public_key, :private_key, :currency, :return_method_post, :close_payment, :keys_directory
|
48
|
+
attr_reader :statuses, :urls
|
49
|
+
|
50
|
+
def initialize
|
51
|
+
config = YAML.load_file(File.join(BASE_PATH, "config", "config.yml"))
|
52
|
+
@base = config["base"]
|
53
|
+
@statuses = config["statuses"]
|
54
|
+
@urls = config["urls"]
|
55
|
+
end
|
56
|
+
|
57
|
+
def base
|
58
|
+
env = @environment.nil? ? "test" : @environment.to_s
|
59
|
+
@base[env]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require "base64"
|
3
|
+
|
4
|
+
module CsobPaymentGateway
|
5
|
+
module Crypt
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def prepare_data_to_sign(data, method)
|
9
|
+
if method == "POST"
|
10
|
+
cart_to_sign = "#{data[:cart][0][:name]}|#{data[:cart][0][:quantity]}|#{data[:cart][0][:amount]}|#{data[:cart][0][:description]}|#{data[:cart][1][:name]}|#{data[:cart][1][:quantity]}|#{data[:cart][1][:amount]}|#{data[:cart][1][:description]}"
|
11
|
+
|
12
|
+
data_to_sign = "#{data[:merchantId]}|#{data[:orderNo]}|#{data[:dttm]}|#{data[:payOperation]}|#{data[:payMethod]}|#{data[:totalAmount]}|#{data[:currency]}|#{data[:closePayment]}|#{data[:returnUrl]}|#{data[:returnMethod]}|#{cart_to_sign}|#{data[:description]}"
|
13
|
+
|
14
|
+
merchant_data = data[:merchantData]
|
15
|
+
data_to_sign = "#{data_to_sign}|#{merchant_data}" unless merchant_data.nil?
|
16
|
+
|
17
|
+
customer_id = data[:customerId]
|
18
|
+
data_to_sign = "#{data_to_sign}|#{customer_id}" if !customer_id.nil? and customer_id.to_s != "0"
|
19
|
+
|
20
|
+
data_to_sign = "#{data_to_sign}|#{data[:language]}"
|
21
|
+
|
22
|
+
data_to_sign = data_to_sign.chop if data_to_sign[-1] == "|"
|
23
|
+
elsif method == "GET"
|
24
|
+
data_to_sign = data
|
25
|
+
end
|
26
|
+
|
27
|
+
data_to_sign
|
28
|
+
end
|
29
|
+
|
30
|
+
def private_key_url
|
31
|
+
::Rails.root.join(CsobPaymentGateway.configuration.keys_directory.to_s, CsobPaymentGateway.configuration.private_key.to_s)
|
32
|
+
end
|
33
|
+
|
34
|
+
def sign(data, method)
|
35
|
+
data_to_sign = prepare_data_to_sign(data, method)
|
36
|
+
key = OpenSSL::PKey::RSA.new(File.read(private_key_url))
|
37
|
+
|
38
|
+
digest = OpenSSL::Digest::SHA1.new
|
39
|
+
signature = key.sign(digest, data_to_sign)
|
40
|
+
|
41
|
+
Base64.encode64(signature).gsub("\n","")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module CsobPaymentGateway
|
4
|
+
class BasePayment
|
5
|
+
|
6
|
+
def initialize(attributes = {})
|
7
|
+
attributes.each do |key, value|
|
8
|
+
instance_variable_set(:"@#{key}", value) if self.respond_to?(key)
|
9
|
+
end
|
10
|
+
|
11
|
+
@merchant_id ||= CsobPaymentGateway.configuration.merchant_id.to_s
|
12
|
+
@public_key ||= CsobPaymentGateway.configuration.public_key.to_s
|
13
|
+
@private_key ||= CsobPaymentGateway.configuration.private_key.to_s
|
14
|
+
@gateway_url ||= CsobPaymentGateway.configuration.gateway_url.to_s
|
15
|
+
@return_url ||= CsobPaymentGateway.configuration.return_url.to_s
|
16
|
+
@default_currency ||= CsobPaymentGateway.configuration.currency.to_s
|
17
|
+
@close_payment ||= CsobPaymentGateway.configuration.close_payment.to_s
|
18
|
+
@keys_directory ||= CsobPaymentGateway.configuration.keys_directory.to_s
|
19
|
+
|
20
|
+
@timestamp = Time.now.strftime("%Y%m%d%H%M%S")
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :merchant_id, :public_key, :gateway_url, :cart_items, :currency, :order_id, :total_price, :customer_id, :timestamp, :default_currency, :close_payment, :return_url, :description, :keys_directory, :logger
|
24
|
+
|
25
|
+
attr_accessor :response
|
26
|
+
|
27
|
+
def payment_init
|
28
|
+
api_init_url = CsobPaymentGateway.configuration.urls["init"]
|
29
|
+
|
30
|
+
response = RestClient.post gateway_url + api_init_url, payment_data.to_json, content_type: :json, accept: :json
|
31
|
+
self.response = JSON.parse(response)
|
32
|
+
end
|
33
|
+
|
34
|
+
def payment_process_url
|
35
|
+
api_process_url = CsobPaymentGateway.configuration.urls["process"]
|
36
|
+
CGI.escapeHTML(@gateway_url + api_process_url + get_data)
|
37
|
+
end
|
38
|
+
|
39
|
+
def payment_status
|
40
|
+
api_status_url = CsobPaymentGateway.configuration.urls["status"]
|
41
|
+
|
42
|
+
status_response = RestClient.get gateway_url + api_status_url + get_data
|
43
|
+
JSON.parse(status_response)
|
44
|
+
end
|
45
|
+
|
46
|
+
def payment_close
|
47
|
+
api_close_url = CsobPaymentGateway.configuration.urls["close"]
|
48
|
+
|
49
|
+
close_response = RestClient.put gateway_url + api_close_url, put_data.to_json, { content_type: :json, accept: :json }
|
50
|
+
JSON.parse(close_response)
|
51
|
+
end
|
52
|
+
|
53
|
+
def payment_reverse
|
54
|
+
api_reverse_url = CsobPaymentGateway.configuration.urls["reverse"]
|
55
|
+
|
56
|
+
reverse_response = RestClient.put gateway_url + api_reverse_url, put_data.to_json, { content_type: :json, accept: :json }
|
57
|
+
JSON.parse(reverse_response)
|
58
|
+
end
|
59
|
+
|
60
|
+
def payment_refund
|
61
|
+
api_refund_url = CsobPaymentGateway.configuration.urls["refund"]
|
62
|
+
|
63
|
+
refund_response = RestClient.put gateway_url + api_refund_url, put_data.to_json, { content_type: :json, accept: :json }
|
64
|
+
JSON.parse(refund_response)
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_data
|
68
|
+
text = [
|
69
|
+
merchant_id,
|
70
|
+
response["payId"],
|
71
|
+
timestamp
|
72
|
+
].map { |param| param.is_a?(Hash) ? "" : param.to_s }.join("|")
|
73
|
+
|
74
|
+
signature = CsobPaymentGateway::Crypt.sign(text, "GET")
|
75
|
+
"#{merchant_id}/#{response["payId"]}/#{timestamp}/#{CGI.escape(signature)}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def put_data
|
79
|
+
data = {
|
80
|
+
"merchantId": merchant_id,
|
81
|
+
"payId": response["payId"],
|
82
|
+
"dttm": timestamp
|
83
|
+
}
|
84
|
+
|
85
|
+
text = [
|
86
|
+
merchant_id,
|
87
|
+
response["payId"],
|
88
|
+
timestamp
|
89
|
+
].map { |param| param.is_a?(Hash) ? "" : param.to_s }.join("|")
|
90
|
+
|
91
|
+
signature = CsobPaymentGateway::Crypt.sign(text, "GET")
|
92
|
+
data.merge("signature": signature)
|
93
|
+
end
|
94
|
+
|
95
|
+
def payment_data
|
96
|
+
data = {
|
97
|
+
"merchantId": merchant_id,
|
98
|
+
"orderNo": order_id,
|
99
|
+
"dttm": timestamp,
|
100
|
+
"payOperation": "payment",
|
101
|
+
"payMethod": "card",
|
102
|
+
"totalAmount": total_price * 100,
|
103
|
+
"currency": currency ? currency : default_currency,
|
104
|
+
"closePayment": close_payment,
|
105
|
+
"returnUrl": return_url,
|
106
|
+
"returnMethod": "POST",
|
107
|
+
"cart": cart_items,
|
108
|
+
"description": description,
|
109
|
+
"merchantData": nil
|
110
|
+
}
|
111
|
+
data.merge!("customerId": customer_id) if !customer_id.nil? and customer_id.to_s != "0"
|
112
|
+
data.merge!("language": "EN")
|
113
|
+
data.merge("signature": CsobPaymentGateway::Crypt.sign(data, "POST"))
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
data/readme.md
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
require 'csob_payment_gateway'
|
2
|
+
CsobPaymentGateway.configure_from_yaml("config/csob.yml")
|
3
|
+
data = CsobPaymentGateway::BasePayment.new(total_price: 6000,cart_items: [{ name: "Tier 1",quantity: 1, amount: 5000, description: "Tier 1" }, { name: "Delivery",quantity: 1, amount: 1000, description: "Delviery" }],order_id: 1234, description: "Order from kingdomcomerpg.com - Tier 1 for 5000$", customer_id: 1234 ).payment_data
|
4
|
+
|
5
|
+
|
6
|
+
gem build csob_payment_gateway.gemspec & gem install ./csob_payment_gateway-0.0.1.gem
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: csob_payment_gateway
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jiří Kratochvíl
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
description: Gem for integration CSOB PaymentGateway in Ruby
|
28
|
+
email: me@kratochviljiri.cz
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- Gemfile
|
34
|
+
- config/config.yml
|
35
|
+
- csob_payment_gateway.gemspec
|
36
|
+
- init.rb
|
37
|
+
- lib/csob_payment_gateway.rb
|
38
|
+
- lib/csob_payment_gateway/config.rb
|
39
|
+
- lib/csob_payment_gateway/crypt.rb
|
40
|
+
- lib/csob_payment_gateway/models/base_payment.rb
|
41
|
+
- lib/csob_payment_gateway/railtie.rb
|
42
|
+
- lib/csob_payment_gateway/version.rb
|
43
|
+
- readme.md
|
44
|
+
homepage: http://rubygems.org/gems/csob_payment_gateway
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata: {}
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 2.5.1
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: Ruby implementation of CSOB PaymentGateway
|
68
|
+
test_files: []
|