Class: SpreeBoxnow::CancelVoucher
- Inherits:
-
Object
- Object
- SpreeBoxnow::CancelVoucher
- Defined in:
- app/services/spree_boxnow/cancel_voucher.rb
Defined Under Namespace
Classes: VoucherError
Instance Attribute Summary collapse
-
#shipment ⇒ Object
readonly
Returns the value of attribute shipment.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(shipment) ⇒ CancelVoucher
constructor
A new instance of CancelVoucher.
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
#shipment ⇒ Object (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
#call ⇒ Object
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. end |