Method: Transbank::Onepay::Transaction.create
- Defined in:
- lib/transbank/sdk/onepay/models/transaction.rb
.create(shopping_cart:, channel: nil, external_unique_number: nil, options: nil) ⇒ TransactionCreateResponse
Create a [Transaction], initiating the purchase process. Includes data that you will need to #commit your [Transaction]
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 |
# File 'lib/transbank/sdk/onepay/models/transaction.rb', line 23 def create(shopping_cart:, channel: nil, external_unique_number: nil, options: nil) if (channel) = channel channel = nil end if (external_unique_number) = external_unique_number external_unique_number = nil end validate_channel!(channel) validate_shopping_cart!(shopping_cart) = () create_request = create_transaction(shopping_cart: shopping_cart, channel: channel, external_unique_number: external_unique_number, options: ) response = http_post(uri_string: transaction_create_path, body: create_request.to_h) validate_create_response!(response) transaction_create_response = TransactionCreateResponse.new JSON.parse(response.body) signature_is_valid = transaction_create_response.valid_signature?(.fetch(:shared_secret)) unless signature_is_valid raise Errors::SignatureError, "The response's signature is not valid." end transaction_create_response end |