paygent 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *pem
6
+ *crt
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in paygent.gemspec
4
+ gemspec
data/README ADDED
@@ -0,0 +1 @@
1
+ Ruby wrapper for paygent (www.paygent.co.jp/)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/paygent.rb ADDED
@@ -0,0 +1,25 @@
1
+ module Paygent
2
+ class << self
3
+ attr_accessor :client_file_path, :ca_file_path, :log_output_path, :debug_flg, :timeout, :select_max_cnt, :cert_password
4
+ attr_accessor :merchant_id, :default_id, :default_password, :telegram_version
5
+ end
6
+
7
+ Paygent.merchant_id = ""
8
+ Paygent.default_id = ""
9
+ Paygent.default_password = ""
10
+ Paygent.telegram_version = "1.0"
11
+
12
+ Paygent.client_file_path = "config/paygent/client_mdev_20090123.pem"
13
+ Paygent.ca_file_path = "config/paygent/curl-ca-bundle.crt"
14
+ Paygent.cert_password = "changeit"
15
+ Paygent.log_output_path = "log/paygent.log"
16
+ Paygent.debug_flg = 0
17
+ Paygent.timeout = 2000
18
+ Paygent.select_max_cnt = 2000
19
+
20
+ def self.init(option={})
21
+ Paygent::Request.new(option)
22
+ end
23
+ end
24
+
25
+ require "paygent/request"
@@ -0,0 +1,4 @@
1
+ module Paygent
2
+ class Entity
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Paygent
2
+ class Exception
3
+ end
4
+ end
@@ -0,0 +1,100 @@
1
+ require 'curb'
2
+ require 'iconv'
3
+
4
+ module Paygent
5
+ class Request
6
+ attr_accessor :_params, :body_str, :header_str, :response_code, :request, :process_id
7
+
8
+ def initialize(option={})
9
+ self._params ||= {}
10
+ self._params.update(option)
11
+ self.process_id = (rand * 100000000).to_i
12
+ end
13
+
14
+ def valid?
15
+ end
16
+
17
+ def replaceTelegramKana
18
+ end
19
+
20
+ def validateTelegramLengthCheck
21
+ end
22
+
23
+ def reqPut(key, value)
24
+ _params ||= {}
25
+ _params[key.to_sym] = value
26
+ end
27
+
28
+ def reqGet(key)
29
+ params[key.to_sym]
30
+ end
31
+
32
+ def params
33
+ {
34
+ :merchant_id => Paygent.merchant_id,
35
+ :connect_id => Paygent.default_id,
36
+ :connect_password => Paygent.default_password,
37
+ :limit_count => Paygent.select_max_cnt,
38
+ :telegram_version => Paygent.telegram_version,
39
+ }.merge(_params || {})
40
+ end
41
+
42
+ def params_str
43
+ params.map{|f,k| "#{Curl::Easy.new.escape(f)}=#{Curl::Easy.new.escape(k)}"}.join('&')
44
+ end
45
+
46
+ def post
47
+ # $this->replaceTelegramKana();
48
+ # $this->validateTelegramLengthCheck();
49
+
50
+ url = "https://mdev.paygent.co.jp/n/card/request?" + params_str
51
+ c = Curl::Easy.new(url)
52
+ c.cacert = Paygent.ca_file_path
53
+ c.cert = Paygent.client_file_path
54
+ c.certpassword = Paygent.cert_password
55
+ c.connect_timeout = Paygent.timeout
56
+ c.verbose = true
57
+ c.ssl_verify_host = false
58
+ c.multipart_form_post = true
59
+
60
+ c.headers["Content-Type"] = "application/x-www-form-urlencoded"
61
+ c.headers["charset"] = "Windows-31J"
62
+ c.headers["User-Agent"] = "curl_php"
63
+
64
+ c.http_post()
65
+
66
+ self.response_code = c.response_code
67
+ self.body_str = Iconv.conv('utf-8','Windows-31J', c.body_str)
68
+ self.header_str = c.header_str
69
+ self.request = c
70
+
71
+ log("URL: #{url}")
72
+ log("BODY: #{body_str}")
73
+ log("HEAD: #{header_str}\n\n")
74
+
75
+ self
76
+ end
77
+
78
+ def log(str)
79
+ if File.exist?(Paygent.log_output_path)
80
+ File.open(Paygent.log_output_path, "a") do |file|
81
+ file.puts "[#{process_id}] #{str}"
82
+ end
83
+ end
84
+ end
85
+
86
+ def success_response?
87
+ response_code.to_i == 200
88
+ end
89
+
90
+ def success_processed?
91
+ body_hash[:result].to_i != 1
92
+ end
93
+
94
+ def body_hash
95
+ hash = {}
96
+ body_str.scan(/\r\n(\w+)=(<!DOCTYPE.*?<\/HTML>|.*?)\r\n/m) { hash.update($1 => $2) }
97
+ hash.with_indifferent_access
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,5 @@
1
+ module Paygent
2
+ class Util
3
+ end
4
+ end
5
+
data/paygent.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "paygent"
6
+ s.version = "0.0.1"
7
+ s.authors = ["Jinzhu"]
8
+ s.email = ["wosmvp@gmail.com"]
9
+ s.homepage = ""
10
+ s.summary = %q{Ruby wrapper for paygent}
11
+ s.description = %q{Ruby wrapper for paygent}
12
+
13
+ s.rubyforge_project = "paygent"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ # specify any dependencies here; for example:
21
+ # s.add_development_dependency "rspec"
22
+ s.add_runtime_dependency "curb"
23
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paygent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jinzhu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: curb
16
+ requirement: &14654320 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *14654320
25
+ description: Ruby wrapper for paygent
26
+ email:
27
+ - wosmvp@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README
35
+ - Rakefile
36
+ - lib/paygent.rb
37
+ - lib/paygent/entity.rb
38
+ - lib/paygent/exception.rb
39
+ - lib/paygent/request.rb
40
+ - lib/paygent/util.rb
41
+ - paygent.gemspec
42
+ homepage: ''
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project: paygent
62
+ rubygems_version: 1.8.10
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Ruby wrapper for paygent
66
+ test_files: []
67
+ has_rdoc: