Class: Devdraft::TestPaymentsApi

Inherits:
Object
  • Object
show all
Defined in:
lib/devdraft/api/test_payments_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ TestPaymentsApi

Returns a new instance of TestPaymentsApi.



19
20
21
# File 'lib/devdraft/api/test_payments_api.rb', line 19

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



17
18
19
# File 'lib/devdraft/api/test_payments_api.rb', line 17

def api_client
  @api_client
end

Instance Method Details

#test_payment_controller_create_payment_v0(idempotency_key, payment_request_dto, opts = {}) ⇒ PaymentResponseDto

Process a test payment Creates a new payment. Requires an idempotency key to prevent duplicate payments on retry. ## Idempotency Key Best Practices 1. **Generate unique keys**: Use UUIDs or similar unique identifiers, prefixed with a descriptive operation name 2. **Store keys client-side**: Save the key with the original request so you can retry with the same key 3. **Key format**: Between 6-64 alphanumeric characters 4. Expiration: Keys expire after 24 hours by default 5. **Use case**: Perfect for ensuring payment operations are never processed twice, even during network failures ## Example Request (curl) “‘bash curl -X POST \ api.example.com/rest-api/v0/test-payment \ -H ’Content-Type: application/json’ \ -H ‘Client-Key: your-api-key’ \ -H ‘Client-Secret: your-api-secret’ \ -H ‘Idempotency-Key: payment_123456_unique_key’ \ -d ‘{ "amount": 100.00, "currency": "USD", "description": "Test payment for order #12345", "customerId": "cus_12345" }’ “‘ ## Example Response (First Request) “`json { "id": "pay_abc123xyz456", "amount": 100.00, "currency": "USD", "status": "succeeded", "timestamp": "2023-07-01T12:00:00.000Z" } “` ## Example Response (Duplicate Request) The exact same response will be returned for any duplicate request with the same idempotency key, without creating a new payment. ## Retry Scenario Example Network failure during payment submission: 1. Client creates payment request with idempotency key: "payment_123456_unique_key" 2. Request begins processing, but network connection fails before response received 3. Client retries the exact same request with the same idempotency key 4. Server detects duplicate idempotency key and returns the result of the first request 5. No duplicate payment is created If you retry with same key but different parameters (e.g., different amount), you’ll receive a 409 Conflict error.

Parameters:

  • idempotency_key (String)

    Unique key to ensure the request is idempotent. If a request with the same key is sent multiple times, only the first will be processed, and subsequent requests will return the same response.

  • payment_request_dto (PaymentRequestDto)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



28
29
30
31
# File 'lib/devdraft/api/test_payments_api.rb', line 28

def test_payment_controller_create_payment_v0(idempotency_key, payment_request_dto, opts = {})
  data, _status_code, _headers = test_payment_controller_create_payment_v0_with_http_info(idempotency_key, payment_request_dto, opts)
  data
end

#test_payment_controller_create_payment_v0_with_http_info(idempotency_key, payment_request_dto, opts = {}) ⇒ Array<(PaymentResponseDto, Integer, Hash)>

Process a test payment Creates a new payment. Requires an idempotency key to prevent duplicate payments on retry. ## Idempotency Key Best Practices 1. **Generate unique keys**: Use UUIDs or similar unique identifiers, prefixed with a descriptive operation name 2. **Store keys client-side**: Save the key with the original request so you can retry with the same key 3. **Key format**: Between 6-64 alphanumeric characters 4. Expiration: Keys expire after 24 hours by default 5. **Use case**: Perfect for ensuring payment operations are never processed twice, even during network failures ## Example Request (curl) &#x60;&#x60;&#x60;bash curl -X POST \ api.example.com/rest-api/v0/test-payment \ -H &#39;Content-Type: application/json&#39; \ -H &#39;Client-Key: your-api-key&#39; \ -H &#39;Client-Secret: your-api-secret&#39; \ -H &#39;Idempotency-Key: payment_123456_unique_key&#39; \ -d &#39;{ &quot;amount&quot;: 100.00, &quot;currency&quot;: &quot;USD&quot;, &quot;description&quot;: &quot;Test payment for order #12345&quot;, &quot;customerId&quot;: &quot;cus_12345&quot; }&#39; &#x60;&#x60;&#x60; ## Example Response (First Request) &#x60;&#x60;&#x60;json { &quot;id&quot;: &quot;pay_abc123xyz456&quot;, &quot;amount&quot;: 100.00, &quot;currency&quot;: &quot;USD&quot;, &quot;status&quot;: &quot;succeeded&quot;, &quot;timestamp&quot;: &quot;2023-07-01T12:00:00.000Z&quot; } &#x60;&#x60;&#x60; ## Example Response (Duplicate Request) The exact same response will be returned for any duplicate request with the same idempotency key, without creating a new payment. ## Retry Scenario Example Network failure during payment submission: 1. Client creates payment request with idempotency key: &quot;payment_123456_unique_key&quot; 2. Request begins processing, but network connection fails before response received 3. Client retries the exact same request with the same idempotency key 4. Server detects duplicate idempotency key and returns the result of the first request 5. No duplicate payment is created If you retry with same key but different parameters (e.g., different amount), you&#39;ll receive a 409 Conflict error.

