Module: Quaderno::Behavior::Payment::InstanceMethods
- Includes:
- Helpers::Authentication
- Defined in:
- lib/quaderno-ruby/behavior/payment.rb
Instance Method Summary collapse
Methods included from Helpers::Authentication
Instance Method Details
#add_payment(params = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/quaderno-ruby/behavior/payment.rb', line 11 def add_payment(params = {}) if (params.keys.map(&:to_s) & %w(auth_token access_token api_url mode api_model)).any? self.authentication_data = get_authentication(params.merge(api_model: api_model)) params = params.dup.delete_if { |k, _| %w(auth_token access_token api_url mode api_model).include? k.to_s } end response = api_model.post("#{authentication_data[:url]}#{api_model.api_path}/#{id}/payments.json", body: params, basic_auth: authentication_data[:basic_auth], headers: self.class.default_headers.merge(authentication_data[:headers]) ) 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 instance.rate_limit_info = response instance end |
#remove_payment(payment_id, options = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/quaderno-ruby/behavior/payment.rb', line 33 def remove_payment(payment_id, = nil) self.authentication_data = get_authentication(.merge(api_model: api_model)) if .is_a?(Hash) response = HTTParty.delete("#{authentication_data[:url]}#{api_model.api_path}/#{id}/payments/#{payment_id}.json", basic_auth: authentication_data[:basic_auth], headers: self.class.default_headers.merge(authentication_data[:headers]) ) api_model.check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true }) self.payments.delete_if { |payment| payment.id == payment_id } hash = { deleted: true, id: payment_id} object = Quaderno::Payment.new(hash) object.rate_limit_info = response object end |