View Source KoraPay (korapay v0.1.0)
KoraPay client wrapper (https://docs.korapay.com/).
installation
Installation
Set the the required environment variables for production.
For development/sandbox data set config/dev.exs
.
see: https://developers.korapay.com/docs/api-keys
config :kora_pay,
public: "test_yourkey",
private: "test_yourkey",
webhook_url: "https://www.myserver.com/webhook",
usage
Usage
defmodule MyApp do
def all_banks do
case KoraPay.list_banks() do
{:ok, banks} -> IO.inspect(banks)
{:error, error} -> IO.inspect(error)
end
end
end
Link to this section Summary
Functions
Authorize a charge that is :processing
.
Return account balances. (currently naira only)
Create a charge on a card.
Find the details of a charge by providing a reference.
Create a generic payment.
Create a virutal bank account.
Payout to a bank account.
All supported bank accounts.
Verify a bank account.
All transactions for a client.
Check on a payout's status.
Link to this section Types
@type auth_model() :: :otp | :three_ds | :avs | :pin
@type channel() :: :card | :bank_transfer
@type charge_response() :: %{ amount: non_neg_integer(), amount_charged: non_neg_integer(), auth_model: auth_model(), currency: String.t(), fee: float(), vat: float(), response_message: String.t(), payment_reference: String.t(), status: status(), transaction_reference: String.t(), authorization: %{}, card: card() }
@type charge_status() :: %{ reference: String.t(), amount: non_neg_integer(), fee: float(), currency: String.t(), status: status(), description: String.t(), created_at: DateTime.t(), payer_bank_account: payer_bank_account(), card: card() }
@type disbursement_status() :: %{ type: transaction_type(), transaction_status: String.t(), transaction_date: DateTime.t(), channel: channel(), disbursement: disbursement() }
@type error() :: {:error, %{reason: String.t(), details: %{}}}
@type status() :: :success | :pending | :processing | :expired | :failed
@type transaction_type() :: :collection | :disubursement
@type virtual_account() :: %{ account_reference: String.t(), unique_id: String.t(), account_status: String.t(), created_at: DateTime.t(), currency: String.t(), bank_account: bank_account(), customer: customer() }
Link to this section Functions
@spec authorize_charge(String.t(), auth_model(), auth_options()) :: charge_response() | error()
Authorize a charge that is :processing
.
examples
Examples
iex(1)> KoraPay.authorize_charge("test-txn", :otp, "12345")
iex(2)> KoraPay.authorize_charge("test-txn", :pin, "1234")
iex(3)> KoraPay.authorize_charge("test-txn", :avs, %{state: "Lagos", city: "Lekki", ...})
options
Options
- Required only if auth type is
:pin
- Required only if auth type is
:otp
- Required only if auth type is
:avs
- state
- city
- country
- address
- zip_codes
Return account balances. (currently naira only)
examples
Examples
iex(1)> KoraPay.balances()
{:ok, %{"NGN" => %{"available_balance" => 946, "pending_balance" => 0}}}
@spec charge_card(String.t()) :: charge_response() | error()
Create a charge on a card.
examples
Examples
enc_data = "test_encrypted_base64_data"
iex(1)> KoraPay.charge_card(enc_data)
{:ok, %{
"amount" => 200,
"amount_charged" => 200,
"auth_model" => "OTP",
"currency" => "NGN",
"fee": 2.6,
"vat": 0.2,
"response_message" => "Please enter the OTP sent to your mobile number 080****** and email te**@rave**.com",
"payment_reference"=> "1To64uTVkRcRA",
"status" => "processing",
"transaction_reference"=> "KPY-CA-b5Mit73shYeQ",
"card" => {
"card_type": "mastercard",
"first_six": "539983",
"last_four": "8381",
"expiry": "10/31"
}
}
}
@spec charge_status(String.t()) :: charge_status() | error()
Find the details of a charge by providing a reference.
examples
Examples
iex(1)> KoraPay.charge_status("test-txn")
{:ok, %{
"amount" => "1000.00",
"currency" => "NGN",
"description" => "Fix Test Webhook",
"fee" => nil,
"reference" => "test-txn",
"status" => "processing"
}
}
create_charge(amount, currency, narration, customer, reference \\ generate_reference(), charge_options \\ %{})
View Source@spec create_charge( non_neg_integer(), String.t(), String.t(), customer(), String.t(), charge_options() ) :: charge_response() | error()
Create a generic payment.
see: https://docs.korapay.com/#f192d2e8-aab2-4f5a-98ef-fa0ed7e2d853
examples
Examples
iex(1)> KoraPay.create_charge(1000, "NGN", "test-xyz", %{email: "jycdmbhw@sharklasers.com"})
{:ok, %{
"checkout_url" => "https://test-checkout.korapay.com/test-txn/pay",
"reference" => "test-txn" # reference is automatically generated by library.
}
}
charge-options
Charge options
reference
: transaction reference, if not provided, will be auto generated.charge_options
: map of zero or more attributes.
:redirect_url
: URL to redirect your customer when the transaction is complete.:default_channel
: channel that shows up when client modal is instantiated. E.g"bank_transfer"
:channels
: Allowed payment channels for this transaction e.g["card", "bank_transfer"]
create_virtual_bank_account(name, permanent, bvn, bank_code, customer, reference \\ generate_reference())
View Source@spec create_virtual_bank_account( String.t(), boolean(), [String.t()], String.t(), customer(), String.t() ) :: virtual_account() | error()
Create a virutal bank account.
examples
Examples
iex(1)> KoraPay.create_virtual_bank_account("Steph James", true, ["12345678901"], "035", %{ "name" => "Don Alpha"})
options
Options
reference
: transaction reference, if not provided, will be auto generated. ##
disburse(amount, currency, bank_account, customer, reference \\ generate_reference(), type \\ "bank_account")
View SourcePayout to a bank account.
examples
Examples
iex(1)> bank_account = %{"bank" => "033", "account" => "0000000000"}
iex(2)> customer = %{"name" => "John Doe", "email" => "johndoe@korapay.com"}
iex(3)> KoraPay.disburse(1000, "NGN", bank_account, customer)
{:ok, %{
"amount" => "100.00",
"fee" => "2.50",
"currency" => "NGN",
"status" => "processing",
"reference" => "KPY-D-t74azVrw9oPLtv9",
"narration" => "Test Transfer Payment",
"customer" => %{
"name" => "John Doe",
"email" => "johndoe@korapay.com"
}
}
}
options
Options
reference
: transaction reference, if not provided, will be auto generated.type
: destination type. defaults to"bank_account"
@spec list_banks() :: [misc_bank_account()] | error()
All supported bank accounts.
example
Example
iex(1)> KoraPay.list_banks()
{:ok, [%{
name: "First Bank of Nigeria",
slug: "firstbank",
code: "011",
nibss_bank_code: "000016",
country: "NG"
}, ...]}
@spec resolve_bank_account(String.t(), String.t()) :: bank_account() | error()
Verify a bank account.
examples
Examples
iex(1)> KoraPay.resolve_bank_account("058", "0234247896")
{:ok, %{
"account_name" => "OLAEGBE GBENGA EMMANUEL",
"account_number" => "0234247896",
"bank_code" => "058",
"bank_name" => "GTBank Plc"
}}
@spec transactions() :: [transaction()] | error()
All transactions for a client.
examples
Examples
iex(1)> KoraPay.transactions()
{:ok, [
%{
"type" => "collection",
"amount" => 1000,
"fee" => 10,
"narration" => "payment for a book",
"currency" => "NGN",
"created_at" => "2019-08-05T20:29:49.000Z",
"status" => "success",
"transaction_status" => "success",
"reference" => "KPY-D-jLo7Zbk",
"callback_url" => "https://example.com",
"meta" => "{'product_name':'Becoming by Michelle Obama','product_description':''}",
"customer" => %{
"name" => "Timi Adesoji",
"email" => "johndoe@korapay.com",
}
}, ...]}
@spec verify_disbursement(String.t()) :: disbursement_status() | error()
Check on a payout's status.
examples
Examples
iex(1)> KoraPay.verify_disbursement("KPY_jLo7Zbk")
{:ok, %{
"amount" => 1000,
"fee" => 10,
"narration" => "payout to customer",
"currency" => "NGN",
"created_at" => "2019-08-05T20:29:49.000Z",
"status" => "success",
"reference" => "KPY_jLo7Zbk",
"callback_url" => "https://example.com",
"trace_id" => "000000000000000111111111111111",
"message" => "Payout successful",
"customer" => %{
"name" => "John Doe",
"email" => "johndoe@korapay.com",
}
}
}
@spec virtual_bank_account_details(String.t()) :: virtual_account() | error()
@spec virtual_bank_account_transactions(account_number :: String.t()) :: [virtual_bank_account_txn_response()] | error()