Sha256: ba03decfb63238bc7ec3e0b527dad7c176cf282298f00bc75378fde83168c5b3

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

module Workarea
  module Forter
    module Tender
      class Paypal
        class PaypalDependencyError < StandardError; end
        attr_reader :tender, :options

        def initialize(tender, options = {})
          @tender = tender
          @options = options
        end

        # @return Hash
        def to_h
          raise PaypalDependencyError.new("Paypal plugin not installed but paypal transaction detected") unless Plugin.installed?("Workarea::Paypal")
          {
            paypal: {
              payerId: tender.payer_id,
              fullPaypalResponsePayload: transaction.response.params,
              payerEmail:  tender.details["payer"],
              paymentStatus: transaction.response.params["payment_status"],
              paymentMethod:  transaction.response.params["payment_type"],
              payerAddressStatus: tender.details["address_status"],
              payerStatus: tender.details["payer_status"]
            }
          }
        end

        private

          def transaction
            @transaction ||= tender.transactions.detect { |t| t.success? }
          end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
workarea-forter-1.3.2 app/services/workarea/forter/tender/paypal.rb
workarea-forter-1.3.1 app/services/workarea/forter/tender/paypal.rb
workarea-forter-1.3.0 app/services/workarea/forter/tender/paypal.rb
workarea-forter-1.2.4 app/services/workarea/forter/tender/paypal.rb
workarea-forter-1.2.3 app/services/workarea/forter/tender/paypal.rb