univapay-client-sdk 1.0.0

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.
Files changed (241) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +28 -0
  3. data/README.md +212 -0
  4. data/bin/console +15 -0
  5. data/lib/univapay_client_sdk/api_helper.rb +10 -0
  6. data/lib/univapay_client_sdk/apis/base_api.rb +67 -0
  7. data/lib/univapay_client_sdk/apis/cancels_api.rb +293 -0
  8. data/lib/univapay_client_sdk/apis/charges_api.rb +909 -0
  9. data/lib/univapay_client_sdk/apis/merchants_api.rb +57 -0
  10. data/lib/univapay_client_sdk/apis/refunds_api.rb +298 -0
  11. data/lib/univapay_client_sdk/apis/stores_api.rb +126 -0
  12. data/lib/univapay_client_sdk/apis/subscriptions_api.rb +1014 -0
  13. data/lib/univapay_client_sdk/apis/transaction_tokens_api.rb +455 -0
  14. data/lib/univapay_client_sdk/apis/webhooks_api.rb +463 -0
  15. data/lib/univapay_client_sdk/client.rb +128 -0
  16. data/lib/univapay_client_sdk/configuration.rb +179 -0
  17. data/lib/univapay_client_sdk/events/unknown_event.rb +32 -0
  18. data/lib/univapay_client_sdk/events/webhooks/bank_transfer_handler.rb +37 -0
  19. data/lib/univapay_client_sdk/events/webhooks/cancel_handler.rb +37 -0
  20. data/lib/univapay_client_sdk/events/webhooks/charge_handler.rb +37 -0
  21. data/lib/univapay_client_sdk/events/webhooks/customs_handler.rb +37 -0
  22. data/lib/univapay_client_sdk/events/webhooks/refund_handler.rb +37 -0
  23. data/lib/univapay_client_sdk/events/webhooks/subscription_handler.rb +37 -0
  24. data/lib/univapay_client_sdk/events/webhooks/token_handler.rb +37 -0
  25. data/lib/univapay_client_sdk/exceptions/api_error_exception.rb +199 -0
  26. data/lib/univapay_client_sdk/exceptions/api_exception.rb +21 -0
  27. data/lib/univapay_client_sdk/extensions.rb +127 -0
  28. data/lib/univapay_client_sdk/http/api_response.rb +19 -0
  29. data/lib/univapay_client_sdk/http/auth/oauth_2.rb +58 -0
  30. data/lib/univapay_client_sdk/http/http_call_back.rb +10 -0
  31. data/lib/univapay_client_sdk/http/http_method_enum.rb +10 -0
  32. data/lib/univapay_client_sdk/http/http_request.rb +10 -0
  33. data/lib/univapay_client_sdk/http/http_response.rb +10 -0
  34. data/lib/univapay_client_sdk/http/proxy_settings.rb +22 -0
  35. data/lib/univapay_client_sdk/logging/configuration/api_logging_configuration.rb +186 -0
  36. data/lib/univapay_client_sdk/logging/sdk_logger.rb +17 -0
  37. data/lib/univapay_client_sdk/models/api_error_detail.rb +87 -0
  38. data/lib/univapay_client_sdk/models/api_error_status.rb +26 -0
  39. data/lib/univapay_client_sdk/models/bank_transfer_event.rb +27 -0
  40. data/lib/univapay_client_sdk/models/bank_transfer_ledger.rb +199 -0
  41. data/lib/univapay_client_sdk/models/bank_transfer_ledger_bank_ledger_type.rb +36 -0
  42. data/lib/univapay_client_sdk/models/bank_transfer_ledger_list.rb +104 -0
  43. data/lib/univapay_client_sdk/models/bank_transfer_ledger_mode.rb +36 -0
  44. data/lib/univapay_client_sdk/models/bank_transfer_payment_status.rb +44 -0
  45. data/lib/univapay_client_sdk/models/bank_transfer_status_data.rb +229 -0
  46. data/lib/univapay_client_sdk/models/bank_transfer_status_webhook_callback.rb +134 -0
  47. data/lib/univapay_client_sdk/models/bank_transfer_status_webhook_callback_extension.rb +75 -0
  48. data/lib/univapay_client_sdk/models/base_bank_transfer_data.rb +100 -0
  49. data/lib/univapay_client_sdk/models/base_konbini_data.rb +99 -0
  50. data/lib/univapay_client_sdk/models/base_konbini_data_convenience_store.rb +60 -0
  51. data/lib/univapay_client_sdk/models/base_model.rb +110 -0
  52. data/lib/univapay_client_sdk/models/base_online_data.rb +123 -0
  53. data/lib/univapay_client_sdk/models/base_online_data_brand.rb +48 -0
  54. data/lib/univapay_client_sdk/models/base_online_data_call_method.rb +52 -0
  55. data/lib/univapay_client_sdk/models/base_online_data_os_type.rb +36 -0
  56. data/lib/univapay_client_sdk/models/base_online_data_user_identifier_source.rb +36 -0
  57. data/lib/univapay_client_sdk/models/cancel.rb +183 -0
  58. data/lib/univapay_client_sdk/models/cancel_create_request.rb +77 -0
  59. data/lib/univapay_client_sdk/models/cancel_event.rb +26 -0
  60. data/lib/univapay_client_sdk/models/cancel_list.rb +94 -0
  61. data/lib/univapay_client_sdk/models/cancel_status.rb +44 -0
  62. data/lib/univapay_client_sdk/models/cancel_update_request.rb +76 -0
  63. data/lib/univapay_client_sdk/models/cancel_webhook_callback.rb +132 -0
  64. data/lib/univapay_client_sdk/models/cancel_webhook_callback_extension.rb +74 -0
  65. data/lib/univapay_client_sdk/models/card_processor_installment_config.rb +89 -0
  66. data/lib/univapay_client_sdk/models/charge.rb +411 -0
  67. data/lib/univapay_client_sdk/models/charge_capture_request.rb +84 -0
  68. data/lib/univapay_client_sdk/models/charge_create_request.rb +179 -0
  69. data/lib/univapay_client_sdk/models/charge_create_request_client_metadata.rb +76 -0
  70. data/lib/univapay_client_sdk/models/charge_create_request_redirect.rb +75 -0
  71. data/lib/univapay_client_sdk/models/charge_create_request_three_ds.rb +88 -0
  72. data/lib/univapay_client_sdk/models/charge_create_request_three_ds_mode.rb +44 -0
  73. data/lib/univapay_client_sdk/models/charge_event.rb +36 -0
  74. data/lib/univapay_client_sdk/models/charge_list.rb +104 -0
  75. data/lib/univapay_client_sdk/models/charge_mode.rb +36 -0
  76. data/lib/univapay_client_sdk/models/charge_redirect.rb +96 -0
  77. data/lib/univapay_client_sdk/models/charge_status.rb +56 -0
  78. data/lib/univapay_client_sdk/models/charge_three_ds.rb +97 -0
  79. data/lib/univapay_client_sdk/models/charge_transaction_token_type.rb +40 -0
  80. data/lib/univapay_client_sdk/models/charge_update_request.rb +75 -0
  81. data/lib/univapay_client_sdk/models/charge_webhook_event.rb +138 -0
  82. data/lib/univapay_client_sdk/models/cursor_direction_query.rb +36 -0
  83. data/lib/univapay_client_sdk/models/customs_declaration_create_request.rb +106 -0
  84. data/lib/univapay_client_sdk/models/customs_declaration_event.rb +27 -0
  85. data/lib/univapay_client_sdk/models/customs_declaration_patch_request.rb +77 -0
  86. data/lib/univapay_client_sdk/models/customs_declaration_webhook_callback.rb +135 -0
  87. data/lib/univapay_client_sdk/models/customs_declaration_webhook_callback_extension.rb +76 -0
  88. data/lib/univapay_client_sdk/models/customs_declaration_webhook_data.rb +232 -0
  89. data/lib/univapay_client_sdk/models/customs_declaration_webhook_declaration.rb +121 -0
  90. data/lib/univapay_client_sdk/models/customs_declaration_webhook_error.rb +127 -0
  91. data/lib/univapay_client_sdk/models/customs_declaration_webhook_other_error.rb +120 -0
  92. data/lib/univapay_client_sdk/models/customs_declaration_webhook_result.rb +125 -0
  93. data/lib/univapay_client_sdk/models/customs_declaration_webhook_status.rb +44 -0
  94. data/lib/univapay_client_sdk/models/generic_metadata.rb +111 -0
  95. data/lib/univapay_client_sdk/models/installment_fixed_cycles.rb +70 -0
  96. data/lib/univapay_client_sdk/models/installment_plan_type.rb +36 -0
  97. data/lib/univapay_client_sdk/models/issuer_token.rb +177 -0
  98. data/lib/univapay_client_sdk/models/issuer_token_call_method.rb +51 -0
  99. data/lib/univapay_client_sdk/models/issuer_token_payload.rb +105 -0
  100. data/lib/univapay_client_sdk/models/issuer_token_payment_type.rb +36 -0
  101. data/lib/univapay_client_sdk/models/merchant.rb +179 -0
  102. data/lib/univapay_client_sdk/models/merchant_webhook_bank_transfer_configuration.rb +342 -0
  103. data/lib/univapay_client_sdk/models/merchant_webhook_card_brand_percent_fees.rb +167 -0
  104. data/lib/univapay_client_sdk/models/merchant_webhook_card_configuration.rb +301 -0
  105. data/lib/univapay_client_sdk/models/merchant_webhook_checkout_configuration.rb +87 -0
  106. data/lib/univapay_client_sdk/models/merchant_webhook_checkout_toggle.rb +77 -0
  107. data/lib/univapay_client_sdk/models/merchant_webhook_configuration.rb +505 -0
  108. data/lib/univapay_client_sdk/models/merchant_webhook_convenience_configuration.rb +88 -0
  109. data/lib/univapay_client_sdk/models/merchant_webhook_customer_management_configuration.rb +99 -0
  110. data/lib/univapay_client_sdk/models/merchant_webhook_installment_plan_configuration.rb +139 -0
  111. data/lib/univapay_client_sdk/models/merchant_webhook_limit_charge_by_card_configuration.rb +88 -0
  112. data/lib/univapay_client_sdk/models/merchant_webhook_limit_refund_by_sales_configuration.rb +100 -0
  113. data/lib/univapay_client_sdk/models/merchant_webhook_money_amount.rb +85 -0
  114. data/lib/univapay_client_sdk/models/merchant_webhook_online_configuration.rb +77 -0
  115. data/lib/univapay_client_sdk/models/merchant_webhook_paidy_configuration.rb +77 -0
  116. data/lib/univapay_client_sdk/models/merchant_webhook_qr_merchant_configuration.rb +77 -0
  117. data/lib/univapay_client_sdk/models/merchant_webhook_qr_scan_configuration.rb +93 -0
  118. data/lib/univapay_client_sdk/models/merchant_webhook_recurring_cvv_confirmation_config.rb +97 -0
  119. data/lib/univapay_client_sdk/models/merchant_webhook_recurring_token_configuration.rb +109 -0
  120. data/lib/univapay_client_sdk/models/merchant_webhook_security_configuration.rb +234 -0
  121. data/lib/univapay_client_sdk/models/merchant_webhook_subscription_configuration.rb +138 -0
  122. data/lib/univapay_client_sdk/models/merchant_webhook_subscription_plan_configuration.rb +138 -0
  123. data/lib/univapay_client_sdk/models/merchant_webhook_transfer_schedule_configuration.rb +159 -0
  124. data/lib/univapay_client_sdk/models/merchant_webhook_user_transactions_configuration.rb +349 -0
  125. data/lib/univapay_client_sdk/models/mode_query.rb +36 -0
  126. data/lib/univapay_client_sdk/models/payment_error.rb +178 -0
  127. data/lib/univapay_client_sdk/models/plan_settings_type.rb +36 -0
  128. data/lib/univapay_client_sdk/models/refund.rb +240 -0
  129. data/lib/univapay_client_sdk/models/refund_create_request.rb +118 -0
  130. data/lib/univapay_client_sdk/models/refund_event.rb +26 -0
  131. data/lib/univapay_client_sdk/models/refund_list.rb +104 -0
  132. data/lib/univapay_client_sdk/models/refund_reason_request.rb +42 -0
  133. data/lib/univapay_client_sdk/models/refund_reason_response.rb +62 -0
  134. data/lib/univapay_client_sdk/models/refund_status.rb +47 -0
  135. data/lib/univapay_client_sdk/models/refund_update_request.rb +99 -0
  136. data/lib/univapay_client_sdk/models/refund_webhook_callback.rb +132 -0
  137. data/lib/univapay_client_sdk/models/refund_webhook_callback_extension.rb +74 -0
  138. data/lib/univapay_client_sdk/models/restrict_ip_after_failed_charge_config.rb +99 -0
  139. data/lib/univapay_client_sdk/models/store.rb +119 -0
  140. data/lib/univapay_client_sdk/models/store_list.rb +104 -0
  141. data/lib/univapay_client_sdk/models/store_list_item.rb +114 -0
  142. data/lib/univapay_client_sdk/models/subscription.rb +310 -0
  143. data/lib/univapay_client_sdk/models/subscription_create_request.rb +216 -0
  144. data/lib/univapay_client_sdk/models/subscription_event.rb +54 -0
  145. data/lib/univapay_client_sdk/models/subscription_installment_plan.rb +86 -0
  146. data/lib/univapay_client_sdk/models/subscription_list.rb +104 -0
  147. data/lib/univapay_client_sdk/models/subscription_list_item.rb +352 -0
  148. data/lib/univapay_client_sdk/models/subscription_next_payment.rb +222 -0
  149. data/lib/univapay_client_sdk/models/subscription_patch_payment_request.rb +117 -0
  150. data/lib/univapay_client_sdk/models/subscription_patch_token_request.rb +79 -0
  151. data/lib/univapay_client_sdk/models/subscription_payment.rb +185 -0
  152. data/lib/univapay_client_sdk/models/subscription_payment_list.rb +94 -0
  153. data/lib/univapay_client_sdk/models/subscription_period.rb +56 -0
  154. data/lib/univapay_client_sdk/models/subscription_plan_settings.rb +98 -0
  155. data/lib/univapay_client_sdk/models/subscription_schedule_settings.rb +132 -0
  156. data/lib/univapay_client_sdk/models/subscription_status.rb +56 -0
  157. data/lib/univapay_client_sdk/models/subscription_suspend_request.rb +79 -0
  158. data/lib/univapay_client_sdk/models/subscription_terminate_with_status.rb +36 -0
  159. data/lib/univapay_client_sdk/models/subscription_termination_mode.rb +36 -0
  160. data/lib/univapay_client_sdk/models/subscription_update_next_payment.rb +104 -0
  161. data/lib/univapay_client_sdk/models/subscription_update_request.rb +134 -0
  162. data/lib/univapay_client_sdk/models/subscription_update_schedule_settings.rb +110 -0
  163. data/lib/univapay_client_sdk/models/subscription_update_status.rb +37 -0
  164. data/lib/univapay_client_sdk/models/subscription_user_data.rb +134 -0
  165. data/lib/univapay_client_sdk/models/subscription_webhook_event.rb +143 -0
  166. data/lib/univapay_client_sdk/models/suspend_schedule_settings.rb +78 -0
  167. data/lib/univapay_client_sdk/models/three_ds_issuer_token.rb +116 -0
  168. data/lib/univapay_client_sdk/models/three_ds_issuer_token_call_method.rb +26 -0
  169. data/lib/univapay_client_sdk/models/three_ds_issuer_token_payment_type.rb +26 -0
  170. data/lib/univapay_client_sdk/models/token_create_bank_transfer_data.rb +122 -0
  171. data/lib/univapay_client_sdk/models/token_create_card_data.rb +230 -0
  172. data/lib/univapay_client_sdk/models/token_create_card_data_cvv_authorize.rb +95 -0
  173. data/lib/univapay_client_sdk/models/token_create_card_data_three_ds.rb +97 -0
  174. data/lib/univapay_client_sdk/models/token_create_konbini_data.rb +146 -0
  175. data/lib/univapay_client_sdk/models/token_create_online_data.rb +142 -0
  176. data/lib/univapay_client_sdk/models/token_create_phone_number.rb +104 -0
  177. data/lib/univapay_client_sdk/models/token_event.rb +59 -0
  178. data/lib/univapay_client_sdk/models/token_response_bank_transfer_data.rb +181 -0
  179. data/lib/univapay_client_sdk/models/token_response_card_data.rb +129 -0
  180. data/lib/univapay_client_sdk/models/token_response_card_data_billing.rb +153 -0
  181. data/lib/univapay_client_sdk/models/token_response_card_data_card.rb +187 -0
  182. data/lib/univapay_client_sdk/models/token_response_card_data_cvv_authorize.rb +132 -0
  183. data/lib/univapay_client_sdk/models/token_response_card_data_cvv_authorize_check.rb +118 -0
  184. data/lib/univapay_client_sdk/models/token_response_card_data_three_ds.rb +142 -0
  185. data/lib/univapay_client_sdk/models/token_response_card_data_three_ds_status.rb +48 -0
  186. data/lib/univapay_client_sdk/models/token_response_konbini_data.rb +135 -0
  187. data/lib/univapay_client_sdk/models/token_response_online_data.rb +158 -0
  188. data/lib/univapay_client_sdk/models/token_response_phone_number.rb +96 -0
  189. data/lib/univapay_client_sdk/models/token_webhook_event.rb +144 -0
  190. data/lib/univapay_client_sdk/models/transaction_token.rb +250 -0
  191. data/lib/univapay_client_sdk/models/transaction_token_create_request.rb +161 -0
  192. data/lib/univapay_client_sdk/models/transaction_token_create_request_metadata.rb +124 -0
  193. data/lib/univapay_client_sdk/models/transaction_token_create_request_payment_type.rb +44 -0
  194. data/lib/univapay_client_sdk/models/transaction_token_create_request_type.rb +40 -0
  195. data/lib/univapay_client_sdk/models/transaction_token_list.rb +104 -0
  196. data/lib/univapay_client_sdk/models/transaction_token_list_item.rb +204 -0
  197. data/lib/univapay_client_sdk/models/transaction_token_list_item_user_data.rb +96 -0
  198. data/lib/univapay_client_sdk/models/transaction_token_mode.rb +36 -0
  199. data/lib/univapay_client_sdk/models/transaction_token_payment_type.rb +48 -0
  200. data/lib/univapay_client_sdk/models/transaction_token_type.rb +40 -0
  201. data/lib/univapay_client_sdk/models/transaction_token_update_request.rb +95 -0
  202. data/lib/univapay_client_sdk/models/transaction_token_update_request_data.rb +184 -0
  203. data/lib/univapay_client_sdk/models/transaction_token_update_request_data_phone_number.rb +86 -0
  204. data/lib/univapay_client_sdk/models/webhook.rb +191 -0
  205. data/lib/univapay_client_sdk/models/webhook_callback_envelope.rb +98 -0
  206. data/lib/univapay_client_sdk/models/webhook_create_request.rb +97 -0
  207. data/lib/univapay_client_sdk/models/webhook_event.rb +166 -0
  208. data/lib/univapay_client_sdk/models/webhook_event_list.rb +94 -0
  209. data/lib/univapay_client_sdk/models/webhook_list.rb +94 -0
  210. data/lib/univapay_client_sdk/models/webhook_trigger.rb +104 -0
  211. data/lib/univapay_client_sdk/models/webhook_update_request.rb +108 -0
  212. data/lib/univapay_client_sdk/utilities/date_time_helper.rb +11 -0
  213. data/lib/univapay_client_sdk/utilities/file_wrapper.rb +28 -0
  214. data/lib/univapay_client_sdk/utilities/union_type_lookup.rb +182 -0
  215. data/lib/univapay_client_sdk.rb +285 -0
  216. data/test/apis/api_test_base.rb +23 -0
  217. data/test/apis/test_cancels_api.rb +162 -0
  218. data/test/apis/test_charges_api.rb +565 -0
  219. data/test/apis/test_error_messages.rb +38 -0
  220. data/test/apis/test_merchants_api.rb +50 -0
  221. data/test/apis/test_refunds_api.rb +172 -0
  222. data/test/apis/test_stores_api.rb +86 -0
  223. data/test/apis/test_subscriptions_api.rb +579 -0
  224. data/test/apis/test_transaction_tokens_api.rb +305 -0
  225. data/test/apis/test_webhooks_api.rb +245 -0
  226. data/test/events/webhooks/test_bank_transfer_handler.rb +95 -0
  227. data/test/events/webhooks/test_cancel_handler.rb +90 -0
  228. data/test/events/webhooks/test_charge_handler.rb +138 -0
  229. data/test/events/webhooks/test_customs_handler.rb +100 -0
  230. data/test/events/webhooks/test_refund_handler.rb +95 -0
  231. data/test/events/webhooks/test_subscription_handler.rb +346 -0
  232. data/test/events/webhooks/test_token_handler.rb +332 -0
  233. data/test/framework_integrations/rails_app_test_helper.rb +14 -0
  234. data/test/framework_integrations/webhooks/apps/hanami_charge_app.rb +61 -0
  235. data/test/framework_integrations/webhooks/apps/rails_charge_app.rb +24 -0
  236. data/test/framework_integrations/webhooks/apps/sinatra_charge_app.rb +27 -0
  237. data/test/framework_integrations/webhooks/test/test_hanami_charge_app.rb +57 -0
  238. data/test/framework_integrations/webhooks/test/test_rails_charge_app.rb +57 -0
  239. data/test/framework_integrations/webhooks/test/test_sinatra_charge_app.rb +58 -0
  240. data/test/http_response_catcher.rb +32 -0
  241. metadata +366 -0
