Skip to content

Instantly share code, notes, and snippets.

@aarvay
Created August 27, 2016 14:40
Show Gist options
  • Save aarvay/7412f70a4de6a2e256bc82130804da1a to your computer and use it in GitHub Desktop.
Save aarvay/7412f70a4de6a2e256bc82130804da1a to your computer and use it in GitHub Desktop.
Anomaly in poison decoder
defmodule Payment do
@derive {Poison.Encoder, except: [:entity, :order_id]}
defstruct [:id, :amount, :currency, :status, :method, :description,
:refund_status, :amount_refunded, :email, :contact, :fee, :service_tax,
:error_code, :error_description, :notes, :created_at]
end
defmodule Collection do
@derive {Poison.Encoder, except: [:entity]}
defstruct [:count, :items]
end
defmodule PoisonAnomaly do
def run do
str = "{\"entity\":\"collection\",\"count\":2,\"items\":[{\"id\":\"fake_id1\",\"entity\":\"payment\",\"amount\":5000,\"currency\":\"INR\",\"status\":\"failed\",\"order_id\":null,\"method\":\"netbanking\",\"amount_refunded\":0,\"refund_status\":null,\"captured\":false,\"description\":\"Purchase Description\",\"card_id\":null,\"bank\":\"HDFC\",\"wallet\":null,\"email\":\"test@test.com\",\"contact\":\"+919123456789\",\"notes\":[],\"fee\":0,\"service_tax\":0,\"error_code\":\"BAD_REQUEST_ERROR\",\"error_description\":\"Payment failed\",\"created_at\":1471720420},{\"id\":\"fake_id2\",\"entity\":\"payment\",\"amount\":5000,\"currency\":\"INR\",\"status\":\"captured\",\"order_id\":null,\"method\":\"netbanking\",\"amount_refunded\":4850,\"refund_status\":\"partial\",\"captured\":true,\"description\":\"Purchase Description\",\"card_id\":null,\"bank\":\"HDFC\",\"wallet\":null,\"email\":\"test@test.com\",\"contact\":\"+919123456789\",\"notes\":[],\"fee\":144,\"service_tax\":19,\"error_code\":null,\"error_description\":null,\"created_at\":1471720235}]}"
Poison.decode!(str, keys: :atoms!, as: %Collection{items: [%Payment{}]})
end
end
PoisonAnomaly.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment