Class: ActiveMerchant::Billing::Gateway

Inherits:
Object
  • Object
show all
Includes:
CreditCardFormatting, PostsData
Defined in:
lib/active_merchant/billing/gateway.rb

Overview

Description

The Gateway class is the base class for all ActiveMerchant gateway implementations.

The standard list of gateway functions that most concrete gateway subclasses implement is:

  • purchase(money, credit_card, options = {})

  • authorize(money, credit_card, options = {})

  • capture(money, authorization, options = {})

  • void(identification, options = {})

  • refund(money, identification, options = {})

  • verify(credit_card, options = {})

Some gateways also support features for storing credit cards:

  • store(credit_card, options = {})

  • unstore(identification, options = {})

Gateway Options

The options hash consists of the following options:

  • :order_id - The order number

  • :ip - The IP address of the customer making the purchase

  • :customer - The name, customer number, or other information that identifies the customer

  • :invoice - The invoice number

  • :merchant - The name or description of the merchant offering the product

  • :description - A description of the transaction

  • :email - The email address of the customer

  • :currency - The currency of the transaction. Only important when you are using a currency that is not the default with a gateway that supports multiple currencies.

  • :billing_address - A hash containing the billing address of the customer.

  • :shipping_address - A hash containing the shipping address of the customer.

The :billing_address, and :shipping_address hashes can have the following keys:

  • :name - The full name of the customer.

  • :company - The company name of the customer.

  • :address1 - The primary street address of the customer.

  • :address2 - Additional line of address information.

  • :city - The city of the customer.

  • :state - The state of the customer. The 2 digit code for US and Canadian addresses. The full name of the state or province for foreign addresses.

  • :country - The [ISO 3166-1-alpha-2 code](www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm) for the customer.

  • :zip - The zip or postal code of the customer.

  • :phone - The phone number of the customer.

Implementing new gateways

See the ActiveMerchant Guide to Contributing

Direct Known Subclasses

