Class Index [+]

Quicksearch

ActiveMerchant::Billing::OgoneGateway

Ogone DirectLink Gateway

DirectLink is the API version of the Ogone Payment Platform. It allows server to server communication between Ogone systems and your e-commerce website.

This implementation follows the specification provided in the DirectLink integration guide version 4.2.0 (26 October 2011), available here: secure.ogone.com/ncol/Ogone_DirectLink_EN.pdf

It also features aliases, which allow to store/unstore credit cards, as specified in the Alias Manager Option guide version 3.2.0 (26 October 2011) available here: secure.ogone.com/ncol/Ogone_Alias_EN.pdf

It was last tested on Release 4.89 of Ogone DirectLink + AliasManager (26 October 2011).

For any questions or comments, please contact one of the following:

Usage

  gateway = ActiveMerchant::Billing::OgoneGateway.new(
              :login                     => "my_ogone_psp_id",
              :user                      => "my_ogone_user_id",
              :password                  => "my_ogone_pswd",
              :signature                 => "my_ogone_sha_signature", # Only if you configured your Ogone environment so.
              :signature_encryptor       => "sha512", # Can be "sha1" (default), "sha256" or "sha512".
                                                      # Must be the same as the one configured in your Ogone account.
           )

  # set up credit card object as in main ActiveMerchant example
  creditcard = ActiveMerchant::Billing::CreditCard.new(
    :type       => 'visa',
    :number     => '4242424242424242',
    :month      => 8,
    :year       => 2009,
    :first_name => 'Bob',
    :last_name  => 'Bobsen'
  )

  # run request
  response = gateway.purchase(1000, creditcard, :order_id => "1") # charge 10 EUR

  If you don't provide an :order_id, the gateway will generate a random one for you.

  puts response.success?      # Check whether the transaction was successful
  puts response.message       # Retrieve the message returned by Ogone
  puts response.authorization # Retrieve the unique transaction ID returned by Ogone

Alias feature

  To use the alias feature, simply add :store in the options hash:

  # Associate the alias to that credit card
  gateway.purchase(1000, creditcard, :order_id => "1", :store => "myawesomecustomer")

  # You can use the alias instead of the credit card for subsequent orders
  gateway.purchase(2000, "myawesomecustomer", :order_id => "2")

Constants

URLS
CVV_MAPPING
AVS_MAPPING
SUCCESS_MESSAGE
OGONE_NO_SIGNATURE_DEPRECATION_MESSAGE
OGONE_LOW_ENCRYPTION_DEPRECATION_MESSAGE

Public Class Methods

new(options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/ogone.rb, line 94
94:       def initialize(options = {})
95:         requires!(options, :login, :user, :password)
96:         @options = options
97:         super
98:       end

Public Instance Methods

authorize(money, payment_source, options = {}) click to toggle source

Verify and reserve the specified amount on the account, without actually doing the transaction.

     # File lib/active_merchant/billing/gateways/ogone.rb, line 101
101:       def authorize(money, payment_source, options = {})
102:         post = {}
103:         add_invoice(post, options)
104:         add_payment_source(post, payment_source, options)
105:         add_address(post, payment_source, options)
106:         add_customer_data(post, options)
107:         add_money(post, money, options)
108:         commit('RES', post)
109:       end
capture(money, authorization, options = {}) click to toggle source

Complete a previously authorized transaction.

     # File lib/active_merchant/billing/gateways/ogone.rb, line 123
123:       def capture(money, authorization, options = {})
124:         post = {}
125:         add_authorization(post, reference_from(authorization))
126:         add_invoice(post, options)
127:         add_customer_data(post, options)
128:         add_money(post, money, options)
129:         commit('SAL', post)
130:       end
credit(money, identification_or_credit_card, options = {}) click to toggle source

Credit the specified account by a specific amount.

     # File lib/active_merchant/billing/gateways/ogone.rb, line 140
140:       def credit(money, identification_or_credit_card, options = {})
141:         if reference_transaction?(identification_or_credit_card)
142:           deprecated CREDIT_DEPRECATION_MESSAGE
143:           # Referenced credit: refund of a settled transaction
144:           refund(money, identification_or_credit_card, options)
145:         else # must be a credit card or card reference
146:           perform_non_referenced_credit(money, identification_or_credit_card, options)
147:         end
148:       end
purchase(money, payment_source, options = {}) click to toggle source

Verify and transfer the specified amount.

     # File lib/active_merchant/billing/gateways/ogone.rb, line 112
112:       def purchase(money, payment_source, options = {})
113:         post = {}
114:         add_invoice(post, options)
115:         add_payment_source(post, payment_source, options)
116:         add_address(post, payment_source, options)
117:         add_customer_data(post, options)
118:         add_money(post, money, options)
119:         commit('SAL', post)
120:       end
refund(money, reference, options = {}) click to toggle source

Refund of a settled transaction

     # File lib/active_merchant/billing/gateways/ogone.rb, line 151
151:       def refund(money, reference, options = {})
152:         perform_reference_credit(money, reference, options)
153:       end
test?() click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 155
155:       def test?
156:         @options[:test] || super
157:       end
void(identification, options = {}) click to toggle source

Cancels a previously authorized transaction.

     # File lib/active_merchant/billing/gateways/ogone.rb, line 133
133:       def void(identification, options = {})
134:         post = {}
135:         add_authorization(post, reference_from(identification))
136:         commit('DES', post)
137:       end

Private Instance Methods

add_address(post, creditcard, options) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 222
222:       def add_address(post, creditcard, options)
223:         return unless options[:billing_address]
224:         add_pair post, 'Owneraddress', options[:billing_address][:address1]
225:         add_pair post, 'OwnerZip',     options[:billing_address][:zip]
226:         add_pair post, 'ownertown',    options[:billing_address][:city]
227:         add_pair post, 'ownercty',     options[:billing_address][:country]
228:         add_pair post, 'ownertelno',   options[:billing_address][:phone]
229:       end
add_alias(post, _alias) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 204
204:       def add_alias(post, _alias)
205:         add_pair post, 'ALIAS', _alias
206:       end
add_authorization(post, authorization) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 208
208:       def add_authorization(post, authorization)
209:         add_pair post, 'PAYID', authorization
210:       end
add_creditcard(post, creditcard) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 236
236:       def add_creditcard(post, creditcard)
237:         add_pair post, 'CN',     creditcard.name
238:         add_pair post, 'CARDNO', creditcard.number
239:         add_pair post, 'ED',     "%02d%02s" % [creditcard.month, creditcard.year.to_s[2..1]]
240:         add_pair post, 'CVC',    creditcard.verification_value
241:       end
add_customer_data(post, options) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 217
217:       def add_customer_data(post, options)
218:         add_pair post, 'EMAIL',       options[:email]
219:         add_pair post, 'REMOTE_ADDR', options[:ip]
220:       end
add_eci(post, eci) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 200
200:       def add_eci(post, eci)
201:         add_pair post, 'ECI', eci.to_s
202:       end
add_invoice(post, options) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 231
231:       def add_invoice(post, options)
232:         add_pair post, 'orderID', options[:order_id] || generate_unique_id[0...30]
233:         add_pair post, 'COM',     options[:description]
234:       end
add_money(post, money, options) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 212
212:       def add_money(post, money, options)
213:         add_pair post, 'currency', options[:currency] || @options[:currency] || currency(money)
214:         add_pair post, 'amount',   amount(money)
215:       end
add_pair(post, key, value) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 317
317:       def add_pair(post, key, value)
318:         post[key] = value if !value.blank?
319:       end
add_payment_source(post, payment_source, options) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 189
189:       def add_payment_source(post, payment_source, options)
190:         if payment_source.is_a?(String)
191:           add_alias(post, payment_source)
192:           add_eci(post, options[:eci] || '9')
193:         else
194:           add_alias(post, options[:store])
195:           add_eci(post, options[:eci] || '7')
196:           add_creditcard(post, payment_source)
197:         end
198:       end
add_signature(parameters) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 295
295:       def add_signature(parameters)
296:         deprecated(OGONE_LOW_ENCRYPTION_DEPRECATION_MESSAGE) unless @options[:signature_encryptor] == 'sha512'
297: 
298:         sha_encryptor = case @options[:signature_encryptor]
299:                         when 'sha256'
300:                           Digest::SHA256
301:                         when 'sha512'
302:                           Digest::SHA512
303:                         else
304:                           Digest::SHA1
305:                         end
306: 
307:         string_to_digest = if @options[:signature_encryptor]
308:           parameters.sort { |a, b| a[0].upcase <=> b[0].upcase }.map { |k, v| "#{k.upcase}=#{v}" }.join(@options[:signature])
309:         else
310:           ]orderID amount currency CARDNO PSPID Operation ALIAS].map { |key| parameters[key] }.join
311:         end
312:         string_to_digest << @options[:signature]
313: 
314:         add_pair parameters, 'SHASign', sha_encryptor.hexdigest(string_to_digest).upcase
315:       end
commit(action, parameters) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 248
248:       def commit(action, parameters)
249:         add_pair parameters, 'PSPID',  @options[:login]
250:         add_pair parameters, 'USERID', @options[:user]
251:         add_pair parameters, 'PSWD',   @options[:password]
252: 
253:         url = URLS[parameters['PAYID'] ? :maintenance : :order] % [test? ? "test" : "prod"]
254:         response = parse(ssl_post(url, post_data(action, parameters)))
255: 
256:         options = {
257:           :authorization => [response["PAYID"], action].join(";"),
258:           :test          => test?,
259:           :avs_result    => { :code => AVS_MAPPING[response["AAVCheck"]] },
260:           :cvv_result    => CVV_MAPPING[response["CVCCheck"]]
261:         }
262:         Response.new(successful?(response), message_from(response), response, options)
263:       end
convert_attributes_to_hash(rexml_attributes) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 321
321:       def convert_attributes_to_hash(rexml_attributes)
322:         response_hash = {}
323:         rexml_attributes.each do |key, value|
324:           response_hash[key] = value
325:         end
326:         response_hash
327:       end
format_error_message(message) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 277
277:       def format_error_message(message)
278:         raw_message = message.to_s.strip
279:         case raw_message
280:         when /\|/
281:           raw_message.split("|").join(", ").capitalize
282:         when /\//
283:           raw_message.split("/").first.to_s.capitalize
284:         else
285:           raw_message.to_s.capitalize
286:         end
287:       end
message_from(response) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 269
269:       def message_from(response)
270:         if successful?(response)
271:           SUCCESS_MESSAGE
272:         else
273:           format_error_message(response["NCERRORPLUS"])
274:         end
275:       end
parse(body) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 243
243:       def parse(body)
244:         xml_root = REXML::Document.new(body).root
245:         convert_attributes_to_hash(xml_root.attributes)
246:       end
perform_non_referenced_credit(money, payment_target, options = {}) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 178
178:       def perform_non_referenced_credit(money, payment_target, options = {})
179:         # Non-referenced credit: acts like a reverse purchase
180:         post = {}
181:         add_invoice(post, options)
182:         add_payment_source(post, payment_target, options)
183:         add_address(post, payment_target, options)
184:         add_customer_data(post, options)
185:         add_money(post, money, options)
186:         commit('RFD', post)
187:       end
perform_reference_credit(money, payment_target, options = {}) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 171
171:       def perform_reference_credit(money, payment_target, options = {})
172:         post = {}
173:         add_authorization(post, reference_from(payment_target))
174:         add_money(post, money, options)
175:         commit('RFD', post)
176:       end
post_data(action, parameters = {}) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 289
289:       def post_data(action, parameters = {})
290:         add_pair parameters, 'Operation', action
291:         @options[:signature] ? add_signature(parameters) : deprecated(OGONE_NO_SIGNATURE_DEPRECATION_MESSAGE)
292:         parameters.to_query
293:       end
reference_from(authorization) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 161
161:       def reference_from(authorization)
162:         authorization.split(";").first
163:       end
reference_transaction?(identifier) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 165
165:       def reference_transaction?(identifier)
166:         return false unless identifier.is_a?(String)
167:         reference, action = identifier.split(";")
168:         !action.nil?
169:       end
successful?(response) click to toggle source
     # File lib/active_merchant/billing/gateways/ogone.rb, line 265
265:       def successful?(response)
266:         response["NCERROR"] == "0"
267:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.