lib/braintree/transaction_gateway.rb in braintree-2.24.0 vs lib/braintree/transaction_gateway.rb in braintree-2.25.0

- old
+ new

@@ -8,10 +8,32 @@ def create(attributes) Util.verify_keys(TransactionGateway._create_signature, attributes) _do_create "/transactions", :transaction => attributes end + def cancel_release(transaction_id) + raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/ + response = @config.http.put "/transactions/#{transaction_id}/cancel_release" + _handle_transaction_response(response) + end + + def hold_in_escrow(transaction_id) + raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/ + response = @config.http.put "/transactions/#{transaction_id}/hold_in_escrow" + _handle_transaction_response(response) + end + + def _handle_transaction_response(response) + if response[:transaction] + SuccessfulResult.new(:transaction => Transaction._new(@gateway, response[:transaction])) + elsif response[:api_error_response] + ErrorResult.new(@gateway, response[:api_error_response]) + else + raise UnexpectedError, "expected :transaction or :response" + end + end + def clone_transaction(transaction_id, attributes) Util.verify_keys(TransactionGateway._clone_signature, attributes) _do_create "/transactions/#{transaction_id}/clone", :transaction_clone => attributes end @@ -38,17 +60,11 @@ raise NotFoundError, "transaction with id #{id.inspect} not found" end def refund(transaction_id, amount = nil) response = @config.http.post "/transactions/#{transaction_id}/refund", :transaction => {:amount => amount} - if response[:transaction] - SuccessfulResult.new(:transaction => Transaction._new(@gateway, response[:transaction])) - elsif response[:api_error_response] - ErrorResult.new(@gateway, response[:api_error_response]) - else - raise UnexpectedError, "expected :transaction or :api_error_response" - end + _handle_transaction_response(response) end def retry_subscription_charge(subscription_id, amount=nil) attributes = { :amount => amount, @@ -68,64 +84,52 @@ response = @config.http.post "/transactions/advanced_search_ids", {:search => search.to_hash} ResourceCollection.new(response) { |ids| _fetch_transactions(search, ids) } end + def release_from_escrow(transaction_id) + raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/ + response = @config.http.put "/transactions/#{transaction_id}/release_from_escrow" + _handle_transaction_response(response) + end + def submit_for_settlement(transaction_id, amount = nil) raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/ response = @config.http.put "/transactions/#{transaction_id}/submit_for_settlement", :transaction => {:amount => amount} - if response[:transaction] - SuccessfulResult.new(:transaction => Transaction._new(@gateway, response[:transaction])) - elsif response[:api_error_response] - ErrorResult.new(@gateway, response[:api_error_response]) - else - raise UnexpectedError, "expected :transaction or :response" - end + _handle_transaction_response(response) end def void(transaction_id) response = @config.http.put "/transactions/#{transaction_id}/void" - if response[:transaction] - SuccessfulResult.new(:transaction => Transaction._new(@gateway, response[:transaction])) - elsif response[:api_error_response] - ErrorResult.new(@gateway, response[:api_error_response]) - else - raise UnexpectedError, "expected :transaction or :api_error_response" - end + _handle_transaction_response(response) end def self._clone_signature # :nodoc: [:amount, :channel, {:options => [:submit_for_settlement]}] end def self._create_signature # :nodoc: [ :amount, :customer_id, :merchant_account_id, :order_id, :channel, :payment_method_token, :purchase_order_number, :recurring, :shipping_address_id, :type, :tax_amount, :tax_exempt, - :venmo_sdk_payment_method_code, :device_session_id, :device_data, + :venmo_sdk_payment_method_code, :device_session_id, :service_fee_amount, :device_data, {:credit_card => [:token, :cardholder_name, :cvv, :expiration_date, :expiration_month, :expiration_year, :number]}, {:customer => [:id, :company, :email, :fax, :first_name, :last_name, :phone, :website]}, { :billing => AddressGateway._shared_signature }, { :shipping => AddressGateway._shared_signature }, - {:options => [:store_in_vault, :store_in_vault_on_success, :submit_for_settlement, :add_billing_address_to_payment_method, :store_shipping_address_in_vault, :venmo_sdk_session]}, + {:options => [:hold_in_escrow, :store_in_vault, :store_in_vault_on_success, :submit_for_settlement, :add_billing_address_to_payment_method, :store_shipping_address_in_vault, :venmo_sdk_session]}, {:custom_fields => :_any_key_}, {:descriptor => [:name, :phone]} ] end def _do_create(url, params=nil) # :nodoc: response = @config.http.post url, params - if response[:transaction] - SuccessfulResult.new(:transaction => Transaction._new(@gateway, response[:transaction])) - elsif response[:api_error_response] - ErrorResult.new(@gateway, response[:api_error_response]) - else - raise UnexpectedError, "expected :transaction or :api_error_response" - end + _handle_transaction_response(response) end def _fetch_transactions(search, ids) # :nodoc: search.ids.in ids response = @config.http.post "/transactions/advanced_search", {:search => search.to_hash}