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,346 @@
1
+ # univapay_client_sdk
2
+ #
3
+ # This file was automatically generated for Univapay
4
+ # by APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+
7
+ require 'json'
8
+ require 'rack'
9
+ require 'stringio'
10
+ require 'minitest/autorun'
11
+ require 'minitest/hell'
12
+ require 'minitest/pride'
13
+ require 'minitest/proveit'
14
+ require 'univapay_client_sdk'
15
+ class TestSubscriptionHandler < Minitest::Test
16
+ parallelize_me!
17
+ include UnivapayClientSdk
18
+ include CoreLibrary
19
+
20
+ def setup
21
+ @handler = SubscriptionHandler.new
22
+ end
23
+
24
+ def json_bytes(obj)
25
+ JSON.generate(obj).encode('utf-8')
26
+ end
27
+
28
+ def make_request(body_obj, add_signature_header: true)
29
+ raw = json_bytes(body_obj)
30
+ env = {
31
+ 'REQUEST_METHOD' => 'POST',
32
+ 'PATH_INFO' => '/webhooks',
33
+ 'rack.input' => StringIO.new(raw),
34
+ 'CONTENT_TYPE' => 'application/json'
35
+ }
36
+ Rack::Request.new(env)
37
+ end
38
+
39
+
40
+ def test_subscription_created_from_subscription_handler
41
+ # Tests the `subscriptionCreated` event from subscriptionHandler.
42
+ # arrange
43
+ event_payload = {
44
+ :id => "11ef0000-0000-4000-8000-000000000001",
45
+ :event => "subscription_created",
46
+ :data => {
47
+ :id => "11ef335e-9aa5-c54a-8313-7f9847da313a",
48
+ :store_id => "11edf541-c42d-653c-8c3d-dfe0a55f95c0",
49
+ :transaction_token_id => "11ef32a7-3a71-8662-803f-1bc27702eeec",
50
+ :amount => 1250,
51
+ :currency => "USD",
52
+ :amount_formatted => 12.5,
53
+ :schedule_settings => {
54
+ :start_on => "2024-07-01",
55
+ :zone_id => "Asia/Tokyo",
56
+ :preserve_end_of_month => false,
57
+ :retry_interval => "P7D",
58
+ :termination_mode => "on_next_payment"
59
+ },
60
+ :only_direct_currency => false,
61
+ :first_charge_authorization_only => false,
62
+ :status => "current",
63
+ :metadata => {
64
+ :order_id => "12345"
65
+ },
66
+ :mode => "test",
67
+ :created_on => "2024-06-26T01:51:28.627023Z",
68
+ :period => "monthly",
69
+ :exampleAdditionalProperty => {
70
+ :key1 => "val1",
71
+ :key2 => "val2"
72
+ }
73
+ },
74
+ :created_on => "2026-04-09T07:35:50.000000Z",
75
+ :exampleAdditionalProperty => {
76
+ :key1 => "val1",
77
+ :key2 => "val2"
78
+ }
79
+ }
80
+ rack_req = make_request(event_payload)
81
+
82
+ # act
83
+ event = @handler.parse_event(rack_req)
84
+
85
+ # assert
86
+ assert event.is_a?(SubscriptionWebhookEvent) && event.event == 'subscription_created'
87
+ end
88
+
89
+ def test_subscription_payment_from_subscription_handler
90
+ # Tests the `subscriptionPayment` event from subscriptionHandler.
91
+ # arrange
92
+ event_payload = {
93
+ :id => "11ef0000-0000-4000-8000-000000000001",
94
+ :event => "subscription_payment",
95
+ :data => {
96
+ :id => "11ef335e-9aa5-c54a-8313-7f9847da313a",
97
+ :store_id => "11edf541-c42d-653c-8c3d-dfe0a55f95c0",
98
+ :transaction_token_id => "11ef32a7-3a71-8662-803f-1bc27702eeec",
99
+ :amount => 1250,
100
+ :currency => "USD",
101
+ :amount_formatted => 12.5,
102
+ :schedule_settings => {
103
+ :start_on => "2024-07-01",
104
+ :zone_id => "Asia/Tokyo",
105
+ :preserve_end_of_month => false,
106
+ :retry_interval => "P7D",
107
+ :termination_mode => "on_next_payment"
108
+ },
109
+ :only_direct_currency => false,
110
+ :first_charge_authorization_only => false,
111
+ :status => "current",
112
+ :metadata => {
113
+ :order_id => "12345"
114
+ },
115
+ :mode => "test",
116
+ :created_on => "2024-06-26T01:51:28.627023Z",
117
+ :period => "monthly",
118
+ :exampleAdditionalProperty => {
119
+ :key1 => "val1",
120
+ :key2 => "val2"
121
+ }
122
+ },
123
+ :created_on => "2026-04-09T07:35:50.000000Z",
124
+ :exampleAdditionalProperty => {
125
+ :key1 => "val1",
126
+ :key2 => "val2"
127
+ }
128
+ }
129
+ rack_req = make_request(event_payload)
130
+
131
+ # act
132
+ event = @handler.parse_event(rack_req)
133
+
134
+ # assert
135
+ assert event.is_a?(SubscriptionWebhookEvent) && event.event == 'subscription_payment'
136
+ end
137
+
138
+ def test_subscription_completed_from_subscription_handler
139
+ # Tests the `subscriptionCompleted` event from subscriptionHandler.
140
+ # arrange
141
+ event_payload = {
142
+ :id => "11ef0000-0000-4000-8000-000000000001",
143
+ :event => "subscription_completed",
144
+ :data => {
145
+ :id => "11ef335e-9aa5-c54a-8313-7f9847da313a",
146
+ :store_id => "11edf541-c42d-653c-8c3d-dfe0a55f95c0",
147
+ :transaction_token_id => "11ef32a7-3a71-8662-803f-1bc27702eeec",
148
+ :amount => 1250,
149
+ :currency => "USD",
150
+ :amount_formatted => 12.5,
151
+ :schedule_settings => {
152
+ :start_on => "2024-07-01",
153
+ :zone_id => "Asia/Tokyo",
154
+ :preserve_end_of_month => false,
155
+ :retry_interval => "P7D",
156
+ :termination_mode => "on_next_payment"
157
+ },
158
+ :only_direct_currency => false,
159
+ :first_charge_authorization_only => false,
160
+ :status => "current",
161
+ :metadata => {
162
+ :order_id => "12345"
163
+ },
164
+ :mode => "test",
165
+ :created_on => "2024-06-26T01:51:28.627023Z",
166
+ :period => "monthly",
167
+ :exampleAdditionalProperty => {
168
+ :key1 => "val1",
169
+ :key2 => "val2"
170
+ }
171
+ },
172
+ :created_on => "2026-04-09T07:35:50.000000Z",
173
+ :exampleAdditionalProperty => {
174
+ :key1 => "val1",
175
+ :key2 => "val2"
176
+ }
177
+ }
178
+ rack_req = make_request(event_payload)
179
+
180
+ # act
181
+ event = @handler.parse_event(rack_req)
182
+
183
+ # assert
184
+ assert event.is_a?(SubscriptionWebhookEvent) && event.event == 'subscription_completed'
185
+ end
186
+
187
+ def test_subscription_failure_from_subscription_handler
188
+ # Tests the `subscriptionFailure` event from subscriptionHandler.
189
+ # arrange
190
+ event_payload = {
191
+ :id => "11ef0000-0000-4000-8000-000000000001",
192
+ :event => "subscription_failure",
193
+ :data => {
194
+ :id => "11ef335e-9aa5-c54a-8313-7f9847da313a",
195
+ :store_id => "11edf541-c42d-653c-8c3d-dfe0a55f95c0",
196
+ :transaction_token_id => "11ef32a7-3a71-8662-803f-1bc27702eeec",
197
+ :amount => 1250,
198
+ :currency => "USD",
199
+ :amount_formatted => 12.5,
200
+ :schedule_settings => {
201
+ :start_on => "2024-07-01",
202
+ :zone_id => "Asia/Tokyo",
203
+ :preserve_end_of_month => false,
204
+ :retry_interval => "P7D",
205
+ :termination_mode => "on_next_payment"
206
+ },
207
+ :only_direct_currency => false,
208
+ :first_charge_authorization_only => false,
209
+ :status => "current",
210
+ :metadata => {
211
+ :order_id => "12345"
212
+ },
213
+ :mode => "test",
214
+ :created_on => "2024-06-26T01:51:28.627023Z",
215
+ :period => "monthly",
216
+ :exampleAdditionalProperty => {
217
+ :key1 => "val1",
218
+ :key2 => "val2"
219
+ }
220
+ },
221
+ :created_on => "2026-04-09T07:35:50.000000Z",
222
+ :exampleAdditionalProperty => {
223
+ :key1 => "val1",
224
+ :key2 => "val2"
225
+ }
226
+ }
227
+ rack_req = make_request(event_payload)
228
+
229
+ # act
230
+ event = @handler.parse_event(rack_req)
231
+
232
+ # assert
233
+ assert event.is_a?(SubscriptionWebhookEvent) && event.event == 'subscription_failure'
234
+ end
235
+
236
+ def test_subscription_canceled_from_subscription_handler
237
+ # Tests the `subscriptionCanceled` event from subscriptionHandler.
238
+ # arrange
239
+ event_payload = {
240
+ :id => "11ef0000-0000-4000-8000-000000000001",
241
+ :event => "subscription_canceled",
242
+ :data => {
243
+ :id => "11ef335e-9aa5-c54a-8313-7f9847da313a",
244
+ :store_id => "11edf541-c42d-653c-8c3d-dfe0a55f95c0",
245
+ :transaction_token_id => "11ef32a7-3a71-8662-803f-1bc27702eeec",
246
+ :amount => 1250,
247
+ :currency => "USD",
248
+ :amount_formatted => 12.5,
249
+ :schedule_settings => {
250
+ :start_on => "2024-07-01",
251
+ :zone_id => "Asia/Tokyo",
252
+ :preserve_end_of_month => false,
253
+ :retry_interval => "P7D",
254
+ :termination_mode => "on_next_payment"
255
+ },
256
+ :only_direct_currency => false,
257
+ :first_charge_authorization_only => false,
258
+ :status => "current",
259
+ :metadata => {
260
+ :order_id => "12345"
261
+ },
262
+ :mode => "test",
263
+ :created_on => "2024-06-26T01:51:28.627023Z",
264
+ :period => "monthly",
265
+ :exampleAdditionalProperty => {
266
+ :key1 => "val1",
267
+ :key2 => "val2"
268
+ }
269
+ },
270
+ :created_on => "2026-04-09T07:35:50.000000Z",
271
+ :exampleAdditionalProperty => {
272
+ :key1 => "val1",
273
+ :key2 => "val2"
274
+ }
275
+ }
276
+ rack_req = make_request(event_payload)
277
+
278
+ # act
279
+ event = @handler.parse_event(rack_req)
280
+
281
+ # assert
282
+ assert event.is_a?(SubscriptionWebhookEvent) && event.event == 'subscription_canceled'
283
+ end
284
+
285
+ def test_subscription_suspended_from_subscription_handler
286
+ # Tests the `subscriptionSuspended` event from subscriptionHandler.
287
+ # arrange
288
+ event_payload = {
289
+ :id => "11ef0000-0000-4000-8000-000000000001",
290
+ :event => "subscription_suspended",
291
+ :data => {
292
+ :id => "11ef335e-9aa5-c54a-8313-7f9847da313a",
293
+ :store_id => "11edf541-c42d-653c-8c3d-dfe0a55f95c0",
294
+ :transaction_token_id => "11ef32a7-3a71-8662-803f-1bc27702eeec",
295
+ :amount => 1250,
296
+ :currency => "USD",
297
+ :amount_formatted => 12.5,
298
+ :schedule_settings => {
299
+ :start_on => "2024-07-01",
300
+ :zone_id => "Asia/Tokyo",
301
+ :preserve_end_of_month => false,
302
+ :retry_interval => "P7D",
303
+ :termination_mode => "on_next_payment"
304
+ },
305
+ :only_direct_currency => false,
306
+ :first_charge_authorization_only => false,
307
+ :status => "current",
308
+ :metadata => {
309
+ :order_id => "12345"
310
+ },
311
+ :mode => "test",
312
+ :created_on => "2024-06-26T01:51:28.627023Z",
313
+ :period => "monthly",
314
+ :exampleAdditionalProperty => {
315
+ :key1 => "val1",
316
+ :key2 => "val2"
317
+ }
318
+ },
319
+ :created_on => "2026-04-09T07:35:50.000000Z",
320
+ :exampleAdditionalProperty => {
321
+ :key1 => "val1",
322
+ :key2 => "val2"
323
+ }
324
+ }
325
+ rack_req = make_request(event_payload)
326
+
327
+ # act
328
+ event = @handler.parse_event(rack_req)
329
+
330
+ # assert
331
+ assert event.is_a?(SubscriptionWebhookEvent) && event.event == 'subscription_suspended'
332
+ end
333
+
334
+ def test_unknown_event
335
+ # arrange
336
+ event_payload = 45.0
337
+ rake_req = make_request(event_payload)
338
+
339
+ # act
340
+ event = @handler.parse_event(rake_req)
341
+
342
+ # assert
343
+ assert event.is_a?(UnknownEvent)
344
+ end
345
+
346
+ end
@@ -0,0 +1,332 @@
1
+ # univapay_client_sdk
2
+ #
3
+ # This file was automatically generated for Univapay
4
+ # by APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+
7
+ require 'json'
8
+ require 'rack'
9
+ require 'stringio'
10
+ require 'minitest/autorun'
11
+ require 'minitest/hell'
12
+ require 'minitest/pride'
13
+ require 'minitest/proveit'
14
+ require 'univapay_client_sdk'
15
+ class TestTokenHandler < Minitest::Test
16
+ parallelize_me!
17
+ include UnivapayClientSdk
18
+ include CoreLibrary
19
+
20
+ def setup
21
+ @handler = TokenHandler.new
22
+ end
23
+
24
+ def json_bytes(obj)
25
+ JSON.generate(obj).encode('utf-8')
26
+ end
27
+
28
+ def make_request(body_obj, add_signature_header: true)
29
+ raw = json_bytes(body_obj)
30
+ env = {
31
+ 'REQUEST_METHOD' => 'POST',
32
+ 'PATH_INFO' => '/webhooks',
33
+ 'rack.input' => StringIO.new(raw),
34
+ 'CONTENT_TYPE' => 'application/json'
35
+ }
36
+ Rack::Request.new(env)
37
+ end
38
+
39
+
40
+ def test_token_created_from_token_handler
41
+ # Tests the `tokenCreated` event from tokenHandler.
42
+ # arrange
43
+ event_payload = {
44
+ :id => "11ef0000-0000-4000-8000-000000000001",
45
+ :event => "token_created",
46
+ :data => {
47
+ :id => "6426bbd2-17bd-41bf-883b-1fe970db48ee",
48
+ :store_id => "fc264608-9a9e-495e-844e-a08129a81af4",
49
+ :email => "test@univapay.com",
50
+ :payment_type => "card",
51
+ :active => true,
52
+ :mode => "live",
53
+ :type => "recurring",
54
+ :confirmed => true,
55
+ :metadata => {
56
+ :customer_id => "cust_12345"
57
+ },
58
+ :created_on => "2026-04-09T07:35:50.000000Z",
59
+ :updated_on => "2026-04-09T07:35:50.000000Z",
60
+ :exampleAdditionalProperty => {
61
+ :key1 => "val1",
62
+ :key2 => "val2"
63
+ }
64
+ },
65
+ :created_on => "2026-04-09T07:35:50.000000Z",
66
+ :exampleAdditionalProperty => {
67
+ :key1 => "val1",
68
+ :key2 => "val2"
69
+ }
70
+ }
71
+ rack_req = make_request(event_payload)
72
+
73
+ # act
74
+ event = @handler.parse_event(rack_req)
75
+
76
+ # assert
77
+ assert event.is_a?(TokenWebhookEvent) && event.event == 'token_created'
78
+ end
79
+
80
+ def test_token_updated_from_token_handler
81
+ # Tests the `tokenUpdated` event from tokenHandler.
82
+ # arrange
83
+ event_payload = {
84
+ :id => "11ef0000-0000-4000-8000-000000000001",
85
+ :event => "token_updated",
86
+ :data => {
87
+ :id => "6426bbd2-17bd-41bf-883b-1fe970db48ee",
88
+ :store_id => "fc264608-9a9e-495e-844e-a08129a81af4",
89
+ :email => "test@univapay.com",
90
+ :payment_type => "card",
91
+ :active => true,
92
+ :mode => "live",
93
+ :type => "recurring",
94
+ :confirmed => true,
95
+ :metadata => {
96
+ :customer_id => "cust_12345"
97
+ },
98
+ :created_on => "2026-04-09T07:35:50.000000Z",
99
+ :updated_on => "2026-04-09T07:35:50.000000Z",
100
+ :exampleAdditionalProperty => {
101
+ :key1 => "val1",
102
+ :key2 => "val2"
103
+ }
104
+ },
105
+ :created_on => "2026-04-09T07:35:50.000000Z",
106
+ :exampleAdditionalProperty => {
107
+ :key1 => "val1",
108
+ :key2 => "val2"
109
+ }
110
+ }
111
+ rack_req = make_request(event_payload)
112
+
113
+ # act
114
+ event = @handler.parse_event(rack_req)
115
+
116
+ # assert
117
+ assert event.is_a?(TokenWebhookEvent) && event.event == 'token_updated'
118
+ end
119
+
120
+ def test_token_three_ds_updated_from_token_handler
121
+ # Tests the `tokenThreeDsUpdated` event from tokenHandler.
122
+ # arrange
123
+ event_payload = {
124
+ :id => "11ef0000-0000-4000-8000-000000000001",
125
+ :event => "token_three_d_s_updated",
126
+ :data => {
127
+ :id => "6426bbd2-17bd-41bf-883b-1fe970db48ee",
128
+ :store_id => "fc264608-9a9e-495e-844e-a08129a81af4",
129
+ :email => "test@univapay.com",
130
+ :payment_type => "card",
131
+ :active => true,
132
+ :mode => "live",
133
+ :type => "recurring",
134
+ :confirmed => true,
135
+ :metadata => {
136
+ :customer_id => "cust_12345"
137
+ },
138
+ :created_on => "2026-04-09T07:35:50.000000Z",
139
+ :updated_on => "2026-04-09T07:35:50.000000Z",
140
+ :exampleAdditionalProperty => {
141
+ :key1 => "val1",
142
+ :key2 => "val2"
143
+ }
144
+ },
145
+ :created_on => "2026-04-09T07:35:50.000000Z",
146
+ :exampleAdditionalProperty => {
147
+ :key1 => "val1",
148
+ :key2 => "val2"
149
+ }
150
+ }
151
+ rack_req = make_request(event_payload)
152
+
153
+ # act
154
+ event = @handler.parse_event(rack_req)
155
+
156
+ # assert
157
+ assert event.is_a?(TokenWebhookEvent) && event.event == 'token_three_d_s_updated'
158
+ end
159
+
160
+ def test_token_cvv_auth_updated_from_token_handler
161
+ # Tests the `tokenCvvAuthUpdated` event from tokenHandler.
162
+ # arrange
163
+ event_payload = {
164
+ :id => "11ef0000-0000-4000-8000-000000000001",
165
+ :event => "token_cvv_auth_updated",
166
+ :data => {
167
+ :id => "6426bbd2-17bd-41bf-883b-1fe970db48ee",
168
+ :store_id => "fc264608-9a9e-495e-844e-a08129a81af4",
169
+ :email => "test@univapay.com",
170
+ :payment_type => "card",
171
+ :active => true,
172
+ :mode => "live",
173
+ :type => "recurring",
174
+ :confirmed => true,
175
+ :metadata => {
176
+ :customer_id => "cust_12345"
177
+ },
178
+ :created_on => "2026-04-09T07:35:50.000000Z",
179
+ :updated_on => "2026-04-09T07:35:50.000000Z",
180
+ :exampleAdditionalProperty => {
181
+ :key1 => "val1",
182
+ :key2 => "val2"
183
+ }
184
+ },
185
+ :created_on => "2026-04-09T07:35:50.000000Z",
186
+ :exampleAdditionalProperty => {
187
+ :key1 => "val1",
188
+ :key2 => "val2"
189
+ }
190
+ }
191
+ rack_req = make_request(event_payload)
192
+
193
+ # act
194
+ event = @handler.parse_event(rack_req)
195
+
196
+ # assert
197
+ assert event.is_a?(TokenWebhookEvent) && event.event == 'token_cvv_auth_updated'
198
+ end
199
+
200
+ def test_token_cvv_auth_check_updated_from_token_handler
201
+ # Tests the `tokenCvvAuthCheckUpdated` event from tokenHandler.
202
+ # arrange
203
+ event_payload = {
204
+ :id => "11ef0000-0000-4000-8000-000000000001",
205
+ :event => "token_cvv_auth_check_updated",
206
+ :data => {
207
+ :id => "6426bbd2-17bd-41bf-883b-1fe970db48ee",
208
+ :store_id => "fc264608-9a9e-495e-844e-a08129a81af4",
209
+ :email => "test@univapay.com",
210
+ :payment_type => "card",
211
+ :active => true,
212
+ :mode => "live",
213
+ :type => "recurring",
214
+ :confirmed => true,
215
+ :metadata => {
216
+ :customer_id => "cust_12345"
217
+ },
218
+ :created_on => "2026-04-09T07:35:50.000000Z",
219
+ :updated_on => "2026-04-09T07:35:50.000000Z",
220
+ :exampleAdditionalProperty => {
221
+ :key1 => "val1",
222
+ :key2 => "val2"
223
+ }
224
+ },
225
+ :created_on => "2026-04-09T07:35:50.000000Z",
226
+ :exampleAdditionalProperty => {
227
+ :key1 => "val1",
228
+ :key2 => "val2"
229
+ }
230
+ }
231
+ rack_req = make_request(event_payload)
232
+
233
+ # act
234
+ event = @handler.parse_event(rack_req)
235
+
236
+ # assert
237
+ assert event.is_a?(TokenWebhookEvent) && event.event == 'token_cvv_auth_check_updated'
238
+ end
239
+
240
+ def test_token_replaced_from_token_handler
241
+ # Tests the `tokenReplaced` event from tokenHandler.
242
+ # arrange
243
+ event_payload = {
244
+ :id => "11ef0000-0000-4000-8000-000000000001",
245
+ :event => "token_replaced",
246
+ :data => {
247
+ :id => "6426bbd2-17bd-41bf-883b-1fe970db48ee",
248
+ :store_id => "fc264608-9a9e-495e-844e-a08129a81af4",
249
+ :email => "test@univapay.com",
250
+ :payment_type => "card",
251
+ :active => true,
252
+ :mode => "live",
253
+ :type => "recurring",
254
+ :confirmed => true,
255
+ :metadata => {
256
+ :customer_id => "cust_12345"
257
+ },
258
+ :created_on => "2026-04-09T07:35:50.000000Z",
259
+ :updated_on => "2026-04-09T07:35:50.000000Z",
260
+ :exampleAdditionalProperty => {
261
+ :key1 => "val1",
262
+ :key2 => "val2"
263
+ }
264
+ },
265
+ :created_on => "2026-04-09T07:35:50.000000Z",
266
+ :exampleAdditionalProperty => {
267
+ :key1 => "val1",
268
+ :key2 => "val2"
269
+ }
270
+ }
271
+ rack_req = make_request(event_payload)
272
+
273
+ # act
274
+ event = @handler.parse_event(rack_req)
275
+
276
+ # assert
277
+ assert event.is_a?(TokenWebhookEvent) && event.event == 'token_replaced'
278
+ end
279
+
280
+ def test_recurring_token_deleted_from_token_handler
281
+ # Tests the `recurringTokenDeleted` event from tokenHandler.
282
+ # arrange
283
+ event_payload = {
284
+ :id => "11ef0000-0000-4000-8000-000000000001",
285
+ :event => "recurring_token_deleted",
286
+ :data => {
287
+ :id => "6426bbd2-17bd-41bf-883b-1fe970db48ee",
288
+ :store_id => "fc264608-9a9e-495e-844e-a08129a81af4",
289
+ :email => "test@univapay.com",
290
+ :payment_type => "card",
291
+ :active => true,
292
+ :mode => "live",
293
+ :type => "recurring",
294
+ :confirmed => true,
295
+ :metadata => {
296
+ :customer_id => "cust_12345"
297
+ },
298
+ :created_on => "2026-04-09T07:35:50.000000Z",
299
+ :updated_on => "2026-04-09T07:35:50.000000Z",
300
+ :exampleAdditionalProperty => {
301
+ :key1 => "val1",
302
+ :key2 => "val2"
303
+ }
304
+ },
305
+ :created_on => "2026-04-09T07:35:50.000000Z",
306
+ :exampleAdditionalProperty => {
307
+ :key1 => "val1",
308
+ :key2 => "val2"
309
+ }
310
+ }
311
+ rack_req = make_request(event_payload)
312
+
313
+ # act
314
+ event = @handler.parse_event(rack_req)
315
+
316
+ # assert
317
+ assert event.is_a?(TokenWebhookEvent) && event.event == 'recurring_token_deleted'
318
+ end
319
+
320
+ def test_unknown_event
321
+ # arrange
322
+ event_payload = 45.0
323
+ rake_req = make_request(event_payload)
324
+
325
+ # act
326
+ event = @handler.parse_event(rake_req)
327
+
328
+ # assert
329
+ assert event.is_a?(UnknownEvent)
330
+ end
331
+
332
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails'
2
+ require 'action_controller/railtie'
3
+ require 'univapay_client_sdk'
4
+
5
+ include UnivapayClientSdk
6
+
7
+ class RailsApp < Rails::Application
8
+ config.secret_key_base = "test"
9
+ config.eager_load = false
10
+ config.hosts.clear
11
+ end
12
+
13
+ Rails.application = RailsApp
14
+ Rails.application.initialize!