Module: Jamm::Charge

Defined in:
lib/jamm/charge.rb

Class Method Summary collapse

Class Method Details

.create_with_redirect(customer:, charge:, redirect: nil) ⇒ Object

DEPRECATED, use Jamm::Payment.on_session



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/jamm/charge.rb', line 11

def self.create_with_redirect(customer:, charge:, redirect: nil)
  Jamm::Deprecation.warn('Jamm::Charge.create_with_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

DEPRECATED, use Jamm::Payment.off_session



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jamm/charge.rb', line 26

def self.create_without_redirect(customer:, charge:)
  Jamm::Deprecation.warn('Jamm::Charge.create_without_redirect')

  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

DEPRECATED, use Jamm::Payment.get



40
41
42
43
44
45
46
47
48
# File 'lib/jamm/charge.rb', line 40

def self.get(charge_id)
  Jamm::Deprecation.warn('Jamm::Charge.get')

  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

DEPRECATED, use Jamm::Payment.list



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/jamm/charge.rb', line 51

def self.list(customer:, pagination: nil)
  Jamm::Deprecation.warn('Jamm::Charge.list')

  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