Class: VendorsService::PaymentService

Inherits:
BaseOperationService show all
Includes:
DefaultErrorContainer
Defined in:
app/services/vendors_service/payment_service.rb

Overview

Service for handle payment from vendor

Instance Attribute Summary collapse

Attributes inherited from BaseOperationService

#outcome

Instance Method Summary collapse

Methods included from DefaultErrorContainer

#error, #error_message_simple, #merge_errors

Methods inherited from BaseOperationService

#success?

Constructor Details

#initialize(reservation) ⇒ PaymentService

Returns a new instance of PaymentService.



10
11
12
# File 'app/services/vendors_service/payment_service.rb', line 10

def initialize(reservation)
  @reservation = reservation
end

Instance Attribute Details

#reservationObject (readonly)

Returns the value of attribute reservation.



8
9
10
# File 'app/services/vendors_service/payment_service.rb', line 8

def reservation
  @reservation
end

Instance Method Details

#create(vendor_payment_attributes) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/vendors_service/payment_service.rb', line 14

def create(vendor_payment_attributes)
  omise_source = create_omise_source
  if omise_source.blank?
    errors.add(:base, 'Failed to create new vendor payment omise source')
    return false
  end

  create_vendor_payment!(vendor_payment_attributes)

  omise_payment = create_omise_payment(omise_source.id, vendor_payment_attributes)
  if omise_payment.blank?
    errors.add(:base, 'Failed to create new omise payment')
    return false
  end

  true
end