alipay_escrow 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6372ec030e21f2a43630981faf8770061b4a4b22
4
+ data.tar.gz: 48fdbcfdd319746a3178e5b4a0bde05e10db0d72
5
+ SHA512:
6
+ metadata.gz: e595ae974aa9a71c63f933ef02633829a4e7f4504c22b6050c8cc3aad9eb38d331261927f6c4dea4898b11d3a9af3a87d6c671d8f88864872246e330d7e849b0
7
+ data.tar.gz: ade9ef98fce5d506b80d2c64976bbc9034b05a02615150ceb6a42a48be61001d579c878950ad35354fc33a4ac32dcd9063188c25b79be98a41fa65b97bf9cda2
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in alipay_escrow.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Akira Nakazawa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # AlipayEscrow
2
+
3
+ AlipayEscrow is a Ruby Interface to Alipay Payment Gateway. Uunofficial. It supports:
4
+
5
+ * create_direct_pay_by_user
6
+ * refund_fastpay_by_platform_pwd
7
+ * notify_verify
8
+ * RSA, ~~DSA~~, ~~MD5~~
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'alipay_escrow'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install alipay_escrow
25
+
26
+ ## Usage
27
+
28
+ create_direct_pay_by_user:
29
+
30
+ $ pid = 'YOUR PARTNER ID'
31
+ $ key = File.read('YOUR RSA PRIVATE KEY')
32
+ $ params = {
33
+ $ trade_no: 'TRANSACTION ID',
34
+ $ subject: 'SUBJECT',
35
+ $ amount: 'TOTAL PRICE',
36
+ $ return_url: 'RETURN URL',
37
+ $ notify_url: 'NOTIFY URL'
38
+ $ }
39
+ $ escrow = AlipayEscrow::Payment.new(params, key, pid)
40
+ $ escrow.payment_url # => https://mapi.alipay.com/gateway.do?_input_charset=utf-8&notify_url=http%3A%2F%2Fexample.comn%2F&out_trade_no=20160121173854779843000&partner=...&payment_type=1&return_url=https%3A%2F%2Fexample.com%2Falipay%2Fasync_notify&seller_id=...&service=create_direct_pay_by_user&sign=...%3D&sign_type=RSA&subject=iPhone6S&total_fee=2900
41
+
42
+ refund_fastpay_by_platform_pwd:
43
+
44
+ $ pid = 'YOUR PARTNER ID'
45
+ $ key = File.read('YOUR RSA PRIVATE KEY')
46
+ $ params # => {
47
+ $ 'notify_url' => 'NOTIFY URL',
48
+ $ 'trade_no' => 'TRADE NO',
49
+ $ 'amount' => '2900',
50
+ $ 'reason' => 'refund reason'
51
+ $ }
52
+ $ escrow = AlipayEscrow::Refund.new(params, key, pid)
53
+ $ escrow.refund_url # => https://mapi.alipay.com/gateway.do?_input_charset=utf-8&batch_no=540460171869518393124404&batch_num=1&detail_data=20160114...%5E2900%5Erefund+reason&notify_url=https%3A%2F%2Fexample.com%2Falipay%2Fasync_notify&partner=...&refund_date=2016-01-21+19%3A21%3A30&seller_user_id=...&service=refund_fastpay_by_platform_pwd&sign=TRlEoMVu2Dyj...&sign_type=RSA
54
+
55
+ notify_verify:
56
+
57
+ # POST params from Alipay
58
+ $ params # => {
59
+ $ "sign" => "Znkt3YzO2kmf...",
60
+ $ "result_details" => "20160120...^2900^SUCCESS",
61
+ $ "notify_time" => "2016-01-21 12:14:07",
62
+ $ "sign_type" => "RSA",
63
+ $ "notify_type" => "batch_refund_notify",
64
+ $ "notify_id" => "1d8e3ad3164...",
65
+ $ "batch_no" => "20160121121...",
66
+ $ "success_num" => "1"
67
+ $ }
68
+ $ pid = 'YOUR PARTNER ID'
69
+ $ key = File.read('ALIPAY RSA PUBLIC KEY')
70
+ $ escrow = AlipayEscrow::Refund.new(params, key, pid)
71
+ $ escrow.verified? # => true/false
72
+
73
+ ## Contributing
74
+
75
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/alipay_escrow. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
76
+
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'alipay_escrow/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "alipay_escrow"
8
+ spec.version = AlipayEscrow::VERSION
9
+ spec.authors = ["Akira Nakazawa"]
10
+ spec.email = ["nakazawa.akira@gmail.com"]
11
+
12
+ spec.summary = %q{A Ruby Interface to Alipay Payment Gateway. Unofficial.}
13
+ spec.description = %q{A Ruby Interface to Alipay Payment Gateway. Unofficial.}
14
+ spec.homepage = "https://github.com/konpeito/alipay_escrow"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest"
25
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "alipay_escrow"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ -----BEGIN PUBLIC KEY-----
2
+ MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRA
3
+ FljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQE
4
+ B/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5Ksi
5
+ NG9zpgmLCUYuLkxpLQIDAQAB
6
+ -----END PUBLIC KEY-----
@@ -0,0 +1,12 @@
1
+ require 'openssl'
2
+ require 'base64'
3
+ require 'active_support'
4
+ require 'httparty'
5
+
6
+ module AlipayEscrow
7
+ extend ActiveSupport::Autoload
8
+
9
+ autoload :Base
10
+ autoload :Payment
11
+ autoload :Refund
12
+ end
@@ -0,0 +1,42 @@
1
+ module AlipayEscrow
2
+ class Base
3
+ attr_reader :params, :key, :partner_id
4
+ attr_accessor :options
5
+
6
+ GATEWAY = 'https://mapi.alipay.com/gateway.do?'
7
+
8
+ def initialize(params, key, partner_id)
9
+ @params = params
10
+ @key = key
11
+ @partner_id = partner_id
12
+ @options = {}
13
+ end
14
+
15
+ def verify
16
+ signature_verify && notification_verify
17
+ end
18
+
19
+ private
20
+
21
+ def signature_verify
22
+ params.delete('sign_type')
23
+ signature = params.delete('sign')
24
+ data = params.sort.map { |item| item.join('=') }.join('&')
25
+ rsa = OpenSSL::PKey::RSA.new(key)
26
+ rsa.verify('sha1', Base64.strict_decode64(signature), data)
27
+ end
28
+
29
+ def notification_verify
30
+ query_params = {
31
+ 'service' => 'notify_verify',
32
+ 'partner' => partner_id,
33
+ 'notify_id' => params['notify_id']
34
+ }
35
+ HTTParty.get("#{GATEWAY}#{query_params.to_query}")
36
+ end
37
+
38
+ def encrypt(str)
39
+ Base64.strict_encode64(OpenSSL::PKey::RSA.new(key).sign('sha1', str))
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,27 @@
1
+ module AlipayEscrow
2
+ class Payment < Base
3
+ def payment_url
4
+ options = Hash[payment_params.map { |k, v| [k.to_s, v] }]
5
+ str = options.sort.map { |item| item.join('=') }.join('&')
6
+ options.merge!(sign_type: 'RSA', sign: encrypt(str))
7
+ "#{GATEWAY}#{options.to_query}"
8
+ end
9
+
10
+ private
11
+
12
+ def payment_params
13
+ {
14
+ out_trade_no: params[:trade_no],
15
+ subject: params[:subject],
16
+ total_fee: params[:amount].to_s,
17
+ return_url: params[:return_url],
18
+ notify_url: params[:notify_url],
19
+ service: 'create_direct_pay_by_user',
20
+ partner: partner_id,
21
+ seller_id: partner_id,
22
+ payment_type: '1',
23
+ _input_charset: 'utf-8'
24
+ }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ module AlipayEscrow
2
+ class Refund < Base
3
+ def refund_url
4
+ options = Hash[refund_params.map { |k, v| [k.to_s, v] }]
5
+ str = options.sort.map { |item| item.join('=') }.join('&')
6
+ options.merge!(sign_type: 'RSA', sign: encrypt(str))
7
+ "#{GATEWAY}#{options.to_query}"
8
+ end
9
+
10
+ private
11
+
12
+ def refund_params
13
+ {
14
+ batch_no: format("%0#{24}d", SecureRandom.random_number(10**24)),
15
+ notify_url: params['notify_url'],
16
+ service: 'refund_fastpay_by_platform_pwd',
17
+ partner: partner_id,
18
+ seller_user_id: partner_id,
19
+ refund_date: Time.now.strftime('%F %T'),
20
+ batch_num: 1,
21
+ detail_data: "#{params['trade_no']}^#{params['amount']}^#{params['reason']}",
22
+ _input_charset: 'utf-8'
23
+ }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module AlipayEscrow
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alipay_escrow
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Akira Nakazawa
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-21 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A Ruby Interface to Alipay Payment Gateway. Unofficial.
56
+ email:
57
+ - nakazawa.akira@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - alipay_escrow.gemspec
70
+ - bin/console
71
+ - bin/setup
72
+ - certs/alipay_rsa.pub
73
+ - lib/alipay_escrow.rb
74
+ - lib/alipay_escrow/base.rb
75
+ - lib/alipay_escrow/payment.rb
76
+ - lib/alipay_escrow/refund.rb
77
+ - lib/alipay_escrow/version.rb
78
+ homepage: https://github.com/konpeito/alipay_escrow
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.8
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: A Ruby Interface to Alipay Payment Gateway. Unofficial.
102
+ test_files: []