Class: ShopeePayService::RefundInvoice

Inherits:
Base
  • Object
show all
Defined in:
app/services/shopee_pay_service/refund_invoice.rb

Instance Method Summary collapse

Constructor Details

#initialize(reservation, options = {}) ⇒ RefundInvoice

Returns a new instance of RefundInvoice.



8
9
10
11
# File 'app/services/shopee_pay_service/refund_invoice.rb', line 8

def initialize(reservation, options = {})
  @reservation = reservation
  @options = options.reverse_merge(platform_type: 'pc')
end

Instance Method Details

#executeObject



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

def execute
  response = super

  if response.present? && response[:errcode] == 0
    service = CancelReservationService.new(@reservation.id, :admin, { require_reason: true })
    service.cancel_reason = 'Shopee pay refund by admin'
    service.execute
    @reservation.update(refund: true)

    if reservation.by_marketplace? && reservation.tagthai_channel?
      Vendors::TagThai::WebhookWorker.perform_async(@reservation.id, ApiVendorV1::Constants::REFUND)
    end
  end

  response
rescue ShopeePayService::Error
  @reservation.errors.add(:base, 'Sorry, something went wrong')
  false
end