Sha256: d1f0cbfa4fcb37a5fb34a96c0950319241d27d8ccd1846ae9016e3fb7f44cb2f

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

module Quaderno
  module Behavior
    module Payment
      def self.included(base)
        base.send :include, InstanceMethods
      end

      module InstanceMethods

        def add_payment(params)
          response = api_model.post "#{api_model.url}#{ api_model.api_path }/#{ id }/payments.json", body: params, basic_auth: { username: api_model.auth_token }, headers: self.class.version_header
          api_model.check_exception_for(response, { rate_limit: true, subdomain_or_token: true, required_fields: true })

          instance = Quaderno::Payment.new(response.parsed_response)
          self.payments << instance

          Quaderno::Payment.new instance
        end

        def remove_payment(payment_id)
          response = HTTParty.delete "#{api_model.url}#{ api_model.api_path }/#{ id }/payments/#{ payment_id }.json", basic_auth: { username: api_model.auth_token }, headers: self.class.version_header
          api_model.check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true })

          self.payments.delete_if { |payment| payment.id == payment_id }

          true
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
quaderno-1.11.2 lib/quaderno-ruby/behavior/payment.rb
quaderno-1.11.1 lib/quaderno-ruby/behavior/payment.rb
quaderno-1.11.0 lib/quaderno-ruby/behavior/payment.rb
quaderno-1.10.0 lib/quaderno-ruby/behavior/payment.rb
quaderno-1.9.2 lib/quaderno-ruby/behavior/payment.rb