Created
January 22, 2016 23:00
-
-
Save imetallica/2d0b20b58f807d44ac63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule PayPal.Transaction do | |
| @moduledoc """ | |
| A Transaction structure. All *fields* are required: | |
| - description: String. (Give a description to the transaction.) | |
| - *ammount*: | |
| - *currency*: String. (A 3-letter currency code. All supported | |
| currencies are listed below.) | |
| - *total*: String. (Total to be charged. 10 characters max with | |
| support for 2 decimal places.) | |
| - details: | |
| - shipping: String. (Amount charged for shipping. 10 characters | |
| max with support for 2 decimal places.) | |
| - subtotal: String. (Amount of the subtotal of the items. | |
| Required if line items are specified. 10 | |
| characters max, with support for 2 decimal | |
| places.) | |
| - tax: String. (Amount charged for tax. 10 characters max | |
| with support for 2 decimal places.) | |
| ## Supported currencies Currency Code | |
| Australian dollar AUD | |
| Brazilian real** BRL | |
| Canadian dollar CAD | |
| Czech koruna CZK | |
| Danish krone DKK | |
| Euro EUR | |
| Hong Kong dollar HKD | |
| Hungarian forint* HUF | |
| Israeli new shekel ILS | |
| Japanese yen* JPY | |
| Malaysian ringgit** MYR | |
| Mexican peso MXN | |
| New Taiwan dollar* TWD | |
| New Zealand dollar NZD | |
| Norwegian krone NOK | |
| Philippine peso PHP | |
| Polish złoty PLN | |
| Pound sterling GBP | |
| Russian ruble RUB | |
| Singapore dollar SGD | |
| Swedish krona SEK | |
| Swiss franc CHF | |
| Thai baht THB | |
| Turkish lira** TRY | |
| United States dollar USD | |
| * This currency does not support decimals. Passing a decimal amount will | |
| result in an error. | |
| ** This currency is supported as a payment currency and a currency balance | |
| for in-country PayPal accounts only. | |
| """ | |
| @derive [Poison.Encoder] | |
| defstruct [description: "", ammount: [total: "", currency: "USD", details: [shipping: "", subtotal: "", tax: ""]]] | |
| end | |
| ## TRY THIS ON iex | |
| Poison.encode! %PayPal.Transaction{description: "yo"} |
Perhaps you need to do something like this:
defmodule PayPal.Transaction.Amount.Details do
defstruct shipping: "", subtotal: "", tax: ""
end
defmodule PayPal.Transaction.Amount do
defstruct total: "", currency: "USD", details: %PayPal.Transaction.Amount.Details{}
end
defmodule PayPal.Transaction do
@derive [Poison.Encoder]
defstruct description: "", amount: %PayPal.Transaction.Amount{}
end
Poison.encode! %PayPal.Transaction{description: "yo"}Related issue in Poison: devinus/poison#32
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The error