Class: GetnetApi::Payment

Inherits:
Base
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/getnet_api/payment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

build_request, default_headers, get_token_de_bearer, valid_bearer

Constructor Details

#initialize(campos = {}) ⇒ Payment

Nova instancia da classe Cliente

Parameters:

  • campos (Hash) (defaults to: {})


66
67
68
69
70
71
72
# File 'lib/getnet_api/payment.rb', line 66

def initialize(campos = {})
  campos.each do |campo, valor|
    if GetnetApi::Payment.public_instance_methods.include? "#{campo}=".to_sym
      send "#{campo}=", valor
    end
  end
end

Instance Attribute Details

#amountObject

amount integer Required Valor da compra em centavos.



10
11
12
# File 'lib/getnet_api/payment.rb', line 10

def amount
  @amount
end

#currencyObject

Definir moeda usada



15
16
17
# File 'lib/getnet_api/payment.rb', line 15

def currency
  @currency
end

#customerObject

Objeto do tipo GetnetApi::Customer



21
22
23
# File 'lib/getnet_api/payment.rb', line 21

def customer
  @customer
end

#orderObject

Objeto do tipo GetnetApi::Order



18
19
20
# File 'lib/getnet_api/payment.rb', line 18

def order
  @order
end

Class Method Details

.create(payment, obj, type) ⇒ Object

a = GetnetApi::Payment.create pagamento, boleto, :boleto



94
95
96
97
98
99
100
101
# File 'lib/getnet_api/payment.rb', line 94

def self.create(payment, obj, type)

  hash = payment.to_request(obj, type)

  response = self.build_request self.endpoint(type), "post", hash

  return JSON.parse(response.read_body)
end

Instance Method Details

#to_request(obj, type) ⇒ Object

Montar o Hash de dados do usuario no padrão utilizado pela Getnet



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/getnet_api/payment.rb', line 75

def to_request obj, type
  payment = {
    seller_id:        GetnetApi.seller_id.to_s,
    amount:           self.amount.to_i,
    currency:         self.currency.to_s,
    order:            self.order.to_request,
    customer:         self.customer.to_request(:payment),
  }

  if type == :boleto
      payment.merge!({"boleto" => obj.to_request,})
  elsif :credit
      payment.merge!({"credit" => obj.to_request,})
  end

  return payment
end