Class: QuickTravel::Payment

Inherits:
Adapter
  • Object
show all
Defined in:
lib/quick_travel/payment.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Adapter

all, belongs_to, create, find, has_many, #to_s, update

Methods included from InitFromHash

#define_readers, #initialize, #to_hash

Class Method Details

.charge_account(booking, payment_options = {}) ⇒ Object



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

def self.(booking, payment_options = {})
  payment_type = booking.

  if payment_type.nil?
    fail ArgumentError, 'Booking not allowed to be paid on account'
  end

  agent_booking_reference = payment_options[:agent_booking_reference]
  amount                  = payment_options[:amount].presence

  options = {
    payment: {
      payment_type_id:   payment_type.id,
      uid:               SecureRandom.hex(16),
      comment:           agent_booking_reference,
      amount:            amount,
      currency_iso_code: 'AUD'
    },
    pay_balance: amount.nil?
  }

  post_and_validate("/api/bookings/#{booking.id}/payments.json", options)
end

Instance Method Details

#payment_typeObject



6
7
8
# File 'lib/quick_travel/payment.rb', line 6

def payment_type
  QuickTravel::PaymentType.find(@payment_type_id)
end