Class: Workarea::Paypal::Setup
- Inherits:
-
Object
- Object
- Workarea::Paypal::Setup
- Defined in:
- app/services/workarea/paypal/setup.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#shipping ⇒ Object
readonly
Returns the value of attribute shipping.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(order, user, shipping, context) ⇒ Setup
constructor
A new instance of Setup.
- #items ⇒ Object
- #paypal_response ⇒ Object
- #redirect_url ⇒ Object
- #shipping_address ⇒ Object
- #subtotal ⇒ Object
- #token ⇒ Object
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
#context ⇒ Object (readonly)
Returns the value of attribute context.
4 5 6 |
# File 'app/services/workarea/paypal/setup.rb', line 4 def context @context end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
4 5 6 |
# File 'app/services/workarea/paypal/setup.rb', line 4 def order @order end |
#shipping ⇒ Object (readonly)
Returns the value of attribute shipping.
4 5 6 |
# File 'app/services/workarea/paypal/setup.rb', line 4 def shipping @shipping end |
#user ⇒ Object (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
#items ⇒ Object
32 33 34 |
# File 'app/services/workarea/paypal/setup.rb', line 32 def items order_items + item_level_discounts + order_level_discounts end |
#paypal_response ⇒ Object
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.( 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_url ⇒ Object
49 50 51 |
# File 'app/services/workarea/paypal/setup.rb', line 49 def redirect_url gateway.redirect_url_for(token) end |
#shipping_address ⇒ Object
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 |
#subtotal ⇒ Object
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 |
#token ⇒ Object
45 46 47 |
# File 'app/services/workarea/paypal/setup.rb', line 45 def token paypal_response.token end |