mangopay-v4 4.0.0 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (234) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +29 -29
  3. data/.rspec +3 -3
  4. data/.rubocop.yml +1 -1
  5. data/.travis.yml +21 -13
  6. data/Gemfile +2 -2
  7. data/LICENSE +20 -20
  8. data/README.md +379 -379
  9. data/bin/mangopay +9 -9
  10. data/lib/mangopay.rb +132 -132
  11. data/lib/mangopay/api/api.rb +8 -8
  12. data/lib/mangopay/api/api_methods.rb +160 -136
  13. data/lib/mangopay/api/auth_token_manager.rb +173 -173
  14. data/lib/mangopay/api/http_client.rb +324 -324
  15. data/lib/mangopay/api/service/bank_accounts.rb +145 -145
  16. data/lib/mangopay/api/service/banking_aliases.rb +83 -0
  17. data/lib/mangopay/api/service/cards.rb +151 -151
  18. data/lib/mangopay/api/service/client_wallets.rb +88 -88
  19. data/lib/mangopay/api/service/clients.rb +67 -67
  20. data/lib/mangopay/api/service/dispute_documents.rb +157 -157
  21. data/lib/mangopay/api/service/disputes.rb +186 -186
  22. data/lib/mangopay/api/service/e_money.rb +63 -41
  23. data/lib/mangopay/api/service/events.rb +46 -46
  24. data/lib/mangopay/api/service/hooks.rb +92 -92
  25. data/lib/mangopay/api/service/kyc_documents.rb +152 -152
  26. data/lib/mangopay/api/service/mandates.rb +141 -141
  27. data/lib/mangopay/api/service/oauth_tokens.rb +24 -24
  28. data/lib/mangopay/api/service/pay_ins.rb +369 -259
  29. data/lib/mangopay/api/service/pay_outs.rb +53 -53
  30. data/lib/mangopay/api/service/pre_authorizations.rb +126 -68
  31. data/lib/mangopay/api/service/refunds.rb +159 -61
  32. data/lib/mangopay/api/service/reports.rb +150 -150
  33. data/lib/mangopay/api/service/repudiations.rb +31 -31
  34. data/lib/mangopay/api/service/responses.rb +101 -101
  35. data/lib/mangopay/api/service/settlement_transfers.rb +54 -54
  36. data/lib/mangopay/api/service/transactions.rb +246 -182
  37. data/lib/mangopay/api/service/transfers.rb +53 -53
  38. data/lib/mangopay/api/service/ubo_declarations.rb +94 -69
  39. data/lib/mangopay/api/service/users.rb +162 -162
  40. data/lib/mangopay/api/service/wallets.rb +98 -98
  41. data/lib/mangopay/api/uri_provider.rb +32 -34
  42. data/lib/mangopay/common/json_tag_converter.rb +70 -67
  43. data/lib/mangopay/common/jsonifier.rb +266 -248
  44. data/lib/mangopay/common/log_provider.rb +33 -33
  45. data/lib/mangopay/common/rate_limit_interval.rb +16 -16
  46. data/lib/mangopay/common/read_only_fields.rb +26 -26
  47. data/lib/mangopay/common/response_error.rb +61 -61
  48. data/lib/mangopay/common/sort_direction.rb +14 -14
  49. data/lib/mangopay/common/sort_field.rb +12 -12
  50. data/lib/mangopay/common/template_url_options.rb +8 -8
  51. data/lib/mangopay/configuration.rb +38 -38
  52. data/lib/mangopay/environment.rb +65 -65
  53. data/lib/mangopay/model/address.rb +26 -26
  54. data/lib/mangopay/model/billing.rb +13 -0
  55. data/lib/mangopay/model/birthplace.rb +15 -0
  56. data/lib/mangopay/model/declared_ubo.rb +20 -20
  57. data/lib/mangopay/model/dispute_reason.rb +14 -14
  58. data/lib/mangopay/model/document_page_consult.rb +14 -14
  59. data/lib/mangopay/model/e_money.rb +17 -17
  60. data/lib/mangopay/model/entity/account/bank_account.rb +25 -25
  61. data/lib/mangopay/model/entity/account/ca_bank_account.rb +26 -26
  62. data/lib/mangopay/model/entity/account/debited_bank_account.rb +31 -0
  63. data/lib/mangopay/model/entity/account/gb_bank_account.rb +20 -20
  64. data/lib/mangopay/model/entity/account/iban_bank_account.rb +20 -20
  65. data/lib/mangopay/model/entity/account/other_bank_account.rb +23 -23
  66. data/lib/mangopay/model/entity/account/us_bank_account.rb +23 -23
  67. data/lib/mangopay/model/entity/banking_alias.rb +27 -0
  68. data/lib/mangopay/model/entity/card.rb +44 -44
  69. data/lib/mangopay/model/entity/card_registration.rb +42 -42
  70. data/lib/mangopay/model/entity/client.rb +65 -62
  71. data/lib/mangopay/model/entity/client_wallet.rb +22 -22
  72. data/lib/mangopay/model/entity/dispute.rb +49 -49
  73. data/lib/mangopay/model/entity/dispute_document.rb +28 -28
  74. data/lib/mangopay/model/entity/entity_base.rb +17 -17
  75. data/lib/mangopay/model/entity/hook.rb +25 -25
  76. data/lib/mangopay/model/entity/kyc_document.rb +27 -27
  77. data/lib/mangopay/model/entity/mandate.rb +50 -50
  78. data/lib/mangopay/model/entity/pay_in/apple_pay_direct_pay_in.rb +26 -0
  79. data/lib/mangopay/model/entity/pay_in/bank_wire_direct_pay_in.rb +24 -21
  80. data/lib/mangopay/model/entity/pay_in/bank_wire_external_instruction_pay_in.rb +19 -0
  81. data/lib/mangopay/model/entity/pay_in/card_direct_pay_in.rb +41 -32
  82. data/lib/mangopay/model/entity/pay_in/card_pre_authorized_pay_in.rb +15 -12
  83. data/lib/mangopay/model/entity/pay_in/card_web_pay_in.rb +36 -39
  84. data/lib/mangopay/model/entity/pay_in/direct_debit_direct_pay_in.rb +25 -22
  85. data/lib/mangopay/model/entity/pay_in/direct_debit_web_pay_in.rb +37 -37
  86. data/lib/mangopay/model/entity/pay_in/google_pay_direct_pay_in.rb +28 -0
  87. data/lib/mangopay/model/entity/pay_in/pay_in.rb +18 -15
  88. data/lib/mangopay/model/entity/pay_in/paypal_web_pay_in.rb +15 -0
  89. data/lib/mangopay/model/entity/pay_out.rb +21 -21
  90. data/lib/mangopay/model/entity/pre_authorization.rb +74 -67
  91. data/lib/mangopay/model/entity/refund.rb +17 -17
  92. data/lib/mangopay/model/entity/report.rb +50 -50
  93. data/lib/mangopay/model/entity/repudiation.rb +17 -17
  94. data/lib/mangopay/model/entity/settlement_transfer.rb +16 -16
  95. data/lib/mangopay/model/entity/transaction.rb +51 -51
  96. data/lib/mangopay/model/entity/transfer.rb +12 -12
  97. data/lib/mangopay/model/entity/ubo.rb +30 -0
  98. data/lib/mangopay/model/entity/ubo_declaration.rb +29 -31
  99. data/lib/mangopay/model/entity/user/legal_user.rb +55 -52
  100. data/lib/mangopay/model/entity/user/natural_user.rb +49 -49
  101. data/lib/mangopay/model/entity/user/user.rb +17 -17
  102. data/lib/mangopay/model/entity/wallet.rb +27 -27
  103. data/lib/mangopay/model/enum/account_type.rb +23 -23
  104. data/lib/mangopay/model/enum/avs_result.rb +19 -0
  105. data/lib/mangopay/model/enum/banking_alias_type.rb +12 -0
  106. data/lib/mangopay/model/enum/business_type.rb +17 -0
  107. data/lib/mangopay/model/enum/card_status.rb +14 -14
  108. data/lib/mangopay/model/enum/card_type.rb +32 -32
  109. data/lib/mangopay/model/enum/card_validity.rb +18 -18
  110. data/lib/mangopay/model/enum/country_iso.rb +758 -758
  111. data/lib/mangopay/model/enum/culture_code.rb +43 -43
  112. data/lib/mangopay/model/enum/currency_iso.rb +551 -551
  113. data/lib/mangopay/model/enum/declared_ubo_refused_reason_type.rb +15 -15
  114. data/lib/mangopay/model/enum/declared_ubo_status.rb +17 -17
  115. data/lib/mangopay/model/enum/deposit_type.rb +14 -14
  116. data/lib/mangopay/model/enum/direct_debit_type.rb +12 -12
  117. data/lib/mangopay/model/enum/dispute_doc_refused_reason_type.rb +24 -24
  118. data/lib/mangopay/model/enum/dispute_document_type.rb +22 -22
  119. data/lib/mangopay/model/enum/dispute_reason_type.rb +32 -32
  120. data/lib/mangopay/model/enum/dispute_status.rb +20 -20
  121. data/lib/mangopay/model/enum/dispute_type.rb +14 -14
  122. data/lib/mangopay/model/enum/document_status.rb +20 -20
  123. data/lib/mangopay/model/enum/download_format.rb +10 -10
  124. data/lib/mangopay/model/enum/event_type.rb +76 -73
  125. data/lib/mangopay/model/enum/funds_type.rb +14 -14
  126. data/lib/mangopay/model/enum/hook_status.rb +12 -12
  127. data/lib/mangopay/model/enum/hook_validity.rb +14 -14
  128. data/lib/mangopay/model/enum/income_range.rb +20 -20
  129. data/lib/mangopay/model/enum/kyc_doc_refused_reason_type.rb +36 -36
  130. data/lib/mangopay/model/enum/kyc_document_type.rb +18 -18
  131. data/lib/mangopay/model/enum/kyc_level.rb +12 -12
  132. data/lib/mangopay/model/enum/legal_person_type.rb +14 -14
  133. data/lib/mangopay/model/enum/mandate_culture_code.rb +22 -22
  134. data/lib/mangopay/model/enum/mandate_execution_type.rb +10 -10
  135. data/lib/mangopay/model/enum/mandate_scheme.rb +12 -12
  136. data/lib/mangopay/model/enum/mandate_status.rb +23 -23
  137. data/lib/mangopay/model/enum/mandate_type.rb +10 -10
  138. data/lib/mangopay/model/enum/natural_user_capacity.rb +14 -14
  139. data/lib/mangopay/model/enum/pay_in_execution_type.rb +17 -17
  140. data/lib/mangopay/model/enum/pay_in_payment_type.rb +29 -20
  141. data/lib/mangopay/model/enum/pay_out_payment_type.rb +10 -10
  142. data/lib/mangopay/model/enum/payment_status.rb +20 -20
  143. data/lib/mangopay/model/enum/person_type.rb +14 -14
  144. data/lib/mangopay/model/enum/platform_type.rb +22 -22
  145. data/lib/mangopay/model/enum/pre_authorization_execution_type.rb +10 -10
  146. data/lib/mangopay/model/enum/pre_authorization_status.rb +17 -17
  147. data/lib/mangopay/model/enum/refund_reason_type.rb +20 -20
  148. data/lib/mangopay/model/enum/report_status.rb +16 -16
  149. data/lib/mangopay/model/enum/report_type.rb +12 -12
  150. data/lib/mangopay/model/enum/sector.rb +29 -0
  151. data/lib/mangopay/model/enum/secure_mode.rb +15 -15
  152. data/lib/mangopay/model/enum/transaction_nature.rb +16 -16
  153. data/lib/mangopay/model/enum/transaction_status.rb +14 -14
  154. data/lib/mangopay/model/enum/transaction_type.rb +14 -14
  155. data/lib/mangopay/model/enum/ubo_declaration_refused_reason_type.rb +18 -18
  156. data/lib/mangopay/model/enum/ubo_declaration_status.rb +20 -20
  157. data/lib/mangopay/model/event.rb +17 -17
  158. data/lib/mangopay/model/model.rb +214 -193
  159. data/lib/mangopay/model/money.rb +16 -16
  160. data/lib/mangopay/model/pay_in_web_extended_view.rb +30 -30
  161. data/lib/mangopay/model/platform_categorization.rb +15 -0
  162. data/lib/mangopay/model/refund_reason.rb +14 -14
  163. data/lib/mangopay/model/report_filter.rb +82 -82
  164. data/lib/mangopay/model/request/cancel_request.rb +15 -15
  165. data/lib/mangopay/model/request/complete_registration_request.rb +12 -12
  166. data/lib/mangopay/model/request/currency_request.rb +12 -12
  167. data/lib/mangopay/model/request/deactivation_request.rb +9 -9
  168. data/lib/mangopay/model/request/filter_request.rb +37 -37
  169. data/lib/mangopay/model/request/submit_document_request.rb +13 -13
  170. data/lib/mangopay/model/request/submit_ubo_declaration_request.rb +16 -13
  171. data/lib/mangopay/model/request/upload_file_request.rb +8 -8
  172. data/lib/mangopay/model/response_replica.rb +26 -26
  173. data/lib/mangopay/model/security_info.rb +13 -0
  174. data/lib/mangopay/util/custom_formatter.rb +11 -11
  175. data/lib/mangopay/util/custom_logger.rb +33 -33
  176. data/lib/mangopay/util/enum.rb +51 -51
  177. data/lib/mangopay/util/file_encoder.rb +15 -15
  178. data/lib/mangopay/util/non_instantiable.rb +5 -5
  179. data/lib/mangopay/util/storage_strategy.rb +9 -9
  180. data/lib/mangopay/util/void_logger.rb +5 -5
  181. data/mangopay-v4.gemspec +32 -0
  182. data/mangopay.gemspec +32 -32
  183. data/spec/context/address_context.rb +24 -24
  184. data/spec/context/bank_account_context.rb +137 -137
  185. data/spec/context/banking_alias_context.rb +17 -0
  186. data/spec/context/birthplace_context.rb +17 -0
  187. data/spec/context/card_context.rb +45 -45
  188. data/spec/context/client_context.rb +43 -44
  189. data/spec/context/dispute_context.rb +36 -36
  190. data/spec/context/dispute_document_context.rb +19 -19
  191. data/spec/context/hook_context.rb +15 -15
  192. data/spec/context/kyc_document_context.rb +22 -22
  193. data/spec/context/mandate_context.rb +26 -26
  194. data/spec/context/pay_in_context.rb +319 -224
  195. data/spec/context/pay_out_context.rb +39 -38
  196. data/spec/context/pre_authorization_context.rb +44 -40
  197. data/spec/context/refund_context.rb +32 -32
  198. data/spec/context/report_context.rb +21 -21
  199. data/spec/context/repudiation_context.rb +18 -18
  200. data/spec/context/settlement_transfer_context.rb +27 -27
  201. data/spec/context/transfer_context.rb +50 -50
  202. data/spec/context/ubo_declaration_context.rb +29 -24
  203. data/spec/context/user_context.rb +83 -82
  204. data/spec/context/wallet_context.rb +52 -52
  205. data/spec/mangopay/bank_accounts_spec.rb +228 -228
  206. data/spec/mangopay/banking_alias_spec.rb +85 -0
  207. data/spec/mangopay/cards_spec.rb +133 -134
  208. data/spec/mangopay/client_wallets_spec.rb +147 -147
  209. data/spec/mangopay/clients_spec.rb +56 -54
  210. data/spec/mangopay/configuration_spec.rb +125 -125
  211. data/spec/mangopay/dispute_documents_spec.rb +173 -173
  212. data/spec/mangopay/disputes_spec.rb +264 -264
  213. data/spec/mangopay/e_money_spec.rb +57 -37
  214. data/spec/mangopay/events_spec.rb +49 -49
  215. data/spec/mangopay/hooks_spec.rb +70 -70
  216. data/spec/mangopay/kyc_documents_spec.rb +179 -179
  217. data/spec/mangopay/mandates_spec.rb +218 -218
  218. data/spec/mangopay/oauth_tokens_spec.rb +40 -40
  219. data/spec/mangopay/pay_ins_spec.rb +279 -180
  220. data/spec/mangopay/pay_outs_spec.rb +38 -38
  221. data/spec/mangopay/pre_authorizations_spec.rb +134 -57
  222. data/spec/mangopay/refunds_spec.rb +187 -39
  223. data/spec/mangopay/reports_spec.rb +118 -120
  224. data/spec/mangopay/responses_spec.rb +324 -294
  225. data/spec/mangopay/settlement_transfers_spec.rb +36 -36
  226. data/spec/mangopay/transactions_spec.rb +347 -232
  227. data/spec/mangopay/transfers_spec.rb +37 -37
  228. data/spec/mangopay/ubo_declarations_spec.rb +127 -64
  229. data/spec/mangopay/users_spec.rb +145 -145
  230. data/spec/mangopay/wallets_spec.rb +103 -103
  231. data/spec/spec_helper.rb +72 -72
  232. data/spec/tmp/MangoPay.AuthorizationToken.FileStore.tmp +6 -0
  233. data/spec/tmp/mangopay.log.tmp +1201 -0
  234. metadata +31 -5
