Class: Spree::Payment::GatewayOptions

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/payment/gateway_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payment) ⇒ GatewayOptions

Returns a new instance of GatewayOptions.



4
5
6
7
# File 'app/models/spree/payment/gateway_options.rb', line 4

def initialize(payment)
  @payment = payment
  @order = payment.order
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order.



9
10
11
# File 'app/models/spree/payment/gateway_options.rb', line 9

def order
  @order
end

#paymentObject (readonly)

Returns the value of attribute payment.



9
10
11
# File 'app/models/spree/payment/gateway_options.rb', line 9

def payment
  @payment
end

Instance Method Details

#billing_addressObject



53
54
55
# File 'app/models/spree/payment/gateway_options.rb', line 53

def billing_address
  order.bill_address.try(:active_merchant_hash)
end

#customerObject



17
18
19
# File 'app/models/spree/payment/gateway_options.rb', line 17

def customer
  order.email
end

#customer_idObject



21
22
23
# File 'app/models/spree/payment/gateway_options.rb', line 21

def customer_id
  order.user_id
end

#discountObject



49
50
51
# File 'app/models/spree/payment/gateway_options.rb', line 49

def discount
  order.promo_total * exchange_multiplier
end

#hash_methodsObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/spree/payment/gateway_options.rb', line 61

def hash_methods
  [
    :email,
    :customer,
    :customer_id,
    :ip,
    :order_id,
    :payment_id,
    :shipping,
    :tax,
    :subtotal,
    :discount,
    :currency,
    :billing_address,
    :shipping_address
  ]
end

#ipObject



25
26
27
# File 'app/models/spree/payment/gateway_options.rb', line 25

def ip
  order.last_ip_address
end

#order_idObject



29
30
31
# File 'app/models/spree/payment/gateway_options.rb', line 29

def order_id
  "#{order.number}-#{payment.number}"
end

#payment_idObject



33
34
35
# File 'app/models/spree/payment/gateway_options.rb', line 33

def payment_id
  payment.number
end

#shippingObject



37
38
39
# File 'app/models/spree/payment/gateway_options.rb', line 37

def shipping
  order.ship_total * exchange_multiplier
end

#shipping_addressObject



57
58
59
# File 'app/models/spree/payment/gateway_options.rb', line 57

def shipping_address
  order.ship_address.try(:active_merchant_hash)
end

#statement_descriptor_suffixObject



13
14
15
# File 'app/models/spree/payment/gateway_options.rb', line 13

def statement_descriptor_suffix
  order.number
end

#subtotalObject



45
46
47
# File 'app/models/spree/payment/gateway_options.rb', line 45

def subtotal
  order.item_total * exchange_multiplier
end

#taxObject



41
42
43
# File 'app/models/spree/payment/gateway_options.rb', line 41

def tax
  order.additional_tax_total * exchange_multiplier
end

#to_hashObject



79
80
81
82
83
# File 'app/models/spree/payment/gateway_options.rb', line 79

def to_hash
  Hash[hash_methods.map do |method|
    [method, send(method)]
  end]
end