jamm 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/build.yml +23 -0
- data/.github/workflows/ruby-publish.yml +24 -0
- data/.gitignore +57 -0
- data/.rubocop.yml +53 -0
- data/CONTRIBUTORS +1 -0
- data/Gemfile +13 -0
- data/LICENSE +21 -0
- data/README.md +86 -0
- data/Rakefile +11 -0
- data/images/jamm_logo.png +0 -0
- data/jamm.gemspec +26 -0
- data/lib/jamm/api_operations/create.rb +16 -0
- data/lib/jamm/api_operations/get.rb +16 -0
- data/lib/jamm/api_operations/list.rb +16 -0
- data/lib/jamm/api_operations/update.rb +16 -0
- data/lib/jamm/api_resource.rb +5 -0
- data/lib/jamm/charge.rb +10 -0
- data/lib/jamm/errors.rb +36 -0
- data/lib/jamm/jamm_object.rb +249 -0
- data/lib/jamm/oauth.rb +66 -0
- data/lib/jamm/payment.rb +18 -0
- data/lib/jamm/request.rb +13 -0
- data/lib/jamm/time_util.rb +41 -0
- data/lib/jamm/token.rb +10 -0
- data/lib/jamm/util.rb +76 -0
- data/lib/jamm/version.rb +3 -0
- data/lib/jamm.rb +146 -0
- data/test/jamm/charge_test.rb +56 -0
- data/test/jamm/oauth_test.rb +47 -0
- data/test/jamm/payment_test.rb +17 -0
- data/test/jamm/time_util_test.rb +18 -0
- data/test/jamm/token_test.rb +52 -0
- data/test/test_data.rb +118 -0
- data/test/test_helper.rb +59 -0
- metadata +98 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path('../test_helper', __dir__)
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
module Jamm
|
5
|
+
class OAuthTest < Test::Unit::TestCase
|
6
|
+
should 'raise an error when bad request was returned' do
|
7
|
+
@mock.expects(:post).once.raises(RestClient::ExceptionWithResponse)
|
8
|
+
assert_raise OAuthError do
|
9
|
+
Jamm::OAuth.oauth_token
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
should 'raise an error when SocketError happened' do
|
14
|
+
@mock.expects(:post).once.raises(SocketError)
|
15
|
+
assert_raise OAuthError do
|
16
|
+
Jamm::OAuth.oauth_token
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'raise an error when timeout happened' do
|
21
|
+
@mock.expects(:post).once.raises(RestClient::RequestTimeout)
|
22
|
+
assert_raise OAuthError do
|
23
|
+
Jamm::OAuth.oauth_token
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
should 'raise an error when an unexpected exception happened' do
|
28
|
+
@mock.expects(:post).once.raises(RestClient::Exception)
|
29
|
+
assert_raise OAuthError do
|
30
|
+
Jamm::OAuth.oauth_token
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
should 'raise an error when unexpected response was returned' do
|
35
|
+
@mock.expects(:post).once.returns(test_response({}, 200))
|
36
|
+
assert_raise OAuthError do
|
37
|
+
Jamm::OAuth.oauth_token
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
should 'return an access token when valid response was returned' do
|
42
|
+
@mock.expects(:post).once.returns(test_response(test_cognito_response))
|
43
|
+
actual = Jamm::OAuth.oauth_token
|
44
|
+
assert_equal actual, 'access_token'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path('../test_helper', __dir__)
|
2
|
+
|
3
|
+
module Jamm
|
4
|
+
class PaymentTest < Test::Unit::TestCase
|
5
|
+
should 'return a result when Payment.create return valid response' do
|
6
|
+
# Arrange
|
7
|
+
@mock.stubs(:post).returns(test_response(test_cognito_response)).then.returns(test_response(test_create_payment_response))
|
8
|
+
# Act
|
9
|
+
actual = Jamm::Payment.create(test_create_payment_request)
|
10
|
+
# Assert
|
11
|
+
assert_equal actual.token_id, 'dt_f5e599d3-8b9e-4d46-9a52-1a37e7b5b8ef'
|
12
|
+
assert_equal actual.charge_id, 'ct_h5e599d3-0000-4d46-9a52-1a37e7b5b8ef'
|
13
|
+
assert_equal actual.payment_url, 'https://jamm-pay.com/K5e599d3-8b9e-4d46-9a72-1a37e7b5b8ef'
|
14
|
+
assert_equal actual.created_at, '2023-11-07T15:30:00.000+03:00'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('../test_helper', __dir__)
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
module Jamm
|
5
|
+
class TimeUtilTest < Test::Unit::TestCase
|
6
|
+
should 'compute relative time when relative scale is specified' do
|
7
|
+
now = Time.now
|
8
|
+
Time.expects(:now).once.returns(now)
|
9
|
+
actual = Jamm::TimeUtil.relative_time_to_iso('6 minutes')
|
10
|
+
assert_equal actual, (now + 6 * 60).strftime('%Y-%m-%dT%H:%M:%SZ')
|
11
|
+
end
|
12
|
+
|
13
|
+
should 'return input when absolute scale is specified' do
|
14
|
+
actual = Jamm::TimeUtil.relative_time_to_iso('2024-04-11T16:28:07.420Z')
|
15
|
+
assert_equal actual, '2024-04-11T16:28:07.420Z'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path('../test_helper', __dir__)
|
2
|
+
|
3
|
+
module Jamm
|
4
|
+
class TokenTest < Test::Unit::TestCase
|
5
|
+
should 'return a list of contract tokens when Token.list return valid response' do
|
6
|
+
# Arrange
|
7
|
+
@mock.expects(:post).once.returns(test_response(test_cognito_response))
|
8
|
+
@mock.expects(:get).once.returns(test_response(test_token_list))
|
9
|
+
# Act
|
10
|
+
actual = Jamm::Token.list
|
11
|
+
# Assert
|
12
|
+
assert actual.is_a? Array
|
13
|
+
assert_equal actual[0].contract_id, 'dt_f5e599d3-8b9e-4d46-9a52-1a37e7b5b8ef'
|
14
|
+
assert_equal actual[0].status, 'CREATED'
|
15
|
+
assert_equal actual[0].description, 'Gold Gym'
|
16
|
+
assert_equal actual[0].currency, 'JPY'
|
17
|
+
assert_equal actual[0].initial_amount, 1000
|
18
|
+
assert_equal actual[0].metadata.key1, 'value1'
|
19
|
+
assert_equal actual[0].metadata.key2, 'value2'
|
20
|
+
assert_equal actual[0].created_at, '2023-11-07T15:30:00.000+03:00'
|
21
|
+
assert_equal actual[0].updated_at, '2023-11-11T15:30:00.000+03:00'
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'raise an error when Token.list return timeout' do
|
25
|
+
# Arrange
|
26
|
+
@mock.expects(:post).once.returns(test_response(test_cognito_response))
|
27
|
+
@mock.expects(:get).once.raises(RestClient::RequestTimeout)
|
28
|
+
# Assert
|
29
|
+
assert_raise ApiConnectionError do
|
30
|
+
Jamm::Token.list
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
should 'return a contract tokens when Token.get return valid response' do
|
35
|
+
# Arrange
|
36
|
+
@mock.expects(:post).once.returns(test_response(test_cognito_response))
|
37
|
+
@mock.expects(:get).once.returns(test_response(test_token))
|
38
|
+
# Act
|
39
|
+
actual = Jamm::Token.get('dt_f5e599d3-8b9e-4d46-9a52-1a37e7b5b8ef')
|
40
|
+
# Assert
|
41
|
+
assert_equal actual.contract_id, 'dt_f5e599d3-8b9e-4d46-9a52-1a37e7b5b8ef'
|
42
|
+
assert_equal actual.status, 'CREATED'
|
43
|
+
assert_equal actual.description, 'Gold Gym'
|
44
|
+
assert_equal actual.currency, 'JPY'
|
45
|
+
assert_equal actual.initial_amount, 1000
|
46
|
+
assert_equal actual.metadata.key1, 'value1'
|
47
|
+
assert_equal actual.metadata.key2, 'value2'
|
48
|
+
assert_equal actual.created_at, '2023-11-07T15:30:00.000+03:00'
|
49
|
+
assert_equal actual.updated_at, '2023-11-11T15:30:00.000+03:00'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/test/test_data.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
module Jamm
|
2
|
+
module TestData
|
3
|
+
def test_response(body, code = 200)
|
4
|
+
body = JSON.generate(body) unless body.is_a? String
|
5
|
+
m = mock
|
6
|
+
m.instance_variable_set('@jamm_values', { body: body, code: code })
|
7
|
+
def m.body
|
8
|
+
@jamm_values[:body]
|
9
|
+
end
|
10
|
+
|
11
|
+
def m.code
|
12
|
+
@jamm_values[:code]
|
13
|
+
end
|
14
|
+
m
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_bad_request
|
18
|
+
{
|
19
|
+
"timestamp": '2023-11-07T15:30:00.000+09:00',
|
20
|
+
"status": 400,
|
21
|
+
"error": 'Bad Request',
|
22
|
+
"message": 'some error message',
|
23
|
+
"path": '/api/v0/deduction_contract_tokens'
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_cognito_response
|
28
|
+
{
|
29
|
+
access_token: 'access_token'
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_token_list
|
34
|
+
[test_token]
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_token
|
38
|
+
{
|
39
|
+
contract_id: 'dt_f5e599d3-8b9e-4d46-9a52-1a37e7b5b8ef',
|
40
|
+
status: 'CREATED',
|
41
|
+
description: 'Gold Gym',
|
42
|
+
initial_amount: 1000,
|
43
|
+
currency: 'JPY',
|
44
|
+
metadata: {
|
45
|
+
key1: 'value1',
|
46
|
+
key2: 'value2'
|
47
|
+
},
|
48
|
+
created_at: '2023-11-07T15:30:00.000+03:00',
|
49
|
+
updated_at: '2023-11-11T15:30:00.000+03:00'
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_create_payment_request
|
54
|
+
{
|
55
|
+
charge: {
|
56
|
+
description: 'Gold Gym',
|
57
|
+
amount: 10_000,
|
58
|
+
currency: 'JPY'
|
59
|
+
},
|
60
|
+
redirect: {
|
61
|
+
success_url: 'http://www.example.com/success',
|
62
|
+
failure_url: 'http://www.example.com/fail',
|
63
|
+
info_url: 'http://www.example.com/customer_service',
|
64
|
+
expired_at: '2024-04-11T16:28:07.420Z'
|
65
|
+
},
|
66
|
+
metadata: {
|
67
|
+
key1: 'value1',
|
68
|
+
key2: 'value2'
|
69
|
+
},
|
70
|
+
customer: {
|
71
|
+
name: 'Taro Taro',
|
72
|
+
katakanaFirstName: 'タロ',
|
73
|
+
katakanaLastName: 'タロ',
|
74
|
+
gender: 'MALE',
|
75
|
+
postNum: '112-0001',
|
76
|
+
address: '東京都渋谷区1−1−1',
|
77
|
+
email: 'test@jamm-pay.jp',
|
78
|
+
phone: '010-1234-5678',
|
79
|
+
birthdate: '2000-01-01'
|
80
|
+
},
|
81
|
+
options: {
|
82
|
+
force_kyc: true
|
83
|
+
}
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_create_payment_response
|
88
|
+
{
|
89
|
+
token_id: 'dt_f5e599d3-8b9e-4d46-9a52-1a37e7b5b8ef',
|
90
|
+
charge_id: 'ct_h5e599d3-0000-4d46-9a52-1a37e7b5b8ef',
|
91
|
+
payment_url: 'https://jamm-pay.com/K5e599d3-8b9e-4d46-9a72-1a37e7b5b8ef',
|
92
|
+
created_at: '2023-11-07T15:30:00.000+03:00'
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_charges
|
97
|
+
[test_charge]
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_charge
|
101
|
+
{
|
102
|
+
charge_id: 'ct_h5e599d3-0000-4d46-9a52-1a37e7b5b8ef',
|
103
|
+
contract_id: 'dt_f5e599d3-8b9e-4d46-9a52-1a37e7b5b8ef',
|
104
|
+
status: 'CREATED',
|
105
|
+
description: 'Gold Gym',
|
106
|
+
amount: 1000,
|
107
|
+
amount_refunded: 800,
|
108
|
+
currency: 'JPY',
|
109
|
+
merchant_metadata: {
|
110
|
+
key1: 'value1',
|
111
|
+
key2: 'value2'
|
112
|
+
},
|
113
|
+
created_at: '2023-11-07T15:30:00.000+03:00',
|
114
|
+
updated_at: '2023-11-11T15:30:00.000+03:00'
|
115
|
+
}
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.join(File.dirname(__FILE__), '..'), 'lib'))
|
2
|
+
require 'test/unit'
|
3
|
+
require 'mocha/test_unit'
|
4
|
+
require 'stringio'
|
5
|
+
require 'jamm'
|
6
|
+
require File.expand_path('test_data', __dir__)
|
7
|
+
|
8
|
+
# monkeypatch request methods
|
9
|
+
module Jamm
|
10
|
+
@mock_rest_client = nil
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_writer :mock_rest_client
|
14
|
+
|
15
|
+
remove_method :execute_request
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.execute_request(options)
|
19
|
+
get_params = (options[:headers] || {})[:params]
|
20
|
+
post_params = options[:payload]
|
21
|
+
case options[:method]
|
22
|
+
when :get then @mock_rest_client.get options[:url], get_params, post_params
|
23
|
+
when :post then @mock_rest_client.post options[:url], get_params, post_params
|
24
|
+
when :patch then @mock_rest_client.patch options[:url], get_params, post_params
|
25
|
+
when :delete then @mock_rest_client.delete options[:url], get_params, post_params
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module Test
|
31
|
+
module Unit
|
32
|
+
class TestCase
|
33
|
+
include Jamm::TestData
|
34
|
+
include Mocha
|
35
|
+
|
36
|
+
class << self
|
37
|
+
alias context sub_test_case
|
38
|
+
alias should test
|
39
|
+
end
|
40
|
+
|
41
|
+
def encode_credentials(client_id, client_secret)
|
42
|
+
"Basic #{Base64.strict_encode64("#{client_id}:#{client_secret}")}"
|
43
|
+
end
|
44
|
+
|
45
|
+
setup do
|
46
|
+
@mock = mock
|
47
|
+
Jamm.mock_rest_client = @mock
|
48
|
+
Jamm.client_id = 'client id'
|
49
|
+
Jamm.client_secret = 'client secret'
|
50
|
+
end
|
51
|
+
|
52
|
+
teardown do
|
53
|
+
Jamm.mock_rest_client = nil
|
54
|
+
Jamm.client_id = nil
|
55
|
+
Jamm.client_secret = nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jamm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jamm
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-04-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
description: Jamm help you make payment without credit cards
|
28
|
+
email: support@jamm-pay.jp
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".github/workflows/build.yml"
|
34
|
+
- ".github/workflows/ruby-publish.yml"
|
35
|
+
- ".gitignore"
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- CONTRIBUTORS
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- images/jamm_logo.png
|
43
|
+
- jamm.gemspec
|
44
|
+
- lib/jamm.rb
|
45
|
+
- lib/jamm/api_operations/create.rb
|
46
|
+
- lib/jamm/api_operations/get.rb
|
47
|
+
- lib/jamm/api_operations/list.rb
|
48
|
+
- lib/jamm/api_operations/update.rb
|
49
|
+
- lib/jamm/api_resource.rb
|
50
|
+
- lib/jamm/charge.rb
|
51
|
+
- lib/jamm/errors.rb
|
52
|
+
- lib/jamm/jamm_object.rb
|
53
|
+
- lib/jamm/oauth.rb
|
54
|
+
- lib/jamm/payment.rb
|
55
|
+
- lib/jamm/request.rb
|
56
|
+
- lib/jamm/time_util.rb
|
57
|
+
- lib/jamm/token.rb
|
58
|
+
- lib/jamm/util.rb
|
59
|
+
- lib/jamm/version.rb
|
60
|
+
- test/jamm/charge_test.rb
|
61
|
+
- test/jamm/oauth_test.rb
|
62
|
+
- test/jamm/payment_test.rb
|
63
|
+
- test/jamm/time_util_test.rb
|
64
|
+
- test/jamm/token_test.rb
|
65
|
+
- test/test_data.rb
|
66
|
+
- test/test_helper.rb
|
67
|
+
homepage: ''
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata:
|
71
|
+
source_code_uri: https://github.com/jamm-pay/Jamm-SDK-Ruby
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 2.7.0
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubygems_version: 3.4.19
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Ruby SDK for the Jamm API
|
91
|
+
test_files:
|
92
|
+
- test/jamm/charge_test.rb
|
93
|
+
- test/jamm/oauth_test.rb
|
94
|
+
- test/jamm/payment_test.rb
|
95
|
+
- test/jamm/time_util_test.rb
|
96
|
+
- test/jamm/token_test.rb
|
97
|
+
- test/test_data.rb
|
98
|
+
- test/test_helper.rb
|