Packages

Elixir bindings for the Juspay Express Checkout API's

Current section

Files

Jump to
juspay_api_library lib elixir_lib Customers.ex
Raw

lib/elixir_lib/Customers.ex

defmodule Juspay.Customers do
import Juspay
import Juspay.Exception
@moduledoc """
Represents a customer who is using your service.
"""
@doc """
Create a new customer entity. You may invoke this method whenever someone registers in your website or App.
JusPay will respond with an ID that you can persist in your Database. Pass this ID at the time of order creation
to ensure proper linking of orders/payments belonging to a customer.
## Examples
# input in the form of map (works with both string keyed map and atom keyed map)
iex> Juspay.Customers.create(%{ :object_reference_id => "guest_user",
:mobile_number => "9988776655",
:email_address => "customer@mail.com",
:first_name => "John",
:last_name => "Smith",
:mobile_country_code => "91"
})
# input in the form of list
iex> Juspay.Customers.create([ object_reference_id: "guest_user",
mobile_number:"9988776655",
email_address: "customer@mail.com",
first_name: "John",
last_name: "Smith",
mobile_country_code: "91"
])
# response
%{
"id" => "cst_om2l6ctlptxwxuzj",
"object" => "customer",
"object_reference_id" => "guest_user",
"mobile_number" => "9988776655",
"date_created" => "2016-08-02T08:07:52+0000",
"last_updated" => "2016-08-02T08:07:52+0000",
"email_address" => "customer@gmail.com",
"first_name" => "John",
"last_name" => "Smith",
"mobile_country_code" => "91"
}
"""
@spec create(list|map()) :: map()
def create(parameters) do
parameters = check_params(parameters)
method = "POST"
url = "/customers"
response = request(method,url,parameters)
end
@doc false
@spec list(list) :: list
def list(parameters \\ []) do
method = "GET"
url = "/customers"
offset = parameters[:offset]
count = parameters[:count]
if count == NIL and offset == NIL do
IO.inspect "count & offset can be passed if required.\n"
end
response = request(method,url,[])
end
@doc """
This will return customer information for given identifier.
## Examples
# input in the form of map (works with both string keyed map and atom keyed map)
iex> Juspay.Customers.get(%{ :customer_id => "guest_user" }) or Customers.create([customer_id: "guest_user" ])
# input in the form of list
iex> Juspay.Customers.get([ customer_id: "guest_user" ])
# response
%{
"id" => "cst_om2l6ctlptxwxuzj",
"object" => "customer",
"object_reference_id" => "guest_user",
"mobile_number" => "9988776655",
"date_created" => "2016-08-02T08:07:52+0000",
"last_updated" => "2016-08-02T08:07:52+0000",
"email_address" => "customer@gmail.com",
"first_name" => "John",
"last_name" => "Smith",
"mobile_country_code" => "91"
}
"""
@spec get(list|map()) :: map()
def get(parameters) do
parameters = check_params(parameters)
customer_id =parameters[:customer_id]
if customer_id == NIL do
raise ArgumentError,Juspay.Exception.invalidArgumentError(" Error -> customer_id is a required field for Cards.get()")
end
method = "GET"
url = "/customers/" <> customer_id
response = request(method,url,parameters)
end
@doc """
Update information related to a particulat customer.
## Examples
# input in the form of map (works with both string keyed map and atom keyed map)
iex> Juspay.Customers.update(%{
:customer_id => "guest_user",
:mobile_number => "9988776688",
:customer_email => "customer@mail.com",
:first_name => "udpate_firstname",
:last_name =>"udpate_lastname",
:mobile_country_code => "91"
})
# input in the form of list
iex> Juspay.Customers.update([
customer_id: "guest_user",
mobile_number: "9988776688",
customer_email: "customer@mail.com",
first_name: "udpate_firstname",
last_name: "udpate_lastname",
mobile_country_code: "91"
])
# response
%{
"id" => "cst_om2l6ctlptxwxuzj",
"object" => "customer",
"object_reference_id" => "guest_user",
"mobile_number" => "9988776688",
"date_created" => "2016-08-02T08:07:52+0000",
"last_updated" => "2016-08-02T08:07:58+0000",
"email_address" => "customer@gmail.com",
"first_name" => "John",
"last_name" => "Smith",
"mobile_country_code" => "91"
}
"""
@spec update(list|map()) :: map()
def update(parameters) do
parameters = check_params(parameters)
customer_id =parameters[:customer_id]
if customer_id == NIL do
raise ArgumentError,Juspay.Exception.invalidArgumentError(" Error -> customer_id is a required field for Cards.update()")
end
method = "POST"
url = "/customers/" <> customer_id
response = request(method,url,parameters)
end
@doc false
def delete(parameters) do
raise "ERROR: Not Implemented"
end
end