@@ -0,0 +1,565 @@
1
+ # univapay_client_sdk
2
+ #
3
+ # This file was automatically generated for Univapay
4
+ # by APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ require_relative 'api_test_base'
7
+
8
+ class ChargesApiTest < ApiTestBase
9
+ # Called only once for the class before any test has executed
10
+ def setup
11
+ setup_class
12
+ @controller = @client.charges
13
+ @response_catcher = @controller.http_call_back
14
+ end
15
+
16
+ # Creates a charge on a payment instrument (e.g. transaction token).
17
+ def test_create_charge
18
+ # Parameters for the API call
19
+ idempotency_key = 'f64be872-353d-4c3c-84cb-3dc617fe89f7'
20
+ body = ChargeCreateRequest.from_hash(APIHelper.json_deserialize(
21
+ '{"transaction_token_id":"11ef32a7-3a71-8662-803f-1bc27702eeec","amount"'\
22
+ ':1000,"currency":"JPY","metadata":{"order_id":"12345"},"redirect":{"end'\
23
+ 'point":"https://test.url/"}}', false))
24
+
25
+ # Perform the API call through the SDK function
26
+ result = @controller.create_charge(idempotency_key: idempotency_key,
27
+ body: body)
28
+
29
+ # Test response code
30
+ assert_equal(201, @response_catcher.response.status_code)
31
+ # Test headers
32
+ expected_headers = {}
33
+ expected_headers['content-type'] = 'application/json; charset=utf-8'
34
+
35
+ assert(ComparisonHelper.match_headers(expected_headers, @response_catcher.response.headers))
36
+
37
+ # Test whether the captured response is as we expected
38
+ refute_nil(result)
39
+ expected_body = JSON.parse(
40
+ '{"id":"11ef32c2-4010-a312-aaff-4b63e4d5f92d","store_id":"11edf541-c42d-'\
41
+ '653c-8c3d-dfe0a55f95c0","transaction_token_id":"11ef32a7-3a71-8662-803f'\
42
+ '-1bc27702eeec","transaction_token_type":"recurring","subscription_id":n'\
43
+ 'ull,"merchant_transaction_id":null,"requested_amount":1000,"requested_c'\
44
+ 'urrency":"JPY","requested_amount_formatted":1000,"charged_amount":null,'\
45
+ '"charged_currency":null,"charged_amount_formatted":null,"fee_amount":nu'\
46
+ 'll,"fee_currency":null,"fee_amount_formatted":null,"only_direct_currenc'\
47
+ 'y":false,"capture_at":null,"descriptor":null,"descriptor_phone_number":'\
48
+ 'null,"status":"pending","error":null,"metadata":{"order_id":"12345"},"m'\
49
+ 'ode":"test","created_on":"2024-06-25T07:12:15.16452Z","redirect":{"endp'\
50
+ 'oint":"https://test.url/","redirect_id":"11ef32c2-40cf-f772-8325-1798ab'\
51
+ 'b1110d"}}'
52
+ )
53
+ received_body = JSON.parse(@response_catcher.response.raw_body)
54
+ assert(ComparisonHelper.match_body(expected_body, received_body))
55
+ end
56
+
57
+ # Lists all charges across all stores for the authenticated user.
58
+ def test_list_all_charges
59
+ # Parameters for the API call
60
+ limit = 10
61
+ cursor = '3541d4fa-596d-428e-8a36-f274e1b3d505'
62
+ cursor_direction = 'desc'
63
+ last_four = '4242'
64
+ name = 'TARO YAMADA'
65
+ exp_month = 12
66
+ exp_year = 2026
67
+ from = '2026-04-01T00:00:00Z'
68
+ to = '2026-04-30T23:59:59.999000Z'
69
+ email = 'user@example.com'
70
+ phone = '+8108012341234'
71
+ amount_from = 1000
72
+ amount_to = 5000
73
+ currency = 'JPY'
74
+ mode = 'live'
75
+ metadata = 'order_id: 12345'
76
+ transaction_token_id = 'f33b673e-564c-4645-ae17-ca03846a86b7'
77
+
78
+ # Perform the API call through the SDK function
79
+ result = @controller.list_all_charges(
80
+ limit: limit, cursor: cursor, cursor_direction: cursor_direction,
81
+ last_four: last_four, name: name, exp_month: exp_month,
82
+ exp_year: exp_year, from: from, to: to, email: email, phone: phone,
83
+ amount_from: amount_from, amount_to: amount_to, currency: currency,
84
+ mode: mode, metadata: metadata,
85
+ transaction_token_id: transaction_token_id
86
+ )
87
+
88
+ # Test response code
89
+ assert_equal(200, @response_catcher.response.status_code)
90
+ # Test headers
91
+ expected_headers = {}
92
+ expected_headers['content-type'] = 'application/json; charset=utf-8'
93
+
94
+ assert(ComparisonHelper.match_headers(expected_headers, @response_catcher.response.headers))
95
+
96
+ # Test whether the captured response is as we expected
97
+ refute_nil(result)
98
+ expected_body = JSON.parse(
99
+ '{"items":[{"id":"11ef3500-1a2b-4c3d-8e4f-a1b2c3d4e5f0","store_id":"11ed'\
100
+ 'f541-c42d-653c-8c3d-dfe0a55f95c0","transaction_token_id":"11ef3501-2b3c'\
101
+ '-4d5e-9f60-b2c3d4e5f011","transaction_token_type":"one_time","subscript'\
102
+ 'ion_id":null,"merchant_transaction_id":null,"requested_amount":1000,"re'\
103
+ 'quested_currency":"JPY","requested_amount_formatted":1000,"charged_amou'\
104
+ 'nt":1000,"charged_currency":"JPY","charged_amount_formatted":1000,"fee_'\
105
+ 'amount":null,"fee_currency":null,"fee_amount_formatted":null,"only_dire'\
106
+ 'ct_currency":false,"capture_at":null,"descriptor":null,"descriptor_phon'\
107
+ 'e_number":null,"status":"successful","error":{},"metadata":{"order_id":'\
108
+ '"ORD-2001"},"mode":"live","created_on":"2026-04-09T07:35:50.000000Z","r'\
109
+ 'edirect":{},"merchant_name":"管理画面ガイド","store_name":"管理画面ガイド_TEST店舗"},{"'\
110
+ 'id":"11ef3502-3c4d-5e6f-a071-c3d4e5f01122","store_id":"22af6520-d53e-76'\
111
+ '4d-9d4e-ef01b66fa6d1","transaction_token_id":"11ef3503-4d5e-6f70-b182-d'\
112
+ '4e5f0112233","transaction_token_type":"recurring","subscription_id":nul'\
113
+ 'l,"merchant_transaction_id":null,"requested_amount":1250,"requested_cur'\
114
+ 'rency":"USD","requested_amount_formatted":12.5,"charged_amount":1250,"c'\
115
+ 'harged_currency":"USD","charged_amount_formatted":12.5,"fee_amount":nul'\
116
+ 'l,"fee_currency":null,"fee_amount_formatted":null,"only_direct_currency'\
117
+ '":false,"capture_at":null,"descriptor":null,"descriptor_phone_number":n'\
118
+ 'ull,"status":"successful","error":{},"metadata":{"order_id":"ORD-2002"}'\
119
+ ',"mode":"live","created_on":"2026-04-10T10:20:11.000000Z","redirect":{}'\
120
+ ',"merchant_name":"管理画面ガイド","store_name":"管理画面ガイド_Online店舗"},{"id":"11ef'\
121
+ '3504-5e6f-7081-c293-e5f001223344","store_id":"33af7631-e64f-875e-ae5f-f'\
122
+ '012c77fb7e2","transaction_token_id":"11ef3505-6f70-8192-d3a4-f001122334'\
123
+ '55","transaction_token_type":"one_time","subscription_id":null,"merchan'\
124
+ 't_transaction_id":null,"requested_amount":5000,"requested_currency":"JP'\
125
+ 'Y","requested_amount_formatted":5000,"charged_amount":5000,"charged_cur'\
126
+ 'rency":"JPY","charged_amount_formatted":5000,"fee_amount":null,"fee_cur'\
127
+ 'rency":null,"fee_amount_formatted":null,"only_direct_currency":false,"c'\
128
+ 'apture_at":null,"descriptor":null,"descriptor_phone_number":null,"statu'\
129
+ 's":"successful","error":{},"metadata":{"order_id":"ORD-2003"},"mode":"l'\
130
+ 'ive","created_on":"2026-04-11T14:22:08.000000Z","redirect":{},"merchant'\
131
+ '_name":"管理画面ガイド","store_name":"管理画面ガイド_Osaka店舗"}],"has_more":false,"tot'\
132
+ 'al_hits":3}'
133
+ )
134
+ received_body = JSON.parse(@response_catcher.response.raw_body)
135
+ assert(ComparisonHelper.match_body(expected_body, received_body))
136
+ end
137
+
138
+ # Lists all charges for a specific store.
139
+ def test_list_store_charges
140
+ # Parameters for the API call
141
+ store_id = '0cab399b-5621-425b-993b-f8507eba1e78'
142
+ limit = 10
143
+ cursor = '3541d4fa-596d-428e-8a36-f274e1b3d505'
144
+ cursor_direction = 'desc'
145
+ last_four = '4242'
146
+ name = 'TARO YAMADA'
147
+ exp_month = 12
148
+ exp_year = 2026
149
+ from = '2026-04-01T00:00:00Z'
150
+ to = '2026-04-30T23:59:59.999000Z'
151
+ email = 'user@example.com'
152
+ phone = '+8108012341234'
153
+ amount_from = 1000
154
+ amount_to = 5000
155
+ currency = 'JPY'
156
+ mode = 'live'
157
+ metadata = 'order_id: 12345'
158
+ transaction_token_id = 'f33b673e-564c-4645-ae17-ca03846a86b7'
159
+
160
+ # Perform the API call through the SDK function
161
+ result = @controller.list_store_charges(
162
+ store_id, limit: limit, cursor: cursor,
163
+ cursor_direction: cursor_direction, last_four: last_four, name: name,
164
+ exp_month: exp_month, exp_year: exp_year, from: from, to: to,
165
+ email: email, phone: phone, amount_from: amount_from,
166
+ amount_to: amount_to, currency: currency, mode: mode, metadata: metadata,
167
+ transaction_token_id: transaction_token_id
168
+ )
169
+
170
+ # Test response code
171
+ assert_equal(200, @response_catcher.response.status_code)
172
+ # Test headers
173
+ expected_headers = {}
174
+ expected_headers['content-type'] = 'application/json; charset=utf-8'
175
+
176
+ assert(ComparisonHelper.match_headers(expected_headers, @response_catcher.response.headers))
177
+
178
+ # Test whether the captured response is as we expected
179
+ refute_nil(result)
180
+ expected_body = JSON.parse(
181
+ '{"items":[{"id":"11ef32c4-9ea8-169c-a6c8-bfc29867a226","store_id":"11ed'\
182
+ 'f541-c42d-653c-8c3d-dfe0a55f95c0","transaction_token_id":"11ef32c4-9e89'\
183
+ '-0cac-bd63-17b9a26af61b","transaction_token_type":"one_time","subscript'\
184
+ 'ion_id":null,"merchant_transaction_id":null,"requested_amount":1000,"re'\
185
+ 'quested_currency":"JPY","requested_amount_formatted":1000,"charged_amou'\
186
+ 'nt":1000,"charged_currency":"JPY","charged_amount_formatted":1000,"fee_'\
187
+ 'amount":null,"fee_currency":null,"fee_amount_formatted":null,"only_dire'\
188
+ 'ct_currency":false,"capture_at":null,"descriptor":null,"descriptor_phon'\
189
+ 'e_number":null,"status":"successful","error":{},"metadata":{"univapay-n'\
190
+ 'ame":"taro yamada","univapay-phone-number":"8029854583"},"mode":"test",'\
191
+ '"created_on":"2024-06-25T07:29:12.854865Z","redirect":{},"merchant_name'\
192
+ '":"管理画面ガイド","store_name":"管理画面ガイド_TEST店舗"},{"id":"11ef32c3-3cfe-3bc0-ab'\
193
+ 'ed-0bb96f792078","store_id":"11edf541-c42d-653c-8c3d-dfe0a55f95c0","tra'\
194
+ 'nsaction_token_id":"11ef32c3-3cdd-df92-9dce-c346b9fdf088","transaction_'\
195
+ 'token_type":"one_time","subscription_id":null,"merchant_transaction_id"'\
196
+ ':null,"requested_amount":1000,"requested_currency":"JPY","requested_amo'\
197
+ 'unt_formatted":1000,"charged_amount":1000,"charged_currency":"JPY","cha'\
198
+ 'rged_amount_formatted":1000,"fee_amount":null,"fee_currency":null,"fee_'\
199
+ 'amount_formatted":null,"only_direct_currency":false,"capture_at":null,"'\
200
+ 'descriptor":null,"descriptor_phone_number":null,"status":"successful","'\
201
+ 'error":{},"metadata":{"order_id":"12345"},"mode":"test","created_on":"2'\
202
+ '024-06-25T07:19:19.507637Z","redirect":{},"merchant_name":"管理画面ガイド","st'\
203
+ 'ore_name":"管理画面ガイド_TEST店舗"}],"has_more":false,"total_hits":2}'
204
+ )
205
+ received_body = JSON.parse(@response_catcher.response.raw_body)
206
+ assert(ComparisonHelper.match_body(expected_body, received_body))
207
+ end
208
+
209
+ # Retrieves the details of an existing charge.
210
+ def test_get_charge
211
+ # Parameters for the API call
212
+ store_id = '0cab399b-5621-425b-993b-f8507eba1e78'
213
+ id = 'c4e87129-cad4-47fb-8ded-b4c0a4ae0dd4'
214
+ polling = true
215
+
216
+ # Perform the API call through the SDK function
217
+ result = @controller.get_charge(store_id, id, polling: polling)
218
+
219
+ # Test response code
220
+ assert_equal(200, @response_catcher.response.status_code)
221
+ # Test headers
222
+ expected_headers = {}
223
+ expected_headers['content-type'] = 'application/json; charset=utf-8'
224
+
225
+ assert(ComparisonHelper.match_headers(expected_headers, @response_catcher.response.headers))
226
+
227
+ # Test whether the captured response is as we expected
228
+ refute_nil(result)
229
+ expected_body = JSON.parse(
230
+ '{"id":"11ef32c2-4010-a312-aaff-4b63e4d5f92d","store_id":"11edf541-c42d-'\
231
+ '653c-8c3d-dfe0a55f95c0","transaction_token_id":"11ef32a7-3a71-8662-803f'\
232
+ '-1bc27702eeec","transaction_token_type":"recurring","subscription_id":n'\
233
+ 'ull,"merchant_transaction_id":null,"requested_amount":1000,"requested_c'\
234
+ 'urrency":"JPY","requested_amount_formatted":1000,"charged_amount":1000,'\
235
+ '"charged_currency":"JPY","charged_amount_formatted":1000,"fee_amount":n'\
236
+ 'ull,"fee_currency":null,"fee_amount_formatted":null,"only_direct_curren'\
237
+ 'cy":false,"capture_at":null,"descriptor":null,"descriptor_phone_number"'\
238
+ ':null,"status":"successful","error":null,"metadata":{"order_id":"12345"'\
239
+ '},"mode":"test","created_on":"2024-06-25T07:12:15.16452Z","redirect":{"'\
240
+ 'endpoint":"https://test.url/","redirect_id":"11ef32c2-40cf-f772-8325-17'\
241
+ '98abb1110d"}}'
242
+ )
243
+ received_body = JSON.parse(@response_catcher.response.raw_body)
244
+ assert(ComparisonHelper.match_body(expected_body, received_body))
245
+ end
246
+
247
+ # Use this request to add or modify arbitrary metadata on an existing charge.
248
+ def test_update_charge
249
+ # Parameters for the API call
250
+ store_id = '0cab399b-5621-425b-993b-f8507eba1e78'
251
+ id = 'c4e87129-cad4-47fb-8ded-b4c0a4ae0dd4'
252
+ idempotency_key = 'f64be872-353d-4c3c-84cb-3dc617fe89f7'
253
+ body = ChargeUpdateRequest.from_hash(APIHelper.json_deserialize(
254
+ '{"metadata":{"order_id":"1234"}}', false))
255
+
256
+ # Perform the API call through the SDK function
257
+ result = @controller.update_charge(store_id, id,
258
+ idempotency_key: idempotency_key,
259
+ body: body)
260
+
261
+ # Test response code
262
+ assert_equal(200, @response_catcher.response.status_code)
263
+ # Test headers
264
+ expected_headers = {}
265
+ expected_headers['content-type'] = 'application/json; charset=utf-8'
266
+
267
+ assert(ComparisonHelper.match_headers(expected_headers, @response_catcher.response.headers))
268
+
269
+ # Test whether the captured response is as we expected
270
+ refute_nil(result)
271
+ expected_body = JSON.parse(
272
+ '{"id":"11ef32c2-4010-a312-aaff-4b63e4d5f92d","store_id":"11edf541-c42d-'\
273
+ '653c-8c3d-dfe0a55f95c0","transaction_token_id":"11ef32a7-3a71-8662-803f'\
274
+ '-1bc27702eeec","transaction_token_type":"recurring","subscription_id":n'\
275
+ 'ull,"merchant_transaction_id":null,"requested_amount":1000,"requested_c'\
276
+ 'urrency":"JPY","requested_amount_formatted":1000,"charged_amount":1000,'\
277
+ '"charged_currency":"JPY","charged_amount_formatted":1000,"fee_amount":n'\
278
+ 'ull,"fee_currency":null,"fee_amount_formatted":null,"only_direct_curren'\
279
+ 'cy":false,"capture_at":null,"descriptor":null,"descriptor_phone_number"'\
280
+ ':null,"status":"successful","error":null,"metadata":{"order_id":"1234"}'\
281
+ ',"mode":"test","created_on":"2024-06-25T07:12:15.16452Z","redirect":{"e'\
282
+ 'ndpoint":"https://test.url/","redirect_id":"11ef32c2-40cf-f772-8325-179'\
283
+ '8abb1110d"}}'
284
+ )
285
+ received_body = JSON.parse(@response_catcher.response.raw_body)
286
+ assert(ComparisonHelper.match_body(expected_body, received_body))
287
+ end
288
+
289
+ # Captures a previously authorized charge (where `capture` was set to false during creation). The capture amount must be less than or equal to the authorized amount, and the currency must match.
290
+ def test_capture_charge
291
+ # Parameters for the API call
292
+ store_id = '0cab399b-5621-425b-993b-f8507eba1e78'
293
+ id = 'c4e87129-cad4-47fb-8ded-b4c0a4ae0dd4'
294
+ body = ChargeCaptureRequest.from_hash(APIHelper.json_deserialize(
295
+ '{"amount":1000,"currency":"JPY"}', false))
296
+ idempotency_key = 'f64be872-353d-4c3c-84cb-3dc617fe89f7'
297
+
298
+ # Perform the API call through the SDK function
299
+ result = @controller.capture_charge(store_id, id, body,
300
+ idempotency_key: idempotency_key)
301
+
302
+ # Test response code
303
+ assert_equal(200, @response_catcher.response.status_code)
304
+ # Test headers
305
+ expected_headers = {}
306
+ expected_headers['content-type'] = 'application/json; charset=utf-8'
307
+
308
+ assert(ComparisonHelper.match_headers(expected_headers, @response_catcher.response.headers))
309
+
310
+ # Test whether the captured response is as we expected
311
+ refute_nil(result)
312
+ expected_body = JSON.parse(
313
+ '{}'
314
+ )
315
+ received_body = JSON.parse(@response_catcher.response.raw_body)
316
+ assert(ComparisonHelper.match_body(expected_body, received_body))
317
+ end
318
+
319
+ # Retrieves the necessary payment execution URL (for online payments) or bank account details (for bank transfers).
320
+ #**⚠️ Prerequisite:** The charge `status` must be `awaiting` before requesting the issuer token. If requested while the charge is in any other status, an error will be returned.
321
+ def test_get_charge_issuer_token
322
+ # Parameters for the API call
323
+ store_id = '0cab399b-5621-425b-993b-f8507eba1e78'
324
+ id = 'c4e87129-cad4-47fb-8ded-b4c0a4ae0dd4'
325
+
326
+ # Perform the API call through the SDK function
327
+ result = @controller.get_charge_issuer_token(store_id, id)
328
+
329
+ # Test response code
330
+ assert_equal(200, @response_catcher.response.status_code)
331
+ # Test headers
332
+ expected_headers = {}
333
+ expected_headers['content-type'] = 'application/json; charset=utf-8'
334
+
335
+ assert(ComparisonHelper.match_headers(expected_headers, @response_catcher.response.headers))
336
+
337
+ # Test whether the captured response is as we expected
338
+ refute_nil(result)
339
+ expected_body = JSON.parse(
340
+ '{"issuer_token":"http://test.com/action","call_method":"http_post","pay'\
341
+ 'load":{"request_data":"example_value"},"payment_type":"online"}'
342
+ )
343
+ received_body = JSON.parse(@response_catcher.response.raw_body)
344
+ assert(ComparisonHelper.match_body(expected_body, received_body))
345
+ end
346
+
347
+ # Retrieves the 3-D Secure issuer token details required to authenticate a card charge.
348
+ #**⚠️ Prerequisites:** 1. The charge must be created with `three_ds.mode` set to `normal` or `force`. 2. You must poll the charge until its `status` becomes `awaiting` before making this request.
349
+ #**Execution Flow:** Once retrieved, the client (browser) must execute an `http_post` request to the `issuer_token` URL. The `payload` object must be formatted according to the `content_type` (e.g., URL-encoded) and sent in the body. You can execute this via a redirect or inside an iframe. If using an iframe, continue polling the charge status in the background until it reaches `successful`, `failed`, or `error`.
350
+ def test_get_charge_three_ds_issuer_token
351
+ # Parameters for the API call
352
+ store_id = '0cab399b-5621-425b-993b-f8507eba1e78'
353
+ id = 'c4e87129-cad4-47fb-8ded-b4c0a4ae0dd4'
354
+
355
+ # Perform the API call through the SDK function
356
+ result = @controller.get_charge_three_ds_issuer_token(store_id, id)
357
+
358
+ # Test response code
359
+ assert_equal(200, @response_catcher.response.status_code)
360
+ # Test headers
361
+ expected_headers = {}
362
+ expected_headers['content-type'] = 'application/json; charset=utf-8'
363
+
364
+ assert(ComparisonHelper.match_headers(expected_headers, @response_catcher.response.headers))
365
+
366
+ # Test whether the captured response is as we expected
367
+ refute_nil(result)
368
+ expected_body = JSON.parse(
369
+ '{"issuer_token":"http://test.com/action","call_method":"http_post","pay'\
370
+ 'load":{"request_data":"example_value"},"payment_type":"card","content_t'\
371
+ 'ype":"application/x-www-form-urlencoded; charset=UTF-8"}'
372
+ )
373
+ received_body = JSON.parse(@response_catcher.response.raw_body)
374
+ assert(ComparisonHelper.match_body(expected_body, received_body))
375
+ end
376
+
377
+ # Retrieves bank transfer ledger entries associated with a charge. This is an optional reconciliation endpoint — not part of the required create-charge-and-poll flow.
378
+ #**⚠️ Requires a merchant-level application token**, unlike the rest of the bank transfer flow. A store application token (`Bearer {secret}.{jwt}` scoped to a `store_id`) is not sufficient here, even though the path is store-scoped.
379
+ def test_list_bank_transfer_ledgers
380
+ # Parameters for the API call
381
+ store_id = '0cab399b-5621-425b-993b-f8507eba1e78'
382
+ id = 'c4e87129-cad4-47fb-8ded-b4c0a4ae0dd4'
383
+
384
+ # Perform the API call through the SDK function
385
+ result = @controller.list_bank_transfer_ledgers(store_id, id)
386
+
387
+ # Test response code
388
+ assert_equal(200, @response_catcher.response.status_code)
389
+ # Test headers
390
+ expected_headers = {}
391
+ expected_headers['content-type'] = 'application/json; charset=utf-8'
392
+
393
+ assert(ComparisonHelper.match_headers(expected_headers, @response_catcher.response.headers))
394
+
395
+ # Test whether the captured response is as we expected
396
+ refute_nil(result)
397
+ expected_body = JSON.parse(
398
+ '{"items":[{"bank_ledger_type":"payment","amount":1000,"balance":0,"virt'\
399
+ 'ual_bank_account_holder_name":"test holder name","virtual_bank_account_'\
400
+ 'number":"1234567","virtual_account_id":"test account id","transaction_d'\
401
+ 'ate":"2024-06-25","transaction_timestamp":"2024-06-25T07:29:16.367347Z"'\
402
+ ',"mode":"test","created_on":"2024-06-25T07:29:16.373181Z"},{"bank_ledge'\
403
+ 'r_type":"deposit","amount":1000,"balance":1000,"virtual_bank_account_ho'\
404
+ 'lder_name":"test holder name","virtual_bank_account_number":"1234567","'\
405
+ 'virtual_account_id":"test account id","transaction_date":"2024-06-25","'\
406
+ 'transaction_timestamp":"2024-06-25T07:29:16.36731Z","mode":"test","crea'\
407
+ 'ted_on":"2024-06-25T07:29:16.368093Z"}],"has_more":false,"total_hits":2'\
408
+ '}'
409
+ )
410
+ received_body = JSON.parse(@response_catcher.response.raw_body)
411
+ assert(ComparisonHelper.match_body(expected_body, received_body))
412
+ end
413
+
414
+ # Creates a customs declaration for a successful charge. Backend only accepts this request for WeChat Online and WeChat MPM charges. If a declaration already exists and is no longer pending, the backend updates its identity fields and restarts processing instead of creating a new record.
415
+ def test_create_customs_declaration
416
+ # Parameters for the API call
417
+ store_id = '0cab399b-5621-425b-993b-f8507eba1e78'
418
+ charge_id = '6efb4e5c-690a-40f3-a4f1-0e19c5f84e98'
419
+ body = CustomsDeclarationCreateRequest.from_hash(APIHelper.json_deserialize(
420
+ '{"customs":"TOKYO","merchant_customs_no":"1234567890","certificate_id":'\
421
+ '"AB1234567","certificate_name":"TARO YAMADA"}', false))
422
+ idempotency_key = 'f64be872-353d-4c3c-84cb-3dc617fe89f7'
423
+
424
+ # Perform the API call through the SDK function
425
+ result = @controller.create_customs_declaration(
426
+ store_id, charge_id, body, idempotency_key: idempotency_key
427
+ )
428
+
429
+ # Test response code
430
+ assert_equal(200, @response_catcher.response.status_code)
431
+ # Test headers
432
+ expected_headers = {}
433
+ expected_headers['content-type'] = 'application/json; charset=utf-8'
434
+
435
+ assert(ComparisonHelper.match_headers(expected_headers, @response_catcher.response.headers))
436
+
437
+ # Test whether the captured response is as we expected
438
+ refute_nil(result)
439
+ expected_body = JSON.parse(
440
+ '{"id":"11ef0000-0000-4000-8000-000000000040","charge_id":"11ef0000-0000'\
441
+ '-4000-8000-000000000001","merchant_id":"11ef0000-0000-4000-8000-0000000'\
442
+ '00020","store_id":"11ef0000-0000-4000-8000-000000000022","mode":"test",'\
443
+ '"gateway":"wechat_online","declaration":{"customs":"TOKYO","merchant_cu'\
444
+ 'stoms_no":"1234567890","certificate_id":"AB1234567","certificate_name":'\
445
+ '"TARO YAMADA"},"declaration_result":{},"status":"pending","error":null,'\
446
+ '"created_on":"2026-04-09T07:35:50.000000Z"}'
447
+ )
448
+ received_body = JSON.parse(@response_catcher.response.raw_body)
449
+ assert(ComparisonHelper.match_body(expected_body, received_body))
450
+ end
451
+
452
+ # Creates a customs declaration for a successful charge. Backend only accepts this request for WeChat Online and WeChat MPM charges. If a declaration already exists and is no longer pending, the backend updates its identity fields and restarts processing instead of creating a new record.
453
+ def test_create_customs_declaration1
454
+ # Parameters for the API call
455
+ store_id = '0cab399b-5621-425b-993b-f8507eba1e78'
456
+ charge_id = '6efb4e5c-690a-40f3-a4f1-0e19c5f84e98'
457
+ body = CustomsDeclarationCreateRequest.from_hash(APIHelper.json_deserialize(
458
+ '{"customs":"TOKYO","merchant_customs_no":"1234567890","certificate_id":'\
459
+ '"AB1234567","certificate_name":"TARO YAMADA"}', false))
460
+ idempotency_key = 'f64be872-353d-4c3c-84cb-3dc617fe89f7'
461
+
462
+ # Perform the API call through the SDK function
463
+ result = @controller.create_customs_declaration(
464
+ store_id, charge_id, body, idempotency_key: idempotency_key
465
+ )
466
+
467
+ # Test response code
468
+ assert_equal(201, @response_catcher.response.status_code)
469
+ # Test headers
470
+ expected_headers = {}
471
+ expected_headers['content-type'] = 'application/json; charset=utf-8'
472
+
473
+ assert(ComparisonHelper.match_headers(expected_headers, @response_catcher.response.headers))
474
+
475
+ # Test whether the captured response is as we expected
476
+ refute_nil(result)
477
+ expected_body = JSON.parse(
478
+ '{"id":"11ef0000-0000-4000-8000-000000000040","charge_id":"11ef0000-0000'\
479
+ '-4000-8000-000000000001","merchant_id":"11ef0000-0000-4000-8000-0000000'\
480
+ '00020","store_id":"11ef0000-0000-4000-8000-000000000022","mode":"test",'\
481
+ '"gateway":"wechat_online","declaration":{"customs":"TOKYO","merchant_cu'\
482
+ 'stoms_no":"1234567890","certificate_id":"AB1234567","certificate_name":'\
483
+ '"TARO YAMADA"},"declaration_result":{},"status":"pending","error":null,'\
484
+ '"created_on":"2026-04-09T07:35:50.000000Z"}'
485
+ )
486
+ received_body = JSON.parse(@response_catcher.response.raw_body)
487
+ assert(ComparisonHelper.match_body(expected_body, received_body))
488
+ end
489
+
490
+ # Retrieves a customs declaration for a charge. Supports long polling when `polling=true`, returning once the declaration leaves its current state or the polling timeout is reached.
491
+ def test_get_customs_declaration
492
+ # Parameters for the API call
493
+ store_id = '0cab399b-5621-425b-993b-f8507eba1e78'
494
+ charge_id = '6efb4e5c-690a-40f3-a4f1-0e19c5f84e98'
495
+ id = '11ef0000-0000-4000-8000-000000000040'
496
+ polling = false
497
+
498
+ # Perform the API call through the SDK function
499
+ result = @controller.get_customs_declaration(store_id, charge_id, id,
500
+ polling: polling)
501
+
502
+ # Test response code
503
+ assert_equal(200, @response_catcher.response.status_code)
504
+ # Test headers
505
+ expected_headers = {}
506
+ expected_headers['content-type'] = 'application/json; charset=utf-8'
507
+
508
+ assert(ComparisonHelper.match_headers(expected_headers, @response_catcher.response.headers))
509
+
510
+ # Test whether the captured response is as we expected
511
+ refute_nil(result)
512
+ expected_body = JSON.parse(
513
+ '{"id":"11ef0000-0000-4000-8000-000000000040","charge_id":"11ef0000-0000'\
514
+ '-4000-8000-000000000001","merchant_id":"11ef0000-0000-4000-8000-0000000'\
515
+ '00020","store_id":"11ef0000-0000-4000-8000-000000000022","mode":"test",'\
516
+ '"gateway":"wechat_online","declaration":{"customs":"TOKYO","merchant_cu'\
517
+ 'stoms_no":"1234567890","certificate_id":"AB1234567","certificate_name":'\
518
+ '"TARO YAMADA"},"declaration_result":{"approving_authority":"TOKYO","tra'\
519
+ 'de_id":"wx_trade_12345","transaction_id":"wx_txn_12345","charge_transac'\
520
+ 'tion_id":"wx_charge_12345"},"status":"successful","error":null,"created'\
521
+ '_on":"2026-04-09T07:35:50.000000Z"}'
522
+ )
523
+ received_body = JSON.parse(@response_catcher.response.raw_body)
524
+ assert(ComparisonHelper.match_body(expected_body, received_body))
525
+ end
526
+
527
+ # Updates a customs declaration and requeues processing. Backend patching preserves the original `customs`, `certificate_id`, and `certificate_name` values and only accepts a new `merchant_customs_no`. Pending declarations cannot be patched.
528
+ def test_patch_customs_declaration
529
+ # Parameters for the API call
530
+ store_id = '0cab399b-5621-425b-993b-f8507eba1e78'
531
+ charge_id = '6efb4e5c-690a-40f3-a4f1-0e19c5f84e98'
532
+ id = '11ef0000-0000-4000-8000-000000000040'
533
+ body = CustomsDeclarationPatchRequest.from_hash(APIHelper.json_deserialize(
534
+ '{"merchant_customs_no":"1234567891"}', false))
535
+ idempotency_key = 'f64be872-353d-4c3c-84cb-3dc617fe89f7'
536
+
537
+ # Perform the API call through the SDK function
538
+ result = @controller.patch_customs_declaration(
539
+ store_id, charge_id, id, body, idempotency_key: idempotency_key
540
+ )
541
+
542
+ # Test response code
543
+ assert_equal(200, @response_catcher.response.status_code)
544
+ # Test headers
545
+ expected_headers = {}
546
+ expected_headers['content-type'] = 'application/json; charset=utf-8'
547
+
548
+ assert(ComparisonHelper.match_headers(expected_headers, @response_catcher.response.headers))
549
+
550
+ # Test whether the captured response is as we expected
551
+ refute_nil(result)
552
+ expected_body = JSON.parse(
553
+ '{"id":"11ef0000-0000-4000-8000-000000000040","charge_id":"11ef0000-0000'\
554
+ '-4000-8000-000000000001","merchant_id":"11ef0000-0000-4000-8000-0000000'\
555
+ '00020","store_id":"11ef0000-0000-4000-8000-000000000022","mode":"test",'\
556
+ '"gateway":"wechat_online","declaration":{"customs":"TOKYO","merchant_cu'\
557
+ 'stoms_no":"1234567891","certificate_id":"AB1234567","certificate_name":'\
558
+ '"TARO YAMADA"},"declaration_result":{},"status":"pending","error":null,'\
559
+ '"created_on":"2026-04-09T07:35:50.000000Z"}'
560
+ )
561
+ received_body = JSON.parse(@response_catcher.response.raw_body)
562
+ assert(ComparisonHelper.match_body(expected_body, received_body))
563
+ end
564
+
565
+ end
@@ -0,0 +1,38 @@
1
+ # Custom test (not auto-generated): verifies APIMatic dynamic error messages.
2
+ #
3
+ # Forces Prism to return the 400 BadRequest example via the `Prefer: code=400`
4
+ # header (injected by HttpResponseCatcher for this test) and asserts:
5
+ # 1. the raised exception's MESSAGE is interpolated from the response body
6
+ # (contains the templated `code`), proving the x-operation-settings
7
+ # ErrorTemplates took effect;
8
+ # 2. the full typed `errors[]` array is still accessible on the exception,
9
+ # proving the array is not lost (templates only shape the message string).
10
+
11
+ require_relative 'api_test_base'
12
+
13
+ class ErrorMessagesTest < ApiTestBase
14
+ def setup
15
+ setup_class
16
+ @controller = @client.charges
17
+ @response_catcher = @controller.http_call_back
18
+ end
19
+
20
+ def test_dynamic_error_message_and_errors_array
21
+ error = assert_raises(ApiErrorException) do
22
+ @controller.create_charge
23
+ end
24
+
25
+ # The 400 ErrorTemplate is throwable, so the SDK raises the typed
26
+ # ApiErrorException (vs. silently returning the response). The SDK overrides
27
+ # #message/#to_s to a structured dump, so the interpolated template string
28
+ # is not cleanly accessible here; we assert the parsed error body instead.
29
+
30
+ # 1. Error code: deserialized from the response body onto the exception.
31
+ assert_equal('VALIDATION_ERROR', error.code)
32
+
33
+ # 2. Array preserved: full typed errors[] is readable off the exception.
34
+ refute_nil(error.errors)
35
+ assert_operator(error.errors.length, :>=, 1)
36
+ assert_equal('INVALID_CARD_NUMBER', error.errors[0].reason)
37
+ end
38
+ end
@@ -0,0 +1,50 @@
1
+ # univapay_client_sdk
2
+ #
3
+ # This file was automatically generated for Univapay
4
+ # by APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ require_relative 'api_test_base'
7
+
8
+ class MerchantsApiTest < ApiTestBase
9
+ # Called only once for the class before any test has executed
10
+ def setup
11
+ setup_class
12
+ @controller = @client.merchants
13
+ @response_catcher = @controller.http_call_back
14
+ end
15
+
16
+ # Returns merchant identity and the effective configuration resolved from bearer credentials. Treat this as the canonical introspection endpoint for merchant integrations.
17
+ def test_get_current_merchant
18
+
19
+ # Perform the API call through the SDK function
20
+ result = @controller.get_current_merchant()
21
+
22
+ # Test response code
23
+ assert_equal(200, @response_catcher.response.status_code)
24
+ # Test headers
25
+ expected_headers = {}
26
+ expected_headers['content-type'] = 'application/json; charset=utf-8'
27
+
28
+ assert(ComparisonHelper.match_headers(expected_headers, @response_catcher.response.headers))
29
+
30
+ # Test whether the captured response is as we expected
31
+ refute_nil(result)
32
+ expected_body = JSON.parse(
33
+ '{"id":"11ef0000-0000-4000-8000-000000000020","verification_data_id":"11'\
34
+ 'ef0000-0000-4000-8000-000000000021","name":"Example Merchant","email":"'\
35
+ 'owner@example.com","notification_email":"alerts@example.com","finance_n'\
36
+ 'otification_email":"finance@example.com","verified":true,"configuration'\
37
+ '":{"percent_fee":3.6,"country":"JP","language":"ja","minimum_charge_amo'\
38
+ 'unts":[{"amount":100,"currency":"JPY"}],"maximum_charge_amounts":[{"amo'\
39
+ 'unt":100000,"currency":"JPY"}],"user_transactions_configuration":{"enab'\
40
+ 'led":true,"notify_customer":true,"notify_on_webhook_failure":true},"car'\
41
+ 'd_configuration":{"enabled":true,"debit_enabled":true,"prepaid_enabled"'\
42
+ ':false,"three_ds_required":true},"online_configuration":{"enabled":true'\
43
+ '},"bank_transfer_configuration":{"enabled":true,"match_amount":true,"ex'\
44
+ 'piration":"P7D"}},"created_on":"2026-04-09T07:35:50.000000Z"}'
45
+ )
46
+ received_body = JSON.parse(@response_catcher.response.raw_body)
47
+ assert(ComparisonHelper.match_body(expected_body, received_body))
48
+ end
49
+
50
+ end