Class: Braintree::TransactionGateway
- Inherits:
-
Object
- Object
- Braintree::TransactionGateway
- Includes:
- BaseModule
- Defined in:
- lib/braintree/transaction_gateway.rb
Overview
:nodoc:
Class Method Summary collapse
- ._adjust_authorization_signature ⇒ Object
-
._clone_signature ⇒ Object
:nodoc:.
-
._create_signature ⇒ Object
:nodoc:.
- ._refund_signature ⇒ Object
-
._submit_for_settlement_signature ⇒ Object
:nodoc:.
-
._update_details_signature ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#_do_create(path, params = nil) ⇒ Object
:nodoc:.
-
#_fetch_transactions(search, ids) ⇒ Object
:nodoc:.
- #_handle_transaction_response(response) ⇒ Object
- #adjust_authorization(transaction_id, amount) ⇒ Object
- #adjust_authorization!(*args) ⇒ Object
- #cancel_release(transaction_id) ⇒ Object
- #cancel_release!(*args) ⇒ Object
- #clone_transaction(transaction_id, attributes) ⇒ Object
- #clone_transaction!(*args) ⇒ Object
- #create(attributes) ⇒ Object
- #credit(attributes) ⇒ Object
- #credit!(*args) ⇒ Object
- #find(id) ⇒ Object
- #hold_in_escrow(transaction_id) ⇒ Object
- #hold_in_escrow!(*args) ⇒ Object
-
#initialize(gateway) ⇒ TransactionGateway
constructor
A new instance of TransactionGateway.
- #refund(transaction_id, amount_or_options = nil) ⇒ Object
- #refund!(*args) ⇒ Object
- #release_from_escrow(transaction_id) ⇒ Object
- #release_from_escrow!(*args) ⇒ Object
- #retry_subscription_charge(subscription_id, amount = nil, submit_for_settlement = false) ⇒ Object
- #sale(attributes) ⇒ Object
- #sale!(*args) ⇒ Object
- #search(&block) ⇒ Object
- #submit_for_partial_settlement(authorized_transaction_id, amount = nil, options = {}) ⇒ Object
- #submit_for_partial_settlement!(*args) ⇒ Object
- #submit_for_settlement(transaction_id, amount = nil, options = {}) ⇒ Object
- #submit_for_settlement!(*args) ⇒ Object
- #update_details(transaction_id, options = {}) ⇒ Object
- #void(transaction_id) ⇒ Object
- #void!(*args) ⇒ Object
Methods included from BaseModule
Methods included from BaseModule::Methods
#copy_instance_variables_from_object, #return_object_or_raise, #set_instance_variables_from_hash, #singleton_class
Constructor Details
#initialize(gateway) ⇒ TransactionGateway
Returns a new instance of TransactionGateway.
5 6 7 8 9 |
# File 'lib/braintree/transaction_gateway.rb', line 5 def initialize(gateway) @gateway = gateway @config = gateway.config @config.assert_has_access_token_or_keys end |
Class Method Details
._adjust_authorization_signature ⇒ Object
280 281 282 283 284 |
# File 'lib/braintree/transaction_gateway.rb', line 280 def self. [ :amount ] end |
._clone_signature ⇒ Object
:nodoc:
182 183 184 |
# File 'lib/braintree/transaction_gateway.rb', line 182 def self._clone_signature # :nodoc: [:amount, :channel, {:options => [:submit_for_settlement]}] end |
._create_signature ⇒ Object
:nodoc:
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/braintree/transaction_gateway.rb', line 186 def self._create_signature # :nodoc: [ :amount, :billing_address_id, :channel, :customer_id, :device_data, :discount_amount, :merchant_account_id, :order_id, :payment_method_nonce, :payment_method_token, :product_sku, :purchase_order_number, :service_fee_amount, :shared_billing_address_id, :shared_customer_id, :shared_payment_method_nonce, :shared_payment_method_token, :shared_shipping_address_id, :shipping_address_id, :shipping_amount, :ships_from_postal_code, :tax_amount, :tax_exempt, :three_d_secure_authentication_id, :three_d_secure_token, :transaction_source, :type, :venmo_sdk_payment_method_code, :sca_exemption, :currency_iso_code, :exchange_rate_quote_id, {:line_items => [:quantity, :name, :description, :kind, :unit_amount, :unit_tax_amount, :total_amount, :discount_amount, :tax_amount, :unit_of_measure, :product_code, :commodity_code, :url]}, {:risk_data => [:customer_browser, :customer_device_id, :customer_ip, :customer_location_zip, :customer_tenure]}, {:credit_card => [:token, :cardholder_name, :cvv, :expiration_date, :expiration_month, :expiration_year, :number, {:payment_reader_card_details => [:encrypted_card_data, :key_serial_number]}]}, {:customer => [:id, :company, :email, :fax, :first_name, :last_name, :phone, :website]}, { :billing => AddressGateway._shared_signature }, { :shipping => AddressGateway._shared_signature + [:shipping_method], }, { :three_d_secure_pass_thru => [ :eci_flag, :cavv, :xid, :three_d_secure_version, :authentication_response, :directory_response, :cavv_algorithm, :ds_transaction_id, ] }, {: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, :payee_id, :payee_email, :skip_advanced_fraud_checking, :skip_avs, :skip_cvv, {:paypal => [:custom_field, :payee_id, :payee_email, :description, {:supplementary_data => :_any_key_}]}, {:three_d_secure => [:required]}, {:amex_rewards => [:request_id, :points, :currency_amount, :currency_iso_code]}, {:venmo => [:profile_id]}, {:credit_card => [:account_type]}, ] }, {:external_vault => [ :status, :previous_network_transaction_id, ]}, {:custom_fields => :_any_key_}, {:descriptor => [:name, :phone, :url]}, {:paypal_account => [:email, :token, :paypal_data, :payee_id, :payee_email, :payer_id, :payment_id]}, {:industry => [ :industry_type, {:data => [ :folio_number, :check_in_date, :check_out_date, :travel_package, :lodging_check_in_date, :lodging_check_out_date, :departure_date, :lodging_name, :room_rate, :room_tax, :passenger_first_name, :passenger_last_name, :passenger_middle_initial, :passenger_title, :issued_date, :travel_agency_name, :travel_agency_code, :ticket_number, :issuing_carrier_code, :customer_code, :fare_amount, :fee_amount, :tax_amount, :restricted_ticket, :no_show, :advanced_deposit, :fire_safe, :property_phone, {:legs => [ :conjunction_ticket, :exchange_ticket, :coupon_number, :service_class, :carrier_code, :fare_basis_code, :flight_number, :departure_date, :departure_airport_code, :departure_time, :arrival_airport_code, :arrival_time, :stopover_permitted, :fare_amount, :fee_amount, :tax_amount, :endorsement_or_restrictions, ]}, {:additional_charges => [ :kind, :amount, ]}, ]}, ]}, {:apple_pay_card => [:number, :cardholder_name, :cryptogram, :expiration_month, :expiration_year, :eci_indicator]}, {:google_pay_card => [:number, :cryptogram, :google_transaction_id, :expiration_month, :expiration_year, :source_card_type, :source_card_last_four, :eci_indicator]}, {:installments => [:count]}, ] end |
._refund_signature ⇒ Object
294 295 296 297 298 299 300 |
# File 'lib/braintree/transaction_gateway.rb', line 294 def self._refund_signature [ :amount, :merchant_account_id, :order_id, ] end |
._submit_for_settlement_signature ⇒ Object
:nodoc:
266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/braintree/transaction_gateway.rb', line 266 def self._submit_for_settlement_signature # :nodoc: [ :order_id, {:descriptor => [:name, :phone, :url]}, :purchase_order_number, :tax_amount, :tax_exempt, :discount_amount, :shipping_amount, :ships_from_postal_code, :line_items => [:commodity_code, :description, :discount_amount, :kind, :name, :product_code, :quantity, :tax_amount, :total_amount, :unit_amount, :unit_of_measure, :unit_tax_amount, :url, :tax_amount], ] end |
._update_details_signature ⇒ Object
:nodoc:
286 287 288 289 290 291 292 |
# File 'lib/braintree/transaction_gateway.rb', line 286 def self._update_details_signature # :nodoc: [ :amount, :order_id, {:descriptor => [:name, :phone, :url]}, ] end |
Instance Method Details
#_do_create(path, params = nil) ⇒ Object
:nodoc:
302 303 304 305 306 307 308 |
# File 'lib/braintree/transaction_gateway.rb', line 302 def _do_create(path, params=nil) # :nodoc: if !params.nil? params = Util.replace_key(params, :google_pay_card, :android_pay_card) end response = @config.http.post("#{@config.base_merchant_path}#{path}", params) _handle_transaction_response(response) end |
#_fetch_transactions(search, ids) ⇒ Object
:nodoc:
310 311 312 313 314 315 |
# File 'lib/braintree/transaction_gateway.rb', line 310 def _fetch_transactions(search, ids) # :nodoc: search.ids.in ids response = @config.http.post("#{@config.base_merchant_path}/transactions/advanced_search", {:search => search.to_hash}) attributes = response[:credit_card_transactions] Util.extract_attribute_as_array(attributes, :transaction).map { |attrs| Transaction._new(@gateway, attrs) } end |
#_handle_transaction_response(response) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/braintree/transaction_gateway.rb', line 36 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 |
#adjust_authorization(transaction_id, amount) ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/braintree/transaction_gateway.rb', line 142 def (transaction_id, amount) raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/ Util.verify_keys(TransactionGateway., {}) transaction_params = {:amount => amount} response = @config.http.put("#{@config.base_merchant_path}/transactions/#{transaction_id}/adjust_authorization", :transaction => transaction_params) _handle_transaction_response(response) end |
#adjust_authorization!(*args) ⇒ Object
150 151 152 |
# File 'lib/braintree/transaction_gateway.rb', line 150 def (*args) return_object_or_raise(:transaction) { (*args) } end |
#cancel_release(transaction_id) ⇒ Object
16 17 18 19 20 |
# File 'lib/braintree/transaction_gateway.rb', line 16 def cancel_release(transaction_id) raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/ response = @config.http.put("#{@config.base_merchant_path}/transactions/#{transaction_id}/cancel_release") _handle_transaction_response(response) end |
#cancel_release!(*args) ⇒ Object
22 23 24 |
# File 'lib/braintree/transaction_gateway.rb', line 22 def cancel_release!(*args) return_object_or_raise(:transaction) { cancel_release(*args) } end |
#clone_transaction(transaction_id, attributes) ⇒ Object
46 47 48 49 |
# File 'lib/braintree/transaction_gateway.rb', line 46 def clone_transaction(transaction_id, attributes) Util.verify_keys(TransactionGateway._clone_signature, attributes) _do_create "/transactions/#{transaction_id}/clone", :transaction_clone => attributes end |
#clone_transaction!(*args) ⇒ Object
51 52 53 |
# File 'lib/braintree/transaction_gateway.rb', line 51 def clone_transaction!(*args) return_object_or_raise(:transaction) { clone_transaction(*args) } end |
#create(attributes) ⇒ Object
11 12 13 14 |
# File 'lib/braintree/transaction_gateway.rb', line 11 def create(attributes) Util.verify_keys(TransactionGateway._create_signature, attributes) _do_create "/transactions", :transaction => attributes end |
#credit(attributes) ⇒ Object
55 56 57 |
# File 'lib/braintree/transaction_gateway.rb', line 55 def credit(attributes) create(attributes.merge(:type => "credit")) end |
#credit!(*args) ⇒ Object
59 60 61 |
# File 'lib/braintree/transaction_gateway.rb', line 59 def credit!(*args) return_object_or_raise(:transaction) { credit(*args) } end |
#find(id) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/braintree/transaction_gateway.rb', line 63 def find(id) raise ArgumentError, "id can not be empty" if id.nil? || id.strip.to_s == "" response = @config.http.get("#{@config.base_merchant_path}/transactions/#{id}") Transaction._new(@gateway, response[:transaction]) rescue NotFoundError raise NotFoundError, "transaction with id #{id.inspect} not found" end |
#hold_in_escrow(transaction_id) ⇒ Object
26 27 28 29 30 |
# File 'lib/braintree/transaction_gateway.rb', line 26 def hold_in_escrow(transaction_id) raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/ response = @config.http.put("#{@config.base_merchant_path}/transactions/#{transaction_id}/hold_in_escrow") _handle_transaction_response(response) end |
#hold_in_escrow!(*args) ⇒ Object
32 33 34 |
# File 'lib/braintree/transaction_gateway.rb', line 32 def hold_in_escrow!(*args) return_object_or_raise(:transaction) { hold_in_escrow(*args) } end |
#refund(transaction_id, amount_or_options = nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/braintree/transaction_gateway.rb', line 71 def refund(transaction_id, = nil) = if .is_a?(Hash) else {:amount => } end Util.verify_keys(TransactionGateway._refund_signature, ) response = @config.http.post("#{@config.base_merchant_path}/transactions/#{transaction_id}/refund", :transaction => ) _handle_transaction_response(response) end |
#refund!(*args) ⇒ Object
83 84 85 |
# File 'lib/braintree/transaction_gateway.rb', line 83 def refund!(*args) return_object_or_raise(:transaction) { refund(*args) } end |
#release_from_escrow(transaction_id) ⇒ Object
120 121 122 123 124 |
# File 'lib/braintree/transaction_gateway.rb', line 120 def release_from_escrow(transaction_id) raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/ response = @config.http.put("#{@config.base_merchant_path}/transactions/#{transaction_id}/release_from_escrow") _handle_transaction_response(response) end |
#release_from_escrow!(*args) ⇒ Object
126 127 128 |
# File 'lib/braintree/transaction_gateway.rb', line 126 def release_from_escrow!(*args) return_object_or_raise(:transaction) { release_from_escrow(*args) } end |
#retry_subscription_charge(subscription_id, amount = nil, submit_for_settlement = false) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/braintree/transaction_gateway.rb', line 87 def retry_subscription_charge(subscription_id, amount=nil, submit_for_settlement=false) attributes = { :amount => amount, :subscription_id => subscription_id, :type => Transaction::Type::Sale, :options => { :submit_for_settlement => submit_for_settlement } } _do_create "/transactions", :transaction => attributes end |
#sale(attributes) ⇒ Object
99 100 101 |
# File 'lib/braintree/transaction_gateway.rb', line 99 def sale(attributes) create(attributes.merge(:type => "sale")) end |
#sale!(*args) ⇒ Object
103 104 105 |
# File 'lib/braintree/transaction_gateway.rb', line 103 def sale!(*args) return_object_or_raise(:transaction) { sale(*args) } end |
#search(&block) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/braintree/transaction_gateway.rb', line 107 def search(&block) search = TransactionSearch.new block.call(search) if block response = @config.http.post("#{@config.base_merchant_path}/transactions/advanced_search_ids", {:search => search.to_hash}) if response.has_key?(:search_results) ResourceCollection.new(response) { |ids| _fetch_transactions(search, ids) } else raise UnexpectedError, "expected :search_results" end end |
#submit_for_partial_settlement(authorized_transaction_id, amount = nil, options = {}) ⇒ Object
161 162 163 164 165 166 167 |
# File 'lib/braintree/transaction_gateway.rb', line 161 def submit_for_partial_settlement(, amount = nil, = {}) raise ArgumentError, "authorized_transaction_id is invalid" unless =~ /\A[0-9a-z]+\z/ Util.verify_keys(TransactionGateway._submit_for_settlement_signature, ) transaction_params = {:amount => amount}.merge() response = @config.http.post("#{@config.base_merchant_path}/transactions/#{}/submit_for_partial_settlement", :transaction => transaction_params) _handle_transaction_response(response) end |
#submit_for_partial_settlement!(*args) ⇒ Object
169 170 171 |
# File 'lib/braintree/transaction_gateway.rb', line 169 def submit_for_partial_settlement!(*args) return_object_or_raise(:transaction) { submit_for_partial_settlement(*args) } end |
#submit_for_settlement(transaction_id, amount = nil, options = {}) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/braintree/transaction_gateway.rb', line 130 def submit_for_settlement(transaction_id, amount = nil, = {}) raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/ Util.verify_keys(TransactionGateway._submit_for_settlement_signature, ) transaction_params = {:amount => amount}.merge() response = @config.http.put("#{@config.base_merchant_path}/transactions/#{transaction_id}/submit_for_settlement", :transaction => transaction_params) _handle_transaction_response(response) end |
#submit_for_settlement!(*args) ⇒ Object
138 139 140 |
# File 'lib/braintree/transaction_gateway.rb', line 138 def submit_for_settlement!(*args) return_object_or_raise(:transaction) { submit_for_settlement(*args) } end |
#update_details(transaction_id, options = {}) ⇒ Object
154 155 156 157 158 159 |
# File 'lib/braintree/transaction_gateway.rb', line 154 def update_details(transaction_id, = {}) raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/ Util.verify_keys(TransactionGateway._update_details_signature, ) response = @config.http.put("#{@config.base_merchant_path}/transactions/#{transaction_id}/update_details", :transaction => ) _handle_transaction_response(response) end |
#void(transaction_id) ⇒ Object
173 174 175 176 |
# File 'lib/braintree/transaction_gateway.rb', line 173 def void(transaction_id) response = @config.http.put("#{@config.base_merchant_path}/transactions/#{transaction_id}/void") _handle_transaction_response(response) end |
#void!(*args) ⇒ Object
178 179 180 |
# File 'lib/braintree/transaction_gateway.rb', line 178 def void!(*args) return_object_or_raise(:transaction) { void(*args) } end |