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.
- .endpoint(type) ⇒ Object
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
55 56 57 58 59 60 61 |
# File 'lib/getnet_api/payment.rb', line 55 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
90 91 92 93 94 95 96 |
# File 'lib/getnet_api/payment.rb', line 90 def self.create(payment, obj, type) hash = payment.to_request(obj, type) response = build_request(endpoint(type), "post", hash) JSON.parse(response.read_body) end |
.endpoint(type) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/getnet_api/payment.rb', line 98 def self.endpoint type if type == :boleto "payments/boleto" elsif type == :credit "payments/credit" elsif type == :pix "payments/qrcode/pix" end end |
Instance Method Details
#to_request(obj, type) ⇒ Object
Montar o Hash de dados do usuario no padrão utilizado pela Getnet
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/getnet_api/payment.rb', line 64 def to_request obj, type payment = { seller_id: GetnetApi.seller_id.to_s, amount: amount.to_i, currency: currency.to_s, order: order.to_request, customer: customer.to_request(:payment) } if type == :boleto || type == :credit payment[:order] = order.to_request payment[:customer] = customer.to_request(:payment) end if type == :boleto payment[:boleto] = obj.to_request elsif type == :credit payment[:credit] = obj.to_request elsif type == :pix payment.merge!(obj.to_request) end payment end |