payjp 0.0.6 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +20 -0
- data/.gitignore +0 -0
- data/.rubocop.yml +0 -0
- data/.rubocop_todo.yml +0 -0
- data/CONTRIBUTORS +0 -0
- data/Gemfile +0 -0
- data/History.txt +0 -0
- data/LICENSE +0 -0
- data/README.md +87 -0
- data/Rakefile +0 -0
- data/lib/payjp/account.rb +0 -0
- data/lib/payjp/api_operations/create.rb +0 -0
- data/lib/payjp/api_operations/delete.rb +0 -0
- data/lib/payjp/api_operations/list.rb +0 -0
- data/lib/payjp/api_operations/request.rb +0 -0
- data/lib/payjp/api_operations/update.rb +0 -0
- data/lib/payjp/api_resource.rb +0 -0
- data/lib/payjp/card.rb +0 -0
- data/lib/payjp/charge.rb +9 -0
- data/lib/payjp/customer.rb +0 -0
- data/lib/payjp/errors/api_connection_error.rb +0 -0
- data/lib/payjp/errors/api_error.rb +0 -0
- data/lib/payjp/errors/authentication_error.rb +0 -0
- data/lib/payjp/errors/card_error.rb +0 -0
- data/lib/payjp/errors/invalid_request_error.rb +0 -0
- data/lib/payjp/errors/payjp_error.rb +0 -0
- data/lib/payjp/event.rb +0 -0
- data/lib/payjp/list_object.rb +0 -0
- data/lib/payjp/payjp_object.rb +0 -0
- data/lib/payjp/plan.rb +0 -0
- data/lib/payjp/subscription.rb +0 -0
- data/lib/payjp/tenant.rb +19 -0
- data/lib/payjp/token.rb +0 -0
- data/lib/payjp/transfer.rb +0 -0
- data/lib/payjp/util.rb +1 -0
- data/lib/payjp/version.rb +1 -1
- data/lib/payjp.rb +34 -7
- data/payjp.gemspec +4 -1
- data/test/payjp/account_test.rb +0 -0
- data/test/payjp/api_resource_test.rb +135 -0
- data/test/payjp/charge_test.rb +12 -0
- data/test/payjp/customer_card_test.rb +0 -0
- data/test/payjp/customer_test.rb +0 -0
- data/test/payjp/event_test.rb +0 -0
- data/test/payjp/list_object_test.rb +0 -0
- data/test/payjp/metadata_test.rb +0 -0
- data/test/payjp/payjp_object_test.rb +0 -0
- data/test/payjp/plan_test.rb +0 -0
- data/test/payjp/subscription_test.rb +0 -0
- data/test/payjp/tenant_test.rb +42 -0
- data/test/payjp/token_test.rb +0 -0
- data/test/payjp/transfer_test.rb +0 -0
- data/test/payjp/util_test.rb +0 -0
- data/test/test_data.rb +38 -0
- data/test/test_helper.rb +0 -0
- metadata +29 -26
- data/.travis.yml +0 -10
- data/README.rdoc +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ea73b4ff6c1c71f4c571eca0fe6b9ecc907e71b4fc1914a10438eacf7eb50b6c
|
4
|
+
data.tar.gz: 5212a4b8341623b164dbb4869a13a4c423454b7bbfbad2ec43b09f78bdce177f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e6f7dd0643142735d9929e6f8c5b9bf08ea7239597e26ed88f43a32fd082ab524f4b3ce13c35647458b53a283a23bea409e0d2e04e5d78a8470acd25eb804cd
|
7
|
+
data.tar.gz: 3239795693202e338eea11b1b88c61ea5ffdd7fac72d1545580276700b2d37b0949651e0bf7239eefd4c328af7695fb1275f22d3f37d710c60705eb53e2e88ac
|
@@ -0,0 +1,20 @@
|
|
1
|
+
name: Ruby Build Test
|
2
|
+
|
3
|
+
on: push
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build-test:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
strategy:
|
10
|
+
matrix:
|
11
|
+
ruby-version: [2.0.0, 2.1, 2.2, 2.3.0, 2.7.0, jruby-9.2.17.0]
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
15
|
+
uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: ${{ matrix.ruby-version }}
|
18
|
+
bundler-cache: true
|
19
|
+
- name: Run tests
|
20
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
File without changes
|
data/.rubocop.yml
CHANGED
File without changes
|
data/.rubocop_todo.yml
CHANGED
File without changes
|
data/CONTRIBUTORS
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/History.txt
CHANGED
File without changes
|
data/LICENSE
CHANGED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# PAY.JP for Ruby
|
2
|
+
|
3
|
+
## How to Use
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
require 'payjp'
|
7
|
+
Payjp.api_key = 'sk_test_c62fade9d045b54cd76d7036'
|
8
|
+
Payjp.open_timeout = 30 # optionally
|
9
|
+
Payjp.read_timeout = 90 # optionally
|
10
|
+
|
11
|
+
# ex, create charge
|
12
|
+
charge = Payjp::Charge.create(
|
13
|
+
:amount => 3500,
|
14
|
+
:card => 'token_id',
|
15
|
+
:currency => 'jpy',
|
16
|
+
)
|
17
|
+
```
|
18
|
+
|
19
|
+
| `Payjp` variables | type | required | description |
|
20
|
+
| ----------------- | ---- | -------- | ----------- |
|
21
|
+
| api_key | String | yes | your secret key |
|
22
|
+
| open_timeout | Integer | no | the second to wait for TCP connection opening (default 30) |
|
23
|
+
| read_timeout | Integer | no | the second to wait from request to reading response (default 90) |
|
24
|
+
|
25
|
+
For detail, See [PAY.JP API Docs](https://pay.jp/docs/api/)
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
```sh
|
30
|
+
gem install payjp
|
31
|
+
```
|
32
|
+
|
33
|
+
If you want to build the gem from source:
|
34
|
+
|
35
|
+
```sh
|
36
|
+
gem build payjp.gemspec
|
37
|
+
```
|
38
|
+
|
39
|
+
### Requirements
|
40
|
+
|
41
|
+
* Ruby 2.0.0 or above.
|
42
|
+
* rest-client
|
43
|
+
|
44
|
+
### Retry on HTTP Status Code 429
|
45
|
+
* See [Rate Limit Guideline](https://pay.jp/docs/guideline-rate-limit#2-%E3%83%AA%E3%83%88%E3%83%A9%E3%82%A4)
|
46
|
+
* When you exceeded rate-limit, you can retry request by setting `max_retry`
|
47
|
+
like `Payjp.max_retry = 3` .
|
48
|
+
* The retry interval base value is `retry_initial_delay`
|
49
|
+
Adjust the value like `Payjp.retry_initial_delay = 4`
|
50
|
+
The smaller is shorter.
|
51
|
+
* The Maximum retry time is `retry_max_delay`.
|
52
|
+
Adjust the value like 'Payjp.retry_max_delay = 32'
|
53
|
+
* The retry interval calcurating is based on "Exponential backoff with equal jitter" algorithm.
|
54
|
+
See https://aws.amazon.com/jp/blogs/architecture/exponential-backoff-and-jitter/
|
55
|
+
|
56
|
+
how to use
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
require 'payjp'
|
60
|
+
Payjp.api_key = 'sk_test_c62fade9d045b54cd76d7036'
|
61
|
+
Payjp.max_retry = 3
|
62
|
+
Payjp.retry_initial_delay = 2
|
63
|
+
Payjp.retry_max_delay = 32
|
64
|
+
|
65
|
+
charge = Payjp::Charge.create(
|
66
|
+
:amount => 3500,
|
67
|
+
:card => 'token_id',
|
68
|
+
:currency => 'jpy',
|
69
|
+
)
|
70
|
+
```
|
71
|
+
|
72
|
+
### Bundler
|
73
|
+
|
74
|
+
If you are installing via bundler, you should be sure to use the https
|
75
|
+
rubygems source in your Gemfile, as any gems fetched over http could potentially be
|
76
|
+
compromised in transit and alter the code of gems fetched securely over https:
|
77
|
+
|
78
|
+
```
|
79
|
+
source 'https://rubygems.org'
|
80
|
+
|
81
|
+
gem 'rails'
|
82
|
+
gem 'payjp'
|
83
|
+
```
|
84
|
+
|
85
|
+
## Development
|
86
|
+
|
87
|
+
Test cases can be run with: `bundle exec rake test`
|
data/Rakefile
CHANGED
File without changes
|
data/lib/payjp/account.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/payjp/api_resource.rb
CHANGED
File without changes
|
data/lib/payjp/card.rb
CHANGED
File without changes
|
data/lib/payjp/charge.rb
CHANGED
@@ -19,6 +19,11 @@ module Payjp
|
|
19
19
|
refresh_from(response, opts)
|
20
20
|
end
|
21
21
|
|
22
|
+
def tds_finish(params = {}, opts = {})
|
23
|
+
response, opts = request(:post, tds_finish_url, params, opts)
|
24
|
+
refresh_from(response, opts)
|
25
|
+
end
|
26
|
+
|
22
27
|
private
|
23
28
|
|
24
29
|
def refund_url
|
@@ -32,5 +37,9 @@ module Payjp
|
|
32
37
|
def reauth_url
|
33
38
|
url + '/reauth'
|
34
39
|
end
|
40
|
+
|
41
|
+
def tds_finish_url
|
42
|
+
url + '/tds_finish'
|
43
|
+
end
|
35
44
|
end
|
36
45
|
end
|
data/lib/payjp/customer.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/payjp/event.rb
CHANGED
File without changes
|
data/lib/payjp/list_object.rb
CHANGED
File without changes
|
data/lib/payjp/payjp_object.rb
CHANGED
File without changes
|
data/lib/payjp/plan.rb
CHANGED
File without changes
|
data/lib/payjp/subscription.rb
CHANGED
File without changes
|
data/lib/payjp/tenant.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Payjp
|
2
|
+
class Tenant < APIResource
|
3
|
+
include Payjp::APIOperations::Create
|
4
|
+
include Payjp::APIOperations::Delete
|
5
|
+
include Payjp::APIOperations::Update
|
6
|
+
include Payjp::APIOperations::List
|
7
|
+
|
8
|
+
def create_application_urls(params = {}, opts = {})
|
9
|
+
response, opts = request(:post, create_application_urls_url, params, opts)
|
10
|
+
response
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def create_application_urls_url
|
16
|
+
url + '/application_urls'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/payjp/token.rb
CHANGED
File without changes
|
data/lib/payjp/transfer.rb
CHANGED
File without changes
|
data/lib/payjp/util.rb
CHANGED
data/lib/payjp/version.rb
CHANGED
data/lib/payjp.rb
CHANGED
@@ -34,6 +34,7 @@ require 'payjp/event'
|
|
34
34
|
require 'payjp/transfer'
|
35
35
|
require 'payjp/card'
|
36
36
|
require 'payjp/subscription'
|
37
|
+
require 'payjp/tenant'
|
37
38
|
|
38
39
|
# Errors
|
39
40
|
require 'payjp/errors/payjp_error'
|
@@ -46,27 +47,43 @@ require 'payjp/errors/authentication_error'
|
|
46
47
|
module Payjp
|
47
48
|
@api_base = 'https://api.pay.jp'
|
48
49
|
@open_timeout = 30
|
49
|
-
@read_timeout =
|
50
|
+
@read_timeout = 90
|
50
51
|
@ssl_ca_file = nil
|
51
52
|
@ssl_ca_path = nil
|
52
53
|
@ssl_cert_store = nil
|
54
|
+
@max_retry = 0
|
55
|
+
@retry_initial_delay = 2
|
56
|
+
@retry_max_delay = 32
|
53
57
|
|
54
58
|
class << self
|
55
59
|
attr_accessor :api_key, :api_base, :api_version, :connect_base, :uploads_base,
|
56
|
-
:open_timeout, :read_timeout, :ssl_ca_file, :ssl_ca_path, :ssl_cert_store
|
60
|
+
:open_timeout, :read_timeout, :ssl_ca_file, :ssl_ca_path, :ssl_cert_store, :max_retry, :retry_initial_delay, :retry_max_delay
|
57
61
|
end
|
58
62
|
|
59
63
|
def self.api_url(url = '', api_base_url = nil)
|
60
64
|
(api_base_url || @api_base) + url
|
61
65
|
end
|
62
66
|
|
63
|
-
def self.
|
67
|
+
def self.get_retry_delay(retry_count, retry_initial_delay, retry_max_delay)
|
68
|
+
# Get retry delay seconds.
|
69
|
+
# Based on "Exponential backoff with equal jitter" algorithm.
|
70
|
+
# https://aws.amazon.com/jp/blogs/architecture/exponential-backoff-and-jitter/
|
71
|
+
|
72
|
+
wait = [retry_max_delay, retry_initial_delay * 2 ** retry_count].min
|
73
|
+
random = Random.new()
|
74
|
+
(wait / 2) + (random.rand(wait / 2.0))
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.request(method, url, api_key, params = {}, headers = {}, api_base_url = nil, open_timeout = nil, read_timeout = nil, ssl_ca_file = nil, ssl_ca_path = nil, ssl_cert_store = nil, max_retry = nil, retry_initial_delay= nil, retry_max_delay = nil)
|
64
78
|
api_base_url ||= @api_base
|
65
79
|
open_timeout ||= @open_timeout
|
66
80
|
read_timeout ||= @read_timeout
|
67
81
|
ssl_ca_file ||= @ssl_ca_file
|
68
82
|
ssl_ca_path ||= @ssl_ca_path
|
69
83
|
ssl_cert_store ||= @ssl_cert_store
|
84
|
+
max_retry ||= @max_retry
|
85
|
+
retry_initial_delay ||= @retry_initial_delay
|
86
|
+
retry_max_delay ||= @retry_max_delay
|
70
87
|
|
71
88
|
unless api_key ||= @api_key
|
72
89
|
raise AuthenticationError.new('No API key provided. ' \
|
@@ -107,6 +124,8 @@ module Payjp
|
|
107
124
|
:ssl_ca_file => ssl_ca_file, :ssl_ca_path => ssl_ca_path,
|
108
125
|
:ssl_cert_store => ssl_cert_store)
|
109
126
|
|
127
|
+
retry_count = 1
|
128
|
+
|
110
129
|
begin
|
111
130
|
# $stderr.puts request_opts
|
112
131
|
|
@@ -122,6 +141,12 @@ module Payjp
|
|
122
141
|
raise
|
123
142
|
end
|
124
143
|
rescue RestClient::ExceptionWithResponse => e
|
144
|
+
if e.http_code == 429 and retry_count <= max_retry then
|
145
|
+
sleep get_retry_delay(retry_count, retry_initial_delay, retry_max_delay)
|
146
|
+
retry_count += 1
|
147
|
+
retry
|
148
|
+
end
|
149
|
+
|
125
150
|
if rcode = e.http_code and rbody = e.http_body
|
126
151
|
handle_api_error(rcode, rbody)
|
127
152
|
else
|
@@ -239,6 +264,8 @@ module Payjp
|
|
239
264
|
raise authentication_error error, rcode, rbody, error_obj
|
240
265
|
when 402
|
241
266
|
raise card_error error, rcode, rbody, error_obj
|
267
|
+
when 429
|
268
|
+
raise api_error error, rcode, rbody, error_obj
|
242
269
|
else
|
243
270
|
raise api_error error, rcode, rbody, error_obj
|
244
271
|
end
|
@@ -266,11 +293,12 @@ module Payjp
|
|
266
293
|
api_base_url = @api_base unless api_base_url
|
267
294
|
connection_message = "Please check your internet connection and try again. " \
|
268
295
|
"If this problem persists, you should check Payjp's service status at " \
|
269
|
-
"https://
|
296
|
+
"https://status.pay.jp or let us know at support@pay.jp."
|
270
297
|
|
271
298
|
case e
|
272
299
|
when RestClient::RequestTimeout
|
273
|
-
message = "
|
300
|
+
message = "Timed out over #{@read_timeout} sec. " \
|
301
|
+
"Check if your request successed or not."
|
274
302
|
|
275
303
|
when RestClient::ServerBrokeConnection
|
276
304
|
message = "The connection to the server (#{api_base_url}) broke before the " \
|
@@ -278,8 +306,7 @@ module Payjp
|
|
278
306
|
|
279
307
|
when SocketError
|
280
308
|
message = "Unexpected error communicating when trying to connect to Payjp. " \
|
281
|
-
"
|
282
|
-
"To check, try running 'host pay.jp' from the command line."
|
309
|
+
"Your DNS may not work. Check 'host api.pay.jp' from the command line."
|
283
310
|
|
284
311
|
else
|
285
312
|
message = "Unexpected error communicating with Payjp. " \
|
data/payjp.gemspec
CHANGED
@@ -23,5 +23,8 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.files = `git ls-files`.split("\n")
|
24
24
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
25
25
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
26
|
-
s.require_paths = ['lib']
|
26
|
+
s.require_paths = ['lib']
|
27
|
+
s.metadata = {
|
28
|
+
"source_code_uri" => "https://github.com/payjp/payjp-ruby",
|
29
|
+
}
|
27
30
|
end
|
data/test/payjp/account_test.rb
CHANGED
File without changes
|
@@ -411,6 +411,25 @@ module Payjp
|
|
411
411
|
|
412
412
|
assert_equal true, rescued
|
413
413
|
end
|
414
|
+
|
415
|
+
should "429s should raise a APIError of over capacity error code" do
|
416
|
+
response = test_response(test_over_capacity_error, 429)
|
417
|
+
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 429))
|
418
|
+
|
419
|
+
rescued = false
|
420
|
+
begin
|
421
|
+
Payjp::Customer.new("test_customer").refresh
|
422
|
+
assert false # shouldn't get here either
|
423
|
+
rescue Payjp::APIError => e # we don't use assert_raises because we want to examine e
|
424
|
+
rescued = true
|
425
|
+
assert e.is_a? Payjp::APIError
|
426
|
+
assert_equal(429, e.http_status)
|
427
|
+
assert_equal(true, !!e.http_body)
|
428
|
+
assert_equal("over_capacity", e.json_body[:error][:code])
|
429
|
+
end
|
430
|
+
|
431
|
+
assert_equal true, rescued
|
432
|
+
end
|
414
433
|
end
|
415
434
|
|
416
435
|
should 'save nothing if nothing changes' do
|
@@ -442,4 +461,120 @@ module Payjp
|
|
442
461
|
end
|
443
462
|
end
|
444
463
|
end
|
464
|
+
|
465
|
+
class APIRequestorRetryTest < Test::Unit::TestCase
|
466
|
+
|
467
|
+
setup do
|
468
|
+
Payjp.max_retry = 0
|
469
|
+
Payjp.retry_initial_delay = 0.1
|
470
|
+
end
|
471
|
+
|
472
|
+
def mock_exceptions(error_codes, call_count)
|
473
|
+
exception_mock = nil
|
474
|
+
error_codes.with_index(1) { |code, id|
|
475
|
+
if id == 1
|
476
|
+
exception_mock = @mock.expects(:get).raises(RestClient::ExceptionWithResponse.new(test_response(test_api_error, code)))
|
477
|
+
else
|
478
|
+
exception_mock = exception_mock.then.raises(RestClient::ExceptionWithResponse.new(test_response(test_api_error, code)))
|
479
|
+
end
|
480
|
+
}
|
481
|
+
exception_mock.at_least(call_count)
|
482
|
+
end
|
483
|
+
|
484
|
+
context "checking retry" do
|
485
|
+
should "over capacity retry disabled" do
|
486
|
+
error_codes = [429, 599].to_enum
|
487
|
+
# returns 599 at 2nd try but max_retry 0 then retry disabled
|
488
|
+
mock_exceptions(error_codes, 1)
|
489
|
+
rescued = false
|
490
|
+
|
491
|
+
begin
|
492
|
+
Payjp::Charge.retrieve("test_charge")
|
493
|
+
rescue Payjp::APIError => e # we don't use assert_raises because we want to examine e
|
494
|
+
assert e.is_a? Payjp::APIError
|
495
|
+
assert_equal(429, e.http_status)
|
496
|
+
rescued = true
|
497
|
+
end
|
498
|
+
assert_equal true, rescued
|
499
|
+
end
|
500
|
+
|
501
|
+
should "no retry" do
|
502
|
+
Payjp.max_retry = 2
|
503
|
+
Payjp.retry_initial_delay = 0.1
|
504
|
+
error_codes = [599, 429, 429, 429].to_enum
|
505
|
+
# returns 599 at first try
|
506
|
+
mock_exceptions(error_codes, 1)
|
507
|
+
rescued = false
|
508
|
+
|
509
|
+
begin
|
510
|
+
Payjp::Charge.retrieve("test_charge")
|
511
|
+
rescue Payjp::APIError => e # we don't use assert_raises because we want to examine e
|
512
|
+
assert e.is_a? Payjp::APIError
|
513
|
+
assert_equal(599, e.http_status)
|
514
|
+
assert_equal(true, !!e.http_body)
|
515
|
+
rescued = true
|
516
|
+
end
|
517
|
+
assert_equal true, rescued
|
518
|
+
end
|
519
|
+
|
520
|
+
should "over capacity full retry" do
|
521
|
+
Payjp.max_retry = 2
|
522
|
+
Payjp.retry_initial_delay = 0.1
|
523
|
+
error_codes = [429, 429, 429, 429, 599].to_enum
|
524
|
+
|
525
|
+
# first try + 2 retries + unexpected 599
|
526
|
+
mock_exceptions(error_codes, 3)
|
527
|
+
rescued = false
|
528
|
+
|
529
|
+
begin
|
530
|
+
Payjp::Charge.retrieve("test_charge")
|
531
|
+
rescue Payjp::APIError => e # we don't use assert_raises because we want to examine e
|
532
|
+
assert e.is_a? Payjp::APIError
|
533
|
+
assert_equal(429, e.http_status)
|
534
|
+
rescued = true
|
535
|
+
end
|
536
|
+
|
537
|
+
assert_equal true, rescued
|
538
|
+
end
|
539
|
+
|
540
|
+
should "over capacity halfway of retries" do
|
541
|
+
Payjp.max_retry = 5
|
542
|
+
Payjp.retry_initial_delay = 0.1
|
543
|
+
|
544
|
+
error_codes = [429, 599, 429, 429, 429].to_enum
|
545
|
+
rescued = false
|
546
|
+
|
547
|
+
# returns not 429 status at 2nd try
|
548
|
+
mock_exceptions(error_codes, 2)
|
549
|
+
begin
|
550
|
+
Payjp::Charge.retrieve("test_charge")
|
551
|
+
rescue Payjp::APIError => e # we don't use assert_raises because we want to examine e
|
552
|
+
assert e.is_a? Payjp::APIError
|
553
|
+
assert_equal(599, e.http_status)
|
554
|
+
rescued = true
|
555
|
+
end
|
556
|
+
|
557
|
+
assert_equal true, rescued
|
558
|
+
end
|
559
|
+
end
|
560
|
+
|
561
|
+
context "retry interval" do
|
562
|
+
should "retry initial delay" do
|
563
|
+
retry_initial_delay = 2
|
564
|
+
retry_max_delay = 32
|
565
|
+
|
566
|
+
assert_equal(true, Payjp.get_retry_delay(0, retry_initial_delay, retry_max_delay).between?(1, 2))
|
567
|
+
assert_equal(true, Payjp.get_retry_delay(1, retry_initial_delay, retry_max_delay).between?(2, 4))
|
568
|
+
assert_equal(true, Payjp.get_retry_delay(2, retry_initial_delay, retry_max_delay).between?(4, 8))
|
569
|
+
# cap
|
570
|
+
assert_equal(true, Payjp.get_retry_delay(4, retry_initial_delay, retry_max_delay).between?(16, 32))
|
571
|
+
assert_equal(true, Payjp.get_retry_delay(10, retry_initial_delay, retry_max_delay).between?(16, 32))
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
575
|
+
teardown do
|
576
|
+
Payjp.max_retry = 0
|
577
|
+
Payjp.retry_initial_delay = 0.1
|
578
|
+
end
|
579
|
+
end
|
445
580
|
end
|
data/test/payjp/charge_test.rb
CHANGED
@@ -91,5 +91,17 @@ module Payjp
|
|
91
91
|
c.reauth
|
92
92
|
assert_equal expired_at.to_i, c.expired_at
|
93
93
|
end
|
94
|
+
|
95
|
+
should "charges should be three_d_secure finishable" do
|
96
|
+
@mock.expects(:get).never
|
97
|
+
@mock.expects(:post).with do |url, api_key, params|
|
98
|
+
url == "#{Payjp.api_base}/v1/charges/test_charge/tds_finish" && api_key.nil? && CGI.parse(params) == {}
|
99
|
+
end.once.returns(test_response({ :id => "test_charge", :paid => true, :captured => true }))
|
100
|
+
|
101
|
+
c = Payjp::Charge.new("test_charge")
|
102
|
+
c.tds_finish
|
103
|
+
assert c.paid
|
104
|
+
assert c.captured
|
105
|
+
end
|
94
106
|
end
|
95
107
|
end
|
File without changes
|
data/test/payjp/customer_test.rb
CHANGED
File without changes
|
data/test/payjp/event_test.rb
CHANGED
File without changes
|
File without changes
|
data/test/payjp/metadata_test.rb
CHANGED
File without changes
|
File without changes
|
data/test/payjp/plan_test.rb
CHANGED
File without changes
|
File without changes
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Payjp
|
4
|
+
class TenantTest < Test::Unit::TestCase
|
5
|
+
should "tenants should be listable" do
|
6
|
+
@mock.expects(:get).once.returns(test_response(test_tenant_array))
|
7
|
+
c = Payjp::Tenant.all.data
|
8
|
+
assert c.is_a? Array
|
9
|
+
assert c[0].is_a? Payjp::Tenant
|
10
|
+
end
|
11
|
+
|
12
|
+
should "tenants should be deletable" do
|
13
|
+
@mock.expects(:delete).once.returns(test_response(test_tenant))
|
14
|
+
c = Payjp::Tenant.new("test_tenant")
|
15
|
+
c.delete
|
16
|
+
end
|
17
|
+
|
18
|
+
should "tenants should be updateable" do
|
19
|
+
@mock.expects(:get).once.returns(test_response(test_tenant({ :name => "foo" })))
|
20
|
+
@mock.expects(:post).once.returns(test_response(test_tenant({ :name => "bar" })))
|
21
|
+
c = Payjp::Tenant.new("test_tenant").refresh
|
22
|
+
assert_equal "foo", c.name
|
23
|
+
c.name = "bar"
|
24
|
+
c.save
|
25
|
+
assert_equal "bar", c.name
|
26
|
+
end
|
27
|
+
|
28
|
+
should "create should return a new tenant" do
|
29
|
+
@mock.expects(:post).once.returns(test_response(test_tenant(:id => 'test_tenant1')))
|
30
|
+
c = Payjp::Tenant.create(:id => 'test_tenant1')
|
31
|
+
assert_equal "test_tenant1", c.id
|
32
|
+
end
|
33
|
+
|
34
|
+
should "create_application_urls should be callable" do
|
35
|
+
@mock.expects(:get).never
|
36
|
+
@mock.expects(:post).once.returns(test_response({ :object => "application_url", :url => 'https://pay.jp/_/applications/start/c24368137e384aa9xxxxxxxxxxxxxxxx', :expires => 1476676539 }))
|
37
|
+
c = Payjp::Tenant.new('test_tenant')
|
38
|
+
response = c.create_application_urls()
|
39
|
+
assert_equal response[:url], 'https://pay.jp/_/applications/start/c24368137e384aa9xxxxxxxxxxxxxxxx'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/test/payjp/token_test.rb
CHANGED
File without changes
|
data/test/payjp/transfer_test.rb
CHANGED
File without changes
|
data/test/payjp/util_test.rb
CHANGED
File without changes
|
data/test/test_data.rb
CHANGED
@@ -250,6 +250,35 @@ module Payjp
|
|
250
250
|
}
|
251
251
|
end
|
252
252
|
|
253
|
+
def test_tenant(params = {})
|
254
|
+
{
|
255
|
+
:created => 1433127983,
|
256
|
+
:name => "test",
|
257
|
+
:id => "test",
|
258
|
+
:livemode => false,
|
259
|
+
:metadata => nil,
|
260
|
+
:object => "tenant",
|
261
|
+
:platform_fee_rate => "10.15",
|
262
|
+
:payjp_fee_included => false,
|
263
|
+
:minimum_transfer_amount => 1000,
|
264
|
+
:bank_account_number => "0001000",
|
265
|
+
:bank_branch_code => "000",
|
266
|
+
:bank_code => "0000",
|
267
|
+
:bank_account_holder_name => "ヤマダ タロウ",
|
268
|
+
:bank_account_type => "普通",
|
269
|
+
:bank_account_status => "pending"
|
270
|
+
}.merge(params)
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_tenant_array
|
274
|
+
{
|
275
|
+
:count => 3,
|
276
|
+
:data => [test_tenant, test_tenant, test_tenant],
|
277
|
+
:object => 'list',
|
278
|
+
:url => '/v1/tenants'
|
279
|
+
}
|
280
|
+
end
|
281
|
+
|
253
282
|
def test_invalid_api_key_error
|
254
283
|
{
|
255
284
|
:error => {
|
@@ -287,5 +316,14 @@ module Payjp
|
|
287
316
|
}
|
288
317
|
}
|
289
318
|
end
|
319
|
+
|
320
|
+
def test_over_capacity_error
|
321
|
+
{
|
322
|
+
:error => {
|
323
|
+
:code => "over_capacity",
|
324
|
+
:type => "api_error"
|
325
|
+
}
|
326
|
+
}
|
327
|
+
end
|
290
328
|
end
|
291
329
|
end
|
data/test/test_helper.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,103 +1,103 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: payjp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PAY.JP
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mocha
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.2.1
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.2.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activesupport
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - <
|
45
|
+
- - "<"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '5.0'
|
48
|
-
- - ~>
|
48
|
+
- - "~>"
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: 4.2.7
|
51
51
|
type: :development
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
|
-
- - <
|
55
|
+
- - "<"
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '5.0'
|
58
|
-
- - ~>
|
58
|
+
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: 4.2.7
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: test-unit
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- - ~>
|
65
|
+
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: 3.2.2
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- - ~>
|
72
|
+
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: 3.2.2
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: rake
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- - ~>
|
79
|
+
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: 11.3.0
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- - ~>
|
86
|
+
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: 11.3.0
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: bundler
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- -
|
93
|
+
- - ">="
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: 1.7.6
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- -
|
100
|
+
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: 1.7.6
|
103
103
|
description: PAY.JP makes it way easier and less expensive to accept payments.
|
@@ -107,15 +107,15 @@ executables: []
|
|
107
107
|
extensions: []
|
108
108
|
extra_rdoc_files: []
|
109
109
|
files:
|
110
|
-
- .
|
111
|
-
- .
|
112
|
-
- .
|
113
|
-
- .
|
110
|
+
- ".github/workflows/test.yml"
|
111
|
+
- ".gitignore"
|
112
|
+
- ".rubocop.yml"
|
113
|
+
- ".rubocop_todo.yml"
|
114
114
|
- CONTRIBUTORS
|
115
115
|
- Gemfile
|
116
116
|
- History.txt
|
117
117
|
- LICENSE
|
118
|
-
- README.
|
118
|
+
- README.md
|
119
119
|
- Rakefile
|
120
120
|
- lib/payjp.rb
|
121
121
|
- lib/payjp/account.rb
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- lib/payjp/payjp_object.rb
|
140
140
|
- lib/payjp/plan.rb
|
141
141
|
- lib/payjp/subscription.rb
|
142
|
+
- lib/payjp/tenant.rb
|
142
143
|
- lib/payjp/token.rb
|
143
144
|
- lib/payjp/transfer.rb
|
144
145
|
- lib/payjp/util.rb
|
@@ -155,6 +156,7 @@ files:
|
|
155
156
|
- test/payjp/payjp_object_test.rb
|
156
157
|
- test/payjp/plan_test.rb
|
157
158
|
- test/payjp/subscription_test.rb
|
159
|
+
- test/payjp/tenant_test.rb
|
158
160
|
- test/payjp/token_test.rb
|
159
161
|
- test/payjp/transfer_test.rb
|
160
162
|
- test/payjp/util_test.rb
|
@@ -163,24 +165,24 @@ files:
|
|
163
165
|
homepage: https://pay.jp
|
164
166
|
licenses:
|
165
167
|
- MIT
|
166
|
-
metadata:
|
168
|
+
metadata:
|
169
|
+
source_code_uri: https://github.com/payjp/payjp-ruby
|
167
170
|
post_install_message:
|
168
171
|
rdoc_options: []
|
169
172
|
require_paths:
|
170
173
|
- lib
|
171
174
|
required_ruby_version: !ruby/object:Gem::Requirement
|
172
175
|
requirements:
|
173
|
-
- -
|
176
|
+
- - ">="
|
174
177
|
- !ruby/object:Gem::Version
|
175
178
|
version: '0'
|
176
179
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
180
|
requirements:
|
178
|
-
- -
|
181
|
+
- - ">="
|
179
182
|
- !ruby/object:Gem::Version
|
180
183
|
version: '0'
|
181
184
|
requirements: []
|
182
|
-
|
183
|
-
rubygems_version: 2.0.14.1
|
185
|
+
rubygems_version: 3.1.2
|
184
186
|
signing_key:
|
185
187
|
specification_version: 4
|
186
188
|
summary: Ruby bindings for the Payjp API
|
@@ -196,6 +198,7 @@ test_files:
|
|
196
198
|
- test/payjp/payjp_object_test.rb
|
197
199
|
- test/payjp/plan_test.rb
|
198
200
|
- test/payjp/subscription_test.rb
|
201
|
+
- test/payjp/tenant_test.rb
|
199
202
|
- test/payjp/token_test.rb
|
200
203
|
- test/payjp/transfer_test.rb
|
201
204
|
- test/payjp/util_test.rb
|
data/.travis.yml
DELETED
data/README.rdoc
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
= PAY.JP for Ruby
|
2
|
-
|
3
|
-
== Documentation
|
4
|
-
|
5
|
-
{PAY.JP API Docs}[https://pay.jp/docs/api/]
|
6
|
-
|
7
|
-
== Installation
|
8
|
-
|
9
|
-
You don't need this source code unless you want to modify the gem. If
|
10
|
-
you just want to use the Payjp Ruby bindings, you should run:
|
11
|
-
|
12
|
-
gem install payjp
|
13
|
-
|
14
|
-
If you want to build the gem from source:
|
15
|
-
|
16
|
-
gem build payjp.gemspec
|
17
|
-
|
18
|
-
== Requirements
|
19
|
-
|
20
|
-
* Ruby 2.0.0 or above.
|
21
|
-
|
22
|
-
* rest-client
|
23
|
-
|
24
|
-
== Bundler
|
25
|
-
|
26
|
-
If you are installing via bundler, you should be sure to use the https
|
27
|
-
rubygems source in your Gemfile, as any gems fetched over http could potentially be
|
28
|
-
compromised in transit and alter the code of gems fetched securely over https:
|
29
|
-
|
30
|
-
source 'https://rubygems.org'
|
31
|
-
|
32
|
-
gem 'rails'
|
33
|
-
gem 'payjp'
|
34
|
-
|
35
|
-
== Development
|
36
|
-
|
37
|
-
Test cases can be run with: `bundle exec rake test`
|