Skip to content

Commit 0a5c26c

Browse files
committed
PaymentLink
- Add PaymentLink structs - Fix nil values
1 parent 3c7d8fc commit 0a5c26c

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

lib/checkouts.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
defmodule Conekta.Checkouts do
22
alias Conekta.Client
33
alias Conekta.Handler
4+
alias Conekta.PaymentLinkResponse
45

56
def create_payment_link(payment_link) do
67
case Client.post_request("checkouts/", payment_link) do
78
{:ok, content} ->
89
body = Handler.handle_status_code(content)
9-
{:ok, Poison.decode!(body)}
10+
{:ok, Poison.decode!(body, as: PaymentLinkResponse)}
1011
end
1112
end
1213
end

lib/client.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ defmodule Conekta.Client do
3333
def encode_params(param) when is_map(param) do
3434
param
3535
|> Map.from_struct()
36+
|> Enum.filter(fn {_key, value} ->
37+
not is_nil(value)
38+
end)
3639
|> Enum.into(%{})
3740
|> Poison.encode()
3841
|> ok

lib/conekta/conekta_structs.ex

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,45 @@ defmodule Conekta.PartialRefund do
353353
@moduledoc false
354354
defstruct reason: nil, amount: nil
355355
end
356+
357+
defmodule Conekta.PaymentLink do
358+
@moduledoc false
359+
defstruct name: nil,
360+
type: "PaymentLink",
361+
metadata: nil,
362+
monthly_installments_enabled: nil,
363+
monthly_installments_options: nil,
364+
needs_shipping_contact: nil,
365+
payments_limit_count: nil,
366+
recurrent: nil,
367+
order_template: nil,
368+
expires_at: nil,
369+
allowed_payment_methods: nil
370+
end
371+
372+
defmodule Conekta.PaymentLinkResponse do
373+
@moduledoc false
374+
defstruct id: nil,
375+
can_not_expire: nil,
376+
emails_sent: nil,
377+
exclude_card_networks: nil,
378+
expires_at: nil,
379+
force_3ds_flow: nil,
380+
allowed_payment_methods: nil,
381+
livemode: nil,
382+
metadata: nil,
383+
monthly_installments_enabled: nil,
384+
monthly_installments_options: nil,
385+
name: nil,
386+
needs_shipping_contact: nil,
387+
object: nil,
388+
paid_payments_count: nil,
389+
payments_limit_count: nil,
390+
recurrent: nil,
391+
slug: nil,
392+
sms_sent: nil,
393+
starts_at: nil,
394+
status: nil,
395+
type: nil,
396+
url: nil
397+
end

0 commit comments

Comments
 (0)