Class: ActiveMerchant::Billing::BraspagGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/braspag.rb

Constant Summary collapse

TEST_URL =
'https://homologacao.pagador.com.br/webservice/pagador.asmx'
LIVE_URL =
'https://www.pagador.com.br/webservice/pagador.asmx'
CREDIT_CARD_CODES =

map credit card to the Braspag expected representation

{
  :visa  => 22,
  :master => 23,
  :american_express => 18
}

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, inherited, supports?

Methods included from Utils

#deprecated, generate_unique_id

Methods included from CreditCardFormatting

#format

Methods included from RequiresParameters

#requires!

Methods included from PostsData

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

Constructor Details

#initialize(options = {}) ⇒ BraspagGateway

Creates a new BraspagGateway

The gateway requires that a valid login in the options hash.

Options

  • :login – The Braspag Merchant ID (REQUIRED)

  • :testtrue or false. If true, perform transactions against the test server.

Otherwise, perform transactions against the production server.



30
31
32
33
34
# File 'lib/active_merchant/billing/gateways/braspag.rb', line 30

def initialize(options = {})
  requires!(options, :login)
  @options = options
  super
end

Instance Method Details

#authorize(money, creditcard, options = {}) ⇒ Object

Performs an authorization, which reserves the funds on the customer’s credit card, but does not charge the card.

Parameters

  • money – The amount to be authorized as an Integer value in cents.

  • creditcard – The CreditCard details for the transaction.

Options

* <tt>:order_id</tt> - A unique reference for this order (REQUIRED).


47
48
49
50
51
52
53
54
55
56
# File 'lib/active_merchant/billing/gateways/braspag.rb', line 47

def authorize(money, creditcard, options = {})
  post = PostData.new
  add_invoice(post, options)
  add_amount(post, money)
  add_creditcard(post, money, creditcard)
  add_customer_data(post, creditcard)
  add_extra_data(post)

  commit(:authorize, post)
end

#capture(money, authorization, options = {}) ⇒ Object

Captures the funds from an authorized transaction.

Parameters

  • money – The amount to be captured as an Integer value in cents.

  • authorization - The authorization string returned from the initial authorization

Options

* <tt>:order_id</tt> - A unique reference for this order (REQUIRED).


67
68
69
70
71
72
73
74
75
# File 'lib/active_merchant/billing/gateways/braspag.rb', line 67

def capture(money, authorization, options = {})
  if authorization.success?
    post = PostData.new
    add_invoice(post, options)
    commit(:capture, post)
  else
    authorization
  end
end

#purchase(money, creditcard, options = {}) ⇒ Object

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.

  • creditcard – The CreditCard details for the transaction.

  • options – A hash of optional parameters.



84
85
86
# File 'lib/active_merchant/billing/gateways/braspag.rb', line 84

def purchase(money, creditcard, options = {})
  capture(money, authorize(money, creditcard, options), options)
end

#void(authorization, options = {}) ⇒ Object

Void a transaction.

Parameters

  • authorization - The authorization string returned from the initial authorization or purchase.

Options

* <tt>:order_id</tt> - A unique reference for this order (REQUIRED).


96
97
98
99
100
101
102
103
104
105
# File 'lib/active_merchant/billing/gateways/braspag.rb', line 96

def void(authorization, options = {})
  if authorization.success?
    requires!(options, :order_id)
    post = PostData.new
    post[:order] = options[:order_id]
    commit(:void_transaction, post)
  else
    authorization
  end
end