Class: Braintree::CreditCardGateway
- Inherits:
-
Object
- Object
- Braintree::CreditCardGateway
- Includes:
- BaseModule
- Defined in:
- lib/braintree/credit_card_gateway.rb
Class Method Summary collapse
Instance Method Summary collapse
- #_do_create(path, params = nil) ⇒ Object
- #_do_update(http_verb, path, params) ⇒ Object
- #_fetch_expired(ids) ⇒ Object
- #_fetch_expiring_between(formatted_start_date, formatted_end_date, ids) ⇒ Object
- #create(attributes) ⇒ Object
- #create!(*args) ⇒ Object
-
#credit(token, transaction_attributes) ⇒ Object
NEXT_MAJOR_VERSION remove this method CreditCard.credit has been deprecated in favor of Transaction.credit.
-
#credit!(*args) ⇒ Object
NEXT_MAJOR_VERSION remove this method CreditCard.credit has been deprecated in favor of Transaction.credit.
- #delete(token) ⇒ Object
- #expired(options = {}) ⇒ Object
- #expiring_between(start_date, end_date, options = {}) ⇒ Object
- #find(token) ⇒ Object
- #from_nonce(nonce) ⇒ Object
-
#initialize(gateway) ⇒ CreditCardGateway
constructor
A new instance of CreditCardGateway.
- #update(token, attributes) ⇒ Object
- #update!(*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) ⇒ CreditCardGateway
Returns a new instance of CreditCardGateway.
5 6 7 8 9 |
# File 'lib/braintree/credit_card_gateway.rb', line 5 def initialize(gateway) @gateway = gateway @config = gateway.config @config.assert_has_access_token_or_keys end |
Class Method Details
._create_signature ⇒ Object
[View source]
86 87 88 |
# File 'lib/braintree/credit_card_gateway.rb', line 86 def self._create_signature _signature(:create) end |
._signature(type) ⇒ Object
[View source]
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/braintree/credit_card_gateway.rb', line 94 def self._signature(type) billing_address_params = AddressGateway._shared_signature # NEXT_MAJOR_VERSION Remove venmo_sdk_session # The old venmo SDK class has been deprecated = [ :fail_on_duplicate_payment_method, :fail_on_duplicate_payment_method_for_customer, :make_default, :skip_advanced_fraud_checking, :venmo_sdk_session, # Deprecated :verification_account_type, :verification_amount, :verification_currency_iso_code, :verification_merchant_account_id, :verify_card ] # NEXT_MAJOR_VERSION Remove venmo_sdk_payment_method_code # The old venmo SDK class has been deprecated signature = [ :billing_address_id, :cardholder_name, :cvv, :expiration_date, :expiration_month, :expiration_year, :number, :token, :venmo_sdk_payment_method_code, # Deprecated :device_data, :payment_method_nonce, {:external_vault => [:network_transaction_id]}, {:options => }, {:billing_address => billing_address_params} ] signature << { :three_d_secure_pass_thru => [ :eci_flag, :cavv, :xid, :three_d_secure_version, :authentication_response, :directory_response, :cavv_algorithm, :ds_transaction_id, ] } case type when :create signature << :customer_id when :update billing_address_params << {:options => [:update_existing]} else raise ArgumentError end return signature end |
._update_signature ⇒ Object
[View source]
90 91 92 |
# File 'lib/braintree/credit_card_gateway.rb', line 90 def self._update_signature _signature(:update) end |
Instance Method Details
#_do_create(path, params = nil) ⇒ Object
[View source]
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/braintree/credit_card_gateway.rb', line 146 def _do_create(path, params=nil) response = @config.http.post("#{@config.base_merchant_path}#{path}", params) if response[:credit_card] SuccessfulResult.new(:credit_card => CreditCard._new(@gateway, response[:credit_card])) elsif response[:api_error_response] ErrorResult.new(@gateway, response[:api_error_response]) else raise UnexpectedError, "expected :credit_card or :api_error_response" end end |
#_do_update(http_verb, path, params) ⇒ Object
[View source]
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/braintree/credit_card_gateway.rb', line 157 def _do_update(http_verb, path, params) response = @config.http.send(http_verb, "#{@config.base_merchant_path}#{path}", params) if response[:credit_card] SuccessfulResult.new(:credit_card => CreditCard._new(@gateway, response[:credit_card])) elsif response[:api_error_response] ErrorResult.new(@gateway, response[:api_error_response]) else raise UnexpectedError, "expected :credit_card or :api_error_response" end end |
#_fetch_expired(ids) ⇒ Object
[View source]
168 169 170 171 172 |
# File 'lib/braintree/credit_card_gateway.rb', line 168 def _fetch_expired(ids) response = @config.http.post("#{@config.base_merchant_path}/payment_methods/all/expired", :search => {:ids => ids}) attributes = response[:payment_methods] Util.extract_attribute_as_array(attributes, :credit_card).map { |attrs| CreditCard._new(@gateway, attrs) } end |
#_fetch_expiring_between(formatted_start_date, formatted_end_date, ids) ⇒ Object
[View source]
174 175 176 177 178 179 180 181 |
# File 'lib/braintree/credit_card_gateway.rb', line 174 def _fetch_expiring_between(formatted_start_date, formatted_end_date, ids) response = @config.http.post( "#{@config.base_merchant_path}/payment_methods/all/expiring?start=#{formatted_start_date}&end=#{formatted_end_date}", :search => {:ids => ids}, ) attributes = response[:payment_methods] Util.extract_attribute_as_array(attributes, :credit_card).map { |attrs| CreditCard._new(@gateway, attrs) } end |
#create(attributes) ⇒ Object
[View source]
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/braintree/credit_card_gateway.rb', line 11 def create(attributes) if attributes.has_key?(:expiration_date) && (attributes.has_key?(:expiration_month) || attributes.has_key?(:expiration_year)) raise ArgumentError.new("create with both expiration_month and expiration_year or only expiration_date") end # NEXT_MAJOR_VERSION remove this check if attributes.has_key?(:venmo_sdk_payment_method_code) || attributes.has_key?(:venmo_sdk_session) warn "[DEPRECATED] The Venmo SDK integration is Unsupported. Please update your integration to use Pay with Venmo instead." end Util.verify_keys(CreditCardGateway._create_signature, attributes) _do_create("/payment_methods", :credit_card => attributes) end |
#create!(*args) ⇒ Object
[View source]
23 24 25 |
# File 'lib/braintree/credit_card_gateway.rb', line 23 def create!(*args) return_object_or_raise(:credit_card) { create(*args) } end |
#credit(token, transaction_attributes) ⇒ Object
NEXT_MAJOR_VERSION remove this method CreditCard.credit has been deprecated in favor of Transaction.credit
29 30 31 32 |
# File 'lib/braintree/credit_card_gateway.rb', line 29 def credit(token, transaction_attributes) warn "[DEPRECATED] CreditCard.credit is deprecated. Use Transaction.credit instead" @gateway.transaction.credit(transaction_attributes.merge(:payment_method_token => token)) end |
#credit!(*args) ⇒ Object
NEXT_MAJOR_VERSION remove this method CreditCard.credit has been deprecated in favor of Transaction.credit
36 37 38 39 |
# File 'lib/braintree/credit_card_gateway.rb', line 36 def credit!(*args) warn "[DEPRECATED] CreditCard.credit is deprecated. Use Transaction.credit instead" return_object_or_raise(:transaction) { credit(*args) } end |
#delete(token) ⇒ Object
[View source]
41 42 43 |
# File 'lib/braintree/credit_card_gateway.rb', line 41 def delete(token) @config.http.delete("#{@config.base_merchant_path}/payment_methods/credit_card/#{token}") end |
#expired(options = {}) ⇒ Object
[View source]
45 46 47 48 |
# File 'lib/braintree/credit_card_gateway.rb', line 45 def expired( = {}) response = @config.http.post("#{@config.base_merchant_path}/payment_methods/all/expired_ids") ResourceCollection.new(response) { |ids| _fetch_expired(ids) } end |
#expiring_between(start_date, end_date, options = {}) ⇒ Object
[View source]
50 51 52 53 54 55 |
# File 'lib/braintree/credit_card_gateway.rb', line 50 def expiring_between(start_date, end_date, = {}) formatted_start_date = start_date.strftime("%m%Y") formatted_end_date = end_date.strftime("%m%Y") response = @config.http.post("#{@config.base_merchant_path}/payment_methods/all/expiring_ids?start=#{formatted_start_date}&end=#{formatted_end_date}") ResourceCollection.new(response) { |ids| _fetch_expiring_between(formatted_start_date, formatted_end_date, ids) } end |
#find(token) ⇒ Object
[View source]
57 58 59 60 61 62 63 |
# File 'lib/braintree/credit_card_gateway.rb', line 57 def find(token) raise ArgumentError if token.nil? || token.to_s.strip == "" response = @config.http.get("#{@config.base_merchant_path}/payment_methods/credit_card/#{token}") CreditCard._new(@gateway, response[:credit_card]) rescue NotFoundError raise NotFoundError, "payment method with token #{token.inspect} not found" end |
#from_nonce(nonce) ⇒ Object
[View source]
65 66 67 68 69 70 71 |
# File 'lib/braintree/credit_card_gateway.rb', line 65 def from_nonce(nonce) raise ArgumentError if nonce.nil? || nonce.to_s.strip == "" response = @config.http.get("#{@config.base_merchant_path}/payment_methods/from_nonce/#{nonce}") CreditCard._new(@gateway, response[:credit_card]) rescue NotFoundError raise NotFoundError, "nonce #{nonce.inspect} locked, consumed, or not found" end |
#update(token, attributes) ⇒ Object
[View source]
73 74 75 76 77 78 79 80 |
# File 'lib/braintree/credit_card_gateway.rb', line 73 def update(token, attributes) # NEXT_MAJOR_VERSION remove this check if attributes.has_key?(:venmo_sdk_payment_method_code) || attributes.has_key?(:venmo_sdk_session) warn "[DEPRECATED] The Venmo SDK integration is Unsupported. Please update your integration to use Pay with Venmo instead." end Util.verify_keys(CreditCardGateway._update_signature, attributes) _do_update(:put, "/payment_methods/credit_card/#{token}", :credit_card => attributes) end |
#update!(*args) ⇒ Object
[View source]
82 83 84 |
# File 'lib/braintree/credit_card_gateway.rb', line 82 def update!(*args) return_object_or_raise(:credit_card) { update(*args) } end |