checkout_sdk 1.2.2 → 1.3.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 (93) hide show
  1. checksums.yaml +4 -4
  2. data/lib/checkout_sdk/accounts/account_holder.rb +10 -2
  3. data/lib/checkout_sdk/accounts/account_holder_corporate.rb +15 -0
  4. data/lib/checkout_sdk/accounts/account_holder_individual.rb +18 -0
  5. data/lib/checkout_sdk/accounts/accounts.rb +23 -0
  6. data/lib/checkout_sdk/accounts/additional_document.rb +11 -0
  7. data/lib/checkout_sdk/accounts/additional_info.rb +17 -0
  8. data/lib/checkout_sdk/accounts/articles_of_association_type.rb +10 -0
  9. data/lib/checkout_sdk/accounts/bank_verification.rb +14 -0
  10. data/lib/checkout_sdk/accounts/bank_verification_type.rb +9 -0
  11. data/lib/checkout_sdk/accounts/company.rb +7 -1
  12. data/lib/checkout_sdk/accounts/contact_details.rb +4 -1
  13. data/lib/checkout_sdk/accounts/date_of_incorporation.rb +14 -0
  14. data/lib/checkout_sdk/accounts/financial_verification.rb +14 -0
  15. data/lib/checkout_sdk/accounts/financial_verification_type.rb +9 -0
  16. data/lib/checkout_sdk/accounts/invitee.rb +11 -0
  17. data/lib/checkout_sdk/accounts/onboard_entity.rb +13 -4
  18. data/lib/checkout_sdk/accounts/onboard_sub_entity_documents.rb +31 -4
  19. data/lib/checkout_sdk/accounts/processing_details.rb +26 -0
  20. data/lib/checkout_sdk/accounts/proof_of_legality.rb +14 -0
  21. data/lib/checkout_sdk/accounts/proof_of_legality_type.rb +9 -0
  22. data/lib/checkout_sdk/accounts/proof_of_principal_address.rb +14 -0
  23. data/lib/checkout_sdk/accounts/proof_of_principal_address_type.rb +9 -0
  24. data/lib/checkout_sdk/accounts/shareholder_structure.rb +14 -0
  25. data/lib/checkout_sdk/accounts/shareholder_structure_type.rb +9 -0
  26. data/lib/checkout_sdk/api_client.rb +59 -50
  27. data/lib/checkout_sdk/client.rb +2 -3
  28. data/lib/checkout_sdk/common/account_change_indicator_type.rb +12 -0
  29. data/lib/checkout_sdk/common/account_holder.rb +12 -9
  30. data/lib/checkout_sdk/common/account_password_change_indicator_type.rb +13 -0
  31. data/lib/checkout_sdk/common/account_type_card_product_type.rb +11 -0
  32. data/lib/checkout_sdk/common/cardholder_account_age_indicator_type.rb +13 -0
  33. data/lib/checkout_sdk/common/common.rb +6 -0
  34. data/lib/checkout_sdk/common/customer_retry.rb +11 -0
  35. data/lib/checkout_sdk/common/destination.rb +38 -0
  36. data/lib/checkout_sdk/common/payment_source_type.rb +8 -0
  37. data/lib/checkout_sdk/common/product.rb +4 -1
  38. data/lib/checkout_sdk/error.rb +24 -8
  39. data/lib/checkout_sdk/payments/applepay.rb +14 -0
  40. data/lib/checkout_sdk/payments/{sessions/card.rb → card.rb} +4 -1
  41. data/lib/checkout_sdk/payments/exemption.rb +2 -0
  42. data/lib/checkout_sdk/payments/googlepay.rb +14 -0
  43. data/lib/checkout_sdk/payments/hosted/hosted_payment_instruction.rb +11 -0
  44. data/lib/checkout_sdk/payments/hosted/hosted_payments_session.rb +44 -23
  45. data/lib/checkout_sdk/payments/hosted/payment_purpose_type.rb +27 -0
  46. data/lib/checkout_sdk/payments/links/payment_link.rb +18 -0
  47. data/lib/checkout_sdk/payments/locale_type.rb +31 -0
  48. data/lib/checkout_sdk/payments/partial_authorization.rb +11 -0
  49. data/lib/checkout_sdk/payments/payment_method_configuration.rb +17 -0
  50. data/lib/checkout_sdk/payments/payment_request.rb +3 -0
  51. data/lib/checkout_sdk/payments/payments.rb +13 -3
  52. data/lib/checkout_sdk/payments/product.rb +3 -0
  53. data/lib/checkout_sdk/payments/refund_order.rb +53 -0
  54. data/lib/checkout_sdk/payments/refund_request.rb +11 -2
  55. data/lib/checkout_sdk/payments/sender/government_sender.rb +3 -0
  56. data/lib/checkout_sdk/payments/sender/individual_sender.rb +3 -0
  57. data/lib/checkout_sdk/payments/sessions/payment_sessions_request.rb +3 -0
  58. data/lib/checkout_sdk/payments/source/apm/ach_source.rb +27 -0
  59. data/lib/checkout_sdk/payments/source/apm/bizum_source.rb +15 -0
  60. data/lib/checkout_sdk/payments/source/apm/octopus_source.rb +11 -0
  61. data/lib/checkout_sdk/payments/source/apm/plaid_source.rb +17 -0
  62. data/lib/checkout_sdk/payments/source/apm/sequra_source.rb +15 -0
  63. data/lib/checkout_sdk/payments/source/card_source.rb +4 -1
  64. data/lib/checkout_sdk/payments/source/customer_source.rb +4 -1
  65. data/lib/checkout_sdk/payments/source/id_source.rb +4 -1
  66. data/lib/checkout_sdk/payments/source/network_token_source.rb +7 -1
  67. data/lib/checkout_sdk/payments/source/token_source.rb +4 -1
  68. data/lib/checkout_sdk/sessions/authentication_method.rb +3 -3
  69. data/lib/checkout_sdk/sessions/authentication_type.rb +3 -3
  70. data/lib/checkout_sdk/sessions/card_holder_account_info.rb +39 -3
  71. data/lib/checkout_sdk/sessions/channel/browser_session.rb +4 -1
  72. data/lib/checkout_sdk/sessions/channel/channel_data_type.rb +1 -0
  73. data/lib/checkout_sdk/sessions/channel/merchant_initiated_session.rb +15 -0
  74. data/lib/checkout_sdk/sessions/channel/request_type.rb +19 -0
  75. data/lib/checkout_sdk/sessions/channel/sdk_interface_type.rb +2 -2
  76. data/lib/checkout_sdk/sessions/initial_transaction.rb +23 -0
  77. data/lib/checkout_sdk/sessions/installment.rb +5 -0
  78. data/lib/checkout_sdk/sessions/merchant_risk_info.rb +20 -2
  79. data/lib/checkout_sdk/sessions/optimization.rb +19 -0
  80. data/lib/checkout_sdk/sessions/optimized_properties.rb +17 -0
  81. data/lib/checkout_sdk/sessions/pre_order_purchase_indicator_type.rb +10 -0
  82. data/lib/checkout_sdk/sessions/recurring.rb +5 -0
  83. data/lib/checkout_sdk/sessions/reorder_items_indicator_type.rb +10 -0
  84. data/lib/checkout_sdk/sessions/session_request.rb +25 -2
  85. data/lib/checkout_sdk/sessions/sessions.rb +9 -0
  86. data/lib/checkout_sdk/sessions/source/card_source.rb +2 -1
  87. data/lib/checkout_sdk/sessions/three_ds_method_completion_request.rb +3 -1
  88. data/lib/checkout_sdk/sessions/three_ds_req_auth_method.rb +16 -0
  89. data/lib/checkout_sdk/sessions/three_ds_requestor_authentication_info.rb +17 -0
  90. data/lib/checkout_sdk/sessions/transaction_type.rb +3 -3
  91. data/lib/checkout_sdk/version.rb +1 -1
  92. metadata +52 -7
  93. data/lib/checkout_sdk/payments/sessions/payment_method_configuration.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8a5d0baf6cbae6fdd117f4d506da563edd5a4b0c34b3d3998502cd44173f06a
4
- data.tar.gz: a692c66bed6a04a4c01e33b0e358814ffbc678bb358047fc427fbc53c7398c9a
3
+ metadata.gz: 26a49fd0dc6d8074742539d0651bdb5c94d255bdaa5ee5be1944c8d7ec2b0c6f
4
+ data.tar.gz: 914ac0e1f225f44336272904d87224442055d6d7f869e99c183301ebc07544c6
5
5
  SHA512:
6
- metadata.gz: a78beb178c7ecfc877df410cee8a1090a02bde9883a706d3a47a11a26fb49ca4cbd4a8821074530d3a81bc07a9d3fa8cab32d383e6db9668ee5c0b8fe4e7929a
7
- data.tar.gz: ce1b9b18e3132c57d9a2e2c520b11c45610e2a5749d53a961f2f41f722396ea6fc2c578ee31ba5f8cfd47b86df397ea97ed04a04fb466985510eaaaa31d70484
6
+ metadata.gz: e32feee8e37ce63ce23dbc396151f12c469d8361da8dad4a3272801ea272d648a3e46b5ff889662d088d4874316159ce30cbaa671f7b4c94d22f3d7352e66341
7
+ data.tar.gz: d4af9e3225ea291ac6570d4d6bcce2892c1816a9163f154d7659b09d03c8a1d68a4fe9f08f937ecb24d74d22268b82bd9706ba92a636ef57e9f1ab1495a1f4b7
@@ -21,8 +21,8 @@ module CheckoutSdk
21
21
  # @!attribute email
22
22
  # @return [String]
23
23
  class AccountHolder
24
- attr_accessor :type,
25
- :tax_id,
24
+ attr_reader :type
25
+ attr_accessor :tax_id,
26
26
  :date_of_birth,
27
27
  :country_of_birth,
28
28
  :residential_status,
@@ -30,6 +30,14 @@ module CheckoutSdk
30
30
  :phone,
31
31
  :identification,
32
32
  :email
33
+
34
+ protected
35
+
36
+ # @abstract
37
+ # @param [String] type {MetadataSourceType}
38
+ def initialize(type)
39
+ @type = type
40
+ end
33
41
  end
34
42
  end
35
43
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ # @!attribute company_name
6
+ # @return [String]
7
+ class AccountHolderCorporate < AccountHolder
8
+ attr_accessor :company_name
9
+
10
+ def initialize
11
+ super AccountHolderType::CORPORATE
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ # @!attribute first_name
6
+ # @return [String]
7
+ # @!attribute last_name
8
+ # @return [String]
9
+ class AccountHolderIndividual < AccountHolder
10
+ attr_accessor :first_name,
11
+ :last_name
12
+
13
+ def initialize
14
+ super AccountHolderType::INDIVIDUAL
15
+ end
16
+ end
17
+ end
18
+ end
@@ -8,6 +8,8 @@ require 'checkout_sdk/accounts/document'
8
8
  require 'checkout_sdk/accounts/individual'
9
9
  require 'checkout_sdk/accounts/business_type'
10
10
  require 'checkout_sdk/accounts/account_holder'
11
+ require 'checkout_sdk/accounts/account_holder_corporate'
12
+ require 'checkout_sdk/accounts/account_holder_individual'
11
13
  require 'checkout_sdk/accounts/entity_financial_details'
12
14
  require 'checkout_sdk/accounts/file_request'
13
15
  require 'checkout_sdk/accounts/date_of_birth'
@@ -36,3 +38,24 @@ require 'checkout_sdk/accounts/payment_instrument_request'
36
38
  require 'checkout_sdk/accounts/payment_instruments_query'
37
39
  require 'checkout_sdk/accounts/headers'
38
40
  require 'checkout_sdk/accounts/update_payment_instrument_request'
