Sha256: 7fe68ab7cc3dce00dd920ba140f577e9691c509e234898f7e8d955fd329f594d

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'bodega/payment_method/base'

module Bodega
  module PaymentMethod
    class Paypal < Base
      options :username, :password, :signature

      def checkout_url(success_url, cancel_url)
        response = client.setup(request, success_url, cancel_url)
        response.redirect_uri
      end

      def complete!
        response = client.checkout!(
          options[:token],
          options[:PayerID],
          request
        )
        require 'pry'; binding.pry
        response.payment_info.last.transaction_id
      end

      protected
      def client
        ::Paypal.sandbox! if Bodega.config.test_mode
        @client ||= ::Paypal::Express::Request.new(
          username:  Bodega.config.paypal.username,
          password:  Bodega.config.paypal.password,
          signature: Bodega.config.paypal.signature
        )
      end

      def request
        @request ||= ::Paypal::Payment::Request.new(
          amount: order.subtotal.to_f,
          description: order.order_products.map(&:quantity_and_name).to_sentence
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bodega-0.3.0 lib/bodega/payment_method/paypal.rb