Class: Workarea::FlowIo::Checkout
- Inherits:
-
Object
- Object
- Workarea::FlowIo::Checkout
- Includes:
- ApplicationHelper
- Defined in:
- app/services/workarea/flow_io/checkout.rb
Instance Attribute Summary collapse
-
#flow_order ⇒ Object
readonly
Returns the value of attribute flow_order.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(flow_order, order) ⇒ Checkout
constructor
A new instance of Checkout.
- #place_order ⇒ Object
Constructor Details
#initialize(flow_order, order) ⇒ Checkout
Returns a new instance of Checkout.
11 12 13 14 |
# File 'app/services/workarea/flow_io/checkout.rb', line 11 def initialize(flow_order, order) @order = order @flow_order = flow_order end |
Instance Attribute Details
#flow_order ⇒ Object (readonly)
Returns the value of attribute flow_order.
6 7 8 |
# File 'app/services/workarea/flow_io/checkout.rb', line 6 def flow_order @flow_order end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
6 7 8 |
# File 'app/services/workarea/flow_io/checkout.rb', line 6 def order @order end |
Instance Method Details
#build ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/services/workarea/flow_io/checkout.rb', line 32 def build order.update_attributes!( experience: { key: experience.key, name: experience.name, region: experience.region.to_hash, country: experience.country, currency: experience.currency, language: experience.language, measurement_system: experience.measurement_system }, flow: true, email: customer.email ) FlowIo::PriceApplier.perform(order: pricing_order, flow_order: flow_order, shipping: pricing_shipping) shipping.update_attributes!(pricing_shipping.as_document) # set the shipping service. shipping.set_flow_shipping!(flow_shipping_method) # set the shipping and billing addresses shipping.set_address(shipping_address_params(flow_order.destination)) payment.set_address(billing_address_params(flow_billing_address)) # use the flow payment processor for this order going forward. # this allows for using a differnt payment processor for # domestic orders payment.operation_tender_type = 'FlowPayment' # build a flow payment so we can refund later if needed. flow_payments.each do |flow_payment| payment.build_flow_payment( details: flow_payment.to_hash, payment_type: flow_payment.type, description: flow_payment.description, amount: Money.from_amount(flow_payment.total.base.amount, flow_payments.first.total.base.currency), flow_amount: Money.from_amount(flow_payment.total.amount, flow_payments.first.total.currency) ) end # build a capture transaction for each payment.tenders.each do |tender| response = ActiveMerchant::Billing::Response.new( true, 'Flow Payment Transaction', { response: tender.details } ) transaction = payment.flow_payment.build_transaction( tender_id: tender.id.to_s, action: Workarea.config.flow_io.default_payment_action, amount: tender.amount, flow_amount: tender.flow_amount, success: true, response: response ) transaction.save! end payment.save! total_order order.update_attributes!(pricing_order.as_document.reverse_merge(items: [])) end |
#place_order ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/services/workarea/flow_io/checkout.rb', line 16 def place_order return false unless shipping.valid? return false unless payment.valid? inventory.purchase return false unless inventory.captured? result = order.place if result CreateFulfillment.new(order).perform end result end |