class ActiveMerchant::Billing::CertoDirectGateway
Public Class Methods
Creates a new CertoDirectGateway
The gateway requires that a valid login and password be passed in the options
hash.
Options¶ ↑
-
:login
– The CertoDirect Shop ID (REQUIRED) -
:password
– The CertoDirect Shop Password. (REQUIRED) -
:test
–true
orfalse
. If true, perform transactions against the test server. Otherwise, perform transactions against the production server.
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 27 def initialize(options = {}) requires!(options, :login, :password) super end
Public Instance Methods
Captures the funds from an authorized transaction.
Parameters¶ ↑
-
money
– The amount to be captured as an Integer value in cents. -
identification
– The authorization returned from the previous authorize request.
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 81 def capture(money, identification, options = {}) commit(build_capture_request(money, identification)) end
Perform a purchase, which is essentially an authorization and capture in a single operation.
Parameters¶ ↑
-
money
– The amount to be purchased as an Integer value in cents. -
credit_card
– TheCreditCard
details for the transaction. -
options
– A hash of optional parameters.
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 39 def purchase(money, credit_card, options = {}) requires!(options, :email, :currency, :ip, :description) commit(build_sale_request(money, credit_card, options)) end
Create a recurring payment.
Parameters¶ ↑
-
options
– A hash of parameters.
Options¶ ↑
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 103 def recurring(identification, options={}) ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE commit(build_recurring_request(identification, options)) end
Refund a transaction.
This transaction indicates to the gateway that money should flow from the merchant to the customer.
Parameters¶ ↑
-
money
– The amount to be credited to the customer as an Integer value in cents. -
identification
– The ID of the original order against which the refund is being issued. -
options
– A hash of parameters.
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 55 def refund(money, identification, options = {}) requires!(options, :reason) commit(build_refund_request(money, identification, options)) end
Void a previous transaction
Parameters¶ ↑
-
money
– The amount to be captured as an Integer value in cents. -
identification
- The authorization returned from the previous authorize request.
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 91 def void(money, identification, options = {}) commit(build_void_request(money, identification)) end
Private Instance Methods
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 217 def add_address(xml, address_type, address) xml.tag! address_type do xml.tag! 'address', address[:address1] xml.tag! 'city', address[:city] xml.tag! 'country', address[:country] xml.tag! 'first_name', address[:first_name] xml.tag! 'last_name', address[:last_name] xml.tag! 'state', address[:state] xml.tag! 'phone', address[:phone] xml.tag! 'zip', address[:zip] end end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 179 def add_order(xml, money, credit_card, options) xml.tag! 'order' do xml.tag!('test', 'true') if test? xml.tag!('return_url', options[:return_url]) if options[:return_url] xml.tag!('cancel_url', options[:cancel_url]) if options[:cancel_url] xml.tag! 'payment_method_type', 'CreditCard' xml.tag! 'payment_method' do xml.tag! 'number', credit_card.number xml.tag! 'exp_month', "%02i" % credit_card.month xml.tag! 'exp_year', credit_card.year xml.tag! 'holder', credit_card.name xml.tag! 'verification_value', credit_card.verification_value end add_order_details(xml, money, options) add_address(xml, 'billing_address', options[:billing_address]) if options[:billing_address] add_address(xml, 'shipping_address', options[:shipping_address]) if options[:shipping_address] end end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 201 def add_order_details(xml, money, options) xml.tag! 'details' do xml.tag!('amount', localized_amount(money, options[:currency]), :type => 'decimal') if money xml.tag!('currency', options[:currency]) if options[:currency] xml.tag!('email', options[:email]) if options[:email] xml.tag!('ip', options[:ip]) if options[:ip] xml.tag!('shipping', options[:shipping], :type => 'decimal') if options[:shipping] xml.tag!('description', options[:description]) if options[:description] end end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 212 def add_reference_info(xml, money, identification, options) xml.tag! 'order_id', identification, :type => 'integer' xml.tag! 'amount', localized_amount(money, options[:currency]), :type => 'decimal' end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 273 def basic_auth 'Basic ' + ["#{@options[:login]}:#{@options[:password]}"].pack('m').delete("\r\n") end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 145 def build_capture_request(money, identification) build_request_xml('Capture') do |xml| add_reference_info(xml, money, identification, options) end end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 157 def build_recurring_request(identification, options) build_request_xml('Sale') do |xml| xml.tag! 'order' do xml.tag!('test', 'true') if test? xml.tag! 'initial_order_id', identification, :type => 'integer' add_order_details(xml, options[:amount], options) if has_any_order_details_key?(options) add_address(xml, 'billing_address', options[:billing_address]) if options[:billing_address] add_address(xml, 'shipping_address', options[:shipping_address]) if options[:shipping_address] end end end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 138 def build_refund_request(money, identification, options) build_request_xml('Refund') do |xml| add_reference_info(xml, money, identification, options) xml.tag! 'reason', options[:reason] end end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 170 def build_request_xml(type, &block) xml = Builder::XmlMarkup.new(:indent => 2) xml.tag! 'transaction' do xml.tag! 'type', type yield(xml) end xml.target! end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 126 def build_sale_request(money, credit_card, options) build_request_xml('Sale') do |xml| add_order(xml, money, credit_card, options) end end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 151 def build_void_request(money, identification) build_request_xml('Void') do |xml| add_reference_info(xml, money, identification, options) end end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 111 def commit(request_xml) begin response = Hash.from_xml(ssl_post(self.live_url, request_xml, headers)) Response.new(success?(response), message(response), response, :test => test?, :authorization => authorization(response)) rescue ResponseError => e raise e unless e.response.code == '403' response = Hash.from_xml(e.response.body)['response'] Response.new(false, message(response), {}, :test => test?) end end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 241 def error?(response) response['errors'] end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 230 def has_any_order_details_key?(options) [ :currency, :amount, :email, :ip, :shipping, :description ].any? do |key| options.has_key?(key) end end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 267 def headers { 'authorization' => basic_auth, 'Accept' => 'application/xml', 'Content-Type' => 'application/xml' } end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 257 def message(response) return response['errors'].join('; ') if error?(response) if state(response) == 'completed' response["transaction"]["response"]["message"] else response['transaction']['message'] end end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 245 def state(response) response["transaction"].try(:[], "state") end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 249 def status(response) response['transaction'].try(:[], 'response').try(:[], 'status') end
# File lib/active_merchant/billing/gateways/certo_direct.rb, line 236 def success?(response) %w(completed forwarding).include?(state(response)) and status(response) == 'success' end