cyberSource_client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/AuthenticationSDK/Cybersource.gemspec +23 -23
- data/AuthenticationSDK/authentication/http/GetSignatureParameter.rb +62 -62
- data/AuthenticationSDK/authentication/http/HttpSignatureHeader.rb +50 -50
- data/AuthenticationSDK/authentication/jwt/JwtToken.rb +62 -62
- data/AuthenticationSDK/authentication/payloadDigest/digest.rb +10 -10
- data/AuthenticationSDK/core/Authorization.rb +24 -24
- data/AuthenticationSDK/core/ITokenGeneration.rb +4 -4
- data/AuthenticationSDK/core/Logger.rb +26 -26
- data/AuthenticationSDK/core/MerchantConfig.rb +181 -181
- data/AuthenticationSDK/util/ApiException.rb +18 -18
- data/AuthenticationSDK/util/Cache.rb +36 -36
- data/AuthenticationSDK/util/Constants.rb +133 -133
- data/AuthenticationSDK/util/PropertiesUtil.rb +21 -21
- data/AuthenticationSDK/util/Utility.rb +30 -30
- data/lib/cyberSource_client.rb +286 -286
- data/lib/cyberSource_client/api/capture_api.rb +133 -133
- data/lib/cyberSource_client/api/credit_api.rb +127 -127
- data/lib/cyberSource_client/api/default_api.rb +75 -75
- data/lib/cyberSource_client/api/instrument_identifier_api.rb +393 -393
- data/lib/cyberSource_client/api/key_generation_api.rb +75 -75
- data/lib/cyberSource_client/api/payment_api.rb +127 -127
- data/lib/cyberSource_client/api/payment_instrument_api.rb +312 -312
- data/lib/cyberSource_client/api/refund_api.rb +191 -191
- data/lib/cyberSource_client/api/reversal_api.rb +133 -133
- data/lib/cyberSource_client/api/tokenization_api.rb +71 -71
- data/lib/cyberSource_client/api/void_api.rb +307 -307
- data/lib/cyberSource_client/api_client.rb +437 -437
- data/lib/cyberSource_client/api_error.rb +38 -38
- data/lib/cyberSource_client/configuration.rb +202 -202
- data/lib/cyberSource_client/models/auth_reversal_request.rb +219 -219
- data/lib/cyberSource_client/models/body.rb +295 -295
- data/lib/cyberSource_client/models/body_1.rb +183 -183
- data/lib/cyberSource_client/models/body_2.rb +331 -331
- data/lib/cyberSource_client/models/body_3.rb +331 -331
- data/lib/cyberSource_client/models/capture_payment_request.rb +267 -267
- data/lib/cyberSource_client/models/card_info.rb +214 -214
- data/lib/cyberSource_client/models/create_credit_request.rb +267 -267
- data/lib/cyberSource_client/models/create_payment_request.rb +285 -285
- data/lib/cyberSource_client/models/der_public_key.rb +205 -205
- data/lib/cyberSource_client/models/error.rb +192 -192
- data/lib/cyberSource_client/models/error_links.rb +205 -205
- data/lib/cyberSource_client/models/error_response.rb +192 -192
- data/lib/cyberSource_client/models/generate_public_key_request.rb +184 -184
- data/lib/cyberSource_client/models/inline_response_200.rb +202 -202
- data/lib/cyberSource_client/models/inline_response_200_1.rb +255 -255
- data/lib/cyberSource_client/models/inline_response_200_2.rb +377 -377
- data/lib/cyberSource_client/models/inline_response_200_2_buyer_information.rb +270 -270
- data/lib/cyberSource_client/models/inline_response_200_2_device_information.rb +219 -219
- data/lib/cyberSource_client/models/inline_response_200_2_merchant_information.rb +233 -233
- data/lib/cyberSource_client/models/inline_response_200_2_order_information.rb +230 -230
- data/lib/cyberSource_client/models/inline_response_200_2_order_information_amount_details.rb +385 -385
- data/lib/cyberSource_client/models/inline_response_200_2_order_information_bill_to.rb +459 -459
- data/lib/cyberSource_client/models/inline_response_200_2_order_information_invoice_details.rb +315 -315
- data/lib/cyberSource_client/models/inline_response_200_2_order_information_line_items.rb +564 -564
- data/lib/cyberSource_client/models/inline_response_200_2_order_information_ship_to.rb +429 -429
- data/lib/cyberSource_client/models/inline_response_200_2_payment_information.rb +192 -192
- data/lib/cyberSource_client/models/inline_response_200_2_payment_information_card.rb +274 -274
- data/lib/cyberSource_client/models/inline_response_200_2_payment_information_tokenized_card.rb +299 -299
- data/lib/cyberSource_client/models/inline_response_200_2_processing_information.rb +199 -199
- data/lib/cyberSource_client/models/inline_response_200_2_processor_information.rb +227 -227
- data/lib/cyberSource_client/models/inline_response_200_2_processor_information_avs.rb +199 -199
- data/lib/cyberSource_client/models/inline_response_200_2_processor_information_card_verification.rb +199 -199
- data/lib/cyberSource_client/models/inline_response_200_3.rb +314 -314
- data/lib/cyberSource_client/models/inline_response_200_4.rb +350 -350
- data/lib/cyberSource_client/models/inline_response_200_4_device_information.rb +199 -199
- data/lib/cyberSource_client/models/inline_response_200_4_order_information.rb +230 -230
- data/lib/cyberSource_client/models/inline_response_200_4_order_information_amount_details.rb +360 -360
- data/lib/cyberSource_client/models/inline_response_200_4_order_information_invoice_details.rb +305 -305
- data/lib/cyberSource_client/models/inline_response_200_4_order_information_ship_to.rb +249 -249
- data/lib/cyberSource_client/models/inline_response_200_4_processing_information.rb +208 -208
- data/lib/cyberSource_client/models/inline_response_200_4_processing_information_authorization_options.rb +199 -199
- data/lib/cyberSource_client/models/inline_response_200_5.rb +305 -305
- data/lib/cyberSource_client/models/inline_response_200_6.rb +305 -305
- data/lib/cyberSource_client/models/inline_response_200_7.rb +295 -295
- data/lib/cyberSource_client/models/inline_response_200_8.rb +277 -277
- data/lib/cyberSource_client/models/inline_response_200_8__links.rb +219 -219
- data/lib/cyberSource_client/models/inline_response_200_8__links_first.rb +184 -184
- data/lib/cyberSource_client/models/inline_response_200_8__links_last.rb +184 -184
- data/lib/cyberSource_client/models/inline_response_200_8__links_next.rb +184 -184
- data/lib/cyberSource_client/models/inline_response_200_8__links_prev.rb +184 -184
- data/lib/cyberSource_client/models/inline_response_200_8__links_self.rb +184 -184
- data/lib/cyberSource_client/models/inline_response_200_der.rb +205 -205
- data/lib/cyberSource_client/models/inline_response_200_jwk.rb +225 -225
- data/lib/cyberSource_client/models/inline_response_201.rb +350 -350
- data/lib/cyberSource_client/models/inline_response_201_1.rb +332 -332
- data/lib/cyberSource_client/models/inline_response_201_1_authorization_information.rb +224 -224
- data/lib/cyberSource_client/models/inline_response_201_1_processor_information.rb +324 -324
- data/lib/cyberSource_client/models/inline_response_201_1_reversal_amount_details.rb +249 -249
- data/lib/cyberSource_client/models/inline_response_201_2.rb +314 -314
- data/lib/cyberSource_client/models/inline_response_201_2__links.rb +201 -201
- data/lib/cyberSource_client/models/inline_response_201_2_order_information.rb +192 -192
- data/lib/cyberSource_client/models/inline_response_201_2_order_information_amount_details.rb +224 -224
- data/lib/cyberSource_client/models/inline_response_201_2_processor_information.rb +199 -199
- data/lib/cyberSource_client/models/inline_response_201_3.rb +323 -323
- data/lib/cyberSource_client/models/inline_response_201_3__links.rb +192 -192
- data/lib/cyberSource_client/models/inline_response_201_3_order_information.rb +183 -183
- data/lib/cyberSource_client/models/inline_response_201_3_processor_information.rb +224 -224
- data/lib/cyberSource_client/models/inline_response_201_3_refund_amount_details.rb +224 -224
- data/lib/cyberSource_client/models/inline_response_201_4.rb +323 -323
- data/lib/cyberSource_client/models/inline_response_201_4_credit_amount_details.rb +224 -224
- data/lib/cyberSource_client/models/inline_response_201_5.rb +280 -280
- data/lib/cyberSource_client/models/inline_response_201_5_void_amount_details.rb +219 -219
- data/lib/cyberSource_client/models/inline_response_201_6.rb +331 -331
- data/lib/cyberSource_client/models/inline_response_201__embedded.rb +183 -183
- data/lib/cyberSource_client/models/inline_response_201__embedded_capture.rb +193 -193
- data/lib/cyberSource_client/models/inline_response_201__embedded_capture__links.rb +183 -183
- data/lib/cyberSource_client/models/inline_response_201__links.rb +201 -201
- data/lib/cyberSource_client/models/inline_response_201__links_self.rb +194 -194
- data/lib/cyberSource_client/models/inline_response_201_client_reference_information.rb +199 -199
- data/lib/cyberSource_client/models/inline_response_201_error_information.rb +239 -239
- data/lib/cyberSource_client/models/inline_response_201_error_information_details.rb +228 -228
- data/lib/cyberSource_client/models/inline_response_201_order_information.rb +192 -192
- data/lib/cyberSource_client/models/inline_response_201_order_information_amount_details.rb +249 -249
- data/lib/cyberSource_client/models/inline_response_201_order_information_invoice_details.rb +184 -184
- data/lib/cyberSource_client/models/inline_response_201_payment_information.rb +201 -201
- data/lib/cyberSource_client/models/inline_response_201_payment_information_account_features.rb +623 -623
- data/lib/cyberSource_client/models/inline_response_201_payment_information_card.rb +199 -199
- data/lib/cyberSource_client/models/inline_response_201_payment_information_tokenized_card.rb +349 -349
- data/lib/cyberSource_client/models/inline_response_201_point_of_sale_information.rb +208 -208
- data/lib/cyberSource_client/models/inline_response_201_point_of_sale_information_emv.rb +199 -199
- data/lib/cyberSource_client/models/inline_response_201_processor_information.rb +642 -642
- data/lib/cyberSource_client/models/inline_response_201_processor_information_avs.rb +224 -224
- data/lib/cyberSource_client/models/inline_response_201_processor_information_card_verification.rb +224 -224
- data/lib/cyberSource_client/models/inline_response_201_processor_information_consumer_authentication_response.rb +224 -224
- data/lib/cyberSource_client/models/inline_response_201_processor_information_customer.rb +199 -199
- data/lib/cyberSource_client/models/inline_response_201_processor_information_electronic_verification_results.rb +474 -474
- data/lib/cyberSource_client/models/inline_response_201_processor_information_issuer.rb +224 -224
- data/lib/cyberSource_client/models/inline_response_201_processor_information_merchant_advice.rb +224 -224
- data/lib/cyberSource_client/models/inline_response_400.rb +271 -271
- data/lib/cyberSource_client/models/inline_response_400_1.rb +271 -271
- data/lib/cyberSource_client/models/inline_response_400_2.rb +271 -271
- data/lib/cyberSource_client/models/inline_response_400_3.rb +271 -271
- data/lib/cyberSource_client/models/inline_response_400_4.rb +271 -271
- data/lib/cyberSource_client/models/inline_response_400_5.rb +259 -259
- data/lib/cyberSource_client/models/inline_response_400_6.rb +202 -202
- data/lib/cyberSource_client/models/inline_response_409.rb +183 -183
- data/lib/cyberSource_client/models/inline_response_409__links.rb +183 -183
- data/lib/cyberSource_client/models/inline_response_409__links_payment_instruments.rb +183 -183
- data/lib/cyberSource_client/models/inline_response_502.rb +260 -260
- data/lib/cyberSource_client/models/inline_response_default.rb +192 -192
- data/lib/cyberSource_client/models/inline_response_default__links.rb +205 -205
- data/lib/cyberSource_client/models/inline_response_default__links_next.rb +204 -204
- data/lib/cyberSource_client/models/inline_response_default_response_status.rb +225 -225
- data/lib/cyberSource_client/models/inline_response_default_response_status_details.rb +194 -194
- data/lib/cyberSource_client/models/instrumentidentifiers__links.rb +201 -201
- data/lib/cyberSource_client/models/instrumentidentifiers__links_self.rb +183 -183
- data/lib/cyberSource_client/models/instrumentidentifiers_authorization_options_merchant_initiated_transaction.rb +184 -184
- data/lib/cyberSource_client/models/instrumentidentifiers_bank_account.rb +194 -194
- data/lib/cyberSource_client/models/instrumentidentifiers_card.rb +184 -184
- data/lib/cyberSource_client/models/instrumentidentifiers_details.rb +194 -194
- data/lib/cyberSource_client/models/instrumentidentifiers_metadata.rb +184 -184
- data/lib/cyberSource_client/models/instrumentidentifiers_processing_information.rb +183 -183
- data/lib/cyberSource_client/models/instrumentidentifiers_processing_information_authorization_options.rb +183 -183
- data/lib/cyberSource_client/models/instrumentidentifiers_processing_information_authorization_options_initiator.rb +183 -183
- data/lib/cyberSource_client/models/json_web_key.rb +225 -225
- data/lib/cyberSource_client/models/key_parameters.rb +184 -184
- data/lib/cyberSource_client/models/key_result.rb +202 -202
- data/lib/cyberSource_client/models/link.rb +204 -204
- data/lib/cyberSource_client/models/links.rb +205 -205
- data/lib/cyberSource_client/models/oct_create_payment_request.rb +237 -237
- data/lib/cyberSource_client/models/paymentinstruments_bank_account.rb +184 -184
- data/lib/cyberSource_client/models/paymentinstruments_bill_to.rb +284 -284
- data/lib/cyberSource_client/models/paymentinstruments_buyer_information.rb +215 -215
- data/lib/cyberSource_client/models/paymentinstruments_buyer_information_issued_by.rb +184 -184
- data/lib/cyberSource_client/models/paymentinstruments_buyer_information_personal_identification.rb +203 -203
- data/lib/cyberSource_client/models/paymentinstruments_card.rb +278 -278
- data/lib/cyberSource_client/models/paymentinstruments_instrument_identifier.rb +295 -295
- data/lib/cyberSource_client/models/paymentinstruments_merchant_information.rb +183 -183
- data/lib/cyberSource_client/models/paymentinstruments_merchant_information_merchant_descriptor.rb +184 -184
- data/lib/cyberSource_client/models/paymentinstruments_processing_information.rb +193 -193
- data/lib/cyberSource_client/models/paymentinstruments_processing_information_bank_transfer_options.rb +184 -184
- data/lib/cyberSource_client/models/paymentsflexv1tokens_card_info.rb +214 -214
- data/lib/cyberSource_client/models/refund_capture_request.rb +267 -267
- data/lib/cyberSource_client/models/refund_payment_request.rb +267 -267
- data/lib/cyberSource_client/models/response_status.rb +225 -225
- data/lib/cyberSource_client/models/response_status_details.rb +194 -194
- data/lib/cyberSource_client/models/tokenize_parameters.rb +193 -193
- data/lib/cyberSource_client/models/tokenize_request.rb +193 -193
- data/lib/cyberSource_client/models/tokenize_result.rb +255 -255
- data/lib/cyberSource_client/models/v2credits_point_of_sale_information.rb +183 -183
- data/lib/cyberSource_client/models/v2credits_point_of_sale_information_emv.rb +221 -221
- data/lib/cyberSource_client/models/v2credits_processing_information.rb +383 -383
- data/lib/cyberSource_client/models/v2payments_aggregator_information.rb +233 -233
- data/lib/cyberSource_client/models/v2payments_aggregator_information_sub_merchant.rb +424 -424
- data/lib/cyberSource_client/models/v2payments_buyer_information.rb +285 -285
- data/lib/cyberSource_client/models/v2payments_buyer_information_personal_identification.rb +252 -252
- data/lib/cyberSource_client/models/v2payments_client_reference_information.rb +219 -219
- data/lib/cyberSource_client/models/v2payments_consumer_authentication_information.rb +374 -374
- data/lib/cyberSource_client/models/v2payments_device_information.rb +249 -249
- data/lib/cyberSource_client/models/v2payments_merchant_defined_information.rb +224 -224
- data/lib/cyberSource_client/models/v2payments_merchant_information.rb +308 -308
- data/lib/cyberSource_client/models/v2payments_merchant_information_merchant_descriptor.rb +374 -374
- data/lib/cyberSource_client/models/v2payments_order_information.rb +230 -230
- data/lib/cyberSource_client/models/v2payments_order_information_amount_details.rb +605 -605
- data/lib/cyberSource_client/models/v2payments_order_information_amount_details_amex_additional_amounts.rb +224 -224
- data/lib/cyberSource_client/models/v2payments_order_information_amount_details_surcharge.rb +209 -209
- data/lib/cyberSource_client/models/v2payments_order_information_amount_details_tax_details.rb +328 -328
- data/lib/cyberSource_client/models/v2payments_order_information_bill_to.rb +618 -618
- data/lib/cyberSource_client/models/v2payments_order_information_invoice_details.rb +330 -330
- data/lib/cyberSource_client/models/v2payments_order_information_invoice_details_transaction_advice_addendum.rb +199 -199
- data/lib/cyberSource_client/models/v2payments_order_information_line_items.rb +649 -649
- data/lib/cyberSource_client/models/v2payments_order_information_ship_to.rb +474 -474
- data/lib/cyberSource_client/models/v2payments_order_information_shipping_details.rb +234 -234
- data/lib/cyberSource_client/models/v2payments_payment_information.rb +210 -210
- data/lib/cyberSource_client/models/v2payments_payment_information_card.rb +474 -474
- data/lib/cyberSource_client/models/v2payments_payment_information_customer.rb +202 -202
- data/lib/cyberSource_client/models/v2payments_payment_information_fluid_data.rb +259 -259
- data/lib/cyberSource_client/models/v2payments_payment_information_tokenized_card.rb +424 -424
- data/lib/cyberSource_client/models/v2payments_point_of_sale_information.rb +440 -440
- data/lib/cyberSource_client/models/v2payments_point_of_sale_information_emv.rb +256 -256
- data/lib/cyberSource_client/models/v2payments_processing_information.rb +432 -432
- data/lib/cyberSource_client/models/v2payments_processing_information_authorization_options.rb +361 -361
- data/lib/cyberSource_client/models/v2payments_processing_information_authorization_options_initiator.rb +247 -247
- data/lib/cyberSource_client/models/{v2payments_processing_information_authorization_options_initiator_merchant_initiated_transaction.rb → v2payments_processing_information_authorization_options_merchant_initiated_transaction.rb} +224 -224
- data/lib/cyberSource_client/models/v2payments_processing_information_capture_options.rb +267 -267
- data/lib/cyberSource_client/models/v2payments_processing_information_issuer.rb +199 -199
- data/lib/cyberSource_client/models/v2payments_processing_information_recurring_options.rb +198 -198
- data/lib/cyberSource_client/models/v2payments_recipient_information.rb +249 -249
- data/lib/cyberSource_client/models/v2paymentsidcaptures_aggregator_information.rb +233 -233
- data/lib/cyberSource_client/models/v2paymentsidcaptures_aggregator_information_sub_merchant.rb +374 -374
- data/lib/cyberSource_client/models/v2paymentsidcaptures_buyer_information.rb +224 -224
- data/lib/cyberSource_client/models/v2paymentsidcaptures_merchant_information.rb +258 -258
- data/lib/cyberSource_client/models/v2paymentsidcaptures_order_information.rb +230 -230
- data/lib/cyberSource_client/models/v2paymentsidcaptures_order_information_amount_details.rb +546 -546
- data/lib/cyberSource_client/models/v2paymentsidcaptures_order_information_bill_to.rb +449 -449
- data/lib/cyberSource_client/models/v2paymentsidcaptures_order_information_invoice_details.rb +320 -320
- data/lib/cyberSource_client/models/v2paymentsidcaptures_order_information_ship_to.rb +249 -249
- data/lib/cyberSource_client/models/v2paymentsidcaptures_order_information_shipping_details.rb +199 -199
- data/lib/cyberSource_client/models/v2paymentsidcaptures_payment_information.rb +183 -183
- data/lib/cyberSource_client/models/v2paymentsidcaptures_point_of_sale_information.rb +208 -208
- data/lib/cyberSource_client/models/v2paymentsidcaptures_point_of_sale_information_emv.rb +211 -211
- data/lib/cyberSource_client/models/v2paymentsidcaptures_processing_information.rb +351 -351
- data/lib/cyberSource_client/models/v2paymentsidcaptures_processing_information_authorization_options.rb +249 -249
- data/lib/cyberSource_client/models/v2paymentsidcaptures_processing_information_capture_options.rb +242 -242
- data/lib/cyberSource_client/models/v2paymentsidrefunds_merchant_information.rb +258 -258
- data/lib/cyberSource_client/models/v2paymentsidrefunds_order_information.rb +230 -230
- data/lib/cyberSource_client/models/v2paymentsidrefunds_order_information_line_items.rb +639 -639
- data/lib/cyberSource_client/models/v2paymentsidrefunds_payment_information.rb +183 -183
- data/lib/cyberSource_client/models/v2paymentsidrefunds_payment_information_card.rb +374 -374
- data/lib/cyberSource_client/models/v2paymentsidrefunds_point_of_sale_information.rb +183 -183
- data/lib/cyberSource_client/models/v2paymentsidrefunds_processing_information.rb +333 -333
- data/lib/cyberSource_client/models/v2paymentsidrefunds_processing_information_recurring_options.rb +186 -186
- data/lib/cyberSource_client/models/v2paymentsidreversals_client_reference_information.rb +209 -209
- data/lib/cyberSource_client/models/v2paymentsidreversals_order_information.rb +185 -185
- data/lib/cyberSource_client/models/v2paymentsidreversals_order_information_line_items.rb +233 -233
- data/lib/cyberSource_client/models/v2paymentsidreversals_point_of_sale_information.rb +183 -183
- data/lib/cyberSource_client/models/v2paymentsidreversals_processing_information.rb +308 -308
- data/lib/cyberSource_client/models/v2paymentsidreversals_reversal_information.rb +211 -211
- data/lib/cyberSource_client/models/v2paymentsidreversals_reversal_information_amount_details.rb +224 -224
- data/lib/cyberSource_client/models/v2payouts_merchant_information.rb +258 -258
- data/lib/cyberSource_client/models/v2payouts_merchant_information_merchant_descriptor.rb +324 -324
- data/lib/cyberSource_client/models/v2payouts_order_information.rb +192 -192
- data/lib/cyberSource_client/models/v2payouts_order_information_amount_details.rb +249 -249
- data/lib/cyberSource_client/models/v2payouts_order_information_bill_to.rb +443 -443
- data/lib/cyberSource_client/models/v2payouts_payment_information.rb +183 -183
- data/lib/cyberSource_client/models/v2payouts_payment_information_card.rb +299 -299
- data/lib/cyberSource_client/models/v2payouts_processing_information.rb +283 -283
- data/lib/cyberSource_client/models/v2payouts_processing_information_payouts_options.rb +274 -274
- data/lib/cyberSource_client/models/v2payouts_recipient_information.rb +433 -433
- data/lib/cyberSource_client/models/v2payouts_sender_information.rb +517 -517
- data/lib/cyberSource_client/models/v2payouts_sender_information_account.rb +233 -233
- data/lib/cyberSource_client/models/void_capture_request.rb +183 -183
- data/lib/cyberSource_client/models/void_credit_request.rb +183 -183
- data/lib/cyberSource_client/models/void_payment_request.rb +183 -183
- data/lib/cyberSource_client/models/void_refund_request.rb +183 -183
- data/lib/cyberSource_client/version.rb +15 -15
- metadata +4 -4
@@ -1,437 +1,437 @@
|
|
1
|
-
=begin
|
2
|
-
#CyberSource Flex API
|
3
|
-
|
4
|
-
#Simple PAN tokenization service
|
5
|
-
|
6
|
-
OpenAPI spec version: 0.0.1
|
7
|
-
|
8
|
-
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
-
Swagger Codegen version: 2.2.3
|
10
|
-
|
11
|
-
=end
|
12
|
-
|
13
|
-
require 'date'
|
14
|
-
require 'json'
|
15
|
-
require 'logger'
|
16
|
-
require 'tempfile'
|
17
|
-
require 'typhoeus'
|
18
|
-
require 'uri'
|
19
|
-
|
20
|
-
module CyberSource
|
21
|
-
class ApiClient
|
22
|
-
# The Configuration object holding settings to be used in the API client.
|
23
|
-
attr_accessor :config
|
24
|
-
|
25
|
-
# Defines the headers to be used in HTTP requests of all API calls by default.
|
26
|
-
#
|
27
|
-
# @return [Hash]
|
28
|
-
attr_accessor :default_headers
|
29
|
-
|
30
|
-
# Initializes the ApiClient
|
31
|
-
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
32
|
-
def initialize(config = Configuration.default)
|
33
|
-
@config = config
|
34
|
-
@user_agent = "Mozilla/5.0"
|
35
|
-
@default_headers = {
|
36
|
-
'Content-Type' => 'application/json',
|
37
|
-
'User-Agent' => @user_agent
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.default
|
42
|
-
@@default ||= ApiClient.new
|
43
|
-
end
|
44
|
-
|
45
|
-
# Call an API with given options.
|
46
|
-
#
|
47
|
-
# @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
|
48
|
-
# the data deserialized from response body (could be nil), response status code and response headers.
|
49
|
-
def call_api(http_method, path, opts = {})
|
50
|
-
request = build_request(http_method, path, opts)
|
51
|
-
response = request.run
|
52
|
-
|
53
|
-
if @config.debugging
|
54
|
-
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
55
|
-
end
|
56
|
-
|
57
|
-
unless response.success?
|
58
|
-
if response.timed_out?
|
59
|
-
fail ApiError.new('Connection timed out')
|
60
|
-
elsif response.code == 0
|
61
|
-
# Errors from libcurl will be made visible here
|
62
|
-
fail ApiError.new(:code => 0,
|
63
|
-
:message => response.return_message)
|
64
|
-
else
|
65
|
-
fail ApiError.new(:code => response.code,
|
66
|
-
:response_headers => response.headers,
|
67
|
-
:response_body => response.body),
|
68
|
-
response.status_message
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
if opts[:return_type]
|
73
|
-
data = deserialize(response, opts[:return_type])
|
74
|
-
else
|
75
|
-
data = nil
|
76
|
-
end
|
77
|
-
return data, response.code, response.headers
|
78
|
-
end
|
79
|
-
|
80
|
-
# Builds the HTTP request
|
81
|
-
#
|
82
|
-
# @param [String] http_method HTTP method/verb (e.g. POST)
|
83
|
-
# @param [String] path URL path (e.g. /account/new)
|
84
|
-
# @option opts [Hash] :header_params Header parameters
|
85
|
-
# @option opts [Hash] :query_params Query parameters
|
86
|
-
# @option opts [Hash] :form_params Query parameters
|
87
|
-
# @option opts [Object] :body HTTP body (JSON/XML)
|
88
|
-
# @return [Typhoeus::Request] A Typhoeus Request
|
89
|
-
def build_request(http_method, path, opts = {})
|
90
|
-
url = build_request_url(path)
|
91
|
-
body_params = opts[:body] || {}
|
92
|
-
headers = CallAuthenticationHeader(http_method, path, body_params, opts[:header_params])
|
93
|
-
http_method = http_method.to_sym.downcase
|
94
|
-
header_params = @default_headers.merge(headers || {})
|
95
|
-
query_params = opts[:query_params] || {}
|
96
|
-
form_params = opts[:form_params] || {}
|
97
|
-
|
98
|
-
|
99
|
-
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
100
|
-
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
101
|
-
|
102
|
-
req_opts = {
|
103
|
-
:method => http_method,
|
104
|
-
:headers => header_params,
|
105
|
-
:params => query_params,
|
106
|
-
:params_encoding => @config.params_encoding,
|
107
|
-
:timeout => @config.timeout,
|
108
|
-
:ssl_verifypeer => @config.verify_ssl,
|
109
|
-
:ssl_verifyhost => _verify_ssl_host,
|
110
|
-
:sslcert => @config.cert_file,
|
111
|
-
:sslkey => @config.key_file,
|
112
|
-
:verbose => @config.debugging
|
113
|
-
}
|
114
|
-
|
115
|
-
# set custom cert, if provided
|
116
|
-
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
117
|
-
|
118
|
-
if [:post, :patch, :put, :delete].include?(http_method)
|
119
|
-
req_body = build_request_body(header_params, form_params, opts[:body])
|
120
|
-
req_opts.update :body => req_body
|
121
|
-
if @config.debugging
|
122
|
-
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
request = Typhoeus::Request.new(url, req_opts)
|
127
|
-
download_file(request) if opts[:return_type] == 'File'
|
128
|
-
request
|
129
|
-
end
|
130
|
-
# Calling Authentication
|
131
|
-
def CallAuthenticationHeader(http_method, path, body_params, header_params)
|
132
|
-
require Dir.getwd + '/data/Configuration.rb'
|
133
|
-
require_relative '../../AuthenticationSDK/core/Merchantconfig.rb'
|
134
|
-
require_relative '../../AuthenticationSDK/core/Authorization.rb'
|
135
|
-
require_relative '../../AuthenticationSDK/authentication/payloadDigest/Digest.rb'
|
136
|
-
# header_params = {}
|
137
|
-
request_target = @config.base_path + path
|
138
|
-
# Request Type. [Non-Editable]
|
139
|
-
request_type = http_method.to_s
|
140
|
-
cybsproperty_obj = MerchantConfiguration.new.merchantConfigProp
|
141
|
-
merchantconfig_obj = Merchantconfig.new(cybsproperty_obj)
|
142
|
-
log_obj = Log.new merchantconfig_obj.logDirectory, merchantconfig_obj.logFilename, merchantconfig_obj.logSize, merchantconfig_obj.enableLog
|
143
|
-
# Set Request Type into the merchant config object.
|
144
|
-
merchantconfig_obj.requestType = request_type
|
145
|
-
# Set Request Target into the merchant config object.
|
146
|
-
merchantconfig_obj.requestTarget = request_target
|
147
|
-
# Construct the URL.
|
148
|
-
url = Constants::HTTPS_URI_PREFIX + merchantconfig_obj.requestHost + merchantconfig_obj.requestTarget
|
149
|
-
# set Request Json to Merchant config object
|
150
|
-
merchantconfig_obj.requestJsonData = body_params
|
151
|
-
# Set URL into the merchant config object.
|
152
|
-
merchantconfig_obj.requestUrl = url
|
153
|
-
# Calling APISDK, Apisdk.controller.
|
154
|
-
gmtDateTime = DateTime.now.httpdate
|
155
|
-
token = Authorization.new.getToken(merchantconfig_obj, gmtDateTime, log_obj)
|
156
|
-
# HTTP header 'Accept' (if needed)
|
157
|
-
if merchantconfig_obj.authenticationType.upcase == Constants::AUTH_TYPE_HTTP
|
158
|
-
# Appending headers for Get Connection
|
159
|
-
header_params['v-c-merchant-id'] = merchantconfig_obj.merchantId
|
160
|
-
header_params['Date'] = gmtDateTime
|
161
|
-
header_params['Host'] = merchantconfig_obj.requestHost
|
162
|
-
header_params['Signature'] = token
|
163
|
-
if request_type == Constants::POST_REQUEST_TYPE
|
164
|
-
digest = DigestGeneration.new.generateDigest(body_params, log_obj)
|
165
|
-
digest_payload = Constants::SHA256 + digest
|
166
|
-
header_params['Digest'] = digest_payload
|
167
|
-
end
|
168
|
-
end
|
169
|
-
if merchantconfig_obj.authenticationType.upcase == Constants::AUTH_TYPE_JWT
|
170
|
-
token = "Bearer " + token
|
171
|
-
header_params['Authorization'] = token
|
172
|
-
end
|
173
|
-
header_params.each do |key, value|
|
174
|
-
log_obj.logger.info("#{key} : #{value}")
|
175
|
-
end
|
176
|
-
return header_params
|
177
|
-
end
|
178
|
-
|
179
|
-
# Check if the given MIME is a JSON MIME.
|
180
|
-
# JSON MIME examples:
|
181
|
-
# application/json
|
182
|
-
# application/json; charset=UTF8
|
183
|
-
# APPLICATION/JSON
|
184
|
-
# */*
|
185
|
-
# @param [String] mime MIME
|
186
|
-
# @return [Boolean] True if the MIME is application/json
|
187
|
-
def json_mime?(mime)
|
188
|
-
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
189
|
-
end
|
190
|
-
|
191
|
-
# Deserialize the response to the given return type.
|
192
|
-
#
|
193
|
-
# @param [Response] response HTTP response
|
194
|
-
# @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
|
195
|
-
def deserialize(response, return_type)
|
196
|
-
body = response.body
|
197
|
-
|
198
|
-
# handle file downloading - return the File instance processed in request callbacks
|
199
|
-
# note that response body is empty when the file is written in chunks in request on_body callback
|
200
|
-
return @tempfile if return_type == 'File'
|
201
|
-
|
202
|
-
return nil if body.nil? || body.empty?
|
203
|
-
|
204
|
-
# return response body directly for String return type
|
205
|
-
return body if return_type == 'String'
|
206
|
-
|
207
|
-
# ensuring a default content type
|
208
|
-
content_type = response.headers['Content-Type'] || 'application/json'
|
209
|
-
|
210
|
-
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
211
|
-
|
212
|
-
begin
|
213
|
-
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
214
|
-
rescue JSON::ParserError => e
|
215
|
-
if %w(String Date DateTime).include?(return_type)
|
216
|
-
data = body
|
217
|
-
else
|
218
|
-
raise e
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
convert_to_type data, return_type
|
223
|
-
end
|
224
|
-
|
225
|
-
# Convert data to the given return type.
|
226
|
-
# @param [Object] data Data to be converted
|
227
|
-
# @param [String] return_type Return type
|
228
|
-
# @return [Mixed] Data in a particular type
|
229
|
-
def convert_to_type(data, return_type)
|
230
|
-
return nil if data.nil?
|
231
|
-
case return_type
|
232
|
-
when 'String'
|
233
|
-
data.to_s
|
234
|
-
when 'Integer'
|
235
|
-
data.to_i
|
236
|
-
when 'Float'
|
237
|
-
data.to_f
|
238
|
-
when 'BOOLEAN'
|
239
|
-
data == true
|
240
|
-
when 'DateTime'
|
241
|
-
# parse date time (expecting ISO 8601 format)
|
242
|
-
DateTime.parse data
|
243
|
-
when 'Date'
|
244
|
-
# parse date time (expecting ISO 8601 format)
|
245
|
-
Date.parse data
|
246
|
-
when 'Object'
|
247
|
-
# generic object (usually a Hash), return directly
|
248
|
-
data
|
249
|
-
when /\AArray<(.+)>\z/
|
250
|
-
# e.g. Array<Pet>
|
251
|
-
sub_type = $1
|
252
|
-
data.map { |item| convert_to_type(item, sub_type) }
|
253
|
-
when /\AHash\<String, (.+)\>\z/
|
254
|
-
# e.g. Hash<String, Integer>
|
255
|
-
sub_type = $1
|
256
|
-
{}.tap do |hash|
|
257
|
-
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
258
|
-
end
|
259
|
-
else
|
260
|
-
# models, e.g. Pet
|
261
|
-
CyberSource.const_get(return_type).new.tap do |model|
|
262
|
-
model.build_from_hash data
|
263
|
-
end
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
# Save response body into a file in (the defined) temporary folder, using the filename
|
268
|
-
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
269
|
-
# The response body is written to the file in chunks in order to handle files which
|
270
|
-
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
271
|
-
# process can use.
|
272
|
-
#
|
273
|
-
# @see Configuration#temp_folder_path
|
274
|
-
def download_file(request)
|
275
|
-
tempfile = nil
|
276
|
-
encoding = nil
|
277
|
-
request.on_headers do |response|
|
278
|
-
content_disposition = response.headers['Content-Disposition']
|
279
|
-
if content_disposition && content_disposition =~ /filename=/i
|
280
|
-
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
281
|
-
prefix = sanitize_filename(filename)
|
282
|
-
else
|
283
|
-
prefix = 'download-'
|
284
|
-
end
|
285
|
-
prefix = prefix + '-' unless prefix.end_with?('-')
|
286
|
-
encoding = response.body.encoding
|
287
|
-
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
288
|
-
@tempfile = tempfile
|
289
|
-
end
|
290
|
-
request.on_body do |chunk|
|
291
|
-
chunk.force_encoding(encoding)
|
292
|
-
tempfile.write(chunk)
|
293
|
-
end
|
294
|
-
request.on_complete do |response|
|
295
|
-
tempfile.close
|
296
|
-
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
297
|
-
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
298
|
-
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
299
|
-
"explicitly with `tempfile.delete`"
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
# Sanitize filename by removing path.
|
304
|
-
# e.g. ../../sun.gif becomes sun.gif
|
305
|
-
#
|
306
|
-
# @param [String] filename the filename to be sanitized
|
307
|
-
# @return [String] the sanitized filename
|
308
|
-
def sanitize_filename(filename)
|
309
|
-
filename.gsub(/.*[\/\\]/, '')
|
310
|
-
end
|
311
|
-
|
312
|
-
def build_request_url(path)
|
313
|
-
# Add leading and trailing slashes to path
|
314
|
-
path = "/#{path}".gsub(/\/+/, '/')
|
315
|
-
URI.encode(@config.base_url + path)
|
316
|
-
end
|
317
|
-
|
318
|
-
# Builds the HTTP request body
|
319
|
-
#
|
320
|
-
# @param [Hash] header_params Header parameters
|
321
|
-
# @param [Hash] form_params Query parameters
|
322
|
-
# @param [Object] body HTTP body (JSON/XML)
|
323
|
-
# @return [String] HTTP body data in the form of string
|
324
|
-
def build_request_body(header_params, form_params, body)
|
325
|
-
# http form
|
326
|
-
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
327
|
-
header_params['Content-Type'] == 'multipart/form-data'
|
328
|
-
data = {}
|
329
|
-
form_params.each do |key, value|
|
330
|
-
case value
|
331
|
-
when ::File, ::Array, nil
|
332
|
-
# let typhoeus handle File, Array and nil parameters
|
333
|
-
data[key] = value
|
334
|
-
else
|
335
|
-
data[key] = value.to_s
|
336
|
-
end
|
337
|
-
end
|
338
|
-
elsif body
|
339
|
-
data = body.is_a?(String) ? body : body.to_json
|
340
|
-
else
|
341
|
-
data = nil
|
342
|
-
end
|
343
|
-
data
|
344
|
-
end
|
345
|
-
|
346
|
-
# Update hearder and query params based on authentication settings.
|
347
|
-
#
|
348
|
-
# @param [Hash] header_params Header parameters
|
349
|
-
# @param [Hash] query_params Query parameters
|
350
|
-
# @param [String] auth_names Authentication scheme name
|
351
|
-
def update_params_for_auth!(header_params, query_params, auth_names)
|
352
|
-
Array(auth_names).each do |auth_name|
|
353
|
-
auth_setting = @config.auth_settings[auth_name]
|
354
|
-
next unless auth_setting
|
355
|
-
case auth_setting[:in]
|
356
|
-
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
357
|
-
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
358
|
-
else fail ArgumentError, 'Authentication token must be in `query` of `header`'
|
359
|
-
end
|
360
|
-
end
|
361
|
-
end
|
362
|
-
|
363
|
-
# Sets user agent in HTTP header
|
364
|
-
#
|
365
|
-
# @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
|
366
|
-
def user_agent=(user_agent)
|
367
|
-
@user_agent = user_agent
|
368
|
-
@default_headers['User-Agent'] = @user_agent
|
369
|
-
end
|
370
|
-
|
371
|
-
# Return Accept header based on an array of accepts provided.
|
372
|
-
# @param [Array] accepts array for Accept
|
373
|
-
# @return [String] the Accept header (e.g. application/json)
|
374
|
-
def select_header_accept(accepts)
|
375
|
-
return nil if accepts.nil? || accepts.empty?
|
376
|
-
# use JSON when present, otherwise use all of the provided
|
377
|
-
json_accept = accepts.find { |s| json_mime?(s) }
|
378
|
-
json_accept || accepts.join(',')
|
379
|
-
end
|
380
|
-
|
381
|
-
# Return Content-Type header based on an array of content types provided.
|
382
|
-
# @param [Array] content_types array for Content-Type
|
383
|
-
# @return [String] the Content-Type header (e.g. application/json)
|
384
|
-
def select_header_content_type(content_types)
|
385
|
-
# use application/json by default
|
386
|
-
return 'application/json' if content_types.nil? || content_types.empty?
|
387
|
-
# use JSON when present, otherwise use the first one
|
388
|
-
json_content_type = content_types.find { |s| json_mime?(s) }
|
389
|
-
json_content_type || content_types.first
|
390
|
-
end
|
391
|
-
|
392
|
-
# Convert object (array, hash, object, etc) to JSON string.
|
393
|
-
# @param [Object] model object to be converted into JSON string
|
394
|
-
# @return [String] JSON string representation of the object
|
395
|
-
def object_to_http_body(model)
|
396
|
-
return model if model.nil? || model.is_a?(String)
|
397
|
-
local_body = nil
|
398
|
-
if model.is_a?(Array)
|
399
|
-
local_body = model.map { |m| object_to_hash(m) }
|
400
|
-
else
|
401
|
-
local_body = object_to_hash(model)
|
402
|
-
end
|
403
|
-
local_body.to_json
|
404
|
-
end
|
405
|
-
|
406
|
-
# Convert object(non-array) to hash.
|
407
|
-
# @param [Object] obj object to be converted into JSON string
|
408
|
-
# @return [String] JSON string representation of the object
|
409
|
-
def object_to_hash(obj)
|
410
|
-
if obj.respond_to?(:to_hash)
|
411
|
-
obj.to_hash
|
412
|
-
else
|
413
|
-
obj
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
# Build parameter value according to the given collection format.
|
418
|
-
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
419
|
-
def build_collection_param(param, collection_format)
|
420
|
-
case collection_format
|
421
|
-
when :csv
|
422
|
-
param.join(',')
|
423
|
-
when :ssv
|
424
|
-
param.join(' ')
|
425
|
-
when :tsv
|
426
|
-
param.join("\t")
|
427
|
-
when :pipes
|
428
|
-
param.join('|')
|
429
|
-
when :multi
|
430
|
-
# return the array directly as typhoeus will handle it as expected
|
431
|
-
param
|
432
|
-
else
|
433
|
-
fail "unknown collection format: #{collection_format.inspect}"
|
434
|
-
end
|
435
|
-
end
|
436
|
-
end
|
437
|
-
end
|
1
|
+
=begin
|
2
|
+
#CyberSource Flex API
|
3
|
+
|
4
|
+
#Simple PAN tokenization service
|
5
|
+
|
6
|
+
OpenAPI spec version: 0.0.1
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 2.2.3
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
require 'json'
|
15
|
+
require 'logger'
|
16
|
+
require 'tempfile'
|
17
|
+
require 'typhoeus'
|
18
|
+
require 'uri'
|
19
|
+
|
20
|
+
module CyberSource
|
21
|
+
class ApiClient
|
22
|
+
# The Configuration object holding settings to be used in the API client.
|
23
|
+
attr_accessor :config
|
24
|
+
|
25
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
26
|
+
#
|
27
|
+
# @return [Hash]
|
28
|
+
attr_accessor :default_headers
|
29
|
+
|
30
|
+
# Initializes the ApiClient
|
31
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
32
|
+
def initialize(config = Configuration.default)
|
33
|
+
@config = config
|
34
|
+
@user_agent = "Mozilla/5.0"
|
35
|
+
@default_headers = {
|
36
|
+
'Content-Type' => 'application/json',
|
37
|
+
'User-Agent' => @user_agent
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.default
|
42
|
+
@@default ||= ApiClient.new
|
43
|
+
end
|
44
|
+
|
45
|
+
# Call an API with given options.
|
46
|
+
#
|
47
|
+
# @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
|
48
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
49
|
+
def call_api(http_method, path, opts = {})
|
50
|
+
request = build_request(http_method, path, opts)
|
51
|
+
response = request.run
|
52
|
+
|
53
|
+
if @config.debugging
|
54
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
55
|
+
end
|
56
|
+
|
57
|
+
unless response.success?
|
58
|
+
if response.timed_out?
|
59
|
+
fail ApiError.new('Connection timed out')
|
60
|
+
elsif response.code == 0
|
61
|
+
# Errors from libcurl will be made visible here
|
62
|
+
fail ApiError.new(:code => 0,
|
63
|
+
:message => response.return_message)
|
64
|
+
else
|
65
|
+
fail ApiError.new(:code => response.code,
|
66
|
+
:response_headers => response.headers,
|
67
|
+
:response_body => response.body),
|
68
|
+
response.status_message
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
if opts[:return_type]
|
73
|
+
data = deserialize(response, opts[:return_type])
|
74
|
+
else
|
75
|
+
data = nil
|
76
|
+
end
|
77
|
+
return data, response.code, response.headers
|
78
|
+
end
|
79
|
+
|
80
|
+
# Builds the HTTP request
|
81
|
+
#
|
82
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
83
|
+
# @param [String] path URL path (e.g. /account/new)
|
84
|
+
# @option opts [Hash] :header_params Header parameters
|
85
|
+
# @option opts [Hash] :query_params Query parameters
|
86
|
+
# @option opts [Hash] :form_params Query parameters
|
87
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
88
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
89
|
+
def build_request(http_method, path, opts = {})
|
90
|
+
url = build_request_url(path)
|
91
|
+
body_params = opts[:body] || {}
|
92
|
+
headers = CallAuthenticationHeader(http_method, path, body_params, opts[:header_params])
|
93
|
+
http_method = http_method.to_sym.downcase
|
94
|
+
header_params = @default_headers.merge(headers || {})
|
95
|
+
query_params = opts[:query_params] || {}
|
96
|
+
form_params = opts[:form_params] || {}
|
97
|
+
|
98
|
+
|
99
|
+
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
100
|
+
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
101
|
+
|
102
|
+
req_opts = {
|
103
|
+
:method => http_method,
|
104
|
+
:headers => header_params,
|
105
|
+
:params => query_params,
|
106
|
+
:params_encoding => @config.params_encoding,
|
107
|
+
:timeout => @config.timeout,
|
108
|
+
:ssl_verifypeer => @config.verify_ssl,
|
109
|
+
:ssl_verifyhost => _verify_ssl_host,
|
110
|
+
:sslcert => @config.cert_file,
|
111
|
+
:sslkey => @config.key_file,
|
112
|
+
:verbose => @config.debugging
|
113
|
+
}
|
114
|
+
|
115
|
+
# set custom cert, if provided
|
116
|
+
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
117
|
+
|
118
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
119
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
120
|
+
req_opts.update :body => req_body
|
121
|
+
if @config.debugging
|
122
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
request = Typhoeus::Request.new(url, req_opts)
|
127
|
+
download_file(request) if opts[:return_type] == 'File'
|
128
|
+
request
|
129
|
+
end
|
130
|
+
# Calling Authentication
|
131
|
+
def CallAuthenticationHeader(http_method, path, body_params, header_params)
|
132
|
+
require Dir.getwd + '/data/Configuration.rb'
|
133
|
+
require_relative '../../AuthenticationSDK/core/Merchantconfig.rb'
|
134
|
+
require_relative '../../AuthenticationSDK/core/Authorization.rb'
|
135
|
+
require_relative '../../AuthenticationSDK/authentication/payloadDigest/Digest.rb'
|
136
|
+
# header_params = {}
|
137
|
+
request_target = @config.base_path + path
|
138
|
+
# Request Type. [Non-Editable]
|
139
|
+
request_type = http_method.to_s
|
140
|
+
cybsproperty_obj = MerchantConfiguration.new.merchantConfigProp
|
141
|
+
merchantconfig_obj = Merchantconfig.new(cybsproperty_obj)
|
142
|
+
log_obj = Log.new merchantconfig_obj.logDirectory, merchantconfig_obj.logFilename, merchantconfig_obj.logSize, merchantconfig_obj.enableLog
|
143
|
+
# Set Request Type into the merchant config object.
|
144
|
+
merchantconfig_obj.requestType = request_type
|
145
|
+
# Set Request Target into the merchant config object.
|
146
|
+
merchantconfig_obj.requestTarget = request_target
|
147
|
+
# Construct the URL.
|
148
|
+
url = Constants::HTTPS_URI_PREFIX + merchantconfig_obj.requestHost + merchantconfig_obj.requestTarget
|
149
|
+
# set Request Json to Merchant config object
|
150
|
+
merchantconfig_obj.requestJsonData = body_params
|
151
|
+
# Set URL into the merchant config object.
|
152
|
+
merchantconfig_obj.requestUrl = url
|
153
|
+
# Calling APISDK, Apisdk.controller.
|
154
|
+
gmtDateTime = DateTime.now.httpdate
|
155
|
+
token = Authorization.new.getToken(merchantconfig_obj, gmtDateTime, log_obj)
|
156
|
+
# HTTP header 'Accept' (if needed)
|
157
|
+
if merchantconfig_obj.authenticationType.upcase == Constants::AUTH_TYPE_HTTP
|
158
|
+
# Appending headers for Get Connection
|
159
|
+
header_params['v-c-merchant-id'] = merchantconfig_obj.merchantId
|
160
|
+
header_params['Date'] = gmtDateTime
|
161
|
+
header_params['Host'] = merchantconfig_obj.requestHost
|
162
|
+
header_params['Signature'] = token
|
163
|
+
if request_type == Constants::POST_REQUEST_TYPE
|
164
|
+
digest = DigestGeneration.new.generateDigest(body_params, log_obj)
|
165
|
+
digest_payload = Constants::SHA256 + digest
|
166
|
+
header_params['Digest'] = digest_payload
|
167
|
+
end
|
168
|
+
end
|
169
|
+
if merchantconfig_obj.authenticationType.upcase == Constants::AUTH_TYPE_JWT
|
170
|
+
token = "Bearer " + token
|
171
|
+
header_params['Authorization'] = token
|
172
|
+
end
|
173
|
+
header_params.each do |key, value|
|
174
|
+
log_obj.logger.info("#{key} : #{value}")
|
175
|
+
end
|
176
|
+
return header_params
|
177
|
+
end
|
178
|
+
|
179
|
+
# Check if the given MIME is a JSON MIME.
|
180
|
+
# JSON MIME examples:
|
181
|
+
# application/json
|
182
|
+
# application/json; charset=UTF8
|
183
|
+
# APPLICATION/JSON
|
184
|
+
# */*
|
185
|
+
# @param [String] mime MIME
|
186
|
+
# @return [Boolean] True if the MIME is application/json
|
187
|
+
def json_mime?(mime)
|
188
|
+
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
189
|
+
end
|
190
|
+
|
191
|
+
# Deserialize the response to the given return type.
|
192
|
+
#
|
193
|
+
# @param [Response] response HTTP response
|
194
|
+
# @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
|
195
|
+
def deserialize(response, return_type)
|
196
|
+
body = response.body
|
197
|
+
|
198
|
+
# handle file downloading - return the File instance processed in request callbacks
|
199
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
200
|
+
return @tempfile if return_type == 'File'
|
201
|
+
|
202
|
+
return nil if body.nil? || body.empty?
|
203
|
+
|
204
|
+
# return response body directly for String return type
|
205
|
+
return body if return_type == 'String'
|
206
|
+
|
207
|
+
# ensuring a default content type
|
208
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
209
|
+
|
210
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
211
|
+
|
212
|
+
begin
|
213
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
214
|
+
rescue JSON::ParserError => e
|
215
|
+
if %w(String Date DateTime).include?(return_type)
|
216
|
+
data = body
|
217
|
+
else
|
218
|
+
raise e
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
convert_to_type data, return_type
|
223
|
+
end
|
224
|
+
|
225
|
+
# Convert data to the given return type.
|
226
|
+
# @param [Object] data Data to be converted
|
227
|
+
# @param [String] return_type Return type
|
228
|
+
# @return [Mixed] Data in a particular type
|
229
|
+
def convert_to_type(data, return_type)
|
230
|
+
return nil if data.nil?
|
231
|
+
case return_type
|
232
|
+
when 'String'
|
233
|
+
data.to_s
|
234
|
+
when 'Integer'
|
235
|
+
data.to_i
|
236
|
+
when 'Float'
|
237
|
+
data.to_f
|
238
|
+
when 'BOOLEAN'
|
239
|
+
data == true
|
240
|
+
when 'DateTime'
|
241
|
+
# parse date time (expecting ISO 8601 format)
|
242
|
+
DateTime.parse data
|
243
|
+
when 'Date'
|
244
|
+
# parse date time (expecting ISO 8601 format)
|
245
|
+
Date.parse data
|
246
|
+
when 'Object'
|
247
|
+
# generic object (usually a Hash), return directly
|
248
|
+
data
|
249
|
+
when /\AArray<(.+)>\z/
|
250
|
+
# e.g. Array<Pet>
|
251
|
+
sub_type = $1
|
252
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
253
|
+
when /\AHash\<String, (.+)\>\z/
|
254
|
+
# e.g. Hash<String, Integer>
|
255
|
+
sub_type = $1
|
256
|
+
{}.tap do |hash|
|
257
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
258
|
+
end
|
259
|
+
else
|
260
|
+
# models, e.g. Pet
|
261
|
+
CyberSource.const_get(return_type).new.tap do |model|
|
262
|
+
model.build_from_hash data
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
268
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
269
|
+
# The response body is written to the file in chunks in order to handle files which
|
270
|
+
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
271
|
+
# process can use.
|
272
|
+
#
|
273
|
+
# @see Configuration#temp_folder_path
|
274
|
+
def download_file(request)
|
275
|
+
tempfile = nil
|
276
|
+
encoding = nil
|
277
|
+
request.on_headers do |response|
|
278
|
+
content_disposition = response.headers['Content-Disposition']
|
279
|
+
if content_disposition && content_disposition =~ /filename=/i
|
280
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
281
|
+
prefix = sanitize_filename(filename)
|
282
|
+
else
|
283
|
+
prefix = 'download-'
|
284
|
+
end
|
285
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
286
|
+
encoding = response.body.encoding
|
287
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
288
|
+
@tempfile = tempfile
|
289
|
+
end
|
290
|
+
request.on_body do |chunk|
|
291
|
+
chunk.force_encoding(encoding)
|
292
|
+
tempfile.write(chunk)
|
293
|
+
end
|
294
|
+
request.on_complete do |response|
|
295
|
+
tempfile.close
|
296
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
297
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
298
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
299
|
+
"explicitly with `tempfile.delete`"
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
# Sanitize filename by removing path.
|
304
|
+
# e.g. ../../sun.gif becomes sun.gif
|
305
|
+
#
|
306
|
+
# @param [String] filename the filename to be sanitized
|
307
|
+
# @return [String] the sanitized filename
|
308
|
+
def sanitize_filename(filename)
|
309
|
+
filename.gsub(/.*[\/\\]/, '')
|
310
|
+
end
|
311
|
+
|
312
|
+
def build_request_url(path)
|
313
|
+
# Add leading and trailing slashes to path
|
314
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
315
|
+
URI.encode(@config.base_url + path)
|
316
|
+
end
|
317
|
+
|
318
|
+
# Builds the HTTP request body
|
319
|
+
#
|
320
|
+
# @param [Hash] header_params Header parameters
|
321
|
+
# @param [Hash] form_params Query parameters
|
322
|
+
# @param [Object] body HTTP body (JSON/XML)
|
323
|
+
# @return [String] HTTP body data in the form of string
|
324
|
+
def build_request_body(header_params, form_params, body)
|
325
|
+
# http form
|
326
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
327
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
328
|
+
data = {}
|
329
|
+
form_params.each do |key, value|
|
330
|
+
case value
|
331
|
+
when ::File, ::Array, nil
|
332
|
+
# let typhoeus handle File, Array and nil parameters
|
333
|
+
data[key] = value
|
334
|
+
else
|
335
|
+
data[key] = value.to_s
|
336
|
+
end
|
337
|
+
end
|
338
|
+
elsif body
|
339
|
+
data = body.is_a?(String) ? body : body.to_json
|
340
|
+
else
|
341
|
+
data = nil
|
342
|
+
end
|
343
|
+
data
|
344
|
+
end
|
345
|
+
|
346
|
+
# Update hearder and query params based on authentication settings.
|
347
|
+
#
|
348
|
+
# @param [Hash] header_params Header parameters
|
349
|
+
# @param [Hash] query_params Query parameters
|
350
|
+
# @param [String] auth_names Authentication scheme name
|
351
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
352
|
+
Array(auth_names).each do |auth_name|
|
353
|
+
auth_setting = @config.auth_settings[auth_name]
|
354
|
+
next unless auth_setting
|
355
|
+
case auth_setting[:in]
|
356
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
357
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
358
|
+
else fail ArgumentError, 'Authentication token must be in `query` of `header`'
|
359
|
+
end
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
# Sets user agent in HTTP header
|
364
|
+
#
|
365
|
+
# @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
|
366
|
+
def user_agent=(user_agent)
|
367
|
+
@user_agent = user_agent
|
368
|
+
@default_headers['User-Agent'] = @user_agent
|
369
|
+
end
|
370
|
+
|
371
|
+
# Return Accept header based on an array of accepts provided.
|
372
|
+
# @param [Array] accepts array for Accept
|
373
|
+
# @return [String] the Accept header (e.g. application/json)
|
374
|
+
def select_header_accept(accepts)
|
375
|
+
return nil if accepts.nil? || accepts.empty?
|
376
|
+
# use JSON when present, otherwise use all of the provided
|
377
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
378
|
+
json_accept || accepts.join(',')
|
379
|
+
end
|
380
|
+
|
381
|
+
# Return Content-Type header based on an array of content types provided.
|
382
|
+
# @param [Array] content_types array for Content-Type
|
383
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
384
|
+
def select_header_content_type(content_types)
|
385
|
+
# use application/json by default
|
386
|
+
return 'application/json' if content_types.nil? || content_types.empty?
|
387
|
+
# use JSON when present, otherwise use the first one
|
388
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
389
|
+
json_content_type || content_types.first
|
390
|
+
end
|
391
|
+
|
392
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
393
|
+
# @param [Object] model object to be converted into JSON string
|
394
|
+
# @return [String] JSON string representation of the object
|
395
|
+
def object_to_http_body(model)
|
396
|
+
return model if model.nil? || model.is_a?(String)
|
397
|
+
local_body = nil
|
398
|
+
if model.is_a?(Array)
|
399
|
+
local_body = model.map { |m| object_to_hash(m) }
|
400
|
+
else
|
401
|
+
local_body = object_to_hash(model)
|
402
|
+
end
|
403
|
+
local_body.to_json
|
404
|
+
end
|
405
|
+
|
406
|
+
# Convert object(non-array) to hash.
|
407
|
+
# @param [Object] obj object to be converted into JSON string
|
408
|
+
# @return [String] JSON string representation of the object
|
409
|
+
def object_to_hash(obj)
|
410
|
+
if obj.respond_to?(:to_hash)
|
411
|
+
obj.to_hash
|
412
|
+
else
|
413
|
+
obj
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
# Build parameter value according to the given collection format.
|
418
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
419
|
+
def build_collection_param(param, collection_format)
|
420
|
+
case collection_format
|
421
|
+
when :csv
|
422
|
+
param.join(',')
|
423
|
+
when :ssv
|
424
|
+
param.join(' ')
|
425
|
+
when :tsv
|
426
|
+
param.join("\t")
|
427
|
+
when :pipes
|
428
|
+
param.join('|')
|
429
|
+
when :multi
|
430
|
+
# return the array directly as typhoeus will handle it as expected
|
431
|
+
param
|
432
|
+
else
|
433
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
434
|
+
end
|
435
|
+
end
|
436
|
+
end
|
437
|
+
end
|