tappay 0.3.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 21493887adfa6b88dd60cada47e4a83c0fc87947
4
+ data.tar.gz: 2d4428ccbee61216c781e738530294390fd6a2e0
5
+ SHA512:
6
+ metadata.gz: 9ba03c79565d636ffe34fd7309ec3be526cd0f022cd55d55c22d27f19b9d61b8ed9f8d32ad8cbacd442b3c0c0d15b8cab6ade0026fc7fc299a6928042f115dce
7
+ data.tar.gz: cfee2a276f9b0179be238c14e5649c0eba0bf36b3fbc855f0fded219f5c00116b6e876ed24d35349178259e9c71a18a6fe55301315b1a0528abc3880aed72e6e
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in tappay.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 HzChris
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.
@@ -0,0 +1,99 @@
1
+ # TapPay
2
+
3
+ A very simple [TapPay](https://www.tappaysdk.com/tch) API Wrapper.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'tappay'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install tappay
20
+
21
+ ## API Documentation
22
+ See [TapPay Backend API](https://docs.tappaysdk.com/tutorial/zh/back.html#back).
23
+
24
+ ## Usage
25
+
26
+ You need to setup env, partner_key and merchant_id.
27
+ The partner_key and merchant_id are optional, you could also specify them in request params.
28
+
29
+ ```ruby
30
+ TapPay.setup do |config|
31
+ config.env = 'test' # default: sandbox
32
+ config.partner_key = 'your_partner_key' # optional
33
+ config.merchant_id = 'your_merchant_id' # optional
34
+ end
35
+ ```
36
+
37
+ ### Pay By Prime
38
+ ```ruby
39
+ params = {
40
+ prime: 'test_3a2fb2b7e892b914a03c95dd4dd5dc7970c908df67a49527c0a648b2bc9',
41
+ details: "TapPay Test",
42
+ amount: 100,
43
+ cardholder: {
44
+ phone_number: '0912345678',
45
+ name: "王小明",
46
+ email: "LittleMing@Wang.com",
47
+ zip_code: "100",
48
+ address: "台北市天龍區芝麻街1號1樓",
49
+ national_id: "A123456789"
50
+ },
51
+ remember: true
52
+ }
53
+
54
+ res = TapPay.pay_by_prime(params)
55
+ res #=> {"status"=>0, "msg"=>"Success", "amount"=>100, ...}
56
+ res['status'] #=> 0
57
+ res['msg'] #=> Success
58
+
59
+ # Block Style
60
+ TapPay.pay_by_prime(params) do |res|
61
+ res #=> {"status"=>0, "msg"=>"Success", "amount"=>100, ...}
62
+ end
63
+ ```
64
+
65
+ ### Pay By Token
66
+ ```ruby
67
+ params = {
68
+ card_key: 'your_card_key_after_pay_by_prime_with_remember_true',
69
+ card_token: 'your_card_token_after_pay_by_prime_with_remember_true',
70
+ amount: 1,
71
+ currency: "TWD",
72
+ details: "An apple and a pen."
73
+ }
74
+
75
+ res = TapPay.pay_by_token(params)
76
+
77
+ # Block Style
78
+ TapPay.pay_by_token(params) do |res|
79
+ res #=> {"status"=>0, "msg"=>"Success", "amount"=>100, ...}
80
+ end
81
+ ```
82
+
83
+ ### Refund
84
+ ```ruby
85
+ params = {
86
+ rec_trade_id: 'your_rec_trade_id'
87
+ }
88
+
89
+ res = TapPay.refund(params)
90
+
91
+ # Block Style
92
+ TapPay.refund(params) do |res|
93
+ res
94
+ end
95
+ ```
96
+ ## License
97
+
98
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
99
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tappay"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,55 @@
1
+ require "tappay/version"
2
+
3
+ require 'tappay/request'
4
+ require 'tappay/api_resource'
5
+ require 'tappay/pay_by_prime'
6
+ require 'tappay/pay_by_token'
7
+ require 'tappay/refund'
8
+
9
+ module TapPay
10
+ @@env = 'sandbox'
11
+ @@partner_key = ''
12
+ @@merchant_id = ''
13
+
14
+ class << self
15
+ def setup
16
+ yield(self)
17
+ end
18
+
19
+ def env=(env)
20
+ @@env = env.to_s
21
+ end
22
+
23
+ def partner_key=(partner_key)
24
+ @@partner_key = partner_key.to_s
25
+ end
26
+
27
+ def merchant_id=(merchant_id)
28
+ @@merchant_id = merchant_id.to_s
29
+ end
30
+
31
+ def env
32
+ @@env
33
+ end
34
+
35
+ def partner_key
36
+ @@partner_key
37
+ end
38
+
39
+ def merchant_id
40
+ @@merchant_id
41
+ end
42
+
43
+ def pay_by_prime(payload, &block)
44
+ TapPay::PayByPrime.call(payload, &block)
45
+ end
46
+
47
+ def pay_by_token(payload, &block)
48
+ TapPay::PayByToken.call(payload, &block)
49
+ end
50
+
51
+ def refund(payload, &block)
52
+ TapPay::Refund.call(payload, &block)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,23 @@
1
+ module TapPay
2
+ module APIResource
3
+ def self.base_url
4
+ if TapPay.env == 'production'
5
+ 'https://prod.tappaysdk.com'
6
+ else
7
+ 'https://sandbox.tappaysdk.com'
8
+ end
9
+ end
10
+
11
+ def self.pay_by_prime_url
12
+ "#{base_url}/tpc/payment/pay-by-prime"
13
+ end
14
+
15
+ def self.pay_by_token_url
16
+ "#{base_url}/tpc/payment/pay-by-token"
17
+ end
18
+
19
+ def self.refund_url
20
+ "#{base_url}/tpc/transaction/refund"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ module TapPay
2
+ class PayByPrime
3
+ def self.call(params = {}, &block)
4
+ TapPay::Request.send(TapPay::APIResource.pay_by_prime_url, params, &block)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module TapPay
2
+ class PayByToken
3
+ def self.call(params = {}, &block)
4
+ TapPay::Request.send(TapPay::APIResource.pay_by_token_url, params, &block)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module TapPay
2
+ class Refund
3
+ def self.call(params = {}, &block)
4
+ TapPay::Request.send(TapPay::APIResource.refund_url, params, &block)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ module TapPay
5
+ class Request
6
+ def self.send(url, params = {}, &block)
7
+ payload = default_params.merge(params).to_json
8
+ uri = URI(url)
9
+ req = Net::HTTP::Post.new(uri)
10
+
11
+ req['Content-Type'] = 'application/json'
12
+ req['x-api-key'] = params[:partner_key] || TapPay.partner_key
13
+ req.body = payload
14
+
15
+ res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http|
16
+ http.request(req)
17
+ }
18
+ res_json = JSON.parse(res.body)
19
+
20
+ block_given? ? yield(res_json) : res_json
21
+ end
22
+
23
+ def self.default_params
24
+ {
25
+ partner_key: TapPay.partner_key,
26
+ merchant_id: TapPay.merchant_id
27
+ }
28
+ end
29
+
30
+ private_class_method :default_params
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module TapPay
2
+ VERSION = "0.3.1"
3
+ end
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "tappay/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tappay"
8
+ spec.version = TapPay::VERSION
9
+ spec.authors = ["HzChris"]
10
+ spec.email = ["hzchirs@gmail.com"]
11
+
12
+ spec.summary = %q{A very simple TapPay API wrapper for ruby.}
13
+ spec.description = %q{A very simple TapPay API wrapper for ruby. Currently support pay_by_prime, pay_by_token and refund.}
14
+ spec.homepage = "https://github.com/hzchirs/tappay-ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "webmock", "~> 3.0"
28
+
29
+ spec.required_ruby_version = '>= 2.0.0'
30
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tappay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - HzChris
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-25 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: A very simple TapPay API wrapper for ruby. Currently support pay_by_prime,
70
+ pay_by_token and refund.
71
+ email:
72
+ - hzchirs@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/tappay.rb
87
+ - lib/tappay/api_resource.rb
88
+ - lib/tappay/pay_by_prime.rb
89
+ - lib/tappay/pay_by_token.rb
90
+ - lib/tappay/refund.rb
91
+ - lib/tappay/request.rb
92
+ - lib/tappay/version.rb
93
+ - tappay.gemspec
94
+ homepage: https://github.com/hzchirs/tappay-ruby
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 2.0.0
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.6.12
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: A very simple TapPay API wrapper for ruby.
118
+ test_files: []