jamm 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c402328942c6868efbc16b8055c6dba5c59c1576e610cfd6402f145d08c3d8a3
4
- data.tar.gz: 148d0550827b88f22de19d79d1fca3b2fb649e4a138b728b7ac57a866e02283a
3
+ metadata.gz: 8f2b7953e94c5584d2c5703e13a054ae3ab58a5cbce6ab623cf8ff0a7c99b065
4
+ data.tar.gz: 92dec2fed68fb705b61c3c730066a31c7bae8f509c068bd6cf547f39f4303d8c
5
5
  SHA512:
6
- metadata.gz: 9b4e508e9499f0412ed1f1d6939d1b00b6465e0184c0f994c09db70de73936731c7d376a1d702b75252b9f9ae4a87119ddb31dc413721c4eba0619fe0e5bea22
7
- data.tar.gz: de45614662b6d47ceec6ce476af65654b74fad81c6e9c083ca99f116458f2b6e83d0abe9c16c52b97e322d43f3ed3c32d9c6f9e362ea67cc27d07935b0d2c75e
6
+ metadata.gz: 5ab43dd8395233738268c7b26b8bd35a3aa58ea179f70508d936a0c5e4777be05e76c1a787b7c5a632d9d08a12dc49b1dc47921ebd4b8b891cdb578a9baa4656
7
+ data.tar.gz: b7cc97b42d35c7a3cbd333a66a756f83e69daba837898e0cb7fe8b14c1970bfb95405251b69f1d4757773250874cde6b7484dafd6be905b08b58535672454112
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jamm (1.0.1)
4
+ jamm (1.0.2)
5
5
  rest-client (~> 2.0)
6
6
  typhoeus (~> 1.0, >= 1.0.1)
7
7
 
@@ -141,5 +141,63 @@ module Api
141
141
  @api_client.config.logger.debug "API called: PaymentApi#create_contract_without_charge\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" if @api_client.config.debugging
142
142
  [data, status_code, headers]
143
143
  end
144
+
145
+ # Get a contract
146
+ # Get a contract information
147
+ # @param contract [String] @gotags: validate:\"required\"
148
+ # @param [Hash] opts the optional parameters
149
+ # @return [GetContractResponse]
150
+ def get_contract(contract, opts = {})
151
+ data, _status_code, _headers = get_contract_with_http_info(contract, opts)
152
+ data
153
+ end
154
+
155
+ # Get a contract
156
+ # Get a contract information
157
+ # @param contract [String] @gotags: validate:\"required\"
158
+ # @param [Hash] opts the optional parameters
159
+ # @return [Array<(GetContractResponse, Integer, Hash)>] GetContractResponse data, response status code and response headers
160
+ def get_contract_with_http_info(contract, opts = {})
161
+ @api_client.config.logger.debug 'Calling API: PaymentApi.get_contract ...' if @api_client.config.debugging
162
+ # verify the required parameter 'contract' is set
163
+ raise ArgumentError, "Missing the required parameter 'contract' when calling PaymentApi.get_contract" if @api_client.config.client_side_validation && contract.nil?
164
+
165
+ # resource path
166
+ local_var_path = '/v1/contracts/{contract}'.sub('{contract}', CGI.escape(contract.to_s))
167
+
168
+ # query parameters
169
+ query_params = opts[:query_params] || {}
170
+
171
+ # header parameters
172
+ header_params = opts[:header_params] || {}
173
+ # HTTP header 'Accept' (if needed)
174
+ header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
175
+
176
+ # form parameters
177
+ form_params = opts[:form_params] || {}
178
+
179
+ # http body (model)
180
+ post_body = opts[:debug_body]
181
+
182
+ # return_type
183
+ return_type = opts[:debug_return_type] || 'GetContractResponse'
184
+
185
+ # auth_names
186
+ auth_names = opts[:debug_auth_names] || []
187
+
188
+ new_options = opts.merge(
189
+ :operation => :"PaymentApi.get_contract",
190
+ :header_params => header_params,
191
+ :query_params => query_params,
192
+ :form_params => form_params,
193
+ :body => post_body,
194
+ :auth_names => auth_names,
195
+ :return_type => return_type
196
+ )
197
+
198
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
199
+ @api_client.config.logger.debug "API called: PaymentApi#get_contract\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" if @api_client.config.debugging
200
+ [data, status_code, headers]
201
+ end
144
202
  end
145
203
  end
@@ -0,0 +1,212 @@
1
+ # frozen_string_literal: true
2
+
3
+ # #api/v1/common.proto
4
+ #
5
+ # No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
+ #
7
+ # The version of the OpenAPI document: version not set
8
+ #
9
+ # Generated by: https://openapi-generator.tech
10
+ # Generator version: 7.9.0
11
+ #
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Api
17
+ class GetContractResponse
18
+ attr_accessor :contract, :customer
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ :contract => :contract,
24
+ :customer => :customer
25
+ }
26
+ end
27
+
28
+ # Returns all the JSON keys this model knows about
29
+ def self.acceptable_attributes
30
+ attribute_map.values
31
+ end
32
+
33
+ # Attribute type mapping.
34
+ def self.openapi_types
35
+ {
36
+ :contract => :Contract,
37
+ :customer => :Customer
38
+ }
39
+ end
40
+
41
+ # List of attributes with nullable: true
42
+ def self.openapi_nullable
43
+ Set.new([])
44
+ end
45
+
46
+ # Initializes the object
47
+ # @param [Hash] attributes Model attributes in the form of hash
48
+ def initialize(attributes = {})
49
+ raise ArgumentError, 'The input argument (attributes) must be a hash in `Api::GetContractResponse` initialize method' unless attributes.is_a?(Hash)
50
+
51
+ # check to see if the attribute exists and convert string to symbol for hash key
52
+ attributes = attributes.each_with_object({}) do |(k, v), h|
53
+ raise ArgumentError, "`#{k}` is not a valid attribute in `Api::GetContractResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect unless self.class.attribute_map.key?(k.to_sym)
54
+
55
+ h[k.to_sym] = v
56
+ end
57
+
58
+ self.contract = attributes[:contract] if attributes.key?(:contract)
59
+
60
+ return unless attributes.key?(:customer)
61
+
62
+ self.customer = attributes[:customer]
63
+ end
64
+
65
+ # Show invalid properties with the reasons. Usually used together with valid?
66
+ # @return Array for valid properties with the reasons
67
+ def list_invalid_properties
68
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
69
+ []
70
+ end
71
+
72
+ # Check to see if the all the properties in the model are valid
73
+ # @return true if the model is valid
74
+ def valid?
75
+ warn '[DEPRECATED] the `valid?` method is obsolete'
76
+ true
77
+ end
78
+
79
+ # Checks equality by comparing each attribute.
80
+ # @param [Object] Object to be compared
81
+ def ==(other)
82
+ return true if equal?(other)
83
+
84
+ self.class == other.class &&
85
+ contract == other.contract &&
86
+ customer == other.customer
87
+ end
88
+
89
+ # @see the `==` method
90
+ # @param [Object] Object to be compared
91
+ def eql?(other)
92
+ self == other
93
+ end
94
+
95
+ # Calculates hash code according to all attributes.
96
+ # @return [Integer] Hash code
97
+ def hash
98
+ [contract, customer].hash
99
+ end
100
+
101
+ # Builds the object from hash
102
+ # @param [Hash] attributes Model attributes in the form of hash
103
+ # @return [Object] Returns the model itself
104
+ def self.build_from_hash(attributes)
105
+ return nil unless attributes.is_a?(Hash)
106
+
107
+ attributes = attributes.transform_keys(&:to_sym)
108
+ transformed_hash = {}
109
+ openapi_types.each_pair do |key, type|
110
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
111
+ transformed_hash[key.to_s] = nil
112
+ elsif type =~ /\AArray<(.*)>/i
113
+ # check to ensure the input is an array given that the attribute
114
+ # is documented as an array but the input is not
115
+ transformed_hash[key.to_s] = attributes[attribute_map[key]].map { |v| _deserialize(::Regexp.last_match(1), v) } if attributes[attribute_map[key]].is_a?(Array)
116
+ elsif !attributes[attribute_map[key]].nil?
117
+ transformed_hash[key.to_s] = _deserialize(type, attributes[attribute_map[key]])
118
+ end
119
+ end
120
+ new(transformed_hash)
121
+ end
122
+
123
+ # Deserializes the data based on type
124
+ # @param string type Data type
125
+ # @param string value Value to be deserialized
126
+ # @return [Object] Deserialized data
127
+ def self._deserialize(type, value)
128
+ case type.to_sym
129
+ when :Time
130
+ Time.parse(value)
131
+ when :Date
132
+ Date.parse(value)
133
+ when :String
134
+ value.to_s
135
+ when :Integer
136
+ value.to_i
137
+ when :Float
138
+ value.to_f
139
+ when :Boolean
140
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
141
+ true
142
+ else
143
+ false
144
+ end
145
+ when :Object
146
+ # generic object (usually a Hash), return directly
147
+ value
148
+ when /\AArray<(?<inner_type>.+)>\z/
149
+ inner_type = Regexp.last_match[:inner_type]
150
+ value.map { |v| _deserialize(inner_type, v) }
151
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
152
+ k_type = Regexp.last_match[:k_type]
153
+ v_type = Regexp.last_match[:v_type]
154
+ {}.tap do |hash|
155
+ value.each do |k, v|
156
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
157
+ end
158
+ end
159
+ else # model
160
+ # models (e.g. Pet) or oneOf
161
+ klass = Api.const_get(type)
162
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
163
+ end
164
+ end
165
+
166
+ # Returns the string representation of the object
167
+ # @return [String] String presentation of the object
168
+ def to_s
169
+ to_hash.to_s
170
+ end
171
+
172
+ # to_body is an alias to to_hash (backward compatibility)
173
+ # @return [Hash] Returns the object in the form of hash
174
+ def to_body
175
+ to_hash
176
+ end
177
+
178
+ # Returns the object in the form of hash
179
+ # @return [Hash] Returns the object in the form of hash
180
+ def to_hash
181
+ hash = {}
182
+ self.class.attribute_map.each_pair do |attr, param|
183
+ value = send(attr)
184
+ if value.nil?
185
+ is_nullable = self.class.openapi_nullable.include?(attr)
186
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
187
+ end
188
+
189
+ hash[param] = _to_hash(value)
190
+ end
191
+ hash
192
+ end
193
+
194
+ # Outputs non-array value in the form of hash
195
+ # For object, use to_hash. Otherwise, just return the value
196
+ # @param [Object] value Any valid value
197
+ # @return [Hash] Returns the value in the form of hash
198
+ def _to_hash(value)
199
+ if value.is_a?(Array)
200
+ value.compact.map { |v| _to_hash(v) }
201
+ elsif value.is_a?(Hash)
202
+ {}.tap do |hash|
203
+ value.each { |k, v| hash[k] = _to_hash(v) }
204
+ end
205
+ elsif value.respond_to? :to_hash
206
+ value.to_hash
207
+ else
208
+ value
209
+ end
210
+ end
211
+ end
212
+ end
@@ -32,7 +32,7 @@ module Api
32
32
  # Attribute type mapping.
33
33
  def self.openapi_types
34
34
  {
35
- :customer => :MerchantCustomer
35
+ :customer => :Customer
36
36
  }
37
37
  end
38
38
 
data/lib/jamm/api.rb CHANGED
@@ -31,6 +31,7 @@ require 'jamm/api/models/v1_create_customer_request'
31
31
  require 'jamm/api/models/v1_create_customer_response'
32
32
  require 'jamm/api/models/v1_customer'
33
33
  require 'jamm/api/models/v1_delete_customer_response'
34
+ require 'jamm/api/models/v1_get_contract_response'
34
35
  require 'jamm/api/models/v1_get_customer_response'
35
36
  require 'jamm/api/models/v1_initial_charge'
36
37
  require 'jamm/api/models/v1_merchant'
@@ -0,0 +1,14 @@
1
+ module Jamm
2
+ module Client
3
+ def self.handler
4
+ base = Jamm::ApiClient.new
5
+
6
+ # Configure
7
+ base.config.host = Jamm.openapi.config.host
8
+ base.config.scheme = Jamm.openapi.config.scheme
9
+ base.default_headers['Authorization'] = "Bearer #{Jamm::OAuth.token}"
10
+
11
+ base
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rest-client'
4
+ require 'json'
5
+ require 'base64'
6
+ require 'jamm/errors'
7
+
8
+ module Jamm
9
+ module Customer
10
+ def self.get(customer:)
11
+ Jamm::CustomerApi.new(Jamm::Client.handler).get customer
12
+ rescue Jamm::ApiError => e
13
+ puts e
14
+ end
15
+
16
+ def self.update(**params)
17
+ Jamm::CustomerApi.new(Jamm::Client.handler).update(params[:id], params)
18
+ rescue Jamm::ApiError => e
19
+ puts e
20
+ end
21
+
22
+ def self.delete(customer:)
23
+ Jamm::CustomerApi.new(Jamm::Client.handler).delete customer
24
+ rescue Jamm::ApiError => e
25
+ puts e
26
+ end
27
+ end
28
+ end
data/lib/jamm/oauth.rb CHANGED
@@ -8,15 +8,13 @@ require 'jamm/errors'
8
8
  module Jamm
9
9
  module OAuth
10
10
  def self.token
11
- client_id = Jamm.client_id
12
- client_secret = Jamm.client_secret
13
- if client_id.nil? || client_secret.nil?
11
+ if Jamm.client_id.nil? || Jamm.client_secret.nil?
14
12
  raise OAuthError, 'No client_id or client_secret is set. ' \
15
13
  'Set your merchant client id and client secret using' \
16
14
  'Jamm.client_id=<your client id> and Jamm=<your client secret>'
17
15
  end
18
16
 
19
- fetch_oauth_token(client_id, client_secret)
17
+ fetch_oauth_token(Jamm.client_id, Jamm.client_secret)
20
18
  end
