Monkey Patch the Peddler Gem

75 views Asked by At

This gem sends data to Amazon. However, its missing one data element that I need to send. Basically the declared value of the item. I am trying to monkey patch this method to also send the declared value.

The method I'm using inside this gem is create_fulfillment_order here is a link to the method, and the method is also pasted below. What I need to do is change the items struct from this:

(:seller_sku, :seller_fulfillment_order_item_id, :quantity)

to this:

(:seller_sku, :seller_fulfillment_order_item_id, :quantity, :per_unit_declared_value)

And then this is the complete code for the method

def create_fulfillment_order(seller_fulfillment_order_id, displayable_order_id, displayable_order_date_time, displayable_order_comment, shipping_speed_category, destination_address, items, opts = {})
  if opts.key?(:cod_settings)
    opts['CODSettings'] = opts.delete(:cod_settings)
  end

  operation('CreateFulfillmentOrder')
    .add(
      opts.merge(
        'SellerFulfillmentOrderId' => seller_fulfillment_order_id,
        'DisplayableOrderId' => displayable_order_id,
        'DisplayableOrderDateTime' => displayable_order_date_time,
        'DisplayableOrderComment' => displayable_order_comment,
        'ShippingSpeedCategory' => shipping_speed_category,
        'DestinationAddress' => destination_address,
        'Items' => items
      )
    )
    .structure!('Items', 'member')
    .structure!('NotificationEmailList', 'member')

  run
end

I call the method like this:

client = MWS::FulfillmentOutboundShipment::Client.new(
  marketplace_id:        "XXXXXX",
  merchant_id:           "XXXXX",
  aws_access_key_id:     "XXXX",
  aws_secret_access_key: "XXXXX+",
  auth_token:            "XXXXXX")


Address = Struct.new(:name, :line_1, :line_2, :line_3, :city, :state_or_province_code,
                      :country_code, :postal_code)

address = Address.new("Todd T", "19712 50th Ave W", "#5", "", "Lynnwood","WA" ,"US" , "98036" )

Value = Struct.new(:currency_code, :value)

value = Value.new("CAD", "10")

Item = Struct.new(:seller_sku, :seller_fulfillment_order_item_id, :quantity, :per_unit_declard_value)

sku = []
first = Item.new("636391317719", "s2", 1, value)
sku << first

begin
  client.create_fulfillment_order("z536", "z536", Time.now.getutc, "Thank You", "Standard", address, sku)
rescue Exception => e
pp e.response
end

The error I'm getting is The request must contain the parameter PerUnitDeclaredValue.

0

There are 0 answers