Sha256: da41a963ec2d61a7208117b5fcb9eff7e6e89b52ee88a83238ad44da3424dad6

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

module Workarea
  module GlobalE
    module Api
      class PerformOrderPayment
        attr_reader :order, :merchant_order

        def initialize(order, merchant_order)
          @order = order
          @merchant_order = merchant_order
        end

        def response
          @response ||=
            begin
              order.global_e_approve!
              update_payment
              update_fulfillment
              Workarea::GlobalE::Merchant::ResponseInfo.new(order: order)
            end
        end

        private

          def update_fulfillment
            fulfillment.update_attributes(
              global_e_tracking_url: merchant_order.international_details&.order_tracking_url
            )
          end

          def fulfillment
            @fulfillment ||= Fulfillment.find order.id
          end

          def update_payment
            payment.with(write: { w: "majority", j: true }) do
              payment.update_attributes!(global_e_approved_at: Time.current)
            end
          end

          def payment
            @payment ||= Workarea::Payment.find order.id
          end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-global_e-1.3.0 app/services/workarea/global_e/api/perform_order_payment.rb
workarea-global_e-1.2.1 app/services/workarea/global_e/api/perform_order_payment.rb