41
+ require 'checkout_sdk/accounts/additional_document'
42
+ require 'checkout_sdk/accounts/additional_info'
43
+ require 'checkout_sdk/accounts/articles_of_association_type'
44
+ require 'checkout_sdk/accounts/bank_verification'
45
+ require 'checkout_sdk/accounts/bank_verification_type'
46
+ require 'checkout_sdk/accounts/company_verification'
47
+ require 'checkout_sdk/accounts/company_verification_type'
48
+ require 'checkout_sdk/accounts/date_of_incorporation'
49
+ require 'checkout_sdk/accounts/financial_verification'
50
+ require 'checkout_sdk/accounts/financial_verification_type'
51
+ require 'checkout_sdk/accounts/invitee'
52
+ require 'checkout_sdk/accounts/onboard_sub_entity_documents'
53
+ require 'checkout_sdk/accounts/processing_details'
54
+ require 'checkout_sdk/accounts/proof_of_legality'
55
+ require 'checkout_sdk/accounts/proof_of_legality_type'
56
+ require 'checkout_sdk/accounts/proof_of_principal_address'
57
+ require 'checkout_sdk/accounts/proof_of_principal_address_type'
58
+ require 'checkout_sdk/accounts/shareholder_structure'
59
+ require 'checkout_sdk/accounts/shareholder_structure_type'
60
+ require 'checkout_sdk/accounts/tax_verification'
61
+ require 'checkout_sdk/accounts/tax_verification_type'
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ # @!attribute front
6
+ # @return [String]
7
+ class AdditionalDocument
8
+ attr_accessor :front
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ # @!attribute field1
6
+ # @return [String]
7
+ # @!attribute field2
8
+ # @return [String]
9
+ # @!attribute field3
10
+ # @return [String]
11
+ class AdditionalInfo
12
+ attr_accessor :field1,
13
+ :field2,
14
+ :field3
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ module ArticlesOfAssociationType
6
+ MEMORANDUM_OF_ASSOCIATION = 'memorandum_of_association'
7
+ ARTICLES_OF_ASSOCIATION = 'articles_of_association'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ # @!attribute type
6
+ # @return [BankVerificationType]
7
+ # @!attribute front
8
+ # @return [String]
9
+ class BankVerification
10
+ attr_accessor :type,
11
+ :front
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ module BankVerificationType
6
+ BANK_STATEMENT = 'bank_statement'
7
+ end
8
+ end
9
+ end
@@ -10,12 +10,16 @@ module CheckoutSdk
10
10
  # @return [String]
11
11
  # @!attribute trading_name
12
12
  # @return [String]
13
+ # @!attribute date_of_incorporation
14
+ # @return [DateOfIncorporation]
15
+ # @!attribute regulatory_licence_number
16
+ # @return [String]
13
17
  # @!attribute principal_address
14
18
  # @return [CheckoutSdk::Common::Address]
15
19
  # @!attribute registered_address
16
20
  # @return [CheckoutSdk::Common::Address]
17
21
  # @!attribute representatives
18
- # @return [Array(Representative)]
22
+ # @return [Array(EntityRepresentative)]
19
23
  # @!attribute document
20
24
  # @return [EntityDocument]
21
25
  # @!attribute financial_details
@@ -25,6 +29,8 @@ module CheckoutSdk
25
29
  :business_type,
26
30
  :legal_name,
27
31
  :trading_name,
32
+ :date_of_incorporation,
33
+ :regulatory_licence_number,
28
34
  :principal_address,
29
35
  :registered_address,
30
36
  :representatives,
@@ -6,9 +6,12 @@ module CheckoutSdk
6
6
  # @return [Phone]
7
7
  # @!attribute email_addresses
8
8
  # @return [EntityEmailAddresses]
9
+ # @!attribute invitee
10
+ # @return [Invitee]
9
11
  class ContactDetails
10
12
  attr_accessor :phone,
11
- :email_addresses
13
+ :email_addresses,
14
+ :invitee
12
15
  end
13
16
  end
14
17
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ # @!attribute month
6
+ # @return [Integer]
7
+ # @!attribute year
8
+ # @return [Integer]
9
+ class DateOfIncorporation
10
+ attr_reader :month,
11
+ :year
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ # @!attribute type
6
+ # @return [FinancialVerificationType]
7
+ # @!attribute front
8
+ # @return [String]
9
+ class FinancialVerification
10
+ attr_reader :type,
11
+ :front
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ module FinancialVerificationType
6
+ FINANCIAL_STATEMENT = 'financial_statement'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ # @!attribute email
6
+ # @return [String]
7
+ class Invitee
8
+ attr_accessor :email
9
+ end
10
+ end
11
+ end
@@ -4,23 +4,32 @@ module CheckoutSdk
4
4
  module Accounts
5
5
  # @!attribute reference
6
6
  # @return [String]
7
- # @!attribute contact_details
8
- # @return [ContactDetails]
7
+ # @!attribute is_draft
8
+ # @return [Boolean]
9
9
  # @!attribute profile
10
10
  # @return [Profile]
11
+ # @!attribute contact_details
12
+ # @return [ContactDetails]
11
13
  # @!attribute company
12
14
  # @return [Company]
15
+ # @!attribute processing_details
16
+ # @return [ProcessingDetails]
13
17
  # @!attribute individual
14
18
  # @return [Individual]
15
19
  # @!attribute documents
16
20
  # @return [OnboardSubEntityDocuments]
21
+ # @!attribute additional_info
22
+ # @return [AdditionalInfo]
17
23
  class OnboardEntity
18
24
  attr_accessor :reference,
19
- :contact_details,
25
+ :is_draft,
20
26
  :profile,
27
+ :contact_details,
21
28
  :company,
29
+ :processing_details,
22
30
  :individual,
23
- :documents
31
+ :documents,
32
+ :additional_info
24
33
  end
25
34
  end
26
35
  end
@@ -2,16 +2,43 @@
2
2
 
3
3
  module CheckoutSdk
4
4
  module Accounts
5
- # @!attribute documents
6
- # @return [Document]
5
+ # @!attribute identity_verification
6
+ # @return [EntityIdentificationDocument]
7
7
  # @!attribute company_verification
8
8
  # @return [CompanyVerification]
9
+ # @!attribute articles_of_association
10
+ # @return [ArticlesOfAssociationType]
11
+ # @!attribute bank_verification
12
+ # @return [BankVerification]
13
+ # @!attribute shareholder_structure
14
+ # @return [ShareholderStructure]
15
+ # @!attribute proof_of_legality
16
+ # @return [ProofOfLegality]
17
+ # @!attribute proof_of_principal_address
18
+ # @return [ProofOfPrincipalAddress]
19
+ # @!attribute additional_document1
20
+ # @return [AdditionalDocument]
21
+ # @!attribute additional_document2
22
+ # @return [AdditionalDocument]
23
+ # @!attribute additional_document3
24
+ # @return [AdditionalDocument]
9
25
  # @!attribute tax_verification
10
26
  # @return [TaxVerification]
27
+ # @!attribute financial_verification
28
+ # @return [FinancialVerification]
11
29
  class OnboardSubEntityDocuments
12
- attr_accessor :documents,
30
+ attr_accessor :identity_verification,
13
31
  :company_verification,
14
- :tax_verification
32
+ :articles_of_association,
33
+ :bank_verification,
34
+ :shareholder_structure,
35
+ :proof_of_legality,
36
+ :proof_of_principal_address,
37
+ :additional_document1,
38
+ :additional_document2,
39
+ :additional_document3,
40
+ :tax_verification,
41
+ :financial_verification
15
42
  end
16
43
  end
17
44
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ # @!attribute settlement_country
6
+ # @return [String]
7
+ # @!attribute target_countries
8
+ # @return [Array(String)]
9
+ # @!attribute annual_processing_volume
10
+ # @return [Integer]
11
+ # @!attribute average_transaction_value
12
+ # @return [Integer]
13
+ # @!attribute highest_transaction_value
14
+ # @return [Integer]
15
+ # @!attribute currency
16
+ # @return [CheckoutSdk::Common::Currency]
17
+ class ProcessingDetails
18
+ attr_accessor :settlement_country,
19
+ :target_countries,
20
+ :annual_processing_volume,
21
+ :average_transaction_value,
22
+ :highest_transaction_value,
23
+ :currency
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ # @!attribute type
6
+ # @return [ProofOfLegalityType]
7
+ # @!attribute front
8
+ # @return [String]
9
+ class ProofOfLegality
10
+ attr_accessor :type,
11
+ :front
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ module ProofOfLegalityType
6
+ PROOF_OF_LEGALITY = 'proof_of_legality'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ # @!attribute type
6
+ # @return [ProofOfPrincipalAddressType]
7
+ # @!attribute front
8
+ # @return [String]
9
+ class ProofOfPrincipalAddress
10
+ attr_reader :type,
11
+ :front
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ module ProofOfPrincipalAddressType
6
+ PROOF_OF_ADDRESS = 'proof_of_address'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ # @!attribute type
6
+ # @return [ShareholderStructureType]
7
+ # @!attribute front
8
+ # @return [String]
9
+ class ShareholderStructure
10
+ attr_accessor :type,
11
+ :front
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckoutSdk
4
+ module Accounts
5
+ module ShareholderStructureType
6
+ CERTIFIED_SHAREHOLDER_STRUCTURE = 'certified_shareholder_structure'
7
+ end
8
+ end
9
+ end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'csv'
4
+
3
5
  module CheckoutSdk
4
6
  class ApiClient
5
7
  attr_accessor :client, :multipart_client, :log
6
8
 
7
- # @param [CheckoutConfiguration] configuration
8
- # @param [String] uri
9
9
  def initialize(configuration, uri)
10
10
  @client = configuration.http_client.clone
11
11
  @client.url_prefix = uri
@@ -14,42 +14,27 @@ module CheckoutSdk
14
14
  @log = configuration.logger
15
15
  end
16
16
 
17
- # @param [String] path
18
- # @param [SdkAuthorization] authorization
19
- # @param [Object] params
20
- def invoke_get(path,
21
- authorization,
22
- params = nil)
17
+ def invoke_get(path, authorization, params = nil)
23
18
  invoke(:get, path, authorization, params: params)
24
19
  end
25
20
 
26
- def invoke_post(path,
27
- authorization,
28
- request = nil,
29
- idempotency_key = nil)
21
+ def invoke_post(path, authorization, request = nil, idempotency_key = nil)
30
22
  invoke(:post, path, authorization, request, idempotency_key)
31
23
  end
32
24
 
33
- def invoke_put(path,
34
- authorization,
35
- request)
25
+ def invoke_put(path, authorization, request)
36
26
  invoke(:put, path, authorization, request)
37
27
  end
38
28
 
39
- def invoke_patch(path,
40
- authorization,
41
- request = nil)
29
+ def invoke_patch(path, authorization, request = nil)
42
30
  invoke(:patch, path, authorization, request)
43
31
  end
44
32
 
45
- def invoke_delete(path,
46
- authorization)
33
+ def invoke_delete(path, authorization)
47
34
  invoke(:delete, path, authorization)
48
35
  end
49
36
 
50
- def submit_file(path,
51
- authorization,
52
- request)
37
+ def submit_file(path, authorization, request)
53
38
  upload(path, authorization, request)
54
39
  end
55
40
 
@@ -58,7 +43,7 @@ module CheckoutSdk
58
43
  def invoke(method, path, authorization, body = nil, idempotency_key = nil, params: nil)
59
44
  path = append_params(path, params) unless params.nil?
60
45
 
61
- headers = get_default_headers authorization
46
+ headers = default_headers(authorization)
62
47
  headers[:'Content-Type'] = 'application/json'
63
48
  headers[:'Cko-Idempotency-Key'] = idempotency_key unless idempotency_key.nil?
64
49
 
@@ -71,26 +56,23 @@ module CheckoutSdk
71
56
  raise CheckoutApiException, e.response
72
57
  end
73
58
 
74
- parse_response response
59
+ parse_response(response)
75
60
  end
76
61
 
77
- def get_default_headers(authorization)
78
- {
79
- 'User-Agent': "checkout-sdk-ruby/#{VERSION}",
80
- Accept: 'application/json',
81
- Authorization: authorization.authorization_header
82
- }
62
+ def default_headers(authorization)
63
+ { 'User-Agent': "checkout-sdk-ruby/#{VERSION}", Accept: 'application/json',
64
+ Authorization: authorization.authorization_header }
83
65
  end
84
66
 
85
67
  def append_params(path, input_params)
86
68
  raise CheckoutArgumentException, 'Query parameters were not provided' if input_params.nil?
87
69
 
88
- if input_params.is_a? String
89
- params = input_params
90
- else
91
- hash = CheckoutSdk::JsonSerializer.to_custom_hash(input_params)
92
- params = URI.encode_www_form(hash)
93
- end
70
+ params = if input_params.is_a? String
71
+ input_params
72
+ else
73
+ hash = CheckoutSdk::JsonSerializer.to_custom_hash(input_params)
74
+ URI.encode_www_form(hash)
75
+ end
94
76
 
95
77
  "#{path}?#{params}"
96
78
  end
@@ -103,16 +85,16 @@ module CheckoutSdk
103
85
  MIME::Types.type_for(file_request.file).first,
104
86
  File.basename(file_request.file)
105
87
  ),
106
- :purpose => file_request.purpose
88
+ purpose: file_request.purpose
107
89
  }
108
90
  end
109
91
 
110
92
  def upload(path, authorization, file_request)
111
- headers = get_default_headers authorization
93
+ headers = default_headers(authorization)
112
94
 
113
95
  file = File.open(file_request.file)
114
96
 
115
- form = build_multipart_request file_request, file
97
+ form = build_multipart_request(file_request, file)
116
98
 
117
99
  begin
118
100
  @log.info "post: /#{path}"
@@ -123,28 +105,55 @@ module CheckoutSdk
123
105
  file.close
124
106
  end
125
107
 
126
- parse_response response
108
+ parse_response(response)
127
109
  end
128
110
 
129
111
  def parse_response(response)
130
- raise CheckoutApiException, response if response.status < 200 || response.status >= 400
112
+ raise CheckoutApiException, response if response.status < 200 || response.status >= 300
131
113
 
132
114
  metadata = CheckoutUtils.map_to_http_metadata(response)
133
- body = parse_json_or_contents(response)
134
- body = OpenStruct.new if body.nil?
135
- body = OpenStruct.new(items: body) if body.is_a? Array
136
- body.http_metadata = metadata if body.is_a? OpenStruct
115
+ body = parse_body(response)
116
+
117
+ if body.is_a?(Array)
118
+ body = OpenStruct.new(items: body)
119
+ elsif !body.is_a?(OpenStruct)
120
+ body = OpenStruct.new(contents: body)
121
+ end
122
+
123
+ body.http_metadata = metadata if body.is_a?(OpenStruct)
124
+
137
125
  body
126
+ rescue JSON::ParserError => e
127
+ raise CheckoutApiException.new(response, "Error parsing JSON: #{e.message}")
128
+ rescue StandardError => e
129
+ @log&.error("Unexpected error occurred: #{e.message}")
130
+ raise
138
131
  end
139
132
 
140
- def parse_json_or_contents(response)
141
- return if response.body.nil? || response.body == ''
133
+ def parse_body(response)
134
+ content_type = response.headers['Content-Type']
135
+ return OpenStruct.new if response.body.nil? || response.body.empty?
142
136
 
143
- if response.body.start_with?('{', '[')
144
- JSON.parse(response.body, object_class: OpenStruct)
137
+ if content_type&.include?('application/json')
138
+ parsed_value = JSON.parse(response.body)
139
+ deep_convert_to_ostruct(parsed_value)
140
+ elsif content_type&.include?('text/csv')
141
+ csv_data = CSV.parse(response.body, headers: true)
142
+ OpenStruct.new(csv: csv_data)
145
143
  else
146
144
  OpenStruct.new(contents: response.body)
147
145
  end
148
146
  end
147
+
148
+ def deep_convert_to_ostruct(obj)
149
+ case obj
150
+ when Hash
151
+ OpenStruct.new(obj.transform_values { |value| deep_convert_to_ostruct(value) })
152
+ when Array
153
+ obj.map { |item| deep_convert_to_ostruct(item) }
154
+ else
155
+ obj
156
+ end
157
+ end
149
158
  end
150
159
  end