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.

Implmenting new gateways

See the ActiveMerchant Guide to Contributing

Direct Known Subclasses

AdyenGateway, App55Gateway, AuthorizeNetArbGateway, AuthorizeNetCimGateway, AuthorizeNetGateway, BalancedGateway, BanwireGateway, BarclaysEpdqGateway, Be2billGateway, BeanstreamGateway, BeanstreamInteracGateway, BluePayGateway, BogusGateway, BorgunGateway, BraintreeBlueGateway, BraintreeGateway, BridgePayGateway, CC5Gateway, CardStreamGateway, CashnetGateway, CecabankGateway, CertoDirectGateway, CommercegateGateway, ConektaGateway, CyberSourceGateway, DataCashGateway, EfsnetGateway, ElavonGateway, EpayGateway, EvoCaGateway, EwayGateway, EwayManagedGateway, EwayRapidGateway, ExactGateway, FatZebraGateway, FederatedCanadaGateway, FirstGivingGateway, FirstPayGateway, FirstdataE4Gateway, GarantiGateway, HdfcGateway, HpsGateway, IatsPaymentsGateway, IdealBaseGateway, InspireGateway, InstapayGateway, IridiumGateway, ItransactGateway, JetpayGateway, LinkpointGateway, LitleGateway, MaxipagoGateway, MerchantESolutionsGateway, MerchantOneGateway, MerchantWareGateway, MerchantWareVersionFourGateway, MerchantWarriorGateway, MercuryGateway, MetricsGlobalGateway, MigsGateway, ModernPaymentsCimGateway, ModernPaymentsGateway, MonerisGateway, MonerisUsGateway, MoneyMoversGateway, NabTransactGateway, NetRegistryGateway, NetaxeptGateway, NetbillingGateway, NetpayGateway, NetworkMerchantsGateway, OgoneGateway, OpenpayGateway, OptimalPaymentGateway, OrbitalGateway, PacNetRavenGateway, PagoFacilGateway, PayGateXmlGateway, PayJunctionGateway, PaySecureGateway, PayboxDirectGateway, PayexGateway, PayflowExpressGateway, PayflowGateway, PaymentExpressGateway, PaymillGateway, PaypalExpressGateway, PaypalGateway, PayscoutGateway, PaystationGateway, PaywayGateway, PinGateway, PlugnpayGateway, PsigateGateway, PslCardGateway, QbmsGateway, QuantumGateway, QuickpayGateway, RealexGateway, RedsysGateway, SageBankcardGateway, SageGateway, SagePayGateway, SageVaultGateway, SageVirtualCheckGateway, SallieMaeGateway, SamuraiGateway, SecureNetGateway, SecurePayAuGateway, SecurePayTechGateway, SkipJackGateway, SmartPs, SoEasyPayGateway, SpreedlyCoreGateway, StripeGateway, SwipeCheckoutGateway, TransFirstGateway, TrustCommerceGateway, UsaEpayAdvancedGateway, UsaEpayGateway, UsaEpayTransactionGateway, VerifiGateway, ViaklixGateway, VindiciaGateway, WepayGateway, WirecardGateway, WorldpayGateway, WorldpayUsGateway

Constant Summary collapse

DEBIT_CARDS =
[ :switch, :solo ]
CURRENCIES_WITHOUT_FRACTIONS =
[ 'BIF', 'BYR', 'CLP', 'CVE', 'DJF', 'GNF', 'HUF', 'ISK', 'JPY', 'KMF', 'KRW', 'PYG', 'RWF', 'TWD', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF' ]
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."
@@implementations =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CreditCardFormatting

#expdate, #format

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.



140
141
142
# File 'lib/active_merchant/billing/gateway.rb', line 140

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



103
104
105
# File 'lib/active_merchant/billing/gateway.rb', line 103

def options
  @options
end

Class Method Details

.card_brand(source) ⇒ Object



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

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

.inherited(subclass) ⇒ Object



67
68
69
70
# File 'lib/active_merchant/billing/gateway.rb', line 67

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

.supported_countriesObject



124
125
126
# File 'lib/active_merchant/billing/gateway.rb', line 124

def self.supported_countries
  @supported_countries ||= []
end

.supported_countries=(country_codes) ⇒ Object



115
116
117
118
119
120
121
122
# File 'lib/active_merchant/billing/gateway.rb', line 115

def self.supported_countries=(country_codes)
  country_codes.each do |country_code|
    unless ActiveMerchant::Country.find(country_code)
      raise ActiveMerchant::InvalidCountryCodeError, "No country could be found for the country #{country_code}"
    end
  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)


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

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

Instance Method Details

#card_brand(source) ⇒ Object



132
133
134
# File 'lib/active_merchant/billing/gateway.rb', line 132

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

#generate_unique_idObject



72
73
74
# File 'lib/active_merchant/billing/gateway.rb', line 72

def generate_unique_id
  SecureRandom.hex(16)
end

#supported_countriesObject



128
129
130
# File 'lib/active_merchant/billing/gateway.rb', line 128

def supported_countries
  self.class.supported_countries
end

#test?Boolean

Are we running in test mode?

Returns:

  • (Boolean)


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

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