Class: SpreeBoxnow::CancelVoucher

Inherits:
Object
  • Object
show all
Defined in:
app/services/spree_boxnow/cancel_voucher.rb

Defined Under Namespace

Classes: VoucherError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shipment) ⇒ CancelVoucher

Returns a new instance of CancelVoucher.



5
6
7
# File 'app/services/spree_boxnow/cancel_voucher.rb', line 5

def initialize(shipment)
  @shipment = shipment
end

Instance Attribute Details

#shipmentObject (readonly)

Returns the value of attribute shipment.



3
4
5
# File 'app/services/spree_boxnow/cancel_voucher.rb', line 3

def shipment
  @shipment
end

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/services/spree_boxnow/cancel_voucher.rb', line 9

def call
  parcel_id = shipment.tracking
  raise VoucherError, 'No BoxNow parcel ID on this shipment' if parcel_id.blank?

  SpreeBoxnow::ApiClient.new.cancel_parcel(parcel_id)

  shipment.tracking = nil
  shipment..delete('boxnow.vg_child')
  shipment.save!
rescue SpreeBoxnow::ApiClient::ApiError => e
  raise VoucherError, e.message
end