Class: SolidusBolt::Payments::CaptureSyncService

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/solidus_bolt/payments/capture_sync_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

call

Constructor Details

#initialize(payment:, capture_amount:) ⇒ CaptureSyncService

Returns a new instance of CaptureSyncService.



8
9
10
11
12
# File 'app/services/solidus_bolt/payments/capture_sync_service.rb', line 8

def initialize(payment:, capture_amount:)
  @payment = payment
  @capture_amount = capture_amount
  super
end

Instance Attribute Details

#capture_amountObject (readonly)

Returns the value of attribute capture_amount.



6
7
8
# File 'app/services/solidus_bolt/payments/capture_sync_service.rb', line 6

def capture_amount
  @capture_amount
end

#paymentObject (readonly)

Returns the value of attribute payment.



6
7
8
# File 'app/services/solidus_bolt/payments/capture_sync_service.rb', line 6

def payment
  @payment
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
# File 'app/services/solidus_bolt/payments/capture_sync_service.rb', line 14

def call
  return if payment.completed?

  amount = Money.new(capture_amount).to_d

  payment.capture_events.create!(amount: amount)
  payment.update!(amount: amount, state: 'completed')
end