AdyenGateway, AirwallexGateway, AleloGateway, AlliedWalletGateway, AuthorizeNetArbGateway, AuthorizeNetCimGateway, AuthorizeNetGateway, AxcessmsGateway, BalancedGateway, BamboraApacGateway, BankFrickGateway, BanwireGateway, BarclaycardSmartpayGateway, Be2billGateway, BeanstreamGateway, BeanstreamInteracGateway, BluePayGateway, BlueSnapGateway, BogusGateway, BorgunGateway, BpointGateway, BraintreeBlueGateway, BraintreeGateway, BridgePayGateway, CC5Gateway, CamsGateway, CardConnectGateway, CardStreamGateway, CardknoxGateway, CardprocessGateway, CashnetGateway, CecabankGateway, CecabankJsonGateway, CecabankXmlGateway, CenposGateway, CheckoutGateway, CheckoutV2Gateway, CitrusPayGateway, ClearhausGateway, CommerceHubGateway, CommercegateGateway, ConektaGateway, CreditcallGateway, CredoraxGateway, CtPaymentGateway, CulqiGateway, CyberSourceGateway, CyberSourceRestGateway, DLocalGateway, DataCashGateway, DatatransGateway, DecidirGateway, DecidirPlusGateway, DeepstackGateway, DibsGateway, DigitzsGateway, EbanxGateway, EfsnetGateway, ElavonGateway, ElementGateway, EpayGateway, EvoCaGateway, EwayGateway, EwayManagedGateway, EwayRapidGateway, ExactGateway, EzicGateway, FatZebraGateway, FederatedCanadaGateway, FirstGivingGateway, FirstPayGateway, FirstPayJsonGateway, FirstPayXmlGateway, FirstdataE4Gateway, FirstdataE4V27Gateway, FlexChargeGateway, Flo2cashGateway, ForteGateway, FortisGateway, GarantiGateway, GlobalCollectGateway, GlobalTransportGateway, HdfcGateway, HiPayGateway, HpsGateway, IatsPaymentsGateway, InspireGateway, InstapayGateway, IpgGateway, IppGateway, IridiumGateway, ItransactGateway, IveriGateway, IxopayGateway, JetpayGateway, JetpayV2Gateway, KomojuGateway, KushkiGateway, Latitude19Gateway, LinkpointGateway, LitleGateway, MaxipagoGateway, MercadoPagoGateway, MerchantESolutionsGateway, MerchantOneGateway, MerchantPartnersGateway, MerchantWareGateway, MerchantWareVersionFourGateway, MerchantWarriorGateway, MercuryGateway, MetricsGlobalGateway, MicropaymentGateway, MigsGateway, MitGateway, ModernPaymentsCimGateway, ModernPaymentsGateway, MokaGateway, MoneiGateway, MonerisGateway, MoneyMoversGateway, MundipaggGateway, NabTransactGateway, NcrSecurePayGateway, NetRegistryGateway, NetaxeptGateway, NetbanxGateway, NetbillingGateway, NetpayGateway, NetworkMerchantsGateway, NmiGateway, NuveiGateway, OgoneGateway, OmiseGateway, OpenpayGateway, OppGateway, OptimalPaymentGateway, OrbitalGateway, PacNetRavenGateway, PagarmeGateway, PagoFacilGateway, PayArcGateway, PayConexGateway, PayGateXmlGateway, PayHubGateway, PayJunctionGateway, PayJunctionV2Gateway, PaySecureGateway, PayTraceGateway, PayboxDirectGateway, PayeezyGateway, PayexGateway, PayflowExpressGateway, PayflowGateway, PaymentExpressGateway, PaymentezGateway, PaymillGateway, PaypalExpressGateway, PaypalGateway, PaysafeGateway, PayscoutGateway, PaystationGateway, PayuInGateway, PayuLatamGateway, PaywayDotComGateway, PaywayGateway, PinGateway, PlexoGateway, PlugnpayGateway, PriorityGateway, ProPayGateway, PsigateGateway, PslCardGateway, QbmsGateway, QuantumGateway, QuickbooksGateway, QuickpayGateway, QuickpayV10Gateway, QuickpayV4to7Gateway, QvalentGateway, RapydGateway, ReachGateway, RealexGateway, RedsysGateway, RedsysRestGateway, S5Gateway, SafeChargeGateway, SageGateway, SagePayGateway, SallieMaeGateway, SecureNetGateway, SecurePayAuGateway, SecurePayGateway, SecurePayTechGateway, SecurionPayGateway, Shift4Gateway, SimetrikGateway, SkipJackGateway, SmartPs, SoEasyPayGateway, SpreedlyCoreGateway, StripeGateway, SumUpGateway, SwipeCheckoutGateway, TelrGateway, TnsGateway, TransFirstGateway, TransFirstTransactionExpressGateway, TransactProGateway, TrexleGateway, TrustCommerceGateway, UsaEpayAdvancedGateway, UsaEpayGateway, UsaEpayTransactionGateway, VancoGateway, VantivExpressGateway, VerifiGateway, VersaPayGateway, ViaklixGateway, VisanetPeruGateway, VposGateway, WepayGateway, WirecardGateway, WompiGateway, WorldNetGateway, WorldpayGateway, WorldpayOnlinePaymentsGateway, WorldpayUsGateway, XpayGateway

Constant Summary collapse

CREDIT_DEPRECATION_MESSAGE =
'Support for using credit to refund existing transactions is deprecated and will be removed from a future release of ActiveMerchant. Please use the refund method instead.'
RECURRING_DEPRECATION_MESSAGE =
'Recurring functionality in ActiveMerchant is deprecated and will be removed in a future version. Please contact the ActiveMerchant maintainers if you have an interest in taking ownership of a separate gem that continues support for it.'
STANDARD_ERROR_CODE =

Standardized Error Codes

:incorrect_number - Card number does not comply with ISO/IEC 7812 numbering standard :invalid_number - Card number was not matched by processor :invalid_expiry_date - Expiry date does not match correct formatting :invalid_cvc - Security codes does not match correct format (3-4 digits) :expired_card - Card number is expired :incorrect_cvc - Security code was not matched by the processor :incorrect_zip - Zip code is not in correct format :incorrect_address - Billing address info was not matched by the processor :incorrect_pin - Card PIN is incorrect :card_declined - Card number declined by processor :processing_error - Processor error :call_issuer - Transaction requires voice authentication, call issuer :pickup_card - Issuer requests that you pickup the card from merchant :test_mode_live_card - Card was declined. Request was in test mode, but used a non test card. :unsupported_feature - Transaction failed due to gateway or merchant

configuration not supporting a feature used, such
as network tokenization.
{
  incorrect_number: 'incorrect_number',
  invalid_number: 'invalid_number',
  invalid_expiry_date: 'invalid_expiry_date',
  invalid_cvc: 'invalid_cvc',
  expired_card: 'expired_card',
  incorrect_cvc: 'incorrect_cvc',
  incorrect_zip: 'incorrect_zip',
  incorrect_address: 'incorrect_address',
  incorrect_pin: 'incorrect_pin',
  card_declined: 'card_declined',
  processing_error: 'processing_error',
  call_issuer: 'call_issuer',
  pickup_card: 'pick_up_card',
  config_error: 'config_error',
  test_mode_live_card: 'test_mode_live_card',
  unsupported_feature: 'unsupported_feature',
  invalid_amount: 'invalid_amount'
}
@@implementations =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CreditCardFormatting

#expdate, #format, #strftime_yyyymm

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Constructor Details

#initialize(options = {}) ⇒ Gateway

Initialize a new gateway.

See the documentation for the gateway you will be using to make sure there are no other required options.



181
182
183
# File 'lib/active_merchant/billing/gateway.rb', line 181

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



146
147
148
# File 'lib/active_merchant/billing/gateway.rb', line 146

def options
  @options
end

Class Method Details

.card_brand(source) ⇒ Object



153
154
155
156
# File 'lib/active_merchant/billing/gateway.rb', line 153

def self.card_brand(source)
  result = source.respond_to?(:brand) ? source.brand : source.type
  result.to_s.downcase
end

.inherited(subclass) ⇒ Object



105
106
107
108
# File 'lib/active_merchant/billing/gateway.rb', line 105

def self.inherited(subclass)
  super
  @@implementations << subclass
end

.supported_countriesObject



165
166
167
# File 'lib/active_merchant/billing/gateway.rb', line 165

def self.supported_countries
  @supported_countries ||= (self.superclass.supported_countries || [])
end

.supported_countries=(country_codes) ⇒ Object



158
159
160
161
162
163
# File 'lib/active_merchant/billing/gateway.rb', line 158

def self.supported_countries=(country_codes)
  country_codes.each do |country_code|
    raise ActiveMerchant::InvalidCountryCodeError, "No country could be found for the country #{country_code}" unless ActiveMerchant::Country.find(country_code)
  end
  @supported_countries = country_codes.dup
end

.supports?(card_type) ⇒ Boolean

Use this method to check if your gateway of interest supports a credit card of some type

Returns:

  • (Boolean)


149
150
151
# File 'lib/active_merchant/billing/gateway.rb', line 149

def self.supports?(card_type)
  supported_cardtypes.include?(card_type.to_sym)
end

Instance Method Details

#add_field_to_post_if_present(post, options, field) ⇒ Object



209
210
211
# File 'lib/active_merchant/billing/gateway.rb', line 209

def add_field_to_post_if_present(post, options, field)
  post[field] = options[field] if options[field]
end

#add_fields_to_post_if_present(post, options, fields) ⇒ Object



203
204
205
206
207
# File 'lib/active_merchant/billing/gateway.rb', line 203

def add_fields_to_post_if_present(post, options, fields)
  fields.each do |field|
    add_field_to_post_if_present(post, options, field)
  end
end

#card_brand(source) ⇒ Object



173
174
175
# File 'lib/active_merchant/billing/gateway.rb', line 173

def card_brand(source)
  self.class.card_brand(source)
end

#generate_unique_idObject



110
111
112
# File 'lib/active_merchant/billing/gateway.rb', line 110

def generate_unique_id
  SecureRandom.hex(16)
end

#scrub(transcript) ⇒ Object



195
196
197
# File 'lib/active_merchant/billing/gateway.rb', line 195

def scrub(transcript)
  raise 'This gateway does not support scrubbing.'
end

#supported_countriesObject



169
170
171
# File 'lib/active_merchant/billing/gateway.rb', line 169

def supported_countries
  self.class.supported_countries
end

#supports_network_tokenization?Boolean

Returns:

  • (Boolean)


199
200
201
# File 'lib/active_merchant/billing/gateway.rb', line 199

def supports_network_tokenization?
  false
end

#supports_scrubbing?Boolean

Does this gateway know how to scrub sensitive information out of HTTP transcripts?

Returns:

  • (Boolean)


191
192
193
# File 'lib/active_merchant/billing/gateway.rb', line 191

def supports_scrubbing?
  false
end

#test?Boolean

Are we running in test mode?

Returns:

  • (Boolean)


186
187
188
# File 'lib/active_merchant/billing/gateway.rb', line 186

def test?
  (@options.has_key?(:test) ? @options[:test] : Base.test?)
end