Skip to content

Commit 55e69e5

Browse files
committed
chore(payment link): added functions to get and cancel
1 parent b04736a commit 55e69e5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

lib/checkouts.ex

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,42 @@ defmodule Conekta.Checkouts do
1010
{:ok, Poison.decode!(body, as: PaymentLinkResponse)}
1111
end
1212
end
13+
14+
@doc """
15+
Get Payment Link
16+
[Conekta Documenation](https://developers.conekta.com/reference/getcheckout)
17+
18+
**Method**: `GET`
19+
20+
Conekta.Checkouts.get_payment_link(payment_link_id)
21+
# => { :ok, %Conekta.PaymentLinkResponse{}}
22+
"""
23+
@spec get_payment_link(String.t()) :: {:ok, any()}
24+
def get_payment_link(payment_link_id) do
25+
case Client.get_request("checkouts/#{payment_link_id}") do
26+
{:ok, content} ->
27+
content
28+
|> Handler.handle_status_code()
29+
|> then(&{:ok, Poison.decode!(&1, as: PaymentLinkResponse)})
30+
end
31+
end
32+
33+
@doc """
34+
Cancel Payment Link
35+
[Conekta Documenation](https://developers.conekta.com/reference/cancelcheckout)
36+
37+
**Method**: `PUT`
38+
39+
Conekta.Checkouts.cancel_payment_link(payment_link_id)
40+
# => { :ok, %Conekta.PaymentLinkResponse{}}
41+
"""
42+
@spec cancel_payment_link(String.t(), Conekta.PaymentLink.t()) :: {:ok, any()}
43+
def cancel_payment_link(payment_link_id, payment_link) do
44+
case Client.put_request("checkouts/#{payment_link_id}/cancel", payment_link) do
45+
{:ok, content} ->
46+
content
47+
|> Handler.handle_status_code()
48+
|> then(&{:ok, Poison.decode!(&1, as: PaymentLinkResponse)})
49+
end
50+
end
1351
end

0 commit comments

Comments
 (0)