Current section
Files
Jump to
Current section
Files
lib/elixir_lib/Wallets.ex
defmodule Juspay.Wallets do
import Juspay.Exception
import Juspay
@moduledoc """
Represents a wallet account that belongs to a customer.
SECURITY
Wallet account is valid only when your wallet provider has granted you permission for POWER WALLET flow.
A pre-authenticated or a linked wallet account will have an associated token with it. Such a token is assigned by JusPay
and to directly debit from the wallet, you must send this token.
However, to ensure better security JusPay will expire a token within 10 minutes of issuance
(issued when you call /wallets list API). Also a token is valid only for single use.
"""
@doc false
defp create(parameters) do
# raise "ERROR: Not Implemented"
end
@doc """
Wallets can be listed only in the context of a Customer. This API will return list of linked wallets for a given customer.
## Note:
Wallet balance in this response may not be the current balance, last_refreshed field will have the
date when last balance updated. Use refresh wallet API to get updated balance.
## Examples
# input in the form of list
iex> Juspay.Wallets.list([customer_id: "guest_user"])
# input in the form of map (works with both string keyed map and atom keyed map)
iex> Juspay.Wallets.list(%{:customer_id => "guest_user"})
# response
[
%{
"id" => "wlt_q23xzki3pazgtezo",
"object" => "wallet_account",
"wallet" => "MOBIKWIK",
"token" => "tok_winysteev9eftrwcv6me",
"current_balance" => "250.00",
"last_refreshed" => "2016-09-02T08:07:52+0000"
},
...
]
"""
@spec list(list|map()) :: map()
def list(parameters) do
parameters = check_params(parameters)
order =parameters[:order_id]
customer =parameters[:customer_id]
if customer == NIL and order == NIL do
# raise Juspay.Exception.invalidArgumentError("ERROR: `customer_id` or `order_id` is required parameter for list()")
end
url = case customer do
NIL -> "/orders/"<>order<>"/wallets"
_ -> "/customers/"<>customer<>"/wallets"
end
method = "GET"
response = request(method,url,[])["list"]
end
@doc """
Refresh wallet API can be used to get the wallet list with updated balance from wallets.
Here we make check balance call to each of the linked wallet server and return the response.
## Note:
Ensure higher read timeout setup for this API call. Multiple network calls will be made in this API call and
so the response is expected to arrive after some delay.
## Examples
# input in the form of list
iex> Juspay.Wallets.refresh_balance([customer_id: "guest_user"])
# input in the form of map (works with both string keyed map and atom keyed map)
iex> Juspay.Wallets.refresh_balance(%{:customer_id => "guest_user"})
# response
[
%{
"id" => "wlt_q23xzki3pazgtezo",
"object" => "wallet_account",
"wallet" => "MOBIKWIK",
"token" => "tok_winysteev9eftrwcv6me",
"current_balance" => "250.00",
"last_refreshed" => "2016-09-02T08:07:52+0000"
},
...
]
"""
@spec refresh_balance(list|map()) :: map()
def refresh_balance(parameters) do
parameters = check_params(parameters)
customer =parameters[:customer_id]
if customer == NIL do
# raise Juspay.Exception.invalidArgumentError("ERROR: `customer_id` is required parameter for refresh_balance()")
end
url = "/customers/"<>customer<>"/wallets/refresh-balances"
method = "GET"
response = request(method,url,[])["list"]
end
defp delete(parameters) do
# raise "ERROR: Not Implemented"
end
end