payjp_mock 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +75 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/payjp_mock/ext/hash.rb +7 -0
- data/lib/payjp_mock/ext/integer.rb +8 -0
- data/lib/payjp_mock/ext.rb +2 -0
- data/lib/payjp_mock/request.rb +21 -0
- data/lib/payjp_mock/request_builder.rb +206 -0
- data/lib/payjp_mock/response/base.rb +19 -0
- data/lib/payjp_mock/response/deleted.rb +15 -0
- data/lib/payjp_mock/response/error/api_connection_error.rb +18 -0
- data/lib/payjp_mock/response/error/api_error.rb +15 -0
- data/lib/payjp_mock/response/error/authentication_error.rb +15 -0
- data/lib/payjp_mock/response/error/base.rb +11 -0
- data/lib/payjp_mock/response/error/card_error.rb +17 -0
- data/lib/payjp_mock/response/error/invalid_request_error.rb +17 -0
- data/lib/payjp_mock/response/error.rb +9 -0
- data/lib/payjp_mock/response/list.rb +23 -0
- data/lib/payjp_mock/response/resource/account.rb +16 -0
- data/lib/payjp_mock/response/resource/base.rb +16 -0
- data/lib/payjp_mock/response/resource/card.rb +31 -0
- data/lib/payjp_mock/response/resource/charge.rb +33 -0
- data/lib/payjp_mock/response/resource/customer.rb +26 -0
- data/lib/payjp_mock/response/resource/event.rb +18 -0
- data/lib/payjp_mock/response/resource/merchant.rb +30 -0
- data/lib/payjp_mock/response/resource/plan.rb +22 -0
- data/lib/payjp_mock/response/resource/subscription.rb +30 -0
- data/lib/payjp_mock/response/resource/token.rb +17 -0
- data/lib/payjp_mock/response/resource/transfer.rb +47 -0
- data/lib/payjp_mock/response/resource.rb +14 -0
- data/lib/payjp_mock/response.rb +8 -0
- data/lib/payjp_mock/util.rb +11 -0
- data/lib/payjp_mock/version.rb +3 -0
- data/lib/payjp_mock/webmock_wrapper.rb +11 -0
- data/lib/payjp_mock.rb +10 -0
- data/payjp_mock.gemspec +31 -0
- metadata +170 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c3a8a7052de70b5670602d1769638f73427f18a2
|
4
|
+
data.tar.gz: 27ec5981df2d01b0a66664ae1376ec915326d9ff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b8cd9c8ace263a9a886a244dfb154d1d53d518fd975d7fd41feb2f8f5953bc8fb148e6e500c059fb83cb7b52be49a081c6b37f511e4a3cac02f7bb2899a8a2e8
|
7
|
+
data.tar.gz: 75c9e3a067e7c301dd128ee14137a2f755e4d54ce84e0e8c49578c80759b9218e16ab2d2c33876f2bf6cc50b0193a2d02ca4c4783e93b5904f3a8996e1e949de
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 kirikiriyamama
|
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,75 @@
|
|
1
|
+
# PayjpMock
|
2
|
+
|
3
|
+
A stubbing library for PAY.JP
|
4
|
+
|
5
|
+
This library creates PAY.JP API stubs and generates dummy responses. This is under development, so any incompatible change might happen.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'payjp_mock'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install payjp_mock
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Here's an example with RSpec:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# spec/spec_helper.rb
|
29
|
+
require 'payjp_mock'
|
30
|
+
|
31
|
+
RSpec.configure do |config|
|
32
|
+
config.include PayjpMock::WebMockWrapper
|
33
|
+
end
|
34
|
+
|
35
|
+
# Your spec file
|
36
|
+
require 'payjp'
|
37
|
+
|
38
|
+
specify do
|
39
|
+
# Stubbing charge creation
|
40
|
+
payjp_stub(:charges, :create)
|
41
|
+
Payjp::Charge.create(amount: 3500, card: 'tok_xxxxx', currency: 'jpy')
|
42
|
+
|
43
|
+
# Stubbing nested resources operation such as customer's card list retrival
|
44
|
+
payjp_stub(:customer, :retrival)
|
45
|
+
customer = Payjp::Customer.retrieve('cus_xxxxx')
|
46
|
+
|
47
|
+
payjp_stub({ customer: :cards }, :all)
|
48
|
+
customer.cards.all
|
49
|
+
|
50
|
+
# Stubbing error responses
|
51
|
+
payjp_stub({ customer: :cards }, :create, error: :invalid_request_error)
|
52
|
+
customer.cards.create #=> Raises a Payjp::InvalidRequestError
|
53
|
+
|
54
|
+
# snip
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
## Development
|
59
|
+
|
60
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
61
|
+
|
62
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kirikiriyamama/payjp_mock. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
67
|
+
|
68
|
+
## Thanks
|
69
|
+
|
70
|
+
[webpay/webpay-mock](https://github.com/webpay/webpay-mock): As an implementation reference
|
71
|
+
|
72
|
+
## License
|
73
|
+
|
74
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
75
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "payjp_mock"
|
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__)
|
data/bin/setup
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'addressable'
|
2
|
+
require 'webmock'
|
3
|
+
|
4
|
+
class PayjpMock::Request
|
5
|
+
include WebMock::API
|
6
|
+
|
7
|
+
API_HOST = 'api.pay.jp'.freeze
|
8
|
+
API_VERSION = 'v1'.freeze
|
9
|
+
API_BASE = "https://#{API_HOST}/#{API_VERSION}".freeze
|
10
|
+
|
11
|
+
def initialize(method, path_pattern, response)
|
12
|
+
@method = method
|
13
|
+
@url = Addressable::Template.new(API_BASE + path_pattern)
|
14
|
+
@response = response
|
15
|
+
end
|
16
|
+
|
17
|
+
def stub
|
18
|
+
stub_request(@method, @url)
|
19
|
+
.to_return(body: @response.body, status: @response.status, exception: @response.exception)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
require 'payjp_mock/ext/hash'
|
2
|
+
require 'payjp_mock/request'
|
3
|
+
require 'payjp_mock/response'
|
4
|
+
require 'payjp_mock/util'
|
5
|
+
|
6
|
+
module PayjpMock
|
7
|
+
class RequestBuilder
|
8
|
+
include Util
|
9
|
+
|
10
|
+
def initialize(resource, operation, error)
|
11
|
+
@resource = resource.is_a?(Hash) ? resource.symbolize_keys : resource.to_sym
|
12
|
+
@operation = operation.to_sym
|
13
|
+
@error = error&.to_sym
|
14
|
+
end
|
15
|
+
|
16
|
+
def build
|
17
|
+
method, path_pattern, success_resp =
|
18
|
+
case @resource
|
19
|
+
when :charge, :charges
|
20
|
+
case @operation
|
21
|
+
when :create
|
22
|
+
[:post, '/charges', Response::Resource::Charge.new]
|
23
|
+
when :retrieve
|
24
|
+
[:get, '/charges/{id}', Response::Resource::Charge.new]
|
25
|
+
when :save
|
26
|
+
[:post, '/charges/{id}', Response::Resource::Charge.new]
|
27
|
+
when :refund
|
28
|
+
charge = Response::Resource::Charge.new(
|
29
|
+
amount: 1000,
|
30
|
+
amount_refunded: 1000,
|
31
|
+
refunded: true
|
32
|
+
)
|
33
|
+
[:post, '/charges/{id}/refund', charge]
|
34
|
+
when :reauth
|
35
|
+
charge = Response::Resource::Charge.new(
|
36
|
+
captured: false,
|
37
|
+
captured_at: nil,
|
38
|
+
expired_at: Time.now.to_i + 7.days
|
39
|
+
)
|
40
|
+
[:post, '/charges/{id}/reauth', charge]
|
41
|
+
when :capture
|
42
|
+
[:post, '/charges/{id}/capture', Response::Resource::Charge.new(captured: true)]
|
43
|
+
when :all
|
44
|
+
list = Response::List.new('/charges') { Response::Resource::Charge.new }
|
45
|
+
[:get, '/charges', list]
|
46
|
+
else
|
47
|
+
raise UnknownOperation, @operation
|
48
|
+
end
|
49
|
+
when :customer, :customers
|
50
|
+
case @operation
|
51
|
+
when :create
|
52
|
+
[:post, '/customers', Response::Resource::Customer.new]
|
53
|
+
when :retrieve
|
54
|
+
[:get, '/customers/{id}', Response::Resource::Customer.new]
|
55
|
+
when :save
|
56
|
+
[:post, '/customers/{id}', Response::Resource::Customer.new]
|
57
|
+
when :delete
|
58
|
+
cus_id = generate_resource_id(Response::Resource::Customer::PREFIX)
|
59
|
+
[:delete, '/customers/{id}', Response::Deleted.new(cus_id)]
|
60
|
+
when :all
|
61
|
+
list = Response::List.new('/customers') { Response::Resource::Customer.new }
|
62
|
+
[:get, '/customers', list]
|
63
|
+
else
|
64
|
+
raise UnknownOperation, @operation
|
65
|
+
end
|
66
|
+
when { customer: :card }, { customer: :cards }, { customers: :card }, { customers: :cards }
|
67
|
+
case @operation
|
68
|
+
when :create
|
69
|
+
[:post, '/customers/{customer_id}/cards', Response::Resource::Card.new]
|
70
|
+
when :retrieve
|
71
|
+
[:get, '/customers/{customer_id}/cards/{id}', Response::Resource::Card.new]
|
72
|
+
when :save
|
73
|
+
[:post, '/customers/{customer_id}/cards/{id}', Response::Resource::Card.new]
|
74
|
+
when :delete
|
75
|
+
car_id = generate_resource_id(Response::Resource::Card::PREFIX)
|
76
|
+
[:delete, '/customers/{customer_id}/cards/{id}', Response::Deleted.new(car_id)]
|
77
|
+
when :all
|
78
|
+
cus_id = generate_resource_id(Response::Resource::Customer::PREFIX)
|
79
|
+
list = Response::List.new("/customres/#{cus_id}/cards") { Response::Resource::Card.new }
|
80
|
+
[:get, '/customers/{customer_id}/cards', list]
|
81
|
+
else
|
82
|
+
raise UnknownOperation, @operation
|
83
|
+
end
|
84
|
+
when :plan, :plans
|
85
|
+
case @operation
|
86
|
+
when :create
|
87
|
+
[:post, '/plans', Response::Resource::Plan.new]
|
88
|
+
when :retrieve
|
89
|
+
[:get, '/plans/{id}', Response::Resource::Plan.new]
|
90
|
+
when :save
|
91
|
+
[:post, '/plans/{id}', Response::Resource::Plan.new]
|
92
|
+
when :delete
|
93
|
+
pln_id = generate_resource_id(Response::Resource::Plan::PREFIX)
|
94
|
+
[:delete, '/plans/{id}', Response::Deleted.new(pln_id)]
|
95
|
+
when :all
|
96
|
+
list = Response::List.new('/plans') { Response::Resource::Plan.new }
|
97
|
+
[:get, '/plans', list]
|
98
|
+
else
|
99
|
+
raise UnknownOperation, @operation
|
100
|
+
end
|
101
|
+
when :subscription, :subscriptions
|
102
|
+
case @operation
|
103
|
+
when :create
|
104
|
+
[:post, '/subscriptions', Response::Resource::Subscription.new]
|
105
|
+
when :retrieve
|
106
|
+
[:get, '/subscriptions/{id}', Response::Resource::Subscription.new]
|
107
|
+
when :save
|
108
|
+
[:post, '/subscriptions/{id}', Response::Resource::Subscription.new]
|
109
|
+
when :pause
|
110
|
+
subscription = Response::Resource::Subscription.new(
|
111
|
+
status: 'paused',
|
112
|
+
paused_at: Time.now.to_i
|
113
|
+
)
|
114
|
+
[:post, '/subscriptions/{id}/pause', subscription]
|
115
|
+
when :resume
|
116
|
+
subscription = Response::Resource::Subscription.new(
|
117
|
+
status: 'active',
|
118
|
+
resumed_at: Time.now.to_i
|
119
|
+
)
|
120
|
+
[:post, '/subscriptions/{id}/resume', subscription]
|
121
|
+
when :cancel
|
122
|
+
subscription = Response::Resource::Subscription.new(
|
123
|
+
status: 'canceled',
|
124
|
+
canceled_at: Time.now.to_i
|
125
|
+
)
|
126
|
+
[:post, '/subscriptions/{id}/cancel', subscription]
|
127
|
+
when :delete
|
128
|
+
sub_id = generate_resource_id(Response::Resource::Subscription::PREFIX)
|
129
|
+
[:delete, '/subscriptions/{id}', Response::Deleted.new(sub_id)]
|
130
|
+
when :all
|
131
|
+
list = Response::List.new('/subscriptions') { Response::Resource::Subscription.new }
|
132
|
+
[:get, '/subscriptions', list]
|
133
|
+
else
|
134
|
+
raise UnknownOperation, @operation
|
135
|
+
end
|
136
|
+
when :token, :tokens
|
137
|
+
case @operation
|
138
|
+
when :create
|
139
|
+
[:post, '/tokens', Response::Resource::Token.new]
|
140
|
+
when :retrieve
|
141
|
+
[:get, '/tokens/{id}', Response::Resource::Token.new]
|
142
|
+
else
|
143
|
+
raise UnknownOperation, @operation
|
144
|
+
end
|
145
|
+
when :transfer, :transfers
|
146
|
+
case @operation
|
147
|
+
when :retrieve
|
148
|
+
[:get, '/transfers/{id}', Response::Resource::Transfer.new]
|
149
|
+
when :all
|
150
|
+
list = Response::List.new('/transfers') { Response::Resource::Transfer.new }
|
151
|
+
[:get, '/transfers', list]
|
152
|
+
else
|
153
|
+
raise UnknownOperation, @operation
|
154
|
+
end
|
155
|
+
when { transfer: :charge }, { transfer: :charges }, { transfers: :charge }, { transfers: :charges }
|
156
|
+
case @operation
|
157
|
+
when :all
|
158
|
+
tr_id = generate_resource_id(Response::Resource::Transfer::PREFIX)
|
159
|
+
list = Response::List.new("/transfers/#{tr_id}/charges") { Response::Resource::Charge.new }
|
160
|
+
[:get, '/transfers/{transfer_id}/charges', list]
|
161
|
+
else
|
162
|
+
raise UnknownOperation, @operation
|
163
|
+
end
|
164
|
+
when :event, :events
|
165
|
+
case @operation
|
166
|
+
when :retrieve
|
167
|
+
[:get, '/events/{id}', Response::Resource::Event.new]
|
168
|
+
when :all
|
169
|
+
list = Response::List.new('/events') { Response::Resource::Event.new }
|
170
|
+
[:get, '/events', list]
|
171
|
+
else
|
172
|
+
raise UnknownOperation, @operation
|
173
|
+
end
|
174
|
+
when :account, :accounts
|
175
|
+
case @operation
|
176
|
+
when :retrieve
|
177
|
+
[:get, '/accounts', Response::Resource::Account.new]
|
178
|
+
else
|
179
|
+
raise UnknownOperation, @operation
|
180
|
+
end
|
181
|
+
else
|
182
|
+
raise UnknownResource, @resource
|
183
|
+
end
|
184
|
+
|
185
|
+
response =
|
186
|
+
case @error
|
187
|
+
when :card_error
|
188
|
+
Response::Error::CardError.new
|
189
|
+
when :invalid_request_error
|
190
|
+
Response::Error::InvalidRequestError.new
|
191
|
+
when :authentication_error
|
192
|
+
Response::Error::AuthenticationError.new
|
193
|
+
when :api_connection_error
|
194
|
+
Response::Error::ApiConnectionError.new
|
195
|
+
when :api_error
|
196
|
+
Response::Error::ApiError.new
|
197
|
+
else
|
198
|
+
success_resp
|
199
|
+
end
|
200
|
+
Request.new(method, path_pattern, response)
|
201
|
+
end
|
202
|
+
|
203
|
+
UnknownResource = Class.new(StandardError)
|
204
|
+
UnknownOperation = Class.new(StandardError)
|
205
|
+
end
|
206
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PayjpMock::Response::Error
|
2
|
+
class AuthenticationError < Base
|
3
|
+
def default_attributes
|
4
|
+
{
|
5
|
+
message: 'Invalid API Key: sk_test_********************xxxx',
|
6
|
+
status: status,
|
7
|
+
type: 'auth_error'
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def status
|
12
|
+
401
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PayjpMock::Response::Error
|
2
|
+
class CardError < Base
|
3
|
+
def default_attributes
|
4
|
+
{
|
5
|
+
code: 'invalid_number',
|
6
|
+
message: 'Invalid card number',
|
7
|
+
param: 'card[number]',
|
8
|
+
status: status,
|
9
|
+
type: 'card_error'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def status
|
14
|
+
402
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PayjpMock::Response::Error
|
2
|
+
class InvalidRequestError < Base
|
3
|
+
def default_attributes
|
4
|
+
{
|
5
|
+
code: 'missing_param',
|
6
|
+
message: 'Missing required param to charge',
|
7
|
+
param: 'amount',
|
8
|
+
status: status,
|
9
|
+
type: 'client_error'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def status
|
14
|
+
400
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module PayjpMock::Response::Error
|
2
|
+
end
|
3
|
+
|
4
|
+
require 'payjp_mock/response/error/base'
|
5
|
+
require 'payjp_mock/response/error/card_error'
|
6
|
+
require 'payjp_mock/response/error/invalid_request_error'
|
7
|
+
require 'payjp_mock/response/error/authentication_error'
|
8
|
+
require 'payjp_mock/response/error/api_connection_error'
|
9
|
+
require 'payjp_mock/response/error/api_error'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PayjpMock::Response
|
2
|
+
class List < Base
|
3
|
+
OBJECT = 'list'.freeze
|
4
|
+
|
5
|
+
def initialize(path, count: 3)
|
6
|
+
@attributes = {
|
7
|
+
count: 0,
|
8
|
+
data: [],
|
9
|
+
has_more: false,
|
10
|
+
object: OBJECT,
|
11
|
+
url: "/#{PayjpMock::Request::API_VERSION}" + path
|
12
|
+
}
|
13
|
+
return unless block_given?
|
14
|
+
|
15
|
+
@attributes[:count] = count
|
16
|
+
@attributes[:data] = count.times.map { yield.to_h }
|
17
|
+
end
|
18
|
+
|
19
|
+
def status
|
20
|
+
200
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module PayjpMock::Response::Resource
|
2
|
+
class Account < Base
|
3
|
+
PREFIX = 'acct'.freeze
|
4
|
+
OBJECT = 'account'.freeze
|
5
|
+
|
6
|
+
def default_attributes
|
7
|
+
{
|
8
|
+
created: Time.now.to_i,
|
9
|
+
email: 'liveaccount@example.com',
|
10
|
+
id: generate_resource_id(PREFIX),
|
11
|
+
merchant: Merchant.new.to_h,
|
12
|
+
object: OBJECT
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'payjp_mock/ext'
|
2
|
+
require 'payjp_mock/util'
|
3
|
+
|
4
|
+
module PayjpMock
|
5
|
+
class Response::Resource::Base < Response::Base
|
6
|
+
include Util
|
7
|
+
|
8
|
+
def initialize(attributes = {})
|
9
|
+
@attributes = default_attributes.merge(attributes.symbolize_keys)
|
10
|
+
end
|
11
|
+
|
12
|
+
def status
|
13
|
+
200
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module PayjpMock::Response::Resource
|
2
|
+
class Card < Base
|
3
|
+
PREFIX = 'car'.freeze
|
4
|
+
OBJECT = 'card'.freeze
|
5
|
+
|
6
|
+
def default_attributes
|
7
|
+
{
|
8
|
+
address_city: nil,
|
9
|
+
address_line1: nil,
|
10
|
+
address_line2: nil,
|
11
|
+
address_state: nil,
|
12
|
+
address_zip: nil,
|
13
|
+
address_zip_check: 'unchecked',
|
14
|
+
brand: 'Visa',
|
15
|
+
country: nil,
|
16
|
+
created: Time.now.to_i,
|
17
|
+
customer: generate_resource_id(Customer::PREFIX),
|
18
|
+
cvc_check: 'unchecked',
|
19
|
+
exp_month: 2,
|
20
|
+
exp_year: 2020,
|
21
|
+
fingerprint: generate_fingerprint,
|
22
|
+
id: generate_resource_id(PREFIX),
|
23
|
+
last4: '4242',
|
24
|
+
livemode: false,
|
25
|
+
metadata: nil,
|
26
|
+
name: nil,
|
27
|
+
object: OBJECT
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module PayjpMock::Response::Resource
|
2
|
+
class Charge < Base
|
3
|
+
PREFIX = 'ch'.freeze
|
4
|
+
OBJECT = 'charge'.freeze
|
5
|
+
|
6
|
+
def default_attributes
|
7
|
+
now = Time.now.to_i
|
8
|
+
|
9
|
+
{
|
10
|
+
amount: 3500,
|
11
|
+
amount_refunded: 0,
|
12
|
+
captured: true,
|
13
|
+
captured_at: now,
|
14
|
+
card: Card.new.to_h,
|
15
|
+
created: now,
|
16
|
+
currency: 'jpy',
|
17
|
+
customer: nil,
|
18
|
+
description: nil,
|
19
|
+
expired_at: nil,
|
20
|
+
failure_code: nil,
|
21
|
+
failure_message: nil,
|
22
|
+
id: generate_resource_id(PREFIX),
|
23
|
+
livemode: false,
|
24
|
+
metadata: nil,
|
25
|
+
object: OBJECT,
|
26
|
+
paid: true,
|
27
|
+
refund_reason: nil,
|
28
|
+
refunded: false,
|
29
|
+
subscription: nil
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module PayjpMock::Response::Resource
|
2
|
+
class Customer < Base
|
3
|
+
PREFIX = 'cus'.freeze
|
4
|
+
OBJECT = 'customer'.freeze
|
5
|
+
|
6
|
+
def default_attributes
|
7
|
+
id = generate_resource_id(PREFIX)
|
8
|
+
|
9
|
+
{
|
10
|
+
cards: PayjpMock::Response::List.new("/customers/#{id}/cards").to_h,
|
11
|
+
created: Time.now.to_i,
|
12
|
+
default_card: nil,
|
13
|
+
description: 'test',
|
14
|
+
email: nil,
|
15
|
+
id: id,
|
16
|
+
livemode: false,
|
17
|
+
metadata: nil,
|
18
|
+
object: OBJECT,
|
19
|
+
subscriptions: PayjpMock::Response::List.new("/customers/#{id}/subscriptions").to_h
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def override(attributes)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module PayjpMock::Response::Resource
|
2
|
+
class Event < Base
|
3
|
+
PREFIX = 'evnt'.freeze
|
4
|
+
OBJECT = 'event'.freeze
|
5
|
+
|
6
|
+
def default_attributes
|
7
|
+
{
|
8
|
+
created: Time.now.to_i,
|
9
|
+
data: Customer.new.to_h,
|
10
|
+
id: generate_resource_id(PREFIX),
|
11
|
+
livemode: false,
|
12
|
+
object: OBJECT,
|
13
|
+
pending_webhooks: 1,
|
14
|
+
type: 'customer.updated'
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module PayjpMock::Response::Resource
|
2
|
+
class Merchant < Base
|
3
|
+
PREFIX = 'acct_mch'.freeze
|
4
|
+
OBJECT = 'merchant'.freeze
|
5
|
+
|
6
|
+
def default_attributes
|
7
|
+
{
|
8
|
+
bank_enabled: false,
|
9
|
+
brands_accepted: ['Visa', 'MasterCard', 'JCB', 'American Express', 'Diners Club', 'Discover'],
|
10
|
+
business_type: nil,
|
11
|
+
charge_type: nil,
|
12
|
+
contact_phone: nil,
|
13
|
+
country: 'JP',
|
14
|
+
created: Time.now.to_i,
|
15
|
+
currencies_supported: ['jpy'],
|
16
|
+
default_currency: 'jpy',
|
17
|
+
details_submitted: false,
|
18
|
+
id: generate_resource_id(PREFIX),
|
19
|
+
livemode_activated_at: nil,
|
20
|
+
livemode_enabled: false,
|
21
|
+
object: OBJECT,
|
22
|
+
product_detail: nil,
|
23
|
+
product_name: nil,
|
24
|
+
product_type: nil,
|
25
|
+
site_published: nil,
|
26
|
+
url: nil
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module PayjpMock::Response::Resource
|
2
|
+
class Plan < Base
|
3
|
+
PREFIX = 'pln'.freeze
|
4
|
+
OBJECT = 'plan'.freeze
|
5
|
+
|
6
|
+
def default_attributes
|
7
|
+
{
|
8
|
+
amount: 500,
|
9
|
+
billing_day: nil,
|
10
|
+
created: Time.now.to_i,
|
11
|
+
currency: 'jpy',
|
12
|
+
id: generate_resource_id(PREFIX),
|
13
|
+
interval: 'month',
|
14
|
+
livemode: false,
|
15
|
+
metadata: nil,
|
16
|
+
name: nil,
|
17
|
+
object: OBJECT,
|
18
|
+
trial_days: 30
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module PayjpMock::Response::Resource
|
2
|
+
class Subscription < Base
|
3
|
+
PREFIX = 'sub'.freeze
|
4
|
+
OBJECT = 'subscription'.freeze
|
5
|
+
|
6
|
+
def default_attributes
|
7
|
+
now = Time.now.to_i
|
8
|
+
|
9
|
+
{
|
10
|
+
canceled_at: nil,
|
11
|
+
created: now,
|
12
|
+
current_period_end: now + 15.days,
|
13
|
+
current_period_start: now - 15.days,
|
14
|
+
customer: generate_resource_id(Customer::PREFIX),
|
15
|
+
id: generate_resource_id(PREFIX),
|
16
|
+
livemode: false,
|
17
|
+
metadata: nil,
|
18
|
+
object: OBJECT,
|
19
|
+
paused_at: nil,
|
20
|
+
plan: Plan.new.to_h,
|
21
|
+
resumed_at: nil,
|
22
|
+
start: now - 15.days,
|
23
|
+
status: 'active',
|
24
|
+
trial_end: nil,
|
25
|
+
trial_start: nil,
|
26
|
+
prorate: false
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PayjpMock::Response::Resource
|
2
|
+
class Token < Base
|
3
|
+
PREFIX = 'tok'.freeze
|
4
|
+
OBJECT = 'token'.freeze
|
5
|
+
|
6
|
+
def default_attributes
|
7
|
+
{
|
8
|
+
card: Card.new.to_h,
|
9
|
+
created: Time.now.to_i,
|
10
|
+
id: generate_resource_id(PREFIX),
|
11
|
+
livemode: false,
|
12
|
+
object: OBJECT,
|
13
|
+
used: false
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module PayjpMock::Response::Resource
|
2
|
+
class Transfer < Base
|
3
|
+
PREFIX = 'tr'.freeze
|
4
|
+
OBJECT = 'transfer'.freeze
|
5
|
+
|
6
|
+
def default_attributes
|
7
|
+
id = generate_resource_id(PREFIX)
|
8
|
+
now = Time.now
|
9
|
+
|
10
|
+
charged_at = (now + 30.days).to_i
|
11
|
+
charges = PayjpMock::Response::List.new("/transfers/#{id}/charges", count: 1) do
|
12
|
+
Charge.new(
|
13
|
+
amount: 1000,
|
14
|
+
captured_at: charged_at,
|
15
|
+
card: Card.new(created: charged_at).to_h,
|
16
|
+
created: charged_at
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
{
|
21
|
+
amount: 1000,
|
22
|
+
carried_balance: nil,
|
23
|
+
charges: charges.to_h,
|
24
|
+
created: now.to_i,
|
25
|
+
currency: 'jpy',
|
26
|
+
description: nil,
|
27
|
+
id: id,
|
28
|
+
livemode: false,
|
29
|
+
object: OBJECT,
|
30
|
+
scheduled_date: (now + 45.days).strftime('%Y-%m-%d'),
|
31
|
+
status: 'pending',
|
32
|
+
summary: {
|
33
|
+
charge_count: 1,
|
34
|
+
charge_fee: 0,
|
35
|
+
charge_gross: 1000,
|
36
|
+
net: 1000,
|
37
|
+
refund_amount: 0,
|
38
|
+
refund_count: 0
|
39
|
+
},
|
40
|
+
term_end: (now + 15.days).to_i,
|
41
|
+
term_start: now.to_i,
|
42
|
+
transfer_amount: nil,
|
43
|
+
transfer_date: nil
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module PayjpMock::Response::Resource
|
2
|
+
end
|
3
|
+
|
4
|
+
require 'payjp_mock/response/resource/base'
|
5
|
+
require 'payjp_mock/response/resource/charge'
|
6
|
+
require 'payjp_mock/response/resource/customer'
|
7
|
+
require 'payjp_mock/response/resource/card'
|
8
|
+
require 'payjp_mock/response/resource/plan'
|
9
|
+
require 'payjp_mock/response/resource/subscription'
|
10
|
+
require 'payjp_mock/response/resource/token'
|
11
|
+
require 'payjp_mock/response/resource/transfer'
|
12
|
+
require 'payjp_mock/response/resource/event'
|
13
|
+
require 'payjp_mock/response/resource/account'
|
14
|
+
require 'payjp_mock/response/resource/merchant'
|
data/lib/payjp_mock.rb
ADDED
data/payjp_mock.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'payjp_mock/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "payjp_mock"
|
8
|
+
spec.version = PayjpMock::VERSION
|
9
|
+
spec.authors = ["kirikiriyamama"]
|
10
|
+
spec.email = ["kirikiriyamama@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "A stubbing library for PAY.JP"
|
13
|
+
spec.description = "This library creates PAY.JP API stubs and generates dummy responses"
|
14
|
+
spec.homepage = "https://github.com/kirikiriyamama/payjp_mock"
|
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_dependency 'addressable'
|
25
|
+
spec.add_dependency 'webmock'
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency "payjp"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: payjp_mock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kirikiriyamama
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: addressable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: webmock
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: payjp
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: This library creates PAY.JP API stubs and generates dummy responses
|
98
|
+
email:
|
99
|
+
- kirikiriyamama@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- lib/payjp_mock.rb
|
114
|
+
- lib/payjp_mock/ext.rb
|
115
|
+
- lib/payjp_mock/ext/hash.rb
|
116
|
+
- lib/payjp_mock/ext/integer.rb
|
117
|
+
- lib/payjp_mock/request.rb
|
118
|
+
- lib/payjp_mock/request_builder.rb
|
119
|
+
- lib/payjp_mock/response.rb
|
120
|
+
- lib/payjp_mock/response/base.rb
|
121
|
+
- lib/payjp_mock/response/deleted.rb
|
122
|
+
- lib/payjp_mock/response/error.rb
|
123
|
+
- lib/payjp_mock/response/error/api_connection_error.rb
|
124
|
+
- lib/payjp_mock/response/error/api_error.rb
|
125
|
+
- lib/payjp_mock/response/error/authentication_error.rb
|
126
|
+
- lib/payjp_mock/response/error/base.rb
|
127
|
+
- lib/payjp_mock/response/error/card_error.rb
|
128
|
+
- lib/payjp_mock/response/error/invalid_request_error.rb
|
129
|
+
- lib/payjp_mock/response/list.rb
|
130
|
+
- lib/payjp_mock/response/resource.rb
|
131
|
+
- lib/payjp_mock/response/resource/account.rb
|
132
|
+
- lib/payjp_mock/response/resource/base.rb
|
133
|
+
- lib/payjp_mock/response/resource/card.rb
|
134
|
+
- lib/payjp_mock/response/resource/charge.rb
|
135
|
+
- lib/payjp_mock/response/resource/customer.rb
|
136
|
+
- lib/payjp_mock/response/resource/event.rb
|
137
|
+
- lib/payjp_mock/response/resource/merchant.rb
|
138
|
+
- lib/payjp_mock/response/resource/plan.rb
|
139
|
+
- lib/payjp_mock/response/resource/subscription.rb
|
140
|
+
- lib/payjp_mock/response/resource/token.rb
|
141
|
+
- lib/payjp_mock/response/resource/transfer.rb
|
142
|
+
- lib/payjp_mock/util.rb
|
143
|
+
- lib/payjp_mock/version.rb
|
144
|
+
- lib/payjp_mock/webmock_wrapper.rb
|
145
|
+
- payjp_mock.gemspec
|
146
|
+
homepage: https://github.com/kirikiriyamama/payjp_mock
|
147
|
+
licenses:
|
148
|
+
- MIT
|
149
|
+
metadata: {}
|
150
|
+
post_install_message:
|
151
|
+
rdoc_options: []
|
152
|
+
require_paths:
|
153
|
+
- lib
|
154
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
requirements: []
|
165
|
+
rubyforge_project:
|
166
|
+
rubygems_version: 2.5.2
|
167
|
+
signing_key:
|
168
|
+
specification_version: 4
|
169
|
+
summary: A stubbing library for PAY.JP
|
170
|
+
test_files: []
|