@@ -1,99 +1,99 @@
1
- require_relative '../uri_provider'
2
- require_relative '../../model/request/filter_request'
3
-
4
- module MangoApi
5
-
6
- # Provides API method delegates concerning the +Wallet+ entity.
7
- module Wallets
8
- class << self
9
- include UriProvider
10
-
11
- # Creates a new wallet entity.
12
- #
13
- # +Wallet+ properties:
14
- # * Required
15
- # * owners
16
- # * description
17
- # * currency
18
- # * Optional
19
- # * tag
20
- #
21
- # @param +wallet+ [Wallet] model object of wallet to be created
22
- # @param +id_key+ [String] idempotency key for future response replication
23
- # @return [Wallet] the newly-created Wallet entity object
24
- def create(wallet, id_key = nil)
25
- uri = provide_uri(:create_wallet)
26
- response = HttpClient.post(uri, wallet, id_key)
27
- parse response
28
- end
29
-
30
- # Updates the wallet entity identifiable by
31
- # the provided wallet object's ID.
32
- #
33
- # +Wallet+ optional properties:
34
- # * tag
35
- # * description
36
- #
37
- # @param +wallet+ [Wallet] wallet object with corresponding ID
38
- # and updated data
39
- # @return [Wallet] updated wallet entity
40
- def update(wallet)
41
- uri = provide_uri(:update_wallet, wallet)
42
- response = HttpClient.put(uri, wallet)
43
- parse response
44
- end
45
-
46
- # Retrieves a wallet entity.
47
- #
48
- # @param +id+ [String] ID of the wallet to be retrieved
49
- # @return [Wallet] the requested entity
50
- def get(id)
51
- uri = provide_uri(:get_wallet, id)
52
- response = HttpClient.get(uri)
53
- parse response
54
- end
55
-
56
- # Retrieves pages of wallet entities belonging to a certain user entity.
57
- # Allows configuration of paging and sorting parameters by
58
- # yielding a filtering object to a provided block. When no filters
59
- # are specified, will retrieve the first page of 10 newest results.
60
- #
61
- # Allowed +FilterRequest+ params:
62
- # * page
63
- # * per_page
64
- # * sort_field and sort_direction
65
- #
66
- # @param +id+ [String] ID of the user whose wallets to retrieve
67
- # @return [Array] the requested entities
68
- def of_user(id)
69
- uri = provide_uri(:get_users_wallets, id)
70
- filter_request = nil
71
- yield filter_request = FilterRequest.new if block_given?
72
- results = HttpClient.get(uri, filter_request)
73
- parse_results results
74
- end
75
-
76
- private
77
-
78
- # Parses an array of JSON-originating hashes into the corresponding
79
- # Wallet entity objects.
80
- #
81
- # @param +results+ [Array] JSON-originating data hashes
82
- # @return [Array] parsed Wallet entity objects
83
- def parse_results(results)
84
- results.collect do |entity|
85
- parse entity
86
- end
87
- end
88
-
89
- # Parses a JSON-originating hash into the corresponding
90
- # Wallet entity object.
91
- #
92
- # @param +response+ [Hash] JSON-originating data hash
93
- # @return [Wallet] corresponding Wallet entity object
94
- def parse(response)
95
- MangoModel::Wallet.new.dejsonify response
96
- end
97
- end
98
- end
1
+ require_relative '../uri_provider'
2
+ require_relative '../../model/request/filter_request'
3
+
4
+ module MangoApi
5
+
6
+ # Provides API method delegates concerning the +Wallet+ entity.
7
+ module Wallets
8
+ class << self
9
+ include UriProvider
10
+
11
+ # Creates a new wallet entity.
12
+ #
13
+ # +Wallet+ properties:
14
+ # * Required
15
+ # * owners
16
+ # * description
17
+ # * currency
18
+ # * Optional
19
+ # * tag
20
+ #
21
+ # @param +wallet+ [Wallet] model object of wallet to be created
22
+ # @param +id_key+ [String] idempotency key for future response replication
23
+ # @return [Wallet] the newly-created Wallet entity object
24
+ def create(wallet, id_key = nil)
25
+ uri = provide_uri(:create_wallet)
26
+ response = HttpClient.post(uri, wallet, id_key)
27
+ parse response
28
+ end
29
+
30
+ # Updates the wallet entity identifiable by
31
+ # the provided wallet object's ID.
32
+ #
33
+ # +Wallet+ optional properties:
34
+ # * tag
35
+ # * description
36
+ #
37
+ # @param +wallet+ [Wallet] wallet object with corresponding ID
38
+ # and updated data
39
+ # @return [Wallet] updated wallet entity
40
+ def update(wallet)
41
+ uri = provide_uri(:update_wallet, wallet)
42
+ response = HttpClient.put(uri, wallet)
43
+ parse response
44
+ end
45
+
46
+ # Retrieves a wallet entity.
47
+ #
48
+ # @param +id+ [String] ID of the wallet to be retrieved
49
+ # @return [Wallet] the requested entity
50
+ def get(id)
51
+ uri = provide_uri(:get_wallet, id)
52
+ response = HttpClient.get(uri)
53
+ parse response
54
+ end
55
+
56
+ # Retrieves pages of wallet entities belonging to a certain user entity.
57
+ # Allows configuration of paging and sorting parameters by
58
+ # yielding a filtering object to a provided block. When no filters
59
+ # are specified, will retrieve the first page of 10 newest results.
60
+ #
61
+ # Allowed +FilterRequest+ params:
62
+ # * page
63
+ # * per_page
64
+ # * sort_field and sort_direction
65
+ #
66
+ # @param +id+ [String] ID of the user whose wallets to retrieve
67
+ # @return [Array] the requested entities
68
+ def of_user(id)
69
+ uri = provide_uri(:get_users_wallets, id)
70
+ filter_request = nil
71
+ yield filter_request = FilterRequest.new if block_given?
72
+ results = HttpClient.get(uri, filter_request)
73
+ parse_results results
74
+ end
75
+
76
+ private
77
+
78
+ # Parses an array of JSON-originating hashes into the corresponding
79
+ # Wallet entity objects.
80
+ #
81
+ # @param +results+ [Array] JSON-originating data hashes
82
+ # @return [Array] parsed Wallet entity objects
83
+ def parse_results(results)
84
+ results.collect do |entity|
85
+ parse entity
86
+ end
87
+ end
88
+
89
+ # Parses a JSON-originating hash into the corresponding
90
+ # Wallet entity object.
91
+ #
92
+ # @param +response+ [Hash] JSON-originating data hash
93
+ # @return [Wallet] corresponding Wallet entity object
94
+ def parse(response)
95
+ MangoModel::Wallet.new.dejsonify response
96
+ end
97
+ end
98
+ end
99
99
  end
