Class: Workarea::Paypal::Setup

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/paypal/setup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order, user, shipping, context) ⇒ Setup

Returns a new instance of Setup.



8
9
10
11
12
13
# File 'app/services/workarea/paypal/setup.rb', line 8

def initialize(order, user, shipping, context)
  @order = order
  @user = user
  @shipping = shipping
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



4
5
6
# File 'app/services/workarea/paypal/setup.rb', line 4

def context
  @context
end

#orderObject (readonly)

Returns the value of attribute order.



4
5
6
# File 'app/services/workarea/paypal/setup.rb', line 4

def order
  @order
end

#shippingObject (readonly)

Returns the value of attribute shipping.



4
5
6
# File 'app/services/workarea/paypal/setup.rb', line 4

def shipping
  @shipping
end

#userObject (readonly)

Returns the value of attribute user.



4
5
6
# File 'app/services/workarea/paypal/setup.rb', line 4

def user
  @user
end

Instance Method Details

#itemsObject



32
33
34
# File 'app/services/workarea/paypal/setup.rb', line 32

def items
  order_items + item_level_discounts + order_level_discounts
end

#paypal_responseObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/workarea/paypal/setup.rb', line 15

def paypal_response
  @paypal_response ||= gateway.setup_authorization(
    order.total_price.cents,
    ip:                request.remote_ip,
    return_url:        context.complete_paypal_url(order.id),
    cancel_return_url: context.cart_url,
    currency:          order.total_price.currency,
    subtotal:          subtotal,
    shipping:          order.shipping_total.cents,
    handling:          0,
    tax:               order.tax_total.cents,
    items:             items,
    shipping_address:  shipping_address,
    order_id:          order.id
  )
end

#redirect_urlObject



49
50
51
# File 'app/services/workarea/paypal/setup.rb', line 49

def redirect_url
  gateway.redirect_url_for(token)
end

#shipping_addressObject



41
42
43
# File 'app/services/workarea/paypal/setup.rb', line 41

def shipping_address
  serialize_address(shipping.try(:address) || user.try(:default_shipping_address))
end

#subtotalObject



36
37
38
39
# File 'app/services/workarea/paypal/setup.rb', line 36

def subtotal
  order.subtotal_price.cents +
    order.price_adjustments.adjusting('order').discounts.sum.cents
end

#tokenObject



45
46
47
# File 'app/services/workarea/paypal/setup.rb', line 45

def token
  paypal_response.token
end