allpay 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +2 -0
- data/allpay.gemspec +23 -0
- data/lib/allpay.rb +95 -0
- data/lib/allpay/version.rb +3 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e5c5de6c0bfeba05a57aa62acd2e33ba30d91550
|
4
|
+
data.tar.gz: 655f3756c3df731791fe860293d434ed1c365a5f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 76942ba4cd80d73847a273fa65cf6f5368f8f13a639ed41d038fb12002bf55a34182e97c931ab99464cb6ee1b1b0186a50611a2ffb7fb18d169c5075ebe04195
|
7
|
+
data.tar.gz: 892d0d6a2a24d832d8d14a9482033e2f3b56b821b9bcff43dc569a56cb5e09fed060fcca8e11c4b6abd31ae072b26c562bfc445c91e82b5dad5d4984eb3e3cb2
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 odin1in
|
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,62 @@
|
|
1
|
+
Allpay
|
2
|
+
=========
|
3
|
+
|
4
|
+
A Gem for the [Allpay](http://www.allpay.com.tw/).
|
5
|
+
|
6
|
+
Installation
|
7
|
+
=========
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'allpay'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install allpay
|
20
|
+
|
21
|
+
Quick Start
|
22
|
+
=========
|
23
|
+
|
24
|
+
### Initialize
|
25
|
+
|
26
|
+
**vAccount**
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
allpay = Allpay::Client.new(merchant_id: "YOUR MERCHANT ID", key: 'YOUR KEY For Vaccount', iv: 'YOUR IV For Vaccount')
|
30
|
+
```
|
31
|
+
|
32
|
+
**All in one**
|
33
|
+
Not Yet
|
34
|
+
|
35
|
+
### Usage
|
36
|
+
|
37
|
+
**vAccount**
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
allpay.get_vaccount(trade_amount: 1000, reply_url: "YOUR Callback URL")
|
41
|
+
```
|
42
|
+
we also support options below:
|
43
|
+
* are required
|
44
|
+
|
45
|
+
merchant_trade_no -- Default is random 20 digits
|
46
|
+
merchant_trade_date -- Defalt is current time
|
47
|
+
trade_amount -- Default is 10000
|
48
|
+
expire_date -- Default is 7
|
49
|
+
bank_name -- Default is CHINATRUST
|
50
|
+
*reply_url -- Default is empty
|
51
|
+
remark -- Default is empty
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
Contributing
|
56
|
+
=========
|
57
|
+
|
58
|
+
1. Fork it ( https://github.com/odin1in/allpay/fork )
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/allpay.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'allpay/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "allpay"
|
8
|
+
spec.version = Allpay::VERSION
|
9
|
+
spec.authors = ["odin1in"]
|
10
|
+
spec.email = ["odin@pwn.so"]
|
11
|
+
spec.summary = %q{Write a short summary. Required.}
|
12
|
+
spec.description = %q{Write a longer description. Optional.}
|
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.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/allpay.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require "allpay/version"
|
2
|
+
|
3
|
+
require "base64"
|
4
|
+
require 'open-uri'
|
5
|
+
require "nori"
|
6
|
+
require "gyoku"
|
7
|
+
require "addressable/uri"
|
8
|
+
require "openssl"
|
9
|
+
require "securerandom"
|
10
|
+
|
11
|
+
module Allpay
|
12
|
+
class Client
|
13
|
+
attr_accessor :merchant_id, :rest, :http, :api, :all_key, :all_iv, :key, :iv
|
14
|
+
|
15
|
+
def initialize(merchant_id, options = {})
|
16
|
+
@merchant_id = merchant_id
|
17
|
+
begin
|
18
|
+
env = ENV.try("fetch", "RAILS_ENV")
|
19
|
+
rescue
|
20
|
+
env = "development"
|
21
|
+
end
|
22
|
+
|
23
|
+
if env == 'production'
|
24
|
+
@api = 'pay.allpay.com.tw'
|
25
|
+
else
|
26
|
+
@api = 'pay-stage.allpay.com.tw'
|
27
|
+
end
|
28
|
+
@key = options[:key]
|
29
|
+
@iv = options[:iv]
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_vaccount(options = {})
|
33
|
+
has_key?
|
34
|
+
enc_data = encrypt_data(@key, @iv, {
|
35
|
+
'MerchantID' => merchant_id,
|
36
|
+
'MerchantTradeNo' => options[:merchant_trade_no] || SecureRandom.hex(10),
|
37
|
+
'MerchantTradeDate' => options[:merchant_trade_date] || Time.now.strftime('%Y/%m/%d %H:%M:%S'),
|
38
|
+
'TradeAmount' => options[:trade_amount] || 10000,
|
39
|
+
'ExpireDate' => options[:expire_date] || '7',
|
40
|
+
'BankName' => options[:bank_name] || "CHINATRUST",
|
41
|
+
'ReplyURL' => options[:reply_url] || "",
|
42
|
+
'Remark' => options[:remark] || "",
|
43
|
+
})
|
44
|
+
|
45
|
+
begin
|
46
|
+
result = parse_xml(get('/payment/Srv/gateway', {"MerchantID" => merchant_id, "PaymentType" => "vAccount", "XMLData" => enc_data}))
|
47
|
+
rescue => e
|
48
|
+
response = e
|
49
|
+
end
|
50
|
+
|
51
|
+
[result["RtnCode"].to_i, result]
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_vaccount_callback(xmldata)
|
55
|
+
has_key?
|
56
|
+
result = parse_xml(decrypt_data(@key, @iv, xmldata))
|
57
|
+
[result["RtnCode"].to_i, result]
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def has_key?
|
64
|
+
if @key.nil? || @iv.nil?
|
65
|
+
raise "You should set Key, and Iv for vaccount"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def get(path, params = {})
|
70
|
+
uri = Addressable::URI.new
|
71
|
+
uri.query_values = params
|
72
|
+
open("http://#{api}/#{path}?#{uri.query}").read
|
73
|
+
end
|
74
|
+
|
75
|
+
def encrypt_data(key, iv, data)
|
76
|
+
data = Gyoku.xml({"Root" => { "Data" => data}})
|
77
|
+
cipher = OpenSSL::Cipher::AES128.new(:CBC).encrypt
|
78
|
+
cipher.key = key
|
79
|
+
cipher.iv = iv
|
80
|
+
|
81
|
+
Base64.encode64(cipher.update(data) + cipher.final).gsub("\n","")
|
82
|
+
end
|
83
|
+
|
84
|
+
def decrypt_data(key, iv, data)
|
85
|
+
cipher = OpenSSL::Cipher::AES128.new(:CBC).decrypt
|
86
|
+
cipher.key = key
|
87
|
+
cipher.iv = iv
|
88
|
+
cipher.update(Base64.decode64(data.gsub(" ","+"))) + cipher.final
|
89
|
+
end
|
90
|
+
|
91
|
+
def parse_xml(data)
|
92
|
+
Nori.new.parse(data)["Root"]["Data"]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: allpay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- odin1in
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-20 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Write a longer description. Optional.
|
42
|
+
email:
|
43
|
+
- odin@pwn.so
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- allpay.gemspec
|
54
|
+
- lib/allpay.rb
|
55
|
+
- lib/allpay/version.rb
|
56
|
+
homepage: ''
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.2.2
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Write a short summary. Required.
|
80
|
+
test_files: []
|