Parameters:

  • idempotency_key (String)

    Unique key to ensure the request is idempotent. If a request with the same key is sent multiple times, only the first will be processed, and subsequent requests will return the same response.

  • payment_request_dto (PaymentRequestDto)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(PaymentResponseDto, Integer, Hash)>)

    PaymentResponseDto data, response status code and response headers



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/devdraft/api/test_payments_api.rb', line 39

def test_payment_controller_create_payment_v0_with_http_info(idempotency_key, payment_request_dto, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: TestPaymentsApi.test_payment_controller_create_payment_v0 ...'
  end
  # verify the required parameter 'idempotency_key' is set
  if @api_client.config.client_side_validation && idempotency_key.nil?
    fail ArgumentError, "Missing the required parameter 'idempotency_key' when calling TestPaymentsApi.test_payment_controller_create_payment_v0"
  end
  # verify the required parameter 'payment_request_dto' is set
  if @api_client.config.client_side_validation && payment_request_dto.nil?
    fail ArgumentError, "Missing the required parameter 'payment_request_dto' when calling TestPaymentsApi.test_payment_controller_create_payment_v0"
  end
  # resource path
  local_var_path = '/api/v0/test-payment'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end
  header_params[:'idempotency-key'] = idempotency_key

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(payment_request_dto)

  # return_type
  return_type = opts[:debug_return_type] || 'PaymentResponseDto'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['x-client-secret', 'x-client-key']

  new_options = opts.merge(
    :operation => :"TestPaymentsApi.test_payment_controller_create_payment_v0",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: TestPaymentsApi#test_payment_controller_create_payment_v0\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#test_payment_controller_get_payment_v0(id, opts = {}) ⇒ PaymentResponseDto

Get payment details by ID

Parameters:

  • id (String)

    Payment ID

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



101
102
103
104
# File 'lib/devdraft/api/test_payments_api.rb', line 101

def test_payment_controller_get_payment_v0(id, opts = {})
  data, _status_code, _headers = test_payment_controller_get_payment_v0_with_http_info(id, opts)
  data
end

#test_payment_controller_get_payment_v0_with_http_info(id, opts = {}) ⇒ Array<(PaymentResponseDto, Integer, Hash)>

Get payment details by ID

Parameters:

  • id (String)

    Payment ID

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(PaymentResponseDto, Integer, Hash)>)

    PaymentResponseDto data, response status code and response headers



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/devdraft/api/test_payments_api.rb', line 110

def test_payment_controller_get_payment_v0_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: TestPaymentsApi.test_payment_controller_get_payment_v0 ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling TestPaymentsApi.test_payment_controller_get_payment_v0"
  end
  # resource path
  local_var_path = '/api/v0/test-payment/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'PaymentResponseDto'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['x-client-secret', 'x-client-key']

  new_options = opts.merge(
    :operation => :"TestPaymentsApi.test_payment_controller_get_payment_v0",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: TestPaymentsApi#test_payment_controller_get_payment_v0\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#test_payment_controller_refund_payment_v0(id, idempotency_key, opts = {}) ⇒ RefundResponseDto

Refund a payment Refunds an existing payment. Requires an idempotency key to prevent duplicate refunds on retry. ## Idempotency Key Benefits for Refunds Refunds are critical financial operations where duplicates can cause serious issues. Using idempotency keys ensures: 1. **Prevent duplicate refunds**: Even if a request times out or fails, retrying with the same key won’t issue multiple refunds 2. **Safe retries**: Network failures or timeouts won’t risk creating multiple refunds 3. **Consistent response**: Always get the same response for the same operation ## Example Request (curl) “‘bash curl -X POST \ api.example.com/rest-api/v0/test-payment/pay_abc123xyz456/refund \ -H ’Content-Type: application/json’ \ -H ‘Client-Key: your-api-key’ \ -H ‘Client-Secret: your-api-secret’ \ -H ‘Idempotency-Key: refund_123456_unique_key’ “‘ ## Example Response (First Request) “`json { "id": "ref_xyz789", "paymentId": "pay_abc123xyz456", "amount": 100.00, "status": "succeeded", "timestamp": "2023-07-01T14:30:00.000Z" } “` ## Example Response (Duplicate Request) The exact same response will be returned for any duplicate request with the same idempotency key, without creating a new refund. ## Idempotency Key Guidelines - Use a unique key for each distinct refund operation - Store keys client-side to ensure you can retry with the same key if needed - Keys expire after 24 hours by default

Parameters:

  • id (String)

    Payment ID to refund

  • idempotency_key (String)

    Unique key to ensure the refund request is idempotent. If a request with the same key is sent multiple times, only the first will be processed, and subsequent requests will return the same response.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



164
165
166
167
# File 'lib/devdraft/api/test_payments_api.rb', line 164

def test_payment_controller_refund_payment_v0(id, idempotency_key, opts = {})
  data, _status_code, _headers = test_payment_controller_refund_payment_v0_with_http_info(id, idempotency_key, opts)
  data
end

#test_payment_controller_refund_payment_v0_with_http_info(id, idempotency_key, opts = {}) ⇒ Array<(RefundResponseDto, Integer, Hash)>

Refund a payment Refunds an existing payment. Requires an idempotency key to prevent duplicate refunds on retry. ## Idempotency Key Benefits for Refunds Refunds are critical financial operations where duplicates can cause serious issues. Using idempotency keys ensures: 1. **Prevent duplicate refunds**: Even if a request times out or fails, retrying with the same key won&#39;t issue multiple refunds 2. **Safe retries**: Network failures or timeouts won&#39;t risk creating multiple refunds 3. **Consistent response**: Always get the same response for the same operation ## Example Request (curl) &#x60;&#x60;&#x60;bash curl -X POST \ api.example.com/rest-api/v0/test-payment/pay_abc123xyz456/refund \ -H &#39;Content-Type: application/json&#39; \ -H &#39;Client-Key: your-api-key&#39; \ -H &#39;Client-Secret: your-api-secret&#39; \ -H &#39;Idempotency-Key: refund_123456_unique_key&#39; &#x60;&#x60;&#x60; ## Example Response (First Request) &#x60;&#x60;&#x60;json { &quot;id&quot;: &quot;ref_xyz789&quot;, &quot;paymentId&quot;: &quot;pay_abc123xyz456&quot;, &quot;amount&quot;: 100.00, &quot;status&quot;: &quot;succeeded&quot;, &quot;timestamp&quot;: &quot;2023-07-01T14:30:00.000Z&quot; } &#x60;&#x60;&#x60; ## Example Response (Duplicate Request) The exact same response will be returned for any duplicate request with the same idempotency key, without creating a new refund. ## Idempotency Key Guidelines - Use a unique key for each distinct refund operation - Store keys client-side to ensure you can retry with the same key if needed - Keys expire after 24 hours by default

Parameters:

  • id (String)

    Payment ID to refund

  • idempotency_key (String)

    Unique key to ensure the refund request is idempotent. If a request with the same key is sent multiple times, only the first will be processed, and subsequent requests will return the same response.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(RefundResponseDto, Integer, Hash)>)

    RefundResponseDto data, response status code and response headers



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/devdraft/api/test_payments_api.rb', line 175

def test_payment_controller_refund_payment_v0_with_http_info(id, idempotency_key, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: TestPaymentsApi.test_payment_controller_refund_payment_v0 ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling TestPaymentsApi.test_payment_controller_refund_payment_v0"
  end
  # verify the required parameter 'idempotency_key' is set
  if @api_client.config.client_side_validation && idempotency_key.nil?
    fail ArgumentError, "Missing the required parameter 'idempotency_key' when calling TestPaymentsApi.test_payment_controller_refund_payment_v0"
  end
  # resource path
  local_var_path = '/api/v0/test-payment/{id}/refund'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  header_params[:'idempotency-key'] = idempotency_key

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'RefundResponseDto'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['x-client-secret', 'x-client-key']

  new_options = opts.merge(
    :operation => :"TestPaymentsApi.test_payment_controller_refund_payment_v0",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: TestPaymentsApi#test_payment_controller_refund_payment_v0\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end