payjp_mock 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/payjp_mock/ext/hash.rb +10 -0
- data/lib/payjp_mock/request.rb +3 -1
- data/lib/payjp_mock/request_builder.rb +50 -24
- data/lib/payjp_mock/response/error/api_error.rb +3 -2
- data/lib/payjp_mock/response/resource/account.rb +14 -12
- data/lib/payjp_mock/response/resource/base.rb +13 -1
- data/lib/payjp_mock/response/resource/card.rb +40 -27
- data/lib/payjp_mock/response/resource/charge.rb +52 -28
- data/lib/payjp_mock/response/resource/customer.rb +36 -20
- data/lib/payjp_mock/response/resource/event.rb +16 -14
- data/lib/payjp_mock/response/resource/merchant.rb +28 -26
- data/lib/payjp_mock/response/resource/plan.rb +20 -18
- data/lib/payjp_mock/response/resource/subscription.rb +40 -26
- data/lib/payjp_mock/response/resource/token.rb +15 -13
- data/lib/payjp_mock/response/resource/transfer.rb +44 -42
- data/lib/payjp_mock/version.rb +1 -1
- data/lib/payjp_mock/webmock_wrapper.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ed8389c900aa4a05ea613665fb45518dbeb7997
|
4
|
+
data.tar.gz: 580f0e745a5ac4a26fdbc5bc950252702b54af0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64b46adbd7eda489d58e8c484cb3550473ccda45fe6a2f6f610a0181f368e8e3a351870015399f33ee5edc5d23d3495e3c3c3f8a2cd6fba819f2c5c549cabca8
|
7
|
+
data.tar.gz: e852d40d5c61bc00dbac628e055c1eba8daed72d12b190a156888480f077745b9c4bed4d3598f419e6701cd62a1aa108ffbd67dee5f510804d065fc707a3dd25
|
data/README.md
CHANGED
@@ -37,7 +37,7 @@ require 'payjp'
|
|
37
37
|
|
38
38
|
specify do
|
39
39
|
# Stubbing charge creation
|
40
|
-
payjp_stub(:charges, :create)
|
40
|
+
payjp_stub(:charges, :create, params: { amount: 3500, card: 'tok_xxxxx', currency: 'jpy' })
|
41
41
|
Payjp::Charge.create(amount: 3500, card: 'tok_xxxxx', currency: 'jpy')
|
42
42
|
|
43
43
|
# Stubbing nested resource operations such as customer's card list retrival
|
data/lib/payjp_mock/ext/hash.rb
CHANGED
@@ -4,6 +4,16 @@ module PayjpMock::Ext
|
|
4
4
|
def symbolize_keys
|
5
5
|
each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
|
6
6
|
end
|
7
|
+
|
8
|
+
def deep_transform_values(&block)
|
9
|
+
each_with_object({}) do |(k, v), h|
|
10
|
+
h[k] = v.is_a?(::Hash) ? v.deep_transform_values(&block) : block.call(v)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def except(*keys)
|
15
|
+
each_with_object({}) { |(k, v), h| h[k] = v unless keys.include?(k) }
|
16
|
+
end
|
7
17
|
end
|
8
18
|
end
|
9
19
|
end
|
data/lib/payjp_mock/request.rb
CHANGED
@@ -9,14 +9,16 @@ class PayjpMock::Request
|
|
9
9
|
API_VERSION = 'v1'.freeze
|
10
10
|
API_BASE = "https://#{API_HOST}/#{API_VERSION}".freeze
|
11
11
|
|
12
|
-
def initialize(method, path_pattern, response)
|
12
|
+
def initialize(method, path_pattern, params, response)
|
13
13
|
@method = method
|
14
14
|
@url = Addressable::Template.new(API_BASE + path_pattern)
|
15
|
+
@params = params.deep_transform_values(&:to_s)
|
15
16
|
@response = response
|
16
17
|
end
|
17
18
|
|
18
19
|
def stub
|
19
20
|
stub_request(@method, @url)
|
21
|
+
.with(body: @params)
|
20
22
|
.to_return(body: @response.body, status: @response.status, exception: @response.exception)
|
21
23
|
|
22
24
|
JSON.parse(@response.body || '{}').symbolize_keys
|
@@ -3,9 +3,10 @@ module PayjpMock
|
|
3
3
|
include Util
|
4
4
|
using Ext::Hash
|
5
5
|
|
6
|
-
def initialize(resource, operation, error)
|
6
|
+
def initialize(resource, operation, params, error)
|
7
7
|
@resource = resource.is_a?(Hash) ? resource.symbolize_keys : resource.to_sym
|
8
8
|
@operation = operation.to_sym
|
9
|
+
@params = params.symbolize_keys
|
9
10
|
@error = error&.to_sym
|
10
11
|
end
|
11
12
|
|
@@ -15,27 +16,30 @@ module PayjpMock
|
|
15
16
|
when :charge, :charges
|
16
17
|
case @operation
|
17
18
|
when :create
|
18
|
-
[:post, '/charges', Response::Resource::Charge.new]
|
19
|
+
[:post, '/charges', Response::Resource::Charge.new(@params)]
|
19
20
|
when :retrieve
|
20
21
|
[:get, '/charges/{id}', Response::Resource::Charge.new]
|
21
22
|
when :save
|
22
|
-
[:post, '/charges/{id}', Response::Resource::Charge.new]
|
23
|
+
[:post, '/charges/{id}', Response::Resource::Charge.new(@params)]
|
23
24
|
when :refund
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
warn('parameter `amount` cannot be specified yet') if @params[:amount]
|
26
|
+
|
27
|
+
charge = Response::Resource::Charge.new(@params.except(:amount))
|
28
|
+
charge.set(amount_refunded: charge.attributes[:amount], refunded: true)
|
29
|
+
|
29
30
|
[:post, '/charges/{id}/refund', charge]
|
30
31
|
when :reauth
|
31
32
|
charge = Response::Resource::Charge.new(
|
32
33
|
captured: false,
|
33
34
|
captured_at: nil,
|
34
|
-
|
35
|
+
expiry_days: @params[:expiry_days] || 7
|
35
36
|
)
|
36
37
|
[:post, '/charges/{id}/reauth', charge]
|
37
38
|
when :capture
|
38
|
-
|
39
|
+
warn('parameter `amount` cannot be specified yet') if @params[:amount]
|
40
|
+
|
41
|
+
charge = Response::Resource::Charge.new(captured: true, captured_at: Time.now.to_i)
|
42
|
+
[:post, '/charges/{id}/capture', charge]
|
39
43
|
when :all
|
40
44
|
list = Response::List.new('/charges') { Response::Resource::Charge.new }
|
41
45
|
[:get, '/charges', list]
|
@@ -45,11 +49,11 @@ module PayjpMock
|
|
45
49
|
when :customer, :customers
|
46
50
|
case @operation
|
47
51
|
when :create
|
48
|
-
[:post, '/customers', Response::Resource::Customer.new]
|
52
|
+
[:post, '/customers', Response::Resource::Customer.new(@params)]
|
49
53
|
when :retrieve
|
50
54
|
[:get, '/customers/{id}', Response::Resource::Customer.new]
|
51
55
|
when :save
|
52
|
-
[:post, '/customers/{id}', Response::Resource::Customer.new]
|
56
|
+
[:post, '/customers/{id}', Response::Resource::Customer.new(@params)]
|
53
57
|
when :delete
|
54
58
|
cus_id = generate_resource_id(Response::Resource::Customer::PREFIX)
|
55
59
|
[:delete, '/customers/{id}', Response::Deleted.new(cus_id)]
|
@@ -62,11 +66,11 @@ module PayjpMock
|
|
62
66
|
when { customer: :card }, { customer: :cards }, { customers: :card }, { customers: :cards }
|
63
67
|
case @operation
|
64
68
|
when :create
|
65
|
-
[:post, '/customers/{customer_id}/cards', Response::Resource::Card.new]
|
69
|
+
[:post, '/customers/{customer_id}/cards', Response::Resource::Card.new(@params)]
|
66
70
|
when :retrieve
|
67
71
|
[:get, '/customers/{customer_id}/cards/{id}', Response::Resource::Card.new]
|
68
72
|
when :save
|
69
|
-
[:post, '/customers/{customer_id}/cards/{id}', Response::Resource::Card.new]
|
73
|
+
[:post, '/customers/{customer_id}/cards/{id}', Response::Resource::Card.new(@params)]
|
70
74
|
when :delete
|
71
75
|
car_id = generate_resource_id(Response::Resource::Card::PREFIX)
|
72
76
|
[:delete, '/customers/{customer_id}/cards/{id}', Response::Deleted.new(car_id)]
|
@@ -80,11 +84,11 @@ module PayjpMock
|
|
80
84
|
when :plan, :plans
|
81
85
|
case @operation
|
82
86
|
when :create
|
83
|
-
[:post, '/plans', Response::Resource::Plan.new]
|
87
|
+
[:post, '/plans', Response::Resource::Plan.new(@params)]
|
84
88
|
when :retrieve
|
85
89
|
[:get, '/plans/{id}', Response::Resource::Plan.new]
|
86
90
|
when :save
|
87
|
-
[:post, '/plans/{id}', Response::Resource::Plan.new]
|
91
|
+
[:post, '/plans/{id}', Response::Resource::Plan.new(@params)]
|
88
92
|
when :delete
|
89
93
|
pln_id = generate_resource_id(Response::Resource::Plan::PREFIX)
|
90
94
|
[:delete, '/plans/{id}', Response::Deleted.new(pln_id)]
|
@@ -97,11 +101,25 @@ module PayjpMock
|
|
97
101
|
when :subscription, :subscriptions
|
98
102
|
case @operation
|
99
103
|
when :create
|
100
|
-
|
104
|
+
subscription =
|
105
|
+
if @params[:trial_end] == 'now'
|
106
|
+
warn('parameter `trial_end` cannot be set to `now` yet')
|
107
|
+
Response::Resource::Subscription.new(@params.except(:trial_end))
|
108
|
+
else
|
109
|
+
Response::Resource::Subscription.new(@params)
|
110
|
+
end
|
111
|
+
[:post, '/subscriptions', subscription]
|
101
112
|
when :retrieve
|
102
113
|
[:get, '/subscriptions/{id}', Response::Resource::Subscription.new]
|
103
114
|
when :save
|
104
|
-
|
115
|
+
subscription =
|
116
|
+
if @params[:trial_end] == 'now'
|
117
|
+
warn('parameter `trial_end` cannot be set to `now` yet')
|
118
|
+
Response::Resource::Subscription.new(@params.except(:trial_end))
|
119
|
+
else
|
120
|
+
Response::Resource::Subscription.new(@params)
|
121
|
+
end
|
122
|
+
[:post, '/subscriptions/{id}', subscription]
|
105
123
|
when :pause
|
106
124
|
subscription = Response::Resource::Subscription.new(
|
107
125
|
status: 'paused',
|
@@ -109,10 +127,18 @@ module PayjpMock
|
|
109
127
|
)
|
110
128
|
[:post, '/subscriptions/{id}/pause', subscription]
|
111
129
|
when :resume
|
112
|
-
subscription =
|
113
|
-
|
114
|
-
|
115
|
-
|
130
|
+
subscription =
|
131
|
+
case @params[:trial_end]
|
132
|
+
when nil
|
133
|
+
Response::Resource::Subscription.new(@params).set(status: 'active')
|
134
|
+
when 'now'
|
135
|
+
warn('parameter `trial_end` cannot be set to `now` yet')
|
136
|
+
Response::Resource::Subscription.new(@params.except(:trial_end)).set(status: 'active')
|
137
|
+
else
|
138
|
+
Response::Resource::Subscription.new(@params)
|
139
|
+
end
|
140
|
+
subscription.set(resumed_at: Time.now.to_i)
|
141
|
+
|
116
142
|
[:post, '/subscriptions/{id}/resume', subscription]
|
117
143
|
when :cancel
|
118
144
|
subscription = Response::Resource::Subscription.new(
|
@@ -132,7 +158,7 @@ module PayjpMock
|
|
132
158
|
when :token, :tokens
|
133
159
|
case @operation
|
134
160
|
when :create
|
135
|
-
[:post, '/tokens', Response::Resource::Token.new]
|
161
|
+
[:post, '/tokens', Response::Resource::Token.new(@params)]
|
136
162
|
when :retrieve
|
137
163
|
[:get, '/tokens/{id}', Response::Resource::Token.new]
|
138
164
|
else
|
@@ -193,7 +219,7 @@ module PayjpMock
|
|
193
219
|
else
|
194
220
|
success_resp
|
195
221
|
end
|
196
|
-
Request.new(method, path_pattern, response)
|
222
|
+
Request.new(method, path_pattern, @params, response)
|
197
223
|
end
|
198
224
|
|
199
225
|
UnknownResource = Class.new(StandardError)
|
@@ -2,14 +2,15 @@ module PayjpMock::Response::Error
|
|
2
2
|
class ApiError < Base
|
3
3
|
def default_attributes
|
4
4
|
{
|
5
|
-
|
5
|
+
code: 'under_maintenance',
|
6
|
+
message: 'PAY.JP is currently undergoing maintenance. Please try again later.',
|
6
7
|
status: status,
|
7
8
|
type: 'server_error'
|
8
9
|
}
|
9
10
|
end
|
10
11
|
|
11
12
|
def status
|
12
|
-
|
13
|
+
503
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
@@ -1,16 +1,18 @@
|
|
1
|
-
module PayjpMock
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module PayjpMock
|
2
|
+
module Response::Resource
|
3
|
+
class Account < Base
|
4
|
+
PREFIX = 'acct'.freeze
|
5
|
+
OBJECT = 'account'.freeze
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
def default_attributes
|
8
|
+
{
|
9
|
+
created: Time.now.to_i,
|
10
|
+
email: 'liveaccount@example.com',
|
11
|
+
id: generate_resource_id(PREFIX),
|
12
|
+
merchant: Merchant.new.to_h,
|
13
|
+
object: OBJECT
|
14
|
+
}
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
@@ -4,7 +4,19 @@ module PayjpMock
|
|
4
4
|
using Ext::Hash
|
5
5
|
|
6
6
|
def initialize(attributes = {})
|
7
|
-
@attributes = default_attributes
|
7
|
+
@attributes = default_attributes
|
8
|
+
set(attributes.symbolize_keys)
|
9
|
+
end
|
10
|
+
|
11
|
+
def set(attributes)
|
12
|
+
attributes.each do |k, v|
|
13
|
+
@attributes.merge!(canonicalize(k, v))
|
14
|
+
end
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def canonicalize(key, value)
|
19
|
+
{ key => value }
|
8
20
|
end
|
9
21
|
|
10
22
|
def status
|
@@ -1,31 +1,44 @@
|
|
1
|
-
module PayjpMock
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module PayjpMock
|
2
|
+
module Response::Resource
|
3
|
+
class Card < Base
|
4
|
+
PREFIX = 'car'.freeze
|
5
|
+
OBJECT = 'card'.freeze
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
7
|
+
def default_attributes
|
8
|
+
{
|
9
|
+
address_city: nil,
|
10
|
+
address_line1: nil,
|
11
|
+
address_line2: nil,
|
12
|
+
address_state: nil,
|
13
|
+
address_zip: nil,
|
14
|
+
address_zip_check: 'unchecked',
|
15
|
+
brand: 'Visa',
|
16
|
+
country: nil,
|
17
|
+
created: Time.now.to_i,
|
18
|
+
customer: generate_resource_id(Customer::PREFIX),
|
19
|
+
cvc_check: 'unchecked',
|
20
|
+
exp_month: 2,
|
21
|
+
exp_year: 2020,
|
22
|
+
fingerprint: generate_fingerprint,
|
23
|
+
id: generate_resource_id(PREFIX),
|
24
|
+
last4: '4242',
|
25
|
+
livemode: false,
|
26
|
+
metadata: nil,
|
27
|
+
name: nil,
|
28
|
+
object: OBJECT
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def canonicalize(key, value)
|
33
|
+
case key
|
34
|
+
when :number
|
35
|
+
{ last4: value[-4..-1] }
|
36
|
+
when :cvc
|
37
|
+
{}
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
29
42
|
end
|
30
43
|
end
|
31
44
|
end
|
@@ -1,33 +1,57 @@
|
|
1
|
-
module PayjpMock
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module PayjpMock
|
2
|
+
module Response::Resource
|
3
|
+
class Charge < Base
|
4
|
+
using Ext::Integer
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
PREFIX = 'ch'.freeze
|
7
|
+
OBJECT = 'charge'.freeze
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
9
|
+
def default_attributes
|
10
|
+
now = Time.now.to_i
|
11
|
+
|
12
|
+
{
|
13
|
+
amount: 3500,
|
14
|
+
amount_refunded: 0,
|
15
|
+
captured: true,
|
16
|
+
captured_at: now,
|
17
|
+
card: Card.new.to_h,
|
18
|
+
created: now,
|
19
|
+
currency: 'jpy',
|
20
|
+
customer: nil,
|
21
|
+
description: nil,
|
22
|
+
expired_at: nil,
|
23
|
+
failure_code: nil,
|
24
|
+
failure_message: nil,
|
25
|
+
id: generate_resource_id(PREFIX),
|
26
|
+
livemode: false,
|
27
|
+
metadata: nil,
|
28
|
+
object: OBJECT,
|
29
|
+
paid: true,
|
30
|
+
refund_reason: nil,
|
31
|
+
refunded: false,
|
32
|
+
subscription: nil
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def canonicalize(key, value)
|
37
|
+
case key
|
38
|
+
when :card
|
39
|
+
{ card: Card.new(value.is_a?(Hash)? value : {}).to_h }
|
40
|
+
when :capture
|
41
|
+
{ captured: value, captured_at: value ? Time.now.to_i : nil }
|
42
|
+
when :expiry_days
|
43
|
+
expired_at =
|
44
|
+
if value == 60
|
45
|
+
expired_date = Time.now + 59.days
|
46
|
+
Time.local(expired_date.year, expired_date.month, expired_date.day, 23, 59, 59)
|
47
|
+
else
|
48
|
+
Time.now + value.days
|
49
|
+
end
|
50
|
+
{ expired_at: expired_at.to_i }
|
51
|
+
else
|
52
|
+
super
|
53
|
+
end
|
54
|
+
end
|
31
55
|
end
|
32
56
|
end
|
33
57
|
end
|
@@ -1,26 +1,42 @@
|
|
1
|
-
module PayjpMock
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module PayjpMock
|
2
|
+
module Response::Resource
|
3
|
+
class Customer < Base
|
4
|
+
PREFIX = 'cus'.freeze
|
5
|
+
OBJECT = 'customer'.freeze
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
def default_attributes
|
8
|
+
id = generate_resource_id(PREFIX)
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
10
|
+
{
|
11
|
+
cards: Response::List.new("/customers/#{id}/cards").to_h,
|
12
|
+
created: Time.now.to_i,
|
13
|
+
default_card: nil,
|
14
|
+
description: 'test',
|
15
|
+
email: nil,
|
16
|
+
id: id,
|
17
|
+
livemode: false,
|
18
|
+
metadata: nil,
|
19
|
+
object: OBJECT,
|
20
|
+
subscriptions: Response::List.new("/customers/#{id}/subscriptions").to_h
|
21
|
+
}
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
+
def canonicalize(key, value)
|
25
|
+
case key
|
26
|
+
when :card
|
27
|
+
cards = Response::List.new("/customers/#{@attributes[:id]}/cards", count: 1) do
|
28
|
+
Card.new(value.is_a?(Hash) ? value : {})
|
29
|
+
end
|
30
|
+
{ cards: cards.to_h, default_card: cards.attributes[:data][0][:id] }
|
31
|
+
when :default_card
|
32
|
+
cards = Response::List.new("/customers/#{@attributes[:id]}/cards", count: 1) do
|
33
|
+
Card.new(id: value)
|
34
|
+
end
|
35
|
+
{ cards: cards.to_h, default_card: value }
|
36
|
+
else
|
37
|
+
super
|
38
|
+
end
|
39
|
+
end
|
24
40
|
end
|
25
41
|
end
|
26
42
|
end
|
@@ -1,18 +1,20 @@
|
|
1
|
-
module PayjpMock
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module PayjpMock
|
2
|
+
module Response::Resource
|
3
|
+
class Event < Base
|
4
|
+
PREFIX = 'evnt'.freeze
|
5
|
+
OBJECT = 'event'.freeze
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
def default_attributes
|
8
|
+
{
|
9
|
+
created: Time.now.to_i,
|
10
|
+
data: Customer.new.to_h,
|
11
|
+
id: generate_resource_id(PREFIX),
|
12
|
+
livemode: false,
|
13
|
+
object: OBJECT,
|
14
|
+
pending_webhooks: 1,
|
15
|
+
type: 'customer.updated'
|
16
|
+
}
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
@@ -1,30 +1,32 @@
|
|
1
|
-
module PayjpMock
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module PayjpMock
|
2
|
+
module Response::Resource
|
3
|
+
class Merchant < Base
|
4
|
+
PREFIX = 'acct_mch'.freeze
|
5
|
+
OBJECT = 'merchant'.freeze
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
7
|
+
def default_attributes
|
8
|
+
{
|
9
|
+
bank_enabled: false,
|
10
|
+
brands_accepted: ['Visa', 'MasterCard', 'JCB', 'American Express', 'Diners Club', 'Discover'],
|
11
|
+
business_type: nil,
|
12
|
+
charge_type: nil,
|
13
|
+
contact_phone: nil,
|
14
|
+
country: 'JP',
|
15
|
+
created: Time.now.to_i,
|
16
|
+
currencies_supported: ['jpy'],
|
17
|
+
default_currency: 'jpy',
|
18
|
+
details_submitted: false,
|
19
|
+
id: generate_resource_id(PREFIX),
|
20
|
+
livemode_activated_at: nil,
|
21
|
+
livemode_enabled: false,
|
22
|
+
object: OBJECT,
|
23
|
+
product_detail: nil,
|
24
|
+
product_name: nil,
|
25
|
+
product_type: nil,
|
26
|
+
site_published: nil,
|
27
|
+
url: nil
|
28
|
+
}
|
29
|
+
end
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
@@ -1,22 +1,24 @@
|
|
1
|
-
module PayjpMock
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module PayjpMock
|
2
|
+
module Response::Resource
|
3
|
+
class Plan < Base
|
4
|
+
PREFIX = 'pln'.freeze
|
5
|
+
OBJECT = 'plan'.freeze
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
7
|
+
def default_attributes
|
8
|
+
{
|
9
|
+
amount: 500,
|
10
|
+
billing_day: nil,
|
11
|
+
created: Time.now.to_i,
|
12
|
+
currency: 'jpy',
|
13
|
+
id: generate_resource_id(PREFIX),
|
14
|
+
interval: 'month',
|
15
|
+
livemode: false,
|
16
|
+
metadata: nil,
|
17
|
+
name: nil,
|
18
|
+
object: OBJECT,
|
19
|
+
trial_days: 30
|
20
|
+
}
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -1,32 +1,46 @@
|
|
1
|
-
module PayjpMock
|
2
|
-
|
3
|
-
|
1
|
+
module PayjpMock
|
2
|
+
module Response::Resource
|
3
|
+
class Subscription < Base
|
4
|
+
using Ext::Integer
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
PREFIX = 'sub'.freeze
|
7
|
+
OBJECT = 'subscription'.freeze
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
def default_attributes
|
10
|
+
now = Time.now.to_i
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
12
|
+
{
|
13
|
+
canceled_at: nil,
|
14
|
+
created: now,
|
15
|
+
current_period_end: now + 15.days,
|
16
|
+
current_period_start: now - 15.days,
|
17
|
+
customer: generate_resource_id(Customer::PREFIX),
|
18
|
+
id: generate_resource_id(PREFIX),
|
19
|
+
livemode: false,
|
20
|
+
metadata: nil,
|
21
|
+
object: OBJECT,
|
22
|
+
paused_at: nil,
|
23
|
+
plan: Plan.new.to_h,
|
24
|
+
resumed_at: nil,
|
25
|
+
start: now - 15.days,
|
26
|
+
status: 'active',
|
27
|
+
trial_end: nil,
|
28
|
+
trial_start: nil,
|
29
|
+
prorate: false
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def canonicalize(key, value)
|
34
|
+
case key
|
35
|
+
when :plan
|
36
|
+
{ plan: Plan.new(id: value).to_h }
|
37
|
+
when :trial_end
|
38
|
+
now = Time.now.to_i
|
39
|
+
{ status: 'trial', trial_start: now - 10.days, trial_end: value }
|
40
|
+
else
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
30
44
|
end
|
31
45
|
end
|
32
46
|
end
|
@@ -1,17 +1,19 @@
|
|
1
|
-
module PayjpMock
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module PayjpMock
|
2
|
+
module Response::Resource
|
3
|
+
class Token < Base
|
4
|
+
PREFIX = 'tok'.freeze
|
5
|
+
OBJECT = 'token'.freeze
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
def default_attributes
|
8
|
+
{
|
9
|
+
card: Card.new.to_h,
|
10
|
+
created: Time.now.to_i,
|
11
|
+
id: generate_resource_id(PREFIX),
|
12
|
+
livemode: false,
|
13
|
+
object: OBJECT,
|
14
|
+
used: false
|
15
|
+
}
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
@@ -1,49 +1,51 @@
|
|
1
|
-
module PayjpMock
|
2
|
-
|
3
|
-
|
1
|
+
module PayjpMock
|
2
|
+
module Response::Resource
|
3
|
+
class Transfer < Base
|
4
|
+
using Ext::Integer
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
PREFIX = 'tr'.freeze
|
7
|
+
OBJECT = 'transfer'.freeze
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def default_attributes
|
10
|
+
id = generate_resource_id(PREFIX)
|
11
|
+
now = Time.now
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
charged_at = (now + 30.days).to_i
|
14
|
+
charges = Response::List.new("/transfers/#{id}/charges", count: 1) do
|
15
|
+
Charge.new(
|
16
|
+
amount: 1000,
|
17
|
+
captured_at: charged_at,
|
18
|
+
card: Card.new(created: charged_at).to_h,
|
19
|
+
created: charged_at
|
20
|
+
)
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
23
|
+
{
|
24
|
+
amount: 1000,
|
25
|
+
carried_balance: nil,
|
26
|
+
charges: charges.to_h,
|
27
|
+
created: now.to_i,
|
28
|
+
currency: 'jpy',
|
29
|
+
description: nil,
|
30
|
+
id: id,
|
31
|
+
livemode: false,
|
32
|
+
object: OBJECT,
|
33
|
+
scheduled_date: (now + 45.days).strftime('%Y-%m-%d'),
|
34
|
+
status: 'pending',
|
35
|
+
summary: {
|
36
|
+
charge_count: 1,
|
37
|
+
charge_fee: 0,
|
38
|
+
charge_gross: 1000,
|
39
|
+
net: 1000,
|
40
|
+
refund_amount: 0,
|
41
|
+
refund_count: 0
|
42
|
+
},
|
43
|
+
term_end: (now + 15.days).to_i,
|
44
|
+
term_start: now.to_i,
|
45
|
+
transfer_amount: nil,
|
46
|
+
transfer_date: nil
|
47
|
+
}
|
48
|
+
end
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
data/lib/payjp_mock/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module PayjpMock
|
2
2
|
module WebMockWrapper
|
3
|
-
def payjp_stub(resource, operation, error: nil)
|
4
|
-
builder = RequestBuilder.new(resource, operation, error)
|
3
|
+
def payjp_stub(resource, operation, params: {}, error: nil)
|
4
|
+
builder = RequestBuilder.new(resource, operation, params, error)
|
5
5
|
request = builder.build
|
6
6
|
request.stub
|
7
7
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: payjp_mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kirikiriyamama
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|