21
19
 
22
20
  def self.fetch_oauth_token(client_id, client_secret)
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rest-client'
4
+ require 'json'
5
+ require 'base64'
6
+ require 'jamm/errors'
7
+
8
+ module Jamm
9
+ module Payment
10
+ def self.contract_with_charge(**params)
11
+ request = Jamm::CreateContractWithChargeRequest.new(params)
12
+
13
+ begin
14
+ Jamm::PaymentApi.new(Jamm::Client.handler).create_contract_with_charge(request)
15
+ rescue Jamm::ApiError => e
16
+ puts e
17
+ end
18
+ end
19
+
20
+ def self.get_contract(contract:)
21
+ Jamm::PaymentApi.new(Jamm::Client.handler).get_contract(contract)
22
+ rescue Jamm::ApiError => e
23
+ puts e
24
+ end
25
+ end
26
+ end
data/lib/jamm/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jamm
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  end
data/lib/jamm.rb CHANGED
@@ -5,15 +5,20 @@ require 'openssl'
5
5
  require 'json'
6
6
 
7
7
  require 'jamm/api'
8
+ require 'jamm/client'
8
9
  require 'jamm/errors'
9
10
  require 'jamm/oauth'
10
11
  require 'jamm/version'
11
12
 
13
+ # OpenAPI wrappers
14
+ require 'jamm/customer'
15
+ require 'jamm/payment'
16
+
12
17
  # Jamm Ruby SDK
13
18
  module Jamm
14
19
  # Configurable attributes.
15
- @api_base = nil
16
20
  @oauth_base = nil
21
+ @openapi = nil
17
22
  @open_timeout = 30
18
23
  @read_timeout = 90
19
24
  @max_retry = 0
@@ -23,8 +28,36 @@ module Jamm
23
28
  include Api
24
29
 
25
30
  class << self
26
- attr_accessor :api, :client_id, :client_secret, :api_base, :oauth_base, :api_version, :connect_base,
27
- :open_timeout, :read_timeout, :max_retry, :retry_initial_delay, :retry_max_delay
31
+ attr_accessor :api, :client_id, :client_secret, :api_base, :env, :oauth_base, :api_version, :connect_base,
32
+ :openapi, :open_timeout, :read_timeout, :max_retry, :retry_initial_delay, :retry_max_delay
33
+ end
34
+
35
+ def self.configure(client_id:, client_secret:, env:)
36
+ Jamm.client_id = client_id
37
+ Jamm.client_secret = client_secret
38
+
39
+ case env
40
+ when 'prod'
41
+ self.oauth_base = 'https://merchant-identity.jamm-pay.jp'
42
+
43
+ self.openapi = Jamm::ApiClient.new
44
+ openapi.config.host = 'api.jamm-pay.jp'
45
+
46
+ # Debugger mode, uncomment when needed
47
+ # when 'develop'
48
+ # self.oauth_base = "https://merchant-identity.#{env}.jamm-pay.jp"
49
+ #
50
+ # self.openapi = Jamm::ApiClient.new
51
+ # openapi.config.host = 'api.jamm.test'
52
+
53
+ else
54
+ self.oauth_base = "https://merchant-identity.#{env}.jamm-pay.jp"
55
+
56
+ self.openapi = Jamm::ApiClient.new
57
+ openapi.config.host = "api.#{env}.jamm-pay.jp"
58
+ end
59
+
60
+ openapi.config.scheme = 'https'
28
61
  end
29
62
 
30
63
  def self.execute_request(option)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jamm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-23 00:00:00.000000000 Z
11
+ date: 2024-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -80,6 +80,7 @@ files:
80
80
  - lib/jamm/api/models/v1_create_customer_response.rb
81
81
  - lib/jamm/api/models/v1_customer.rb
82
82
  - lib/jamm/api/models/v1_delete_customer_response.rb
83
+ - lib/jamm/api/models/v1_get_contract_response.rb
83
84
  - lib/jamm/api/models/v1_get_customer_response.rb
84
85
  - lib/jamm/api/models/v1_initial_charge.rb
85
86
  - lib/jamm/api/models/v1_merchant.rb
@@ -89,8 +90,11 @@ files:
89
90
  - lib/jamm/api/models/v1_update_customer_response.rb
90
91
  - lib/jamm/api/models/v1_url.rb
91
92
  - lib/jamm/api/version.rb
93
+ - lib/jamm/client.rb
94
+ - lib/jamm/customer.rb
92
95
  - lib/jamm/errors.rb
93
96
  - lib/jamm/oauth.rb
97
+ - lib/jamm/payment.rb
94
98
  - lib/jamm/version.rb
95
99
  homepage: https://jamm-pay.jp
96
100
  licenses: