Sha256: 86192d1a770615425d4b6d8a885a3c22999b01dbf817460a613f15f4899dd668

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

module DHLEcommerceAPI
  class ShipmentDelete < Base
    self.prefix = "/rest/v2/Label/Delete"
    self.element_name = ""

    # Destroy a single shipment
    def self.destroy(shipment_id)
      request_params = delete_shipment_request(shipment_id)

      response = connection.post(collection_path, request_params.to_json, headers)
      
      data = JSON.parse(response.body)      
      data.dig("deleteShipmentResp", "bd", "shipmentItems")&.first
    end
  
    def self.delete_shipment_request(shipment_id)
      {
        "deleteShipmentReq": {
          "hdr": {
            "messageType": "DELETESHIPMENT",
            "messageDateTime": DateTime.now.to_s,
            "accessToken": DHLEcommerceAPI::Authentication.get_token,
            "messageVersion": "1.0"
          },
          "bd": {
            "pickupAccountId": DHLEcommerceAPI.config.pickup_account_id,
            "soldToAccountId": DHLEcommerceAPI.config.sold_to_account_id,
            "shipmentItems": [
              {
                "shipmentID": shipment_id
              }
            ]
          }
        }
      }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dhl_ecommerce_api-0.1.19 lib/dhl_ecommerce_api/resources/shipment_delete.rb
dhl_ecommerce_api-0.1.18 lib/dhl_ecommerce_api/resources/shipment_delete.rb
dhl_ecommerce_api-0.1.17 lib/dhl_ecommerce_api/resources/shipment_delete.rb
dhl_ecommerce_api-0.1.16 lib/dhl_ecommerce_api/resources/shipment_delete.rb