datatrans_helper v0.2.0 DatatransHelper
Small Helper Function to sign Datatrans Request Parameters
Summary
Functions
Generate Map of payment parameters
Generate Map of payment parameters
Generate signature of a Datatrans Request Parameters
Generate signature of a Datatrans Request Parameters
Generate signature of a Datatrans Post Response
Generate signature of a Datatrans Post Response
Check if sign1 signature is correct
Check if sign1 signature is correct
Check if sign2 signature is correct
Check if sign2 signature is correct
Types
datatrans_payment_request() :: %{merchant_id: merchant_id, amount: amount, currency: currency, refno: reference_number, sign: signature}
Functions
generate_payment_info(Money.t, reference_number) :: datatrans_payment_request
Generate Map of payment parameters.
This function is only present, if the optional money package is installed.
Examples
iex> Application.put_env(:datatrans_helper, :merchant_id, "73452")
iex> Application.put_env(:datatrans_helper, :sign1_hmac_key, "16ee1f9c0204842aed558fd57fd38503421dd6876269ad82d490ae5a7d5454d2dd936102190e86d06412ce94631fc96b6215da5fe0a5d1687dba5c5fa351e0fb")
iex> DatatransHelper.generate_payment_info(Money.new(7_20, :CHF), "a5e511e9-7334-44c2-be21-cef964091739")
%{amount: 7_20, currency: "CHF", merchant_id: "73452",
refno: "a5e511e9-7334-44c2-be21-cef964091739",
sign: "1dbf3321ef16b02a638762bc30aa9811ce696656ea49e362a452166020c976c5"}
generate_payment_info(amount, currency, reference_number) :: datatrans_payment_request
Generate Map of payment parameters.
Examples
iex> Application.put_env(:datatrans_helper, :merchant_id, "73452")
iex> Application.put_env(:datatrans_helper, :sign1_hmac_key, "16ee1f9c0204842aed558fd57fd38503421dd6876269ad82d490ae5a7d5454d2dd936102190e86d06412ce94631fc96b6215da5fe0a5d1687dba5c5fa351e0fb")
iex> DatatransHelper.generate_payment_info(7_20, "CHF", "a5e511e9-7334-44c2-be21-cef964091739")
%{amount: 7_20, currency: "CHF", merchant_id: "73452",
refno: "a5e511e9-7334-44c2-be21-cef964091739",
sign: "1dbf3321ef16b02a638762bc30aa9811ce696656ea49e362a452166020c976c5"}
Generate signature of a Datatrans Request Parameters
This function is only present, if the optional money package is installed.
Examples
iex> Application.put_env(:datatrans_helper, :merchant_id, "73452")
iex> Application.put_env(:datatrans_helper, :sign1_hmac_key, "16ee1f9c0204842aed558fd57fd38503421dd6876269ad82d490ae5a7d5454d2dd936102190e86d06412ce94631fc96b6215da5fe0a5d1687dba5c5fa351e0fb")
iex> DatatransHelper.generate_sign1(Money.new(7_20, :CHF), "a5e511e9-7334-44c2-be21-cef964091739")
"1dbf3321ef16b02a638762bc30aa9811ce696656ea49e362a452166020c976c5"
generate_sign1(amount, currency, reference_number) :: signature
Generate signature of a Datatrans Request Parameters
Examples
iex> Application.put_env(:datatrans_helper, :merchant_id, "73452")
iex> Application.put_env(:datatrans_helper, :sign1_hmac_key, "16ee1f9c0204842aed558fd57fd38503421dd6876269ad82d490ae5a7d5454d2dd936102190e86d06412ce94631fc96b6215da5fe0a5d1687dba5c5fa351e0fb")
iex> DatatransHelper.generate_sign1(7_20, "CHF", "a5e511e9-7334-44c2-be21-cef964091739")
"1dbf3321ef16b02a638762bc30aa9811ce696656ea49e362a452166020c976c5"
Generate signature of a Datatrans Post Response
This function is only present, if the optional money package is installed.
Examples
iex> Application.put_env(:datatrans_helper, :merchant_id, "73452")
iex> Application.put_env(:datatrans_helper, :sign2_hmac_key, "16ee1f9c0204842aed558fd57fd38503421dd6876269ad82d490ae5a7d5454d2dd936102190e86d06412ce94631fc96b6215da5fe0a5d1687dba5c5fa351e0fb")
iex> DatatransHelper.generate_sign2(Money.new(7_20, :CHF), 43575623879)
"8037d669282680ed81f510b41b0622b7ce17e644fef620baf6494146313e2269"
generate_sign2(amount, currency, upp_transaction_id) :: signature
Generate signature of a Datatrans Post Response
Examples
iex> Application.put_env(:datatrans_helper, :merchant_id, "73452")
iex> Application.put_env(:datatrans_helper, :sign2_hmac_key, "16ee1f9c0204842aed558fd57fd38503421dd6876269ad82d490ae5a7d5454d2dd936102190e86d06412ce94631fc96b6215da5fe0a5d1687dba5c5fa351e0fb")
iex> DatatransHelper.generate_sign2(7_20, "CHF", 43575623879)
"8037d669282680ed81f510b41b0622b7ce17e644fef620baf6494146313e2269"
Check if sign1 signature is correct
This function is only present, if the optional money package is installed.
Examples
iex> Application.put_env(:datatrans_helper, :merchant_id, "73452")
iex> Application.put_env(:datatrans_helper, :sign1_hmac_key, "16ee1f9c0204842aed558fd57fd38503421dd6876269ad82d490ae5a7d5454d2dd936102190e86d06412ce94631fc96b6215da5fe0a5d1687dba5c5fa351e0fb")
iex> DatatransHelper.valid_sign1?("1dbf3321ef16b02a638762bc30aa9811ce696656ea49e362a452166020c976c5", Money.new(7_20, "CHF"), "a5e511e9-7334-44c2-be21-cef964091739")
true
iex> Application.put_env(:datatrans_helper, :merchant_id, "73452")
iex> Application.put_env(:datatrans_helper, :sign1_hmac_key, "16ee1f9c0204842aed558fd57fd38503421dd6876269ad82d490ae5a7d5454d2dd936102190e86d06412ce94631fc96b6215da5fe0a5d1687dba5c5fa351e0fb")
iex> DatatransHelper.valid_sign1?("invalid signature", Money.new(7_20, "CHF"), "a5e511e9-7334-44c2-be21-cef964091739")
false
valid_sign1?(signature, amount, currency, reference_number) :: boolean
Check if sign1 signature is correct
Examples
iex> Application.put_env(:datatrans_helper, :merchant_id, "73452")
iex> Application.put_env(:datatrans_helper, :sign1_hmac_key, "16ee1f9c0204842aed558fd57fd38503421dd6876269ad82d490ae5a7d5454d2dd936102190e86d06412ce94631fc96b6215da5fe0a5d1687dba5c5fa351e0fb")
iex> DatatransHelper.valid_sign1?("1dbf3321ef16b02a638762bc30aa9811ce696656ea49e362a452166020c976c5", 7_20, "CHF", "a5e511e9-7334-44c2-be21-cef964091739")
true
iex> Application.put_env(:datatrans_helper, :merchant_id, "73452")
iex> Application.put_env(:datatrans_helper, :sign1_hmac_key, "16ee1f9c0204842aed558fd57fd38503421dd6876269ad82d490ae5a7d5454d2dd936102190e86d06412ce94631fc96b6215da5fe0a5d1687dba5c5fa351e0fb")
iex> DatatransHelper.valid_sign1?("invalid signature", 7_20, "CHF", "a5e511e9-7334-44c2-be21-cef964091739")
false
valid_sign2?(signature, Money.t, upp_transaction_id) :: boolean
Check if sign2 signature is correct
This function is only present, if the optional money package is installed.
Examples
iex> Application.put_env(:datatrans_helper, :merchant_id, "73452")
iex> Application.put_env(:datatrans_helper, :sign2_hmac_key, "16ee1f9c0204842aed558fd57fd38503421dd6876269ad82d490ae5a7d5454d2dd936102190e86d06412ce94631fc96b6215da5fe0a5d1687dba5c5fa351e0fb")
iex> DatatransHelper.valid_sign2?("8037d669282680ed81f510b41b0622b7ce17e644fef620baf6494146313e2269", Money.new(7_20, "CHF"), 43575623879)
true
iex> Application.put_env(:datatrans_helper, :merchant_id, "73452")
iex> Application.put_env(:datatrans_helper, :sign2_hmac_key, "16ee1f9c0204842aed558fd57fd38503421dd6876269ad82d490ae5a7d5454d2dd936102190e86d06412ce94631fc96b6215da5fe0a5d1687dba5c5fa351e0fb")
iex> DatatransHelper.valid_sign2?("invalid signature", Money.new(7_20, "CHF"), 43575623879)
false
valid_sign2?(signature, amount, currency, upp_transaction_id) :: boolean
Check if sign2 signature is correct
Examples
iex> Application.put_env(:datatrans_helper, :merchant_id, "73452")
iex> Application.put_env(:datatrans_helper, :sign2_hmac_key, "16ee1f9c0204842aed558fd57fd38503421dd6876269ad82d490ae5a7d5454d2dd936102190e86d06412ce94631fc96b6215da5fe0a5d1687dba5c5fa351e0fb")
iex> DatatransHelper.valid_sign2?("8037d669282680ed81f510b41b0622b7ce17e644fef620baf6494146313e2269", 7_20, "CHF", 43575623879)
true
iex> Application.put_env(:datatrans_helper, :merchant_id, "73452")
iex> Application.put_env(:datatrans_helper, :sign2_hmac_key, "16ee1f9c0204842aed558fd57fd38503421dd6876269ad82d490ae5a7d5454d2dd936102190e86d06412ce94631fc96b6215da5fe0a5d1687dba5c5fa351e0fb")
iex> DatatransHelper.valid_sign2?("invalid signature", 7_20, "CHF", 43575623879)
false