Class: Akatus::Payment
- Inherits:
-
Object
- Object
- Akatus::Payment
- Includes:
- Transferrable
- Defined in:
- lib/akatus/payment.rb
Instance Attribute Summary collapse
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#discount ⇒ Object
Returns the value of attribute discount.
-
#error ⇒ Object
Returns the value of attribute error.
-
#id ⇒ Object
Returns the value of attribute id.
-
#items ⇒ Object
Returns the value of attribute items.
-
#payer ⇒ Object
Returns the value of attribute payer.
-
#payment_method ⇒ Object
Returns the value of attribute payment_method.
-
#receiver ⇒ Object
readonly
Returns the value of attribute receiver.
-
#reference ⇒ Object
Returns the value of attribute reference.
-
#shipping_cost ⇒ Object
Returns the value of attribute shipping_cost.
-
#status ⇒ Object
Returns the value of attribute status.
-
#total_amount ⇒ Object
Returns the value of attribute total_amount.
-
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
-
#url ⇒ Object
Returns the value of attribute url.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Payment
constructor
A new instance of Payment.
- #to_payload ⇒ Object
- #total_discount ⇒ Object
- #total_items_amount ⇒ Object
- #total_shipping_cost ⇒ Object
- #total_weight ⇒ Object
Methods included from Transferrable
Constructor Details
#initialize(opts = {}) ⇒ Payment
Returns a new instance of Payment.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/akatus/payment.rb', line 11 def initialize(opts = {}) = { :items => [], :discount => 0, :shipping_cost => 0, :weight => 0 }.merge(opts) super() @receiver = Receiver.new({ :email => Akatus.config.email, :api_key => Akatus.config.api_key }) end |
Instance Attribute Details
#currency ⇒ Object
Returns the value of attribute currency.
7 8 9 |
# File 'lib/akatus/payment.rb', line 7 def currency @currency end |
#discount ⇒ Object
Returns the value of attribute discount.
7 8 9 |
# File 'lib/akatus/payment.rb', line 7 def discount @discount end |
#error ⇒ Object
Returns the value of attribute error.
7 8 9 |
# File 'lib/akatus/payment.rb', line 7 def error @error end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/akatus/payment.rb', line 7 def id @id end |
#items ⇒ Object
Returns the value of attribute items.
7 8 9 |
# File 'lib/akatus/payment.rb', line 7 def items @items end |
#payer ⇒ Object
Returns the value of attribute payer.
7 8 9 |
# File 'lib/akatus/payment.rb', line 7 def payer @payer end |
#payment_method ⇒ Object
Returns the value of attribute payment_method.
7 8 9 |
# File 'lib/akatus/payment.rb', line 7 def payment_method @payment_method end |
#receiver ⇒ Object (readonly)
Returns the value of attribute receiver.
5 6 7 |
# File 'lib/akatus/payment.rb', line 5 def receiver @receiver end |
#reference ⇒ Object
Returns the value of attribute reference.
7 8 9 |
# File 'lib/akatus/payment.rb', line 7 def reference @reference end |
#shipping_cost ⇒ Object
Returns the value of attribute shipping_cost.
7 8 9 |
# File 'lib/akatus/payment.rb', line 7 def shipping_cost @shipping_cost end |
#status ⇒ Object
Returns the value of attribute status.
7 8 9 |
# File 'lib/akatus/payment.rb', line 7 def status @status end |
#total_amount ⇒ Object
Returns the value of attribute total_amount.
7 8 9 |
# File 'lib/akatus/payment.rb', line 7 def total_amount @total_amount end |
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
7 8 9 |
# File 'lib/akatus/payment.rb', line 7 def transaction_id @transaction_id end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/akatus/payment.rb', line 7 def url @url end |
#weight ⇒ Object
Returns the value of attribute weight.
7 8 9 |
# File 'lib/akatus/payment.rb', line 7 def weight @weight end |
Instance Method Details
#to_payload ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/akatus/payment.rb', line 23 def to_payload hsh = { 'carrinho' => { 'produtos' => { 'produto' => items.map { |i| i.to_payload(false) } }, 'transacao' => { 'peso' => Akatus.format_number(total_weight), 'frete' => Akatus.format_number(total_shipping_cost), 'desconto' => Akatus.format_number(total_discount), 'referencia' => reference, 'moeda' => 'BRL' }.merge(payment_method.to_payload), 'recebedor' => receiver.to_payload(false), 'pagador' => payer.to_payload(false) } } end |
#total_discount ⇒ Object
48 49 50 |
# File 'lib/akatus/payment.rb', line 48 def total_discount discount + items.inject(0) { |sum, item| sum + item.discount } end |
#total_items_amount ⇒ Object
52 53 54 |
# File 'lib/akatus/payment.rb', line 52 def total_items_amount items.inject(0) { |sum, item| sum + item.total_amount } end |
#total_shipping_cost ⇒ Object
44 45 46 |
# File 'lib/akatus/payment.rb', line 44 def total_shipping_cost shipping_cost + items.inject(0) { |sum, item| sum + item.shipping_cost } end |
#total_weight ⇒ Object
40 41 42 |
# File 'lib/akatus/payment.rb', line 40 def total_weight weight + items.inject(0) { |sum, item| sum + item.weight } end |