Current section
9 Versions
Jump to
Current section
9 Versions
Compare versions
7
files changed
+92
additions
-32
deletions
| @@ -1,5 +1,13 @@ | |
| 1 1 | # Changelog |
| 2 2 | |
| 3 | + ## v0.1.6 (2021-01-30) |
| 4 | + |
| 5 | + ### Enhancements |
| 6 | + * `base_cielo_uri` as possible parameter for configure `Cielo.HTTP` module. |
| 7 | + |
| 8 | + ### Fixes |
| 9 | + * Fix not definiton of `Entities.RecurrentPayment` module. |
| 10 | + |
| 3 11 | ## v0.1.5 (2020-11-09) |
| 4 12 | * Tokenization Functions |
| @@ -38,4 +38,4 @@ | |
| 38 38 | {<<"optional">>,false}, |
| 39 39 | {<<"repository">>,<<"hexpm">>}, |
| 40 40 | {<<"requirement">>,<<"~> 0.4">>}]]}. |
| 41 | - {<<"version">>,<<"0.1.5">>}. |
| 41 | + {<<"version">>,<<"0.1.6">>}. |
| @@ -59,6 +59,35 @@ defmodule Cielo.Entities.RecurrentPaymentUpdate do | |
| 59 59 | end |
| 60 60 | end |
| 61 61 | |
| 62 | + defmodule Cielo.Entities.RecurrentPayment do |
| 63 | + use Cielo.Entities.Base |
| 64 | + alias Cielo.Entities |
| 65 | + |
| 66 | + embedded_schema do |
| 67 | + field(:amount, :integer) |
| 68 | + field(:installments, :integer) |
| 69 | + field(:soft_descriptor, :string) |
| 70 | + field(:currency, :string) |
| 71 | + field(:type, :string) |
| 72 | + |
| 73 | + embeds_one(:recurrent_payment, Entities.Recurrent) |
| 74 | + embeds_one(:credit_card, Entities.CreditCard) |
| 75 | + end |
| 76 | + |
| 77 | + def changeset(payment, attrs) do |
| 78 | + payment |
| 79 | + |> cast(attrs, [ |
| 80 | + :amount, |
| 81 | + :installments, |
| 82 | + :soft_descriptor, |
| 83 | + :type |
| 84 | + ]) |
| 85 | + |> cast_embed(:recurrent_payment) |
| 86 | + |> cast_embed(:credit_card) |
| 87 | + |> validate_required([:amount, :installments, :credit_card, :recurrent_payment, :type]) |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 62 91 | defmodule Cielo.Entities.Recurrent do |
| 63 92 | use Cielo.Entities.Base |
| 64 93 | alias Cielo.Entities |
| @@ -77,9 +106,6 @@ defmodule Cielo.Entities.Recurrent do | |
| 77 106 | |> maybe_validate_interval() |
| 78 107 | end |
| 79 108 | |
| 80 | - def maybe_validate_interval(%Ecto.Changeset{changes: %{interval: nil}} = changeset), |
| 81 | - do: changeset |
| 82 | - |
| 83 109 | def maybe_validate_interval(%Ecto.Changeset{changes: %{interval: _interval}} = changeset) do |
| 84 110 | validate_inclusion(changeset, :interval, [ |
| 85 111 | "Monthly", |
| @@ -89,6 +115,9 @@ defmodule Cielo.Entities.Recurrent do | |
| 89 115 | "Annual" |
| 90 116 | ]) |
| 91 117 | end |
| 118 | + |
| 119 | + def maybe_validate_interval(%Ecto.Changeset{changes: _changes} = changeset), |
| 120 | + do: changeset |
| 92 121 | end |
| 93 122 | |
| 94 123 | defmodule Cielo.Entities.DebitCardPayment do |
| @@ -168,20 +168,6 @@ defmodule Cielo.HTTP do | |
| 168 168 | request(unquote(method), path, payload, []) |
| 169 169 | end |
| 170 170 | |
| 171 | - if @method != "GET" do |
| 172 | - @doc """ |
| 173 | - Wrapp a hackey call with #{@method} verb passing path and payload to function |
| 174 | - |
| 175 | - ## Example |
| 176 | - |
| 177 | - iex> Cielo.HTTP.#{method}("/1/sales", %{merchant_order_id: order_key}) |
| 178 | - {:ok, %{ |
| 179 | - merchant_order_id: order_key, |
| 180 | - ... |
| 181 | - }} |
| 182 | - """ |
| 183 | - end |
| 184 | - |
| 185 171 | @impl Cielo.HTTPBehaviour |
| 186 172 | def unquote(method)(path, opts) when is_list(opts) do |
| 187 173 | request(unquote(method), path, %{}, opts) |
| @@ -241,7 +227,8 @@ defmodule Cielo.HTTP do | |
| 241 227 | defp build_url(path, method, opts) do |
| 242 228 | environment = opts |> get_lazy_env(:sandbox) |> is_sandbox?() |
| 243 229 | |
| 244 | - build_endpoint(environment, method) <> "/" <> path |
| 230 | + base_uri = Utils.get_env(:cielo_base_uri) || build_endpoint(environment, method) |
| 231 | + base_uri <> "/" <> path |
| 245 232 | end |
| 246 233 | |
| 247 234 | @impl Cielo.HTTPBehaviour |
| @@ -269,7 +256,7 @@ defmodule Cielo.HTTP do | |
| 269 256 | defp error_response(reason, detail), do: {:error, reason, detail} |
| 270 257 | |
| 271 258 | defp get_lazy_env(opts, key, default \\ nil) do |
| 272 | - Keyword.get_lazy(opts, key, fn -> Utils.get_env(key, default) end) |
| 259 | + Keyword.get_lazy(opts, key, fn -> Utils.get_env!(key, default) end) |
| 273 260 | end |
| 274 261 | |
| 275 262 | defp build_endpoint(sandbox, method) do |
| @@ -25,13 +25,13 @@ defmodule Cielo.Recurrency do | |
| 25 25 | |
| 26 26 | ## Examples |
| 27 27 | |
| 28 | - iex(1)> Cielo.Recurrency.update_end_date(valid_params) |
| 28 | + iex(1)> Cielo.Recurrency.create_payment(valid_params) |
| 29 29 | {:ok, success_map} |
| 30 30 | |
| 31 | - iex(2)> Cielo.Recurrency.update_end_date(invalid_params) |
| 31 | + iex(2)> Cielo.Recurrency.create_payment(invalid_params) |
| 32 32 | {:error, :bad_request, [%{code: 313, message: "Recurrent Payment not found"}]} |
| 33 33 | |
| 34 | - iex(2)> Cielo.Recurrency.update_end_date(invalid_params) |
| 34 | + iex(2)> Cielo.Recurrency.create_payment(invalid_params) |
| 35 35 | {:error, %{ |
| 36 36 | errors: [...] |
| 37 37 | }} |
Loading more files…