Class: ActiveMerchant::Billing::BraspagGateway

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BraspagGateway

Returns a new instance of BraspagGateway.



4
5
6
# File 'lib/active_merchant/billing/gateways/braspag.rb', line 4

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

Instance Method Details

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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/active_merchant/billing/gateways/braspag.rb', line 29

def authorize(money, creditcard, options = {})
  order_options = {
    :merchantId => merchant_id,
    :orderId => options[:order_id],
    :customerName => full_name_from(creditcard),
    :amount => format_amount(options[:subtotal]),
    :paymentMethod => code_for_brand_of(creditcard),
    :holder => full_name_from(creditcard),
    :cardNumber => creditcard.number,
    :expiration => format_expiration_from(creditcard),
    :securityCode => creditcard.verification_value,
    :numberPayments => 1,
    :typePayment => 0
  }

  authorize_response = gateway.authorize! order_options
  debugger
  if success?(authorize_response)
    capture_response =  gateway.capture! :merchantId => merchant_id, :orderId => options[:order_id] if success?(authorize_response)
    Response.new success?(authorize_response), capture_response['message'], { :transaction_id => authorize_response['transactionId'] }, :authorization => authorize_response['authorisationNumber']
  else
    Response.new false, authorize_response['message']
  end                                      
end

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_merchant/billing/gateways/braspag.rb', line 8

def purchase(money, creditcard, options = {})
  full_name = full_name_from creditcard
  authorize_response = gateway.authorize! :merchantId => merchant_id,
                                :orderId => options[:order_id],
                                :customerName => full_name,
                                :amount => format_amount(options[:subtotal]),
                                :paymentMethod => code_for_brand_of(creditcard),
                                :holder => full_name,
                                :cardNumber => creditcard[:number],
                                :expiration => format_expiration_from(creditcard),
                                :securityCode => creditcard[:verification_value],
                                :numberPayments => 1,
                                :typePayment => 0
  if success?(authorize_response)
    capture_response =  gateway.capture! :merchantId => merchant_id, :orderId => options[:order_id] if success?(authorize_response)
    Response.new success?(authorize_response), capture_response['message'], { :transaction_id => authorize_response['transactionId'] }, :authorization => authorize_response['authorisationNumber']
  else
    Response.new false, authorize_response['message']
  end
end