Class: Transbank::Onepay::Transaction
- Inherits:
-
Object
- Object
- Transbank::Onepay::Transaction
- Extended by:
- Utils::RequestBuilder, Utils::NetHelper
- Defined in:
- lib/transbank/sdk/onepay/models/transaction.rb
Overview
Class Transaction
This class creates or commits a Transaction (that is, a purchase)
Constant Summary collapse
- SEND_TRANSACTION =
'sendtransaction'.freeze
- COMMIT_TRANSACTION =
'gettransactionnumber'.freeze
- TRANSACTION_BASE_PATH =
'/ewallet-plugin-api-services/services/transactionservice/'.freeze
Class Method Summary collapse
-
.commit(occ:, external_unique_number:, options: nil) ⇒ TransactionCommitResponse
Commit a [Transaction].
-
.create(shopping_cart:, channel: nil, external_unique_number: nil, options: nil) ⇒ TransactionCreateResponse
Create a [Transaction], initiating the purchase process.
Methods included from Utils::RequestBuilder
commit_transaction, complete_options, create_transaction, default_options, refund_transaction, time_as_number
Methods included from Utils::NetHelper
http_delete, http_get, http_post, http_put, keys_to_camel_case, patpass_comercio_headers, snake_to_camel_case, webpay_headers
Class Method Details
.commit(occ:, external_unique_number:, options: nil) ⇒ TransactionCommitResponse
Commit a [Transaction]. It is MANDATORY for this to be done, and you have 30 seconds to do so, otherwise the [Transaction] is automatically REVERSED
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/transbank/sdk/onepay/models/transaction.rb', line 60 def commit(occ:, external_unique_number:, options: nil) = () commit_request = commit_transaction(occ: occ, external_unique_number: external_unique_number, options: ) response = http_post(uri_string: transaction_commit_path, body: commit_request.to_h) validate_commit_response!(response) transaction_commit_response = TransactionCommitResponse.new(JSON.parse(response.body)) signature_is_valid = transaction_commit_response.valid_signature?(.fetch(:shared_secret)) unless signature_is_valid raise Errors::SignatureError, "The response's signature is not valid." end transaction_commit_response end |
.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 |