Module: Jamm::Payment

Defined in:
lib/jamm/payment.rb

Class Method Summary collapse

Class Method Details

.get(charge_id) ⇒ Object



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

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



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/jamm/payment.rb', line 49

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

.off_session(customer:, charge:) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/jamm/payment.rb', line 30

def self.off_session(customer:, charge:)
  request = Jamm::OpenAPI::OffSessionPaymentRequest.new(
    customer: customer,
    charge: charge
  )

  Jamm::OpenAPI::PaymentApi.new(Jamm::Client.handler).off_session_payment(request)
rescue Jamm::OpenAPI::ApiError => e
  raise Jamm::ApiError.from_error(e)
end

.on_session(charge:, redirect: nil, customer: nil, buyer: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jamm/payment.rb', line 10

def self.on_session(charge:, redirect: nil, customer: nil, buyer: nil)
  request = if customer.nil?
              Jamm::OpenAPI::OnSessionPaymentRequest.new(
                buyer: buyer,
                charge: charge,
                redirect: redirect
              )
            else
              Jamm::OpenAPI::OnSessionPaymentRequest.new(
                customer: customer,
                charge: charge,
                redirect: redirect
              )
            end

  Jamm::OpenAPI::PaymentApi.new(Jamm::Client.handler).on_session_payment(request)
rescue Jamm::OpenAPI::ApiError => e
  raise Jamm::ApiError.from_error(e)
end