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.
- checksums.yaml +5 -5
- data/.gitignore +29 -29
- data/.rspec +3 -3
- data/.rubocop.yml +1 -1
- data/.travis.yml +21 -13
- data/Gemfile +2 -2
- data/LICENSE +20 -20
- data/README.md +379 -379
- data/bin/mangopay +9 -9
- data/lib/mangopay.rb +132 -132
- data/lib/mangopay/api/api.rb +8 -8
- data/lib/mangopay/api/api_methods.rb +160 -136
- data/lib/mangopay/api/auth_token_manager.rb +173 -173
- data/lib/mangopay/api/http_client.rb +324 -324
- data/lib/mangopay/api/service/bank_accounts.rb +145 -145
- data/lib/mangopay/api/service/banking_aliases.rb +83 -0
- data/lib/mangopay/api/service/cards.rb +151 -151
- data/lib/mangopay/api/service/client_wallets.rb +88 -88
- data/lib/mangopay/api/service/clients.rb +67 -67
- data/lib/mangopay/api/service/dispute_documents.rb +157 -157
- data/lib/mangopay/api/service/disputes.rb +186 -186
- data/lib/mangopay/api/service/e_money.rb +63 -41
- data/lib/mangopay/api/service/events.rb +46 -46
- data/lib/mangopay/api/service/hooks.rb +92 -92
- data/lib/mangopay/api/service/kyc_documents.rb +152 -152
- data/lib/mangopay/api/service/mandates.rb +141 -141
- data/lib/mangopay/api/service/oauth_tokens.rb +24 -24
- data/lib/mangopay/api/service/pay_ins.rb +369 -259
- data/lib/mangopay/api/service/pay_outs.rb +53 -53
- data/lib/mangopay/api/service/pre_authorizations.rb +126 -68
- data/lib/mangopay/api/service/refunds.rb +159 -61
- data/lib/mangopay/api/service/reports.rb +150 -150
- data/lib/mangopay/api/service/repudiations.rb +31 -31
- data/lib/mangopay/api/service/responses.rb +101 -101
- data/lib/mangopay/api/service/settlement_transfers.rb +54 -54
- data/lib/mangopay/api/service/transactions.rb +246 -182
- data/lib/mangopay/api/service/transfers.rb +53 -53
- data/lib/mangopay/api/service/ubo_declarations.rb +94 -69
- data/lib/mangopay/api/service/users.rb +162 -162
- data/lib/mangopay/api/service/wallets.rb +98 -98
- data/lib/mangopay/api/uri_provider.rb +32 -34
- data/lib/mangopay/common/json_tag_converter.rb +70 -67
- data/lib/mangopay/common/jsonifier.rb +266 -248
- data/lib/mangopay/common/log_provider.rb +33 -33
- data/lib/mangopay/common/rate_limit_interval.rb +16 -16
- data/lib/mangopay/common/read_only_fields.rb +26 -26
- data/lib/mangopay/common/response_error.rb +61 -61
- data/lib/mangopay/common/sort_direction.rb +14 -14
- data/lib/mangopay/common/sort_field.rb +12 -12
- data/lib/mangopay/common/template_url_options.rb +8 -8
- data/lib/mangopay/configuration.rb +38 -38
- data/lib/mangopay/environment.rb +65 -65
- data/lib/mangopay/model/address.rb +26 -26
- data/lib/mangopay/model/billing.rb +13 -0
- data/lib/mangopay/model/birthplace.rb +15 -0
- data/lib/mangopay/model/declared_ubo.rb +20 -20
- data/lib/mangopay/model/dispute_reason.rb +14 -14
- data/lib/mangopay/model/document_page_consult.rb +14 -14
- data/lib/mangopay/model/e_money.rb +17 -17
- data/lib/mangopay/model/entity/account/bank_account.rb +25 -25
- data/lib/mangopay/model/entity/account/ca_bank_account.rb +26 -26
- data/lib/mangopay/model/entity/account/debited_bank_account.rb +31 -0
- data/lib/mangopay/model/entity/account/gb_bank_account.rb +20 -20
- data/lib/mangopay/model/entity/account/iban_bank_account.rb +20 -20
- data/lib/mangopay/model/entity/account/other_bank_account.rb +23 -23
- data/lib/mangopay/model/entity/account/us_bank_account.rb +23 -23
- data/lib/mangopay/model/entity/banking_alias.rb +27 -0
- data/lib/mangopay/model/entity/card.rb +44 -44
- data/lib/mangopay/model/entity/card_registration.rb +42 -42
- data/lib/mangopay/model/entity/client.rb +65 -62
- data/lib/mangopay/model/entity/client_wallet.rb +22 -22
- data/lib/mangopay/model/entity/dispute.rb +49 -49
- data/lib/mangopay/model/entity/dispute_document.rb +28 -28
- data/lib/mangopay/model/entity/entity_base.rb +17 -17
- data/lib/mangopay/model/entity/hook.rb +25 -25
- data/lib/mangopay/model/entity/kyc_document.rb +27 -27
- data/lib/mangopay/model/entity/mandate.rb +50 -50
- data/lib/mangopay/model/entity/pay_in/apple_pay_direct_pay_in.rb +26 -0
- data/lib/mangopay/model/entity/pay_in/bank_wire_direct_pay_in.rb +24 -21
- data/lib/mangopay/model/entity/pay_in/bank_wire_external_instruction_pay_in.rb +19 -0
- data/lib/mangopay/model/entity/pay_in/card_direct_pay_in.rb +41 -32
- data/lib/mangopay/model/entity/pay_in/card_pre_authorized_pay_in.rb +15 -12
- data/lib/mangopay/model/entity/pay_in/card_web_pay_in.rb +36 -39
- data/lib/mangopay/model/entity/pay_in/direct_debit_direct_pay_in.rb +25 -22
- data/lib/mangopay/model/entity/pay_in/direct_debit_web_pay_in.rb +37 -37
- data/lib/mangopay/model/entity/pay_in/google_pay_direct_pay_in.rb +28 -0
- data/lib/mangopay/model/entity/pay_in/pay_in.rb +18 -15
- data/lib/mangopay/model/entity/pay_in/paypal_web_pay_in.rb +15 -0
- data/lib/mangopay/model/entity/pay_out.rb +21 -21
- data/lib/mangopay/model/entity/pre_authorization.rb +74 -67
- data/lib/mangopay/model/entity/refund.rb +17 -17
- data/lib/mangopay/model/entity/report.rb +50 -50
- data/lib/mangopay/model/entity/repudiation.rb +17 -17
- data/lib/mangopay/model/entity/settlement_transfer.rb +16 -16
- data/lib/mangopay/model/entity/transaction.rb +51 -51
- data/lib/mangopay/model/entity/transfer.rb +12 -12
- data/lib/mangopay/model/entity/ubo.rb +30 -0
- data/lib/mangopay/model/entity/ubo_declaration.rb +29 -31
- data/lib/mangopay/model/entity/user/legal_user.rb +55 -52
- data/lib/mangopay/model/entity/user/natural_user.rb +49 -49
- data/lib/mangopay/model/entity/user/user.rb +17 -17
- data/lib/mangopay/model/entity/wallet.rb +27 -27
- data/lib/mangopay/model/enum/account_type.rb +23 -23
- data/lib/mangopay/model/enum/avs_result.rb +19 -0
- data/lib/mangopay/model/enum/banking_alias_type.rb +12 -0
- data/lib/mangopay/model/enum/business_type.rb +17 -0
- data/lib/mangopay/model/enum/card_status.rb +14 -14
- data/lib/mangopay/model/enum/card_type.rb +32 -32
- data/lib/mangopay/model/enum/card_validity.rb +18 -18
- data/lib/mangopay/model/enum/country_iso.rb +758 -758
- data/lib/mangopay/model/enum/culture_code.rb +43 -43
- data/lib/mangopay/model/enum/currency_iso.rb +551 -551
- data/lib/mangopay/model/enum/declared_ubo_refused_reason_type.rb +15 -15
- data/lib/mangopay/model/enum/declared_ubo_status.rb +17 -17
- data/lib/mangopay/model/enum/deposit_type.rb +14 -14
- data/lib/mangopay/model/enum/direct_debit_type.rb +12 -12
- data/lib/mangopay/model/enum/dispute_doc_refused_reason_type.rb +24 -24
- data/lib/mangopay/model/enum/dispute_document_type.rb +22 -22
- data/lib/mangopay/model/enum/dispute_reason_type.rb +32 -32
- data/lib/mangopay/model/enum/dispute_status.rb +20 -20
- data/lib/mangopay/model/enum/dispute_type.rb +14 -14
- data/lib/mangopay/model/enum/document_status.rb +20 -20
- data/lib/mangopay/model/enum/download_format.rb +10 -10
- data/lib/mangopay/model/enum/event_type.rb +76 -73
- data/lib/mangopay/model/enum/funds_type.rb +14 -14
- data/lib/mangopay/model/enum/hook_status.rb +12 -12
- data/lib/mangopay/model/enum/hook_validity.rb +14 -14
- data/lib/mangopay/model/enum/income_range.rb +20 -20
- data/lib/mangopay/model/enum/kyc_doc_refused_reason_type.rb +36 -36
- data/lib/mangopay/model/enum/kyc_document_type.rb +18 -18
- data/lib/mangopay/model/enum/kyc_level.rb +12 -12
- data/lib/mangopay/model/enum/legal_person_type.rb +14 -14
- data/lib/mangopay/model/enum/mandate_culture_code.rb +22 -22
- data/lib/mangopay/model/enum/mandate_execution_type.rb +10 -10
- data/lib/mangopay/model/enum/mandate_scheme.rb +12 -12
- data/lib/mangopay/model/enum/mandate_status.rb +23 -23
- data/lib/mangopay/model/enum/mandate_type.rb +10 -10
- data/lib/mangopay/model/enum/natural_user_capacity.rb +14 -14
- data/lib/mangopay/model/enum/pay_in_execution_type.rb +17 -17
- data/lib/mangopay/model/enum/pay_in_payment_type.rb +29 -20
- data/lib/mangopay/model/enum/pay_out_payment_type.rb +10 -10
- data/lib/mangopay/model/enum/payment_status.rb +20 -20
- data/lib/mangopay/model/enum/person_type.rb +14 -14
- data/lib/mangopay/model/enum/platform_type.rb +22 -22
- data/lib/mangopay/model/enum/pre_authorization_execution_type.rb +10 -10
- data/lib/mangopay/model/enum/pre_authorization_status.rb +17 -17
- data/lib/mangopay/model/enum/refund_reason_type.rb +20 -20
- data/lib/mangopay/model/enum/report_status.rb +16 -16
- data/lib/mangopay/model/enum/report_type.rb +12 -12
- data/lib/mangopay/model/enum/sector.rb +29 -0
- data/lib/mangopay/model/enum/secure_mode.rb +15 -15
- data/lib/mangopay/model/enum/transaction_nature.rb +16 -16
- data/lib/mangopay/model/enum/transaction_status.rb +14 -14
- data/lib/mangopay/model/enum/transaction_type.rb +14 -14
- data/lib/mangopay/model/enum/ubo_declaration_refused_reason_type.rb +18 -18
- data/lib/mangopay/model/enum/ubo_declaration_status.rb +20 -20
- data/lib/mangopay/model/event.rb +17 -17
- data/lib/mangopay/model/model.rb +214 -193
- data/lib/mangopay/model/money.rb +16 -16
- data/lib/mangopay/model/pay_in_web_extended_view.rb +30 -30
- data/lib/mangopay/model/platform_categorization.rb +15 -0
- data/lib/mangopay/model/refund_reason.rb +14 -14
- data/lib/mangopay/model/report_filter.rb +82 -82
- data/lib/mangopay/model/request/cancel_request.rb +15 -15
- data/lib/mangopay/model/request/complete_registration_request.rb +12 -12
- data/lib/mangopay/model/request/currency_request.rb +12 -12
- data/lib/mangopay/model/request/deactivation_request.rb +9 -9
- data/lib/mangopay/model/request/filter_request.rb +37 -37
- data/lib/mangopay/model/request/submit_document_request.rb +13 -13
- data/lib/mangopay/model/request/submit_ubo_declaration_request.rb +16 -13
- data/lib/mangopay/model/request/upload_file_request.rb +8 -8
- data/lib/mangopay/model/response_replica.rb +26 -26
- data/lib/mangopay/model/security_info.rb +13 -0
- data/lib/mangopay/util/custom_formatter.rb +11 -11
- data/lib/mangopay/util/custom_logger.rb +33 -33
- data/lib/mangopay/util/enum.rb +51 -51
- data/lib/mangopay/util/file_encoder.rb +15 -15
- data/lib/mangopay/util/non_instantiable.rb +5 -5
- data/lib/mangopay/util/storage_strategy.rb +9 -9
- data/lib/mangopay/util/void_logger.rb +5 -5
- data/mangopay-v4.gemspec +32 -0
- data/mangopay.gemspec +32 -32
- data/spec/context/address_context.rb +24 -24
- data/spec/context/bank_account_context.rb +137 -137
- data/spec/context/banking_alias_context.rb +17 -0
- data/spec/context/birthplace_context.rb +17 -0
- data/spec/context/card_context.rb +45 -45
- data/spec/context/client_context.rb +43 -44
- data/spec/context/dispute_context.rb +36 -36
- data/spec/context/dispute_document_context.rb +19 -19
- data/spec/context/hook_context.rb +15 -15
- data/spec/context/kyc_document_context.rb +22 -22
- data/spec/context/mandate_context.rb +26 -26
- data/spec/context/pay_in_context.rb +319 -224
- data/spec/context/pay_out_context.rb +39 -38
- data/spec/context/pre_authorization_context.rb +44 -40
- data/spec/context/refund_context.rb +32 -32
- data/spec/context/report_context.rb +21 -21
- data/spec/context/repudiation_context.rb +18 -18
- data/spec/context/settlement_transfer_context.rb +27 -27
- data/spec/context/transfer_context.rb +50 -50
- data/spec/context/ubo_declaration_context.rb +29 -24
- data/spec/context/user_context.rb +83 -82
- data/spec/context/wallet_context.rb +52 -52
- data/spec/mangopay/bank_accounts_spec.rb +228 -228
- data/spec/mangopay/banking_alias_spec.rb +85 -0
- data/spec/mangopay/cards_spec.rb +133 -134
- data/spec/mangopay/client_wallets_spec.rb +147 -147
- data/spec/mangopay/clients_spec.rb +56 -54
- data/spec/mangopay/configuration_spec.rb +125 -125
- data/spec/mangopay/dispute_documents_spec.rb +173 -173
- data/spec/mangopay/disputes_spec.rb +264 -264
- data/spec/mangopay/e_money_spec.rb +57 -37
- data/spec/mangopay/events_spec.rb +49 -49
- data/spec/mangopay/hooks_spec.rb +70 -70
- data/spec/mangopay/kyc_documents_spec.rb +179 -179
- data/spec/mangopay/mandates_spec.rb +218 -218
- data/spec/mangopay/oauth_tokens_spec.rb +40 -40
- data/spec/mangopay/pay_ins_spec.rb +279 -180
- data/spec/mangopay/pay_outs_spec.rb +38 -38
- data/spec/mangopay/pre_authorizations_spec.rb +134 -57
- data/spec/mangopay/refunds_spec.rb +187 -39
- data/spec/mangopay/reports_spec.rb +118 -120
- data/spec/mangopay/responses_spec.rb +324 -294
- data/spec/mangopay/settlement_transfers_spec.rb +36 -36
- data/spec/mangopay/transactions_spec.rb +347 -232
- data/spec/mangopay/transfers_spec.rb +37 -37
- data/spec/mangopay/ubo_declarations_spec.rb +127 -64
- data/spec/mangopay/users_spec.rb +145 -145
- data/spec/mangopay/wallets_spec.rb +103 -103
- data/spec/spec_helper.rb +72 -72
- data/spec/tmp/MangoPay.AuthorizationToken.FileStore.tmp +6 -0
- data/spec/tmp/mangopay.log.tmp +1201 -0
- 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 [
|
16
|
-
#
|
17
|
-
# @
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
#
|
16
|
-
#
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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/
|
21
|
-
require_relative '../model/entity/
|
22
|
-
require_relative '../model/entity/
|
23
|
-
require_relative '../model/entity/
|
24
|
-
require_relative '../model/entity/
|
25
|
-
require_relative '../model/entity/
|
26
|
-
require_relative '../model/entity/
|
27
|
-
require_relative '../model/entity/
|
28
|
-
require_relative '../model/
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
json.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
json
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
field_value = MangoModel::
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
field_value = MangoModel::
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
end
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
end
|
247
|
-
|
248
|
-
|
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
|