Current section
13 Versions
Jump to
Current section
13 Versions
Compare versions
4
files changed
+29
additions
-25
deletions
| @@ -30,4 +30,4 @@ | |
| 30 30 | {<<"name">>,<<"poison">>}, |
| 31 31 | {<<"optional">>,false}, |
| 32 32 | {<<"requirement">>,<<"~> 2.0">>}]]}. |
| 33 | - {<<"version">>,<<"0.0.1">>}. |
| 33 | + {<<"version">>,<<"0.0.2">>}. |
| @@ -62,7 +62,7 @@ defmodule CyberSourceSDK.Client do | |
| 62 62 | {:error, reason} |
| 63 63 | |
| 64 64 | merchant_reference_code_validated -> |
| 65 | - case check_payment_type(encrypted_payment) do |
| 65 | + case Helper.check_payment_type(encrypted_payment) do |
| 66 66 | {:ok, :apple_pay} -> |
| 67 67 | pay_with_apple_pay(price, merchant_reference_code_validated, card_type, encrypted_payment, bill_to, worker) |
| 68 68 | |
| @@ -243,28 +243,6 @@ defmodule CyberSourceSDK.Client do | |
| 243 243 | end |
| 244 244 | end |
| 245 245 | |
| 246 | - # Internal function to check what type of payment is: |
| 247 | - # |
| 248 | - # {:ok, :android_pay} |
| 249 | - # {:ok, :apple_pay} |
| 250 | - # {:error, :not_found} |
| 251 | - defp check_payment_type(encrypted_payload) do |
| 252 | - case Helper.json_from_base64(encrypted_payload) do |
| 253 | - {:ok, data} -> |
| 254 | - header = Map.get(data, :header) |
| 255 | - signature = Map.get(data, :signature) |
| 256 | - publicKeyHash = Map.get(data, :publicKeyHash) |
| 257 | - |
| 258 | - cond do |
| 259 | - !is_nil(header) && !is_nil(signature) -> {:ok, :apple_pay} |
| 260 | - !is_nil(publicKeyHash) -> {:ok, :android_pay} |
| 261 | - true -> {:ok, :not_found_payment_type} |
| 262 | - end |
| 263 | - |
| 264 | - {:error, _reason} -> {:error, :invalid_base64_or_json} |
| 265 | - end |
| 266 | - end |
| 267 | - |
| 268 246 | # Parse response from CyberSource |
| 269 247 | defp parse_response(xml) do |
| 270 248 | xml |> xmap( |
| @@ -51,4 +51,30 @@ defmodule CyberSourceSDK.Helper do | |
| 51 51 | _ -> {:error, :bad_base64_encoding} |
| 52 52 | end |
| 53 53 | end |
| 54 | + |
| 55 | + @doc """ |
| 56 | + Check what type of payment is: Android Pay or Apple Pay |
| 57 | + |
| 58 | + ## Results |
| 59 | + |
| 60 | + - `{:ok, :android_pay}` |
| 61 | + - `{:ok, :apple_pay}` |
| 62 | + - `{:error, :not_found}` |
| 63 | + """ |
| 64 | + def check_payment_type(encrypted_payload) do |
| 65 | + case json_from_base64(encrypted_payload) do |
| 66 | + {:ok, data} -> |
| 67 | + header = Map.get(data, :header) |
| 68 | + signature = Map.get(data, :signature) |
| 69 | + publicKeyHash = Map.get(data, :publicKeyHash) |
| 70 | + |
| 71 | + cond do |
| 72 | + !is_nil(header) && !is_nil(signature) -> {:ok, :apple_pay} |
| 73 | + !is_nil(publicKeyHash) -> {:ok, :android_pay} |
| 74 | + true -> {:ok, :not_found_payment_type} |
| 75 | + end |
| 76 | + |
| 77 | + {:error, _reason} -> {:error, :invalid_base64_or_json} |
| 78 | + end |
| 79 | + end |
| 54 80 | end |
| @@ -3,7 +3,7 @@ defmodule CyberSourceSDK.Mixfile do | |
| 3 3 | |
| 4 4 | def project do |
| 5 5 | [app: :cybersource_sdk, |
| 6 | - version: "0.0.1", |
| 6 | + version: "0.0.2", |
| 7 7 | elixir: "~> 1.2", |
| 8 8 | deps: deps(), |
| 9 9 | build_embedded: Mix.env == :prod, |