Class: ActivePayment::Models::Sale

Inherits:
Object
  • Object
show all
Defined in:
lib/active_payment/models/sale.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payable:, payer:, payee:) ⇒ Sale

Returns a new instance of Sale.



6
7
8
9
10
# File 'lib/active_payment/models/sale.rb', line 6

def initialize(payable:, payer:, payee:)
  @payable = payable
  @payer = payer
  @payee = payee
end

Instance Attribute Details

#payableObject

Returns the value of attribute payable.



4
5
6
# File 'lib/active_payment/models/sale.rb', line 4

def payable
  @payable
end

#payeeObject

Returns the value of attribute payee.



4
5
6
# File 'lib/active_payment/models/sale.rb', line 4

def payee
  @payee
end

#payerObject

Returns the value of attribute payer.



4
5
6
# File 'lib/active_payment/models/sale.rb', line 4

def payer
  @payer
end

Instance Method Details

#amountObject



12
13
14
# File 'lib/active_payment/models/sale.rb', line 12

def amount
  payable.amount.to_f / 100
end

#amount_in_centsObject



16
17
18
# File 'lib/active_payment/models/sale.rb', line 16

def amount_in_cents
  payable.amount.to_i
end

#descriptionObject



20
21
22
# File 'lib/active_payment/models/sale.rb', line 20

def description
  payable.description
end

#paypal_hashObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/active_payment/models/sale.rb', line 40

def paypal_hash
  {
    description: payable.description,
    invoice_data: {
      item: [{
        name: payable.description,
        item_count: 1,
        item_price: amount,
        price: amount
      }],
      total_shipping: payable.shipping,
      total_tax: payable.tax
    },
    receiver: {
      email: @payee.paypal_identifier
    }
  }
end

#paypal_recipientObject



32
33
34
35
36
37
38
# File 'lib/active_payment/models/sale.rb', line 32

def paypal_recipient
  {
    email: payee.paypal_identifier,
    amount: amount,
    primary: false
  }
end

#shippingObject



24
25
26
# File 'lib/active_payment/models/sale.rb', line 24

def shipping
  payable.shipping || 0
end

#taxObject



28
29
30
# File 'lib/active_payment/models/sale.rb', line 28

def tax
  payable.tax || 0
end