Sha256: a582d2c087e15bf6f565e1ce0c62eb1470e7a14cd87c7ff84ca286b54d8ec9ee

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

module Workarea
  module Paypal
    class UpdateOrder
      delegate :order, :user, :payment, :shippings, :shipping, to: :@checkout
      delegate :paypal_id, to: :payment, allow_nil: true

      def initialize(checkout)
        @checkout = checkout
      end

      def create
        @create ||= Paypal::CreateOrder.new(@checkout)
      end

      def perform
        return false unless payment.paypal?

        Paypal.gateway.update_order(paypal_id, body: request_body)
      end

      def request_body
        shipping = create.shipping_info

        [
          {
            op: 'replace',
            path: "/purchase_units/@reference_id=='default'/shipping/name",
            value: shipping[:name]
          },
          {
            op: 'replace',
            path: "/purchase_units/@reference_id=='default'/shipping/address",
            value: shipping[:address]
          },
          {
            op: 'replace',
            path: "/purchase_units/@reference_id=='default'/amount",
            value: create.amount
          }
        ]
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
workarea-paypal-3.0.6 app/services/workarea/paypal/update_order.rb
workarea-paypal-3.0.5 app/services/workarea/paypal/update_order.rb
workarea-paypal-3.0.4 app/services/workarea/paypal/update_order.rb
workarea-paypal-3.0.3 app/services/workarea/paypal/update_order.rb
workarea-paypal-3.0.2 app/services/workarea/paypal/update_order.rb
workarea-paypal-3.0.1 app/services/workarea/paypal/update_order.rb
workarea-paypal-3.0.0 app/services/workarea/paypal/update_order.rb