Class: GetnetApi::Payment
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/getnet_api/payment.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
amount integer Required Valor da compra em centavos.
-
#currency ⇒ Object
Definir moeda usada.
-
#customer ⇒ Object
Objeto do tipo GetnetApi::Customer.
-
#order ⇒ Object
Objeto do tipo GetnetApi::Order.
Class Method Summary collapse
-
.create(payment, obj, type) ⇒ Object
a = GetnetApi::Payment.create pagamento, boleto, :boleto.
Instance Method Summary collapse
-
#initialize(campos = {}) ⇒ Payment
constructor
Nova instancia da classe Cliente.
-
#to_request(obj, type) ⇒ Object
Montar o Hash de dados do usuario no padrão utilizado pela Getnet.
Methods inherited from Base
build_request, default_headers, get_token_de_bearer, valid_bearer
Constructor Details
#initialize(campos = {}) ⇒ Payment
Nova instancia da classe Cliente
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
#amount ⇒ Object
amount integer Required Valor da compra em centavos.
10 11 12 |
# File 'lib/getnet_api/payment.rb', line 10 def amount @amount end |
#currency ⇒ Object
Definir moeda usada
15 16 17 |
# File 'lib/getnet_api/payment.rb', line 15 def currency @currency end |
#customer ⇒ Object
Objeto do tipo GetnetApi::Customer
21 22 23 |
# File 'lib/getnet_api/payment.rb', line 21 def customer @customer end |
#order ⇒ Object
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 |