Packages

## ECPay 綠界 Payment Gateway Integration for Elixir The purpose of this library is to provide API integration with the ECPay (綠界科技) payment gateway provided by the Taiwan-based Green World FinTech Service Co., Ltd. (綠界科技股份有限公司).

Current section

Files

Jump to
ecpay lib ecpay aio_params.ex
Raw

lib/ecpay/aio_params.ex

defmodule ECPay.AIOParams do
alias ECPay.{Config, AIOParams, Checksum}
defstruct transaction_no: nil,
timestamp: nil,
amount: 1,
description: nil,
item_name: nil
def to_form_data(%AIOParams{} = params) do
map = to_map(params)
mac_value = Checksum.calculate(map)
Map.put(map, "CheckMacValue", mac_value)
end
def to_map(%AIOParams{} = params) do
%{
"EncryptType" => 1,
"MerchantID" => Config.merchant_id(),
"MerchantTradeNo" => params.transaction_no,
"MerchantTradeDate" => normalize(params.timestamp),
"PaymentType" => "aio",
"TotalAmount" => params.amount,
"TradeDesc" => params.description,
"ItemName" => params.item_name,
"ReturnURL" => Config.return_url(),
"ChoosePayment" => "ALL",
"IgnorePayment" => Config.ignored(),
"ExpireDate" => Config.expiration_period()
}
end
defp normalize(%NaiveDateTime{} = time) do
time |> Timex.to_datetime("Etc/UTC") |> Timex.to_datetime("Asia/Taipei") |> format
end
defp normalize(%DateTime{} = time) do
time |> Timex.to_datetime("Asia/Taipei") |> format
end
defp format(timestamp), do: Timex.format!(timestamp, "%Y/%m/%d %H:%M:%S", :strftime)
end