Class: AnPostReturn::Resources::ReturnLabelResource

Inherits:
Object
  • Object
show all
Defined in:
lib/an_post_return/resources/return_label_resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ReturnLabelResource

Returns a new instance of ReturnLabelResource.



7
8
9
# File 'lib/an_post_return/resources/return_label_resource.rb', line 7

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/an_post_return/resources/return_label_resource.rb', line 5

def client
  @client
end

Instance Method Details

#create(params) ⇒ AReturnLabel

Create a return label

Examples:

Create a domestic return label

client.return_labels.create({
  output_response_type: "Label",
  sender: {
    first_name: "Jane",
    last_name: "Smith",
    contact_number: "0871234567",
    email_address: "[email protected]"
  },
  sender_address: {
    address_line1: "Exo Building",
    address_line2: "North Wall Quay",
    city: "Dublin 1",
    eircode: "D01 W5Y2",
    county: "Dublin",
    country: "Ireland",
    countrycode: "IE"
  },
  retailer_account_no: "your_account_number",
  retailer_return_reason: "Does not fit",
  retailer_order_number: "987654321"
})

Create an EU return label

client.return_labels.create({
  output_response_type: "Label",
  sender: { ... },
  sender_address: { ... },
  international_security_declaration_items: [
    { item_description: "book" }
  ],
  retailer_account_no: "your_account_number",
  retailer_return_reason: "Does not fit",
  retailer_order_number: "123456789"
})

Create a non-EU return label

client.return_labels.create({
  customs_information: {
    customs_region_code: "1",
    customs_category_id: 2,
    weight: 1.5,
    value_amount: 55,
    postage_fee_paid: 1,
    insured_value: 55,
    customs_content_items: [
      {
        list_order: 1,
        number_of_units: 1,
        description: "shoes",
        hs_tarriff: "6404191000",
        value_amount: 55,
        weight: 1.5,
        country_of_origin: "IE"
      }
    ]
  },
  output_response_type: "Label",
  sender: { ... },
  sender_address: { ... },
  retailer_account_no: "your_account_number",
  retailer_return_reason: "Does not fit",
  retailer_order_number: "321654987"
})

Parameters:

  • params (Hash)

    The parameters for creating a return label

Options Hash (params):

  • :output_response_type (String)

    Type of response (‘Label’)

  • :sender (Hash)

    Sender information @option sender [String] :first_name Sender’s first name @option sender [String] :last_name Sender’s last name @option sender [String] :contact_number Sender’s contact number @option sender [String] :email_address Sender’s email address

  • :sender_address (Hash)

    Sender’s address details @option sender_address [String] :address_line1 First line of address @option sender_address [String] :address_line2 Second line of address (optional) @option sender_address [String] :city City @option sender_address [String] :eircode Eircode @option sender_address [String] :county County @option sender_address [String] :country Country name @option sender_address [String] :countrycode Country code (ISO 3166-1 alpha-2)

  • :retailer_account_no (String)

    Your An Post account number

  • :retailer_return_reason (String)

    Reason for return

  • :retailer_order_number (String)

    Order number

  • :international_security_declaration_items (Array<Hash>)

    Required for EU returns @option international_security_declaration_items [String] :item_description Description of item

  • :customs_information (Hash)

    Required for non-EU returns @option customs_information [String] :customs_region_code Customs region code @option customs_information [Integer] :customs_category_id Category ID @option customs_information [Float] :weight Weight in kg @option customs_information [Float] :value_amount Value amount @option customs_information [Float] :postage_fee_paid Postage fee paid @option customs_information [Float] :insured_value Insured value @option customs_information [Array<Hash>] :customs_content_items Content items for customs

    @option customs_content_items [Integer] :list_order Order in list
    @option customs_content_items [Integer] :number_of_units Number of units
    @option customs_content_items [String] :description Item description
    @option customs_content_items [String] :hs_tarriff HS tariff code
    @option customs_content_items [Float] :value_amount Item value
    @option customs_content_items [Float] :weight Item weight
    @option customs_content_items [String] :country_of_origin Country of origin code
    

Returns:

  • (AReturnLabel)

    The created return label data

Raises:

  • (ArgumentError)


113
114
115
116
117
118
119
120
# File 'lib/an_post_return/resources/return_label_resource.rb', line 113

def create(params)
  raise ArgumentError, "Missing required parameters" if params.nil?
  raise ArgumentError, "Subscription key not configured" if client.config.subscription_key.nil?

  response = client.connection.post("returnsLabel") { |req| req.body = params }
  response_data = client.send(:handle_response, response)
  ReturnLabel.new(response_data)
end