app/controllers/spree/api/retailops/settlement_controller.rb
# Package adding: This reflects a fairly major impedence mismatch
# between ROP and Spree, insofar as Spree wants to create shipments at
# checkout time and charge exact shipping, while ROP standard practice
# is to charge an abstraction of shipping that's close enough on
# average, and then decide the details of how this order will be
# shipped when it's actually ready to go out the door.  Because of this
# we have to fudge stuff a bit on shipment and recreate the Spree
# shipments to reflect how ROP is actually shipping it, so that the
# customer has the most actionable information.  A complication is that
# Spree's shipping rates are tied to the shipment, and need to be
# converted into order adjustments before we start mangling the
# shipments.  Credit where due: this code is heavily inspired by some
# code written by @schwartzdev for @dotandbo to handle an Ordoro
# integration.
Package adding: This reflects a fairly major impedence mismatch
between ROP and Spree, insofar as Spree wants to create shipments at
checkout time and charge exact shipping, while ROP standard practice
is to charge an abstraction of shipping that's close enough on
average, and then decide the details of how this order will be
shipped when it's actually ready to go out the door.  Because of this
we have to fudge stuff a bit on shipment and recreate the Spree
shipments to reflect how ROP is actually shipping it, so that the
customer has the most actionable information.  A complication is that
Spree's shipping rates are tied to the shipment, and need to be
converted into order adjustments before we start mangling the
shipments.  Credit where due: this code is heavily inspired by some
code written by @schwartzdev for @dotandbo to handle an Ordoro
integration.
Package adding : This reflects a fairly major impedence mismatch between ROP and Spree insofar as Spree wants to create shipments at checkout time and charge exact shipping while ROP standard practice is to charge an abstraction of shipping that ' s close enough on average and then decide the details of how this order will be shipped when it ' s actually ready to go out the door . Because of this we have to fudge stuff a bit on shipment and recreate the Spree shipments to reflect how ROP is actually shipping it so that the customer has the most actionable information . A complication is that Spree ' s shipping rates are tied to the shipment and need to be converted into order adjustments before we start mangling the shipments . Credit where due : this code is heavily inspired by some code written by @schwartzdev for @dotandbo to handle an Ordoro integration .
def partial_settle(cmd)
            @settlement_results = { "errors" => [], "status" => [] }
            bias = cmd['target'] ? BigDecimal.new(cmd['target']) - @order.total : BigDecimal.new(0)
            op = nil
            unless @order.canceled?
              while (cmd["capture"] && options["ok_capture"]) && (@order.outstanding_balance + bias) > 0 && op = pick_payment { |opp| opp.pending? && opp.amount > 0 && opp.amount <= (@order.outstanding_balance + bias) }
                rescue_gateway_error { op.capture! }
              end
              while (cmd["partial_capture"] && options["ok_partial_capture"]) && (@order.outstanding_balance + bias) > 0 && op = pick_payment { |opp| opp.pending? && opp.amount > 0 && opp.amount > (@order.outstanding_balance + bias) }
                op.amount = (@order.outstanding_balance + bias)
                rescue_gateway_error { op.capture! }
              end
              while (cmd["void"] && options["ok_void"]) && (@order.outstanding_balance + bias) <= 0 && op = pick_payment { |opp| opp.pending? && opp.amount > 0 }
                rescue_gateway_error { op.void_transaction! }
              end
              while (cmd["refund"] && options["ok_refund"]) && (@order.outstanding_balance + bias) < 0 && op = pick_payment { |opp| opp.completed? && opp.can_credit? }
                rescue_gateway_error { op.credit! } 
              end
            end
            @order.payments.select{|op| op.amount > 0}.each do |op|
              @settlement_results["status"] << { "id" => op.id, "state" => op.state, "amount" => op.amount, "credit" => op.offsets_total.abs }
            end
          end
def partial_settle ( cmd ) @settlement_results = { "errors" => [ ] , "status" => [ ] } bias = cmd [ 'target' ] ? BigDecimal . new ( cmd [ 'target' ] ) - @order . total : BigDecimal . new ( 0 ) op = nil unless @order . canceled? while ( cmd [ "capture" ] && options [ "ok_capture" ] ) && ( @order . outstanding_balance + bias ) > 0 && op = pick_payment { | opp | opp . pending? && opp . amount > 0 && opp . amount <= ( @order . outstanding_balance + bias ) } rescue_gateway_error { op . capture! } end while ( cmd [ "partial_capture" ] && options [ "ok_partial_capture" ] ) && ( @order . outstanding_balance + bias ) > 0 && op = pick_payment { | opp | opp . pending? && opp . amount > 0 && opp . amount > ( @order . outstanding_balance + bias ) } op . amount = ( @order . outstanding_balance + bias ) rescue_gateway_error { op . capture! } end while ( cmd [ "void" ] && options [ "ok_void" ] ) && ( @order . outstanding_balance + bias ) <= 0 && op = pick_payment { | opp | opp . pending? && opp . amount > 0 } rescue_gateway_error { op . void_transaction! } end while ( cmd [ "refund" ] && options [ "ok_refund" ] ) && ( @order . outstanding_balance + bias ) < 0 && op = pick_payment { | opp | opp . completed? && opp . can_credit? } rescue_gateway_error { op . credit! } end end @order . payments . select { | op | op . amount > 0 } . each do | op | @settlement_results [ "status" ] << { "id" => op . id , "state" => op . state , "amount" => op . amount , "credit" => op . offsets_total . abs } end end
Package adding: This reflects a fairly major impedence mismatch
between ROP and Spree, insofar as Spree wants to create shipments at
checkout time and charge exact shipping, while ROP standard practice
is to charge an abstraction of shipping that's close enough on
average, and then decide the details of how this order will be
shipped when it's actually ready to go out the door.
Package adding : This reflects a fairly major impedence mismatch between ROP and Spree insofar as Spree wants to create shipments at checkout time and charge exact shipping while ROP standard practice is to charge an abstraction of shipping that ' s close enough on average and then decide the details of how this order will be shipped when it ' s actually ready to go out the door .
# Spree 2.2.x allows you to pass an argument to # Spree::Payment#capture! but this does not seem to do quite # what we want.  In particular the payment system treats the # remainder of the payment as pending. # remarkably, THIS one picks the right amount for us # collect payment data
cmd
<not_specific>