@@ -1,35 +1,33 @@
1
- require_relative 'api_methods'
2
-
3
- module MangoApi
4
-
5
- # Provides full contextual URL details for API calls.
6
- module UriProvider
7
-
8
- # Returns the URI for a given API endpoint. Calls `eval` on the
9
- # declared API method string if the URL contains parameter placeholders,
10
- # replacing them with data as passed into the method with the two
11
- # 'param' params.
12
- #
13
- # @param [Symbol] +api_method_symbol+ API endpoint symbol key,
14
- # as specified in ApiMethods
15
- # @param [Object] +_param1+ First entity containing data necessary
16
- # for parsing the URL (i.e. resource ID)
17
- # @param [Object] +_param2+ Second entity containing necessary parsing data
18
- #
19
- # @return [URI] URI for the API endpoint specified by Symbol
20
- def provide_uri(api_method_symbol,
21
- _param1 = nil,
22
- _param2 = nil)
23
- _, unparsed = ApiMethods[api_method_symbol]
24
- raise("No method declared for key :#{api_method_symbol}") unless unparsed
25
- parsed_path = unparsed.include?('%') ? eval(unparsed) : unparsed
26
- config = MangoPay.configuration
27
- full_url = [config.root_url,
28
- config.api_version,
29
- config.client_id,
30
- parsed_path]
31
- .join('/')
32
- URI(full_url)
33
- end
34
- end
1
+ require_relative 'api_methods'
2
+
3
+ module MangoApi
4
+
5
+ # Provides full contextual URL details for API calls.
6
+ module UriProvider
7
+
8
+ # Returns the URI for a given API endpoint. Calls `eval` on the
9
+ # declared API method string if the URL contains parameter placeholders,
10
+ # replacing them with data as passed into the method with the two
11
+ # 'param' params.
12
+ #
13
+ # @param [Symbol] +api_method_symbol+ API endpoint symbol key,
14
+ # as specified in ApiMethods
15
+ # @param [Varargs] +_params+
16
+ #
17
+ # @return [URI] URI for the API endpoint specified by Symbol
18
+ def provide_uri(api_method_symbol,
19
+ *_params)
20
+ _, unparsed = ApiMethods[api_method_symbol]
21
+ raise("No method declared for key :#{api_method_symbol}") unless unparsed
22
+
23
+ parsed_path = unparsed.include?('%') ? eval(unparsed) : unparsed
24
+ config = MangoPay.configuration
25
+ full_url = [config.root_url,
26
+ config.api_version,
27
+ config.client_id,
28
+ parsed_path]
29
+ .join('/')
30
+ URI(full_url)
31
+ end
32
+ end
35
33
  end
@@ -1,68 +1,71 @@
1
- module MangoPay
2
-
3
- # Converts field names between Ruby and API formats.
4
- module JsonTagConverter
5
- class << self
6
-
7
- # Converts a snake_case-named field name to
8
- # its API UpperCamelCase counterpart.
9
- def to_json_tag(field)
10
- field.split('_').collect do |word|
11
- apply_capitalization word
12
- end.join
13
- end
14
-
15
- # Applies necessary capitalization to a word
16
- # in order to match API conventions.
17
- def apply_capitalization(word)
18
- word.sub!('kyc', 'KYC')
19
- word.sub!('url', 'URL')
20
- word.sub!('iban', 'IBAN')
21
- word.sub!('bic', 'BIC')
22
- word.sub!('aba', 'ABA')
23
- word.sub!('ubo', 'UBO')
24
- word[0] = word[0].upcase
25
- word
26
- end
27
-
28
- # Converts an API-returned UpperCamelCase-named JSON tag
29
- # to its Ruby-standard snake_case counterpart.
30
- def from_json_tag(tag)
31
- tag = tag.sub('UBO', 'Ubo')
32
- parts = tag.split(/(?=[A-Z])/)
33
- parts = compress_upcase_strings(parts)
34
- field = ''
35
- parts.each.with_index do |part, index|
36
- decapitalize part
37
- field << '_' if !field.empty? && (part.length > 1\
38
- || (part == 'e' && parts[index + 1] == 'Money'))
39
- field << part
40
- end
41
- field
42
- end
43
-
44
- # Takes an array of strings and sticks together those
45
- # which are single uppercase letters in order to form
46
- # the actual words they compose.
47
- def compress_upcase_strings(strings)
48
- result = []
49
- current = ''
50
- strings.each do |string|
51
- if string.length > 1
52
- result << current unless current.empty?
53
- current = ''
54
- result << string
55
- next
56
- end
57
- current << (current.empty? ? string : string.downcase)
58
- end
59
- current.empty? ? result : result << current
60
- end
61
-
62
- def decapitalize(word)
63
- word[0] = word[0].downcase
64
- word
65
- end
66
- end
67
- end
1
+ module MangoPay
2
+
3
+ # Converts field names between Ruby and API formats.
4
+ module JsonTagConverter
5
+ class << self
6
+
7
+ # Converts a snake_case-named field name to
8
+ # its API UpperCamelCase counterpart.
9
+ def to_json_tag(field)
10
+ field.split('_').collect do |word|
11
+ apply_capitalization! word
12
+ end.join
13
+ end
14
+
15
+ # Converts an API-returned UpperCamelCase-named JSON tag
16
+ # to its Ruby-standard snake_case counterpart.
17
+ def from_json_tag(tag)
18
+ tag = tag.sub('UBO', 'Ubo').sub('AVS', 'Avs')
19
+ parts = tag.split(/(?=[A-Z])/)
20
+ parts = compress_upcase_strings(parts)
21
+ field = ''
22
+ parts.each.with_index do |part, index|
23
+ decapitalize! part
24
+ field << '_' if !field.empty? && (part.length > 1\
25
+ || (part == 'e' && parts[index + 1] == 'Money'))
26
+ field << part
27
+ end
28
+ field
29
+ end
30
+
31
+ private
32
+
33
+ # Applies necessary capitalization to a word
34
+ # in order to match API conventions.
35
+ def apply_capitalization!(word)
36
+ word.sub!('kyc', 'KYC')
37
+ word.sub!('url', 'URL')
38
+ word.sub!('iban', 'IBAN')
39
+ word.sub!('bic', 'BIC')
40
+ word.sub!('aba', 'ABA')
41
+ word.sub!('ubo', 'UBO')
42
+ word.sub!('avs', 'AVS')
43
+ word[0] = word[0].upcase
44
+ word
45
+ end
46
+
47
+ # Takes an array of strings and sticks together those
48
+ # which are single uppercase letters in order to form
49
+ # the actual words they compose.
50
+ def compress_upcase_strings(strings)
51
+ result = []
52
+ current = ''
53
+ strings.each do |string|
54
+ if string.length > 1
55
+ result << current unless current.empty?
56
+ current = ''
57
+ result << string
58
+ next
59
+ end
60
+ current << (current.empty? ? string : string.downcase)
61
+ end
62
+ current.empty? ? result : result << current
63
+ end
64
+
65
+ def decapitalize!(word)
66
+ word[0] = word[0].downcase
67
+ word
68
+ end
69
+ end
70
+ end
68
71
  end
@@ -1,249 +1,267 @@
1
- require 'json'
2
- require_relative 'read_only_fields'
3
- require_relative '../common/json_tag_converter'
4
- require_relative 'log_provider'
5
- require_relative '../model/model'
6
- require_relative '../model/entity/account/bank_account'
7
-
8
- module MangoPay
9
-
10
- # To be included in order to apply JSON de/serialization methods
11
- module Jsonifier
12
- # require here to satisfy circular dependency
13
- require_relative '../model/entity/card_registration'
14
- require_relative '../model/entity/pre_authorization'
15
- require_relative '../model/entity/account/iban_bank_account'
16
- require_relative '../model/entity/account/us_bank_account'
17
- require_relative '../model/entity/account/ca_bank_account'
18
- require_relative '../model/entity/account/gb_bank_account'
19
- require_relative '../model/entity/account/other_bank_account'
20
- require_relative '../model/entity/mandate'
21
- require_relative '../model/entity/kyc_document'
22
- require_relative '../model/entity/pay_out'
23
- require_relative '../model/entity/ubo_declaration'
24
- require_relative '../model/entity/hook'
25
- require_relative '../model/entity/dispute'
26
- require_relative '../model/entity/dispute_document'
27
- require_relative '../model/entity/report'
28
- require_relative '../model/declared_ubo'
29
- LOG = LogProvider.provide(self)
30
-
31
- # Serializes an object to a JSON string.
32
- # Read-only fields will be removed
33
- #
34
- # @return [String] JSON string of non-read-only fields and values
35
- def jsonify!
36
- json = hashed_variables.to_json
37
- # hash.to_json() sometimes adds
38
- # unnecessary backslashes and double quotes
39
- json.delete!('\\')
40
- json.gsub!(/"{/, '{')
41
- json.gsub!(/}"/, '}')
42
- LOG.debug 'JSONIFIED {}', inspect
43
- LOG.debug 'INTO {}', json
44
- json
45
- end
46
-
47
- # De-serializes an object from a JSON-originating hash.
48
- #
49
- # @param +hash+ [Hash] hash converted from an API-returned JSON string
50
- # @return [Object] corresponding object (typed)
51
- def dejsonify(hash)
52
- hash.each do |tag, value|
53
- field = JsonTagConverter.from_json_tag tag
54
- field_value = nil
55
- if field == 'type'
56
- if is_a? MangoModel::BankAccount
57
- field_value = MangoModel::AccountType.value_of value
58
- elsif is_a? MangoModel::KycDocument
59
- field_value = MangoModel::KycDocumentType.value_of value
60
- elsif is_a? MangoModel::DisputeDocument
61
- field_value = MangoModel::DisputeDocumentType.value_of value
62
- end
63
- end
64
- if field == 'status'
65
- if is_a? MangoModel::CardRegistration
66
- field_value = MangoModel::CardStatus.value_of value
67
- elsif is_a? MangoModel::PreAuthorization
68
- field_value = MangoModel::PreAuthorizationStatus.value_of value
69
- elsif is_a?(MangoModel::KycDocument) || is_a?(MangoModel::DisputeDocument)
70
- field_value = MangoModel::DocumentStatus.value_of value
71
- elsif is_a? MangoModel::UboDeclaration
72
- field_value = MangoModel::UboDeclarationStatus.value_of value
73
- elsif is_a? MangoModel::DeclaredUbo
74
- field_value = MangoModel::DeclaredUboStatus.value_of value
75
- elsif is_a? MangoModel::Hook
76
- field_value = MangoModel::HookStatus.value_of value
77
- elsif is_a? MangoModel::Dispute
78
- field_value = MangoModel::DisputeStatus.value_of value
79
- elsif is_a? MangoModel::Report
80
- field_value = MangoModel::ReportStatus.value_of value
81
- end
82
- end
83
- if is_a? MangoModel::Mandate
84
- if field == 'culture'
85
- field_value = MangoModel::MandateCultureCode.value_of value
86
- elsif field == 'status'
87
- field_value = MangoModel::MandateStatus.value_of value
88
- elsif field == 'execution_type'
89
- field_value = MangoModel::MandateExecutionType.value_of value
90
- end
91
- end
92
- if field == 'execution_type' && is_a?(MangoModel::PreAuthorization)
93
- field_value = MangoModel::PreAuthorizationExecutionType.value_of value
94
- end
95
- if field == 'payment_type' && is_a?(MangoModel::PayOut)
96
- field_value = MangoModel::PayOutPaymentType.value_of value
97
- end
98
- if field == 'refused_reason_type'
99
- if is_a? MangoModel::DeclaredUbo
100
- field_value = MangoModel::DeclaredUboRefusedReasonType.value_of value
101
- elsif is_a? MangoModel::DisputeDocument
102
- field_value = MangoModel::DisputeDocRefusedReasonType.value_of value
103
- end
104
- end
105
- if field == 'validity' && is_a?(MangoModel::Hook)
106
- field_value = MangoModel::HookValidity.value_of value
107
- end
108
- if field == 'date' && is_a?(MangoModel::Event)
109
- field_value = value
110
- end
111
- if field == 'declared_ubos' && is_a?(MangoModel::UboDeclaration)
112
- field_value = []
113
- value.each do |declared_ubo|
114
- field_value << MangoModel::DeclaredUbo.new.dejsonify(declared_ubo)
115
- end
116
- end
117
- if field == 'bank_account' && is_a?(MangoModel::BankWireDirectPayIn)
118
- field_value = case value['Type']
119
- when MangoModel::AccountType::IBAN.to_s
120
- MangoModel::IbanBankAccount.new.dejsonify value
121
- when MangoModel::AccountType::US.to_s
122
- MangoModel::UsBankAccount.new.dejsonify value
123
- when MangoModel::AccountType::CA.to_s
124
- MangoModel::CaBankAccount.new.dejsonify value
125
- when MangoModel::AccountType::GB.to_s
126
- MangoModel::GbBankAccount.new.dejsonify value
127
- when MangoModel::AccountType::OTHER.to_s
128
- MangoModel::OtherBankAccount.new.dejsonify value
129
- else
130
- raise 'Unrecognized bank account type: ' + value['Type']
131
- end
132
- end
133
- unless field_value
134
- field_value = case field
135
- when *MangoModel.fields_of_type(MangoModel::Address)
136
- MangoModel::Address.new.dejsonify value
137
- when *MangoModel.fields_of_type(MangoModel::Money)
138
- MangoModel::Money.new.dejsonify value
139
- when *MangoModel.fields_of_type(MangoModel::RefundReason)
140
- MangoModel::RefundReason.new.dejsonify value
141
- when *MangoModel.fields_of_type(MangoModel::DisputeReason)
142
- MangoModel::DisputeReason.new.dejsonify value
143
- when *MangoModel.fields_of_type(MangoModel::PersonType)
144
- MangoModel::PersonType.value_of value
145
- when *MangoModel.fields_of_type(MangoModel::KycLevel)
146
- MangoModel::KycLevel.value_of value
147
- when *MangoModel.fields_of_type(MangoModel::LegalPersonType)
148
- MangoModel::LegalPersonType.value_of value
149
- when *MangoModel.fields_of_type(MangoModel::CountryIso)
150
- MangoModel::CountryIso.value_of value
151
- when *MangoModel.fields_of_type(MangoModel::DepositType)
152
- MangoModel::DepositType.value_of value
153
- when *MangoModel.fields_of_type(MangoModel::CurrencyIso)
154
- MangoModel::CurrencyIso.value_of value
155
- when *MangoModel.fields_of_type(MangoModel::FundsType)
156
- MangoModel::FundsType.value_of value
157
- when *MangoModel.fields_of_type(MangoModel::PlatformType)
158
- MangoModel::PlatformType.value_of value
159
- when *MangoModel.fields_of_type(MangoModel::TransactionType)
160
- MangoModel::TransactionType.value_of value
161
- when *MangoModel.fields_of_type(MangoModel::TransactionNature)
162
- MangoModel::TransactionNature.value_of value
163
- when *MangoModel.fields_of_type(MangoModel::TransactionStatus)
164
- MangoModel::TransactionStatus.value_of value
165
- when *MangoModel.fields_of_type(MangoModel::PayInPaymentType)
166
- MangoModel::PayInPaymentType.value_of value
167
- when *MangoModel.fields_of_type(MangoModel::PayInExecutionType)
168
- MangoModel::PayInExecutionType.value_of value
169
- when *MangoModel.fields_of_type(MangoModel::CardType)
170
- MangoModel::CardType.value_of value
171
- when *MangoModel.fields_of_type(MangoModel::SecureMode)
172
- MangoModel::SecureMode.value_of value
173
- when *MangoModel.fields_of_type(MangoModel::CultureCode)
174
- MangoModel::CultureCode.value_of value
175
- when *MangoModel.fields_of_type(MangoModel::CardValidity)
176
- MangoModel::CardValidity.value_of value
177
- when *MangoModel.fields_of_type(MangoModel::PaymentStatus)
178
- MangoModel::PaymentStatus.value_of value
179
- when *MangoModel.fields_of_type(MangoModel::DirectDebitType)
180
- MangoModel::DirectDebitType.value_of value
181
- when *MangoModel.fields_of_type(MangoModel::MandateScheme)
182
- MangoModel::MandateScheme.value_of value
183
- when *MangoModel.fields_of_type(MangoModel::MandateType)
184
- MangoModel::MandateType.value_of value
185
- when *MangoModel.fields_of_type(MangoModel::KycDocRefusedReasonType)
186
- MangoModel::KycDocRefusedReasonType.value_of value
187
- when *MangoModel.fields_of_type(MangoModel::NaturalUserCapacity)
188
- MangoModel::NaturalUserCapacity.value_of value
189
- when *MangoModel.fields_of_type(MangoModel::EventType)
190
- MangoModel::EventType.value_of value
191
- when *MangoModel.fields_of_type(MangoModel::RefundReasonType)
192
- MangoModel::RefundReasonType.value_of value
193
- when *MangoModel.fields_of_type(MangoModel::DisputeType)
194
- MangoModel::DisputeType.value_of value
195
- when *MangoModel.fields_of_type(MangoModel::DisputeReasonType)
196
- MangoModel::DisputeReasonType.value_of value
197
- when *MangoModel.fields_of_type(MangoModel::DisputeStatus)
198
- MangoModel::DisputeStatus.value_of value
199
- when *MangoModel.fields_of_type(MangoModel::DownloadFormat)
200
- MangoModel::DownloadFormat.value_of value
201
- when *MangoModel.fields_of_type(MangoModel::ReportType)
202
- MangoModel::ReportType.value_of value
203
- when *MangoModel.fields_of_type(DateTime)
204
- DateTime.parse value
205
- else
206
- value
207
- end
208
- end
209
- instance_variable_set "@#{field}", field_value
210
- end
211
- LOG.debug 'DE-JSONIFIED {}', hash
212
- LOG.debug 'INTO {}', inspect
213
- self
214
- end
215
-
216
- private
217
-
218
- # Prepares a hash mapping API-standard
219
- # instance variable names to their JSON values.
220
- # Removes any of the fields which are considered
221
- # read-only by the API
222
- def hashed_variables
223
- hash = {}
224
- instance_variables.each do |var|
225
- key = JsonTagConverter.to_json_tag var.to_s[1..-1]
226
- value = json_value_for var
227
- hash[key] = value
228
- end
229
- ReadOnlyFields.remove_from! hash
230
- hash
231
- end
232
-
233
- # Converts the value in a specified instance variable
234
- # to its JSON representation.
235
- def json_value_for(var_name)
236
- var_value = instance_variable_get var_name
237
- begin
238
- if var_value.singleton_class.included_modules.include? Jsonifier
239
- var_value.jsonify!
240
- else
241
- var_value
242
- end
243
- rescue TypeError
244
- # raised by .singleton_class() when called on primitives
245
- var_value
246
- end
247
- end
248
- end
1
+ require 'json'
2
+ require_relative 'read_only_fields'
3
+ require_relative '../common/json_tag_converter'
4
+ require_relative 'log_provider'
5
+ require_relative '../model/model'
6
+ require_relative '../model/entity/account/bank_account'
7
+
8
+ module MangoPay
9
+
10
+ # To be included in order to apply JSON de/serialization methods
11
+ module Jsonifier
12
+ # require here to satisfy circular dependency
13
+ require_relative '../model/entity/card_registration'
14
+ require_relative '../model/entity/pre_authorization'
15
+ require_relative '../model/entity/account/iban_bank_account'
16
+ require_relative '../model/entity/account/us_bank_account'
17
+ require_relative '../model/entity/account/ca_bank_account'
18
+ require_relative '../model/entity/account/gb_bank_account'
19
+ require_relative '../model/entity/account/other_bank_account'
20
+ require_relative '../model/entity/account/debited_bank_account'
21
+ require_relative '../model/entity/mandate'
22
+ require_relative '../model/entity/kyc_document'
23
+ require_relative '../model/entity/pay_in/pay_in'
24
+ require_relative '../model/entity/pay_in/apple_pay_direct_pay_in'
25
+ require_relative '../model/entity/pay_out'
26
+ require_relative '../model/entity/ubo_declaration'
27
+ require_relative '../model/entity/hook'
28
+ require_relative '../model/entity/dispute'
29
+ require_relative '../model/entity/dispute_document'
30
+ require_relative '../model/entity/report'
31
+ require_relative '../model/entity/banking_alias'
32
+ require_relative '../model/declared_ubo'
33
+ LOG = LogProvider.provide(self)
34
+
35
+ # Serializes an object to a JSON string.
36
+ # Read-only fields will be removed
37
+ #
38
+ # @return [String] JSON string of non-read-only fields and values
39
+ def jsonify!
40
+ json = hashed_variables.to_json
41
+ # hash.to_json() sometimes adds
42
+ # unnecessary backslashes and double quotes
43
+ json.delete!('\\')
44
+ json.gsub!(/"{/, '{')
45
+ json.gsub!(/}"/, '}')
46
+ LOG.debug 'JSONIFIED {}', inspect
47
+ LOG.debug 'INTO {}', json
48
+ json
49
+ end
50
+
51
+ # De-serializes an object from a JSON-originating hash.
52
+ #
53
+ # @param +hash+ [Hash] hash converted from an API-returned JSON string
54
+ # @return [Object] corresponding object (typed)
55
+ def dejsonify(hash)
56
+ return nil unless hash
57
+ hash.each do |tag, value|
58
+ field = JsonTagConverter.from_json_tag tag
59
+ field_value = nil
60
+ if field == 'type'
61
+ if is_a? MangoModel::BankAccount
62
+ field_value = MangoModel::AccountType.value_of value
63
+ elsif is_a? MangoModel::KycDocument
64
+ field_value = MangoModel::KycDocumentType.value_of value
65
+ elsif is_a? MangoModel::DisputeDocument
66
+ field_value = MangoModel::DisputeDocumentType.value_of value
67
+ end
68
+ end
69
+ if field == 'status'
70
+ if is_a? MangoModel::CardRegistration
71
+ field_value = MangoModel::CardStatus.value_of value
72
+ elsif is_a? MangoModel::PreAuthorization
73
+ field_value = MangoModel::PreAuthorizationStatus.value_of value
74
+ elsif is_a?(MangoModel::KycDocument) || is_a?(MangoModel::DisputeDocument)
75
+ field_value = MangoModel::DocumentStatus.value_of value
76
+ elsif is_a? MangoModel::UboDeclaration
77
+ field_value = MangoModel::UboDeclarationStatus.value_of value
78
+ elsif is_a? MangoModel::DeclaredUbo
79
+ field_value = MangoModel::DeclaredUboStatus.value_of value
80
+ elsif is_a? MangoModel::Hook
81
+ field_value = MangoModel::HookStatus.value_of value
82
+ elsif is_a? MangoModel::Dispute
83
+ field_value = MangoModel::DisputeStatus.value_of value
84
+ elsif is_a? MangoModel::Report
85
+ field_value = MangoModel::ReportStatus.value_of value
86
+ end
87
+ end
88
+ if is_a? MangoModel::Mandate
89
+ if field == 'culture'
90
+ field_value = MangoModel::MandateCultureCode.value_of value
91
+ elsif field == 'status'
92
+ field_value = MangoModel::MandateStatus.value_of value
93
+ elsif field == 'execution_type'
94
+ field_value = MangoModel::MandateExecutionType.value_of value
95
+ end
96
+ end
97
+ if field == 'execution_type' && is_a?(MangoModel::PreAuthorization)
98
+ field_value = MangoModel::PreAuthorizationExecutionType.value_of value
99
+ end
100
+ if field == 'payment_type' && is_a?(MangoModel::PayOut)
101
+ field_value = MangoModel::PayOutPaymentType.value_of value
102
+ end
103
+ if field == 'refused_reason_type'
104
+ if is_a? MangoModel::DeclaredUbo
105
+ field_value = MangoModel::DeclaredUboRefusedReasonType.value_of value
106
+ elsif is_a? MangoModel::DisputeDocument
107
+ field_value = MangoModel::DisputeDocRefusedReasonType.value_of value
108
+ end
109
+ end
110
+ if field == 'validity' && is_a?(MangoModel::Hook)
111
+ field_value = MangoModel::HookValidity.value_of value
112
+ end
113
+ if field == 'date' && is_a?(MangoModel::Event)
114
+ field_value = value
115
+ end
116
+ if field == 'declared_ubos' && is_a?(MangoModel::UboDeclaration)
117
+ field_value = []
118
+ value.each do |declared_ubo|
119
+ field_value << MangoModel::DeclaredUbo.new.dejsonify(declared_ubo)
120
+ end
121
+ end
122
+ if field == 'bank_account' && is_a?(MangoModel::BankWireDirectPayIn)
123
+ field_value = case value['Type']
124
+ when MangoModel::AccountType::IBAN.to_s
125
+ MangoModel::IbanBankAccount.new.dejsonify value
126
+ when MangoModel::AccountType::US.to_s
127
+ MangoModel::UsBankAccount.new.dejsonify value
128
+ when MangoModel::AccountType::CA.to_s
129
+ MangoModel::CaBankAccount.new.dejsonify value
130
+ when MangoModel::AccountType::GB.to_s
131
+ MangoModel::GbBankAccount.new.dejsonify value
132
+ when MangoModel::AccountType::OTHER.to_s
133
+ MangoModel::OtherBankAccount.new.dejsonify value
134
+ else
135
+ raise 'Unrecognized bank account type: ' + value['Type']
136
+ end
137
+ end
138
+ if field == 'debited_bank_account' && is_a?(MangoModel::BankWireExternalInstructionPayIn)
139
+ field_value = MangoModel::DebitedBankAccount.new.dejsonify value
140
+ end
141
+ field_value ||= case field
142
+ when *MangoModel.fields_of_type(MangoModel::Address)
143
+ MangoModel::Address.new.dejsonify value
144
+ when *MangoModel.fields_of_type(MangoModel::Money)
145
+ MangoModel::Money.new.dejsonify value
146
+ when *MangoModel.fields_of_type(MangoModel::RefundReason)
147
+ MangoModel::RefundReason.new.dejsonify value
148
+ when *MangoModel.fields_of_type(MangoModel::DisputeReason)
149
+ MangoModel::DisputeReason.new.dejsonify value
150
+ when *MangoModel.fields_of_type(MangoModel::PlatformCategorization)
151
+ MangoModel::PlatformCategorization.new.dejsonify value
152
+ when *MangoModel.fields_of_type(MangoModel::Billing)
153
+ MangoModel::Billing.new.dejsonify value
154
+ when *MangoModel.fields_of_type(MangoModel::SecurityInfo)
155
+ MangoModel::SecurityInfo.new.dejsonify value
156
+ when *MangoModel.fields_of_type(MangoModel::PersonType)
157
+ MangoModel::PersonType.value_of value
158
+ when *MangoModel.fields_of_type(MangoModel::KycLevel)
159
+ MangoModel::KycLevel.value_of value
160
+ when *MangoModel.fields_of_type(MangoModel::LegalPersonType)
161
+ MangoModel::LegalPersonType.value_of value
162
+ when *MangoModel.fields_of_type(MangoModel::CountryIso)
163
+ MangoModel::CountryIso.value_of value
164
+ when *MangoModel.fields_of_type(MangoModel::DepositType)
165
+ MangoModel::DepositType.value_of value
166
+ when *MangoModel.fields_of_type(MangoModel::CurrencyIso)
167
+ MangoModel::CurrencyIso.value_of value
168
+ when *MangoModel.fields_of_type(MangoModel::FundsType)
169
+ MangoModel::FundsType.value_of value
170
+ when *MangoModel.fields_of_type(MangoModel::PlatformType)
171
+ MangoModel::PlatformType.value_of value
172
+ when *MangoModel.fields_of_type(MangoModel::TransactionType)
173
+ MangoModel::TransactionType.value_of value
174
+ when *MangoModel.fields_of_type(MangoModel::TransactionNature)
175
+ MangoModel::TransactionNature.value_of value
176
+ when *MangoModel.fields_of_type(MangoModel::TransactionStatus)
177
+ MangoModel::TransactionStatus.value_of value
178
+ when *MangoModel.fields_of_type(MangoModel::PayInPaymentType)
179
+ MangoModel::PayInPaymentType.value_of value
180
+ when *MangoModel.fields_of_type(MangoModel::PayInExecutionType)
181
+ MangoModel::PayInExecutionType.value_of value
182
+ when *MangoModel.fields_of_type(MangoModel::CardType)
183
+ MangoModel::CardType.value_of value
184
+ when *MangoModel.fields_of_type(MangoModel::SecureMode)
185
+ MangoModel::SecureMode.value_of value
186
+ when *MangoModel.fields_of_type(MangoModel::CultureCode)
187
+ MangoModel::CultureCode.value_of value
188
+ when *MangoModel.fields_of_type(MangoModel::CardValidity)
189
+ MangoModel::CardValidity.value_of value
190
+ when *MangoModel.fields_of_type(MangoModel::PaymentStatus)
191
+ MangoModel::PaymentStatus.value_of value
192
+ when *MangoModel.fields_of_type(MangoModel::DirectDebitType)
193
+ MangoModel::DirectDebitType.value_of value
194
+ when *MangoModel.fields_of_type(MangoModel::MandateScheme)
195
+ MangoModel::MandateScheme.value_of value
196
+ when *MangoModel.fields_of_type(MangoModel::MandateType)
197
+ MangoModel::MandateType.value_of value
198
+ when *MangoModel.fields_of_type(MangoModel::KycDocRefusedReasonType)
199
+ MangoModel::KycDocRefusedReasonType.value_of value
200
+ when *MangoModel.fields_of_type(MangoModel::NaturalUserCapacity)
201
+ MangoModel::NaturalUserCapacity.value_of value
202
+ when *MangoModel.fields_of_type(MangoModel::EventType)
203
+ MangoModel::EventType.value_of value
204
+ when *MangoModel.fields_of_type(MangoModel::RefundReasonType)
205
+ MangoModel::RefundReasonType.value_of value
206
+ when *MangoModel.fields_of_type(MangoModel::DisputeType)
207
+ MangoModel::DisputeType.value_of value
208
+ when *MangoModel.fields_of_type(MangoModel::DisputeReasonType)
209
+ MangoModel::DisputeReasonType.value_of value
210
+ when *MangoModel.fields_of_type(MangoModel::DisputeStatus)
211
+ MangoModel::DisputeStatus.value_of value
212
+ when *MangoModel.fields_of_type(MangoModel::DownloadFormat)
213
+ MangoModel::DownloadFormat.value_of value
214
+ when *MangoModel.fields_of_type(MangoModel::ReportType)
215
+ MangoModel::ReportType.value_of value
216
+ when *MangoModel.fields_of_type(MangoModel::BusinessType)
217
+ MangoModel::BusinessType.value_of value
218
+ when *MangoModel.fields_of_type(MangoModel::Sector)
219
+ MangoModel::Sector.value_of value
220
+ when *MangoModel.fields_of_type(MangoModel::AvsResult)
221
+ MangoModel::AvsResult.value_of value
222
+ when *MangoModel.fields_of_type(DateTime)
223
+ DateTime.parse value
224
+ else
225
+ value
226
+ end
227
+ instance_variable_set "@#{field}", field_value
228
+ end
229
+ LOG.debug 'DE-JSONIFIED {}', hash
230
+ LOG.debug 'INTO {}', inspect
231
+ self
232
+ end
233
+
234
+ private
235
+
236
+ # Prepares a hash mapping API-standard
237
+ # instance variable names to their JSON values.
238
+ # Removes any of the fields which are considered
239
+ # read-only by the API
240
+ def hashed_variables
241
+ hash = {}
242
+ instance_variables.each do |var|
243
+ key = JsonTagConverter.to_json_tag var.to_s[1..-1]
244
+ value = json_value_for var
245
+ hash[key] = value
246
+ end
247
+ ReadOnlyFields.remove_from! hash
248
+ hash
249
+ end
250
+
251
+ # Converts the value in a specified instance variable
252
+ # to its JSON representation.
253
+ def json_value_for(var_name)
254
+ var_value = instance_variable_get var_name
255
+ begin
256
+ if var_value.singleton_class.included_modules.include? Jsonifier
257
+ var_value.jsonify!
258
+ else
259
+ var_value
260
+ end
261
+ rescue TypeError
262
+ # raised by .singleton_class() when called on primitives
263
+ var_value
264
+ end
265
+ end
266
+ end
249
267
  end