Module: Jamm::Charge
- Defined in:
- lib/jamm/charge.rb
Class Method Summary collapse
- .create_with_redirect(customer:, charge:, redirect:) ⇒ Object
- .create_without_redirect(customer:, charge:) ⇒ Object
- .get(charge_id) ⇒ Object
- .list(customer:, pagination: nil) ⇒ Object
Class Method Details
.create_with_redirect(customer:, charge:, redirect:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/jamm/charge.rb', line 10 def self.create_with_redirect(customer:, charge:, redirect:) request = Jamm::OpenAPI::AddChargeRequest.new( customer: customer, charge: charge, redirect: redirect ) Jamm::OpenAPI::PaymentApi.new(Jamm::Client.handler).add_charge(request) rescue Jamm::OpenAPI::ApiError => e raise Jamm::ApiError.from_error(e) end |
.create_without_redirect(customer:, charge:) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jamm/charge.rb', line 22 def self.create_without_redirect(customer:, charge:) request = Jamm::OpenAPI::WithdrawRequest.new( customer: customer, charge: charge ) Jamm::OpenAPI::PaymentApi.new(Jamm::Client.handler).withdraw(request) rescue Jamm::OpenAPI::ApiError => e raise Jamm::ApiError.from_error(e) end |
.get(charge_id) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/jamm/charge.rb', line 33 def self.get(charge_id) Jamm::OpenAPI::PaymentApi.new(Jamm::Client.handler).get_charge(charge_id) rescue Jamm::OpenAPI::ApiError => e return nil if e.code == 404 raise Jamm::ApiError.from_error(e) end |
.list(customer:, pagination: nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/jamm/charge.rb', line 41 def self.list(customer:, pagination: nil) Jamm::OpenAPI::PaymentApi.new(Jamm::Client.handler).get_charges(customer, pagination.nil? ? {} : pagination) rescue Jamm::OpenAPI::ApiError => e if [404].include?(e.code) nil else { charges: [] } end end |