From 94e0edcaeff25e9df40a9c9e0dcbcad94303800d Mon Sep 17 00:00:00 2001 From: voidzero Date: Tue, 19 Dec 2017 20:38:52 +0530 Subject: [PATCH 01/14] Add some docs to wirecard gateway --- lib/gringotts/gateways/wire_card.ex | 81 ++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 19 deletions(-) diff --git a/lib/gringotts/gateways/wire_card.ex b/lib/gringotts/gateways/wire_card.ex index 939a0fef..84f5c506 100644 --- a/lib/gringotts/gateways/wire_card.ex +++ b/lib/gringotts/gateways/wire_card.ex @@ -1,9 +1,52 @@ -# call => Gringotts.Gateways.WireCard.authorize(100, creditcard, options) -import XmlBuilder - defmodule Gringotts.Gateways.WireCard do - @moduledoc """ - WireCard System Plugins + @moduledoc ~S""" + An API client for the [WireCard](http://www.wirecard.com) gateway. + + For reference see [WireCard's CEE integration documentation](https://guides.wirecard.com/_export/pdf/wcp:test_mode) + + The Following Features of WireCard are implemented: + + | `type` | Action | Method | + | ------ | ------ | ------ | + | `PA` | Pre-authorize | `authorize/3` | + | `CP` | Capture | `capture/3` | + | `DB` | Debit | `purchase/3` | + | `RF` | Refund | `refund/3` | + | `RV` | Reversal | `void/2` | + | | Tokenization / Registrations | `store/2` | + + ## The `opts` argument + + Most `Gringotts` API calls accept an optional `Keyword` list `opts` to supply + optional arguments for transactions with the WireCard gateway. The following keys + are supported: + + | Key | Remark | Status | + | ---- | --- | ---- | + | `order_id` | | implemented | + | `billing_address` | [Address Format](#address-format)| implemented | + | `description` | | Not implemented | + | `email` | | implemented | + | `ip` | | implemented | + | `test` | | implemented | + + ## + Address in `opts` should be `Map` with following keys: + + | Key | Remark | Status | + | ---- | --- | ---- | + | `name` | | implemented | + | `address1` | | implemented | + | `address2` | | implemented | + | `company` | | implemented | + | `city` | | implemented | + | `zip` | | implemented | + | `country` | | implemented | + | `phone` | | implemented | + | `fax` | | implemented | + + ## WireCard _quirks_ + * WireCard does not process money in cents, and the `amount` is by default considered to be cents. """ @test_url "https://c3-test.wirecard.com/secure/ssl-gateway" @live_url "https://c3.wirecard.com/secure/ssl-gateway" @@ -25,24 +68,22 @@ defmodule Gringotts.Gateways.WireCard do use Gringotts.Adapter, required_config: [:login, :password, :signature] alias Gringotts.{ - CreditCard, - Address, - Response + CreditCard } - - import Poison, only: [decode!: 1] + + import XmlBuilder @doc """ + Performs a (pre) Authorize operation. + Authorization - the second parameter may be a CreditCard or a String which represents a GuWID reference to an earlier transaction. If a GuWID is given, rather than a CreditCard, then then the :recurring option will be forced to "Repeated" - =========================================================== - TODO: Mandatorily check for :login,:password, :signature in options - Note: payment_menthod for now is only credit_card and - TODO: change it so it can also have GuWID - ================================================ - E.g: => + + ## Examples + Run this in your `iex -S mix` + ``` creditcard = %CreditCard{ number: "4200000000000000", month: 12, @@ -52,6 +93,7 @@ defmodule Gringotts.Gateways.WireCard do verification_code: "123", brand: "visa" } + address = %{ name: "Jim Smith", address1: "456 My Street", @@ -64,6 +106,7 @@ defmodule Gringotts.Gateways.WireCard do phone: "(555)555-5555", fax: "(555)555-6666" } + options = [ config: %{ login: "00000031629CA9FA", @@ -280,7 +323,7 @@ defmodule Gringotts.Gateways.WireCard do end end - def add_action_data(action, money, options) do + defp add_action_data(_action, money, options) do case options[:action] do # returns array of elements action when action in [:preauthorization, :purchase, :authorization_check] -> @@ -364,7 +407,7 @@ defmodule Gringotts.Gateways.WireCard do end # Includes the payment (amount, currency, country) to the transaction-xml - def add_invoice(money, options) do + defp add_invoice(money, options) do [ add_amount(money, options), element(:Currency, currency(options)), @@ -378,7 +421,7 @@ defmodule Gringotts.Gateways.WireCard do # Include the amount in the transaction-xml # TODO: check for localized currency or currency # localized_amount(money, options[:currency] || currency(money)) - defp add_amount(money, options), do: element(:Amount, money) + defp add_amount(money, _options), do: element(:Amount, money) defp atom_to_upcase_string(atom) do atom From d2114ae350ba770f8df590d1460005ddda6b6a0a Mon Sep 17 00:00:00 2001 From: voidzero Date: Wed, 20 Dec 2017 11:50:22 +0530 Subject: [PATCH 02/14] add flatten nested map utils --- lib/kuber_hex/utils/flatten_nested_map.ex | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/kuber_hex/utils/flatten_nested_map.ex diff --git a/lib/kuber_hex/utils/flatten_nested_map.ex b/lib/kuber_hex/utils/flatten_nested_map.ex new file mode 100644 index 00000000..7a18db6b --- /dev/null +++ b/lib/kuber_hex/utils/flatten_nested_map.ex @@ -0,0 +1,21 @@ +defmodule Utils.Json do + def flatten(map) when is_map(map) do + map + |> to_list_of_tuples + |> Enum.into(%{}) + end + + defp to_list_of_tuples(m) do + m + |> Enum.map(&process/1) + |> List.flatten + end + + defp process({key, sub_map}) when is_map(sub_map) do + for { sub_key, value } <- flatten(sub_map) do + { "#{key}.#{sub_key}", value } + end + end + + defp process(next), do: next +end From 4ff05b9ea25082cd265b0c47efd71f1903d3e2aa Mon Sep 17 00:00:00 2001 From: voidzero Date: Wed, 27 Dec 2017 11:11:38 +0530 Subject: [PATCH 03/14] Introduces flatmap utility and a test suite 1. Moved flatmap utility to gringotts 2. Add basic test suite for wirecard --- .../utils/flatten_nested_map.ex | 0 test/gateways/wire_card_test.exs | 109 +++++++++++++++++- test/test_helper.exs | 2 +- 3 files changed, 106 insertions(+), 5 deletions(-) rename lib/{kuber_hex => gringotts}/utils/flatten_nested_map.ex (100%) diff --git a/lib/kuber_hex/utils/flatten_nested_map.ex b/lib/gringotts/utils/flatten_nested_map.ex similarity index 100% rename from lib/kuber_hex/utils/flatten_nested_map.ex rename to lib/gringotts/utils/flatten_nested_map.ex diff --git a/test/gateways/wire_card_test.exs b/test/gateways/wire_card_test.exs index 61633735..5f163887 100644 --- a/test/gateways/wire_card_test.exs +++ b/test/gateways/wire_card_test.exs @@ -7,12 +7,113 @@ defmodule Gringotts.Gateways.WireCardTest do # TEST_AUTHORIZATION_GUWID = 'C822580121385121429927' # TEST_PURCHASE_GUWID = 'C865402121385575982910' # TEST_CAPTURE_GUWID = 'C833707121385268439116' + alias Gringotts.{ + CreditCard, + } - # config = %{credentails: {'user', 'pass'}, default_currency: "EUR"} - :ok + alias Gringotts.Gateways.WireCard, as: Gateway + + @test_authorization_guwid "C822580121385121429927" + @test_purchase_guwid "C865402121385575982910" + @test_capture_guwid "C833707121385268439116" + + @card %CreditCard{ + number: "4200000000000000", + month: 12, + year: 2018, + first_name: "Longbob", + last_name: "Longsen", + verification_code: "123", + brand: "visa" + } + + @declined_card %CreditCard{ + number: "4000300011112220", + month: 12, + year: 2018, + first_name: "Longbob", + last_name: "Longsen", + verification_code: "123", + brand: "visa" + } + + @address %{ + name: "Jim Smith", + address1: "456 My Street", + address2: "Apt 1", + company: "Widgets Inc", + city: "Ottawa", + state: "ON", + zip: "K1C2N6", + country: "CA", + phone: "(555)555-5555", + fax: "(555)555-6666" + } + + @options [ + order_id: 1, + billing_address: @address, + description: 'Wirecard remote test purchase', + email: "soleone@example.com", + ip: "127.0.0.1", + test: true + ] + + describe "authorize/3" do + @tag :pending + test "test_successful_authorization" do + end + + @tag :pending + test "test_successful_reference_authorization" do + end + + @tag :pending + test "test_wrong_credit_card_authorization" do + end end - test "test_successful_authorization" do - assert 1 + 1 == 2 + describe "purchase/3" do + @tag :pending + test "test_successful_purchase" do + end + + @tag :pending + test "test_successful_reference_purchase" do + end + end + + describe "authorize/3 and capture/3" do + @tag :pending + test "test_successful_authorization_and_capture" do + end + + @tag :pending + test "test_successful_authorization_and_partial_capture" do + end + + @tag :pending + test "test_unauthorized_capture" do + end + end + + describe "refund/3" do + @tag :pending + test "test_successful_refund" do + end + + @tag :pending + test "test_failed_refund" do + end + end + + describe "void/2" do + @tag :pending + test "test_successful_void" do + end + + @tag :pending + test "test_failed_void" do + end end end diff --git a/test/test_helper.exs b/test/test_helper.exs index 579b186b..8915c882 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,2 +1,2 @@ -ExUnit.start(trace: true, exclude: [integration: true]) +ExUnit.start(trace: true, exclude: [integration: true, pending: true]) Application.ensure_all_started(:bypass) From 3f75bc4bcd8dc05cb742b1cbe84d30c97bc76660 Mon Sep 17 00:00:00 2001 From: voidzero Date: Wed, 27 Dec 2017 11:38:50 +0530 Subject: [PATCH 04/14] add extra test cases for different scenarios --- test/gateways/wire_card_test.exs | 74 ++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/test/gateways/wire_card_test.exs b/test/gateways/wire_card_test.exs index 5f163887..19945b04 100644 --- a/test/gateways/wire_card_test.exs +++ b/test/gateways/wire_card_test.exs @@ -116,4 +116,78 @@ defmodule Gringotts.Gateways.WireCardTest do test "test_failed_void" do end end + + describe "testing for different scenarios" do + @tag :pending + test "test_no_error_if_no_state_is_provided_in_address" do + end + + @tag :pending + test "test_no_error_if_no_address_provided" do + end + + @tag :pending + test "test_description_trucated_to_32_chars_in_authorize" do + end + + @tag :pending + test "test_description_trucated_to_32_chars_in_purchase" do + end + + @tag :pending + test "test_description_is_ascii_encoded_since_wirecard_does_not_like_utf_8" do + end + + @tag :pending + test "test_failed_avs_response_message" do + end + + @tag :pending + test "test_failed_amex_avs_response_code" do + end + + @tag :pending + test "test_commerce_type_option" do + end + + @tag :pending + test "test_store_sets_recurring_transaction_type_to_initial" do + end + + @tag :pending + test "test_store_sets_amount_to_100_by_default" do + end + + @tag :pending + test "test_store_sets_amount_to_amount_from_options" do + end + + @tag :pending + test "test_authorization_using_reference_sets_proper_elements" do + end + + @tag :pending + test "test_purchase_using_reference_sets_proper_elements" do + end + + @tag :pending + test "test_authorization_with_recurring_transaction_type_initial" do + end + + @tag :pending + test "test_purchase_using_with_recurring_transaction_type_initial" do + end + + @tag :pending + test "test_system_error_response" do + end + + @tag :pending + test "test_system_error_response_without_job" do + end + + @tag :pending + test "test_transcript_scrubbing" do + end + end end From 5ffdc84243023153b72280d60d58225dc2835f7f Mon Sep 17 00:00:00 2001 From: voidzero Date: Wed, 27 Dec 2017 13:14:43 +0530 Subject: [PATCH 05/14] updated test suite with proper describe --- test/gateways/wire_card_test.exs | 47 ++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/test/gateways/wire_card_test.exs b/test/gateways/wire_card_test.exs index 19945b04..8d1d9a13 100644 --- a/test/gateways/wire_card_test.exs +++ b/test/gateways/wire_card_test.exs @@ -117,25 +117,33 @@ defmodule Gringotts.Gateways.WireCardTest do end end - describe "testing for different scenarios" do + describe "store/2" do @tag :pending - test "test_no_error_if_no_state_is_provided_in_address" do + test "test_store_sets_recurring_transaction_type_to_initial" do end @tag :pending - test "test_no_error_if_no_address_provided" do + test "test_store_sets_amount_to_100_by_default" do end @tag :pending - test "test_description_trucated_to_32_chars_in_authorize" do + test "test_store_sets_amount_to_amount_from_options" do end + end + describe "scrubbing/1" do @tag :pending - test "test_description_trucated_to_32_chars_in_purchase" do + test "test_transcript_scrubbing" do end + end + describe "testing response for different request scenarios" do @tag :pending - test "test_description_is_ascii_encoded_since_wirecard_does_not_like_utf_8" do + test "test_no_error_if_no_state_is_provided_in_address" do + end + + @tag :pending + test "test_no_error_if_no_address_provided" do end @tag :pending @@ -147,37 +155,40 @@ defmodule Gringotts.Gateways.WireCardTest do end @tag :pending + # Not sure what is this need to check test "test_commerce_type_option" do end @tag :pending - test "test_store_sets_recurring_transaction_type_to_initial" do + test "test_authorization_using_reference_sets_proper_elements" do end - + @tag :pending - test "test_store_sets_amount_to_100_by_default" do + test "test_purchase_using_reference_sets_proper_elements" do end - + @tag :pending - test "test_store_sets_amount_to_amount_from_options" do + test "test_authorization_with_recurring_transaction_type_initial" do end - + @tag :pending - test "test_authorization_using_reference_sets_proper_elements" do + test "test_purchase_using_with_recurring_transaction_type_initial" do end @tag :pending - test "test_purchase_using_reference_sets_proper_elements" do + test "test_description_trucated_to_32_chars_in_authorize" do end @tag :pending - test "test_authorization_with_recurring_transaction_type_initial" do + test "test_description_trucated_to_32_chars_in_purchase" do end @tag :pending - test "test_purchase_using_with_recurring_transaction_type_initial" do + test "test_description_is_ascii_encoded_since_wirecard_does_not_like_utf_8" do end + end + describe "system error in response in differnt request scenarios" do @tag :pending test "test_system_error_response" do end @@ -185,9 +196,5 @@ defmodule Gringotts.Gateways.WireCardTest do @tag :pending test "test_system_error_response_without_job" do end - - @tag :pending - test "test_transcript_scrubbing" do - end end end From ea32fa7dd85ddc04c56c49050a33719e7e455c65 Mon Sep 17 00:00:00 2001 From: voidzero Date: Wed, 27 Dec 2017 14:06:26 +0530 Subject: [PATCH 06/14] added response mocks for wirecard --- test/mocks/wirecard_mocks.exs | 193 ++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 test/mocks/wirecard_mocks.exs diff --git a/test/mocks/wirecard_mocks.exs b/test/mocks/wirecard_mocks.exs new file mode 100644 index 00000000..5597f16a --- /dev/null +++ b/test/mocks/wirecard_mocks.exs @@ -0,0 +1,193 @@ +defmodule Gringotts.Gateways.WireCardMock do + # Authorization success + def successful_authorization_response do + {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_PREAUTHORIZATION" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AVS" => %{"AuthorizationEntity" => "5", + "AuthorizationEntityMessage" => "Response provided by issuer processor.", + "Message" => "AVS Unavailable.", "ProviderResultCode" => "I", + "ProviderResultMessage" => "Address information is unavailable, or the Issuer does not support AVS. Acquirer has representment rights.", + "ResultCode" => "U"}, "AuthorizationCode" => "914683", + "CVCResponseCode" => "P", "FunctionResult" => "ACK", + "GuWID" => "C621878151436146500573", + "Info" => "THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED.", + "StatusType" => "INFO", "TimeStamp" => "2017-12-27 08:57:45"}, + "TransactionID" => "1"}, "FunctionID" => "dummy_description"}, + "JobID" => %{}}}, + "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + end + + def wrong_creditcard_authorization_response do + {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_PREAUTHORIZATION" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => %{}, + "ERROR" => %{"Advice" => "Only demo card number is allowed for VISA in demo mode.", + "Message" => "Credit card number not allowed in demo mode.", + "Number" => "24997", "Type" => "DATA_ERROR"}, + "FunctionResult" => "NOK", "GuWID" => "C828112151436189571040", + "StatusType" => "INFO", "TimeStamp" => "2017-12-27 09:04:55"}, + "TransactionID" => "1"}, "FunctionID" => "dummy_description"}, + "JobID" => %{}}}, + "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + end + + # Capture success + def successful_capture_response do + {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_CAPTURE" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => "600306", + "CVCResponseCode" => "P", "FunctionResult" => "PENDING", + "GuWID" => "C801119151436209066299", + "Info" => "THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED.", + "StatusType" => "INFO", "TimeStamp" => "2017-12-27 09:08:10"}, + "TransactionID" => "1"}, "FunctionID" => "dummy_description"}, + "JobID" => %{}}}, + "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + end + + # Capture failure + def unauthorized_capture_response do + {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_CAPTURE" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => %{}, + "ERROR" => %{"Message" => "Could not find referenced transaction for GuWID 1234567890123456789012.", + "Number" => "20080", "Type" => "DATA_ERROR"}, + "FunctionResult" => "NOK", "GuWID" => "C837754151436226322557", + "StatusType" => "INFO", "TimeStamp" => "2017-12-27 09:11:03"}, + "TransactionID" => "1"}, "FunctionID" => "dummy_description"}, + "JobID" => %{}}}, + "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + end + + # Purchase success + def successful_purchase_response do + {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_PURCHASE" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => "531750", + "FunctionResult" => "ACK", "GuWID" => "C865402121385575982910", + "Info" => "THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED.", + "StatusType" => "INFO", "TimeStamp" => "2008-06-19 08:09:19"}, + "TransactionID" => "1"}, + "FunctionID" => "Wirecard remote test purchase"}, + "JobID" => "test dummy data"}}, + "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + end + + # Refund success + def successful_refund_response do + {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_BOOKBACK" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => "424492", + "FunctionResult" => "ACK", "GuWID" => "C898842138247065382261", + "Info" => "All good!", "StatusType" => "INFO", + "TimeStamp" => "2013-10-22 21:37:33"}, + "TransactionID" => "2a486b3ab747df694d5460c3cb444591"}, + "FunctionID" => %{}}, "JobID" => %{}}}, + "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + end + + # Refund Failed + def failed_refund_response do + {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_BOOKBACK" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => %{}, + "ERROR" => %{"Message" => "Not prudent", "Number" => "20080", + "Type" => "DATA_ERROR"}, "FunctionResult" => "NOK", + "GuWID" => "C999187138247102291030", "StatusType" => "INFO", + "TimeStamp" => "2013-10-22 21:43:42"}, + "TransactionID" => "98680cbeee81d32e94a2b71397ffdf88"}, + "FunctionID" => %{}}, "JobID" => %{}}}, + "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + end + + # Void Success + def successful_void_response do + {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_REVERSAL" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => "802187", + "FunctionResult" => "ACK", "GuWID" => "C907807138247383379288", + "Info" => "Nice one!", "StatusType" => "INFO", + "TimeStamp" => "2013-10-22 22:30:33"}, + "TransactionID" => "5f1a2ab3fb2ed7a6aaa0eea74dc109e2"}, + "FunctionID" => %{}}, "JobID" => %{}}}, + "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + end + + # Void Failed + def failed_void_response do + {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_REVERSAL" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => %{}, + "ERROR" => %{"Message" => "Not gonna do it", "Number" => "20080", + "Type" => "DATA_ERROR"}, "FunctionResult" => "NOK", + "GuWID" => "C941776138247400010330", "StatusType" => "INFO", + "TimeStamp" => "2013-10-22 22:33:20"}, + "TransactionID" => "c11154e9395cf03c49bd68ec5c7087cc"}, + "FunctionID" => %{}}, "JobID" => %{}}}, + "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + end + + # Purchase failure + def wrong_creditcard_purchase_response do + {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_PURCHASE" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => %{}, + "ERROR" => %{"Advice" => "Only demo card number '4200000000000000' is allowed for VISA in demo mode.", + "Message" => "Credit card number not allowed in demo mode.", + "Number" => "24997", "Type" => "DATA_ERROR"}, + "FunctionResult" => "NOK", "GuWID" => "C824697121385153203112", + "StatusType" => "INFO", "TimeStamp" => "2008-06-19 06:58:51"}, + "TransactionID" => "1"}, + "FunctionID" => "Wirecard remote test purchase"}, + "JobID" => "test dummy data"}}, + "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + end + + # AVS failure + def failed_avs_response do + {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_PURCHASE" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AVS" => %{"AuthorizationEntity" => "5", + "AuthorizationEntityMessage" => "Response provided by issuer processor.", + "Message" => "AVS Unavailable.", "ProviderResultCode" => "A", + "ProviderResultMessage" => "Address information is unavailable, or the Issuer does not support AVS. Acquirer has representment rights.", + "ResultCode" => "U"}, "AuthorizationCode" => "732129", + "FunctionResult" => "PENDING", + "GuWID" => "C997753139988691610455", + "Info" => "THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED.", + "StatusType" => "INFO", "TimeStamp" => "2014-05-12 11:28:36"}, + "TransactionID" => "E0BCBF30B82D0131000000000000E4CF"}, + "FunctionID" => %{}}, "JobID" => %{}}}, + "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + end + + def system_error_response do + {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_PURCHASE" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => %{}, + "ERROR" => %{"Message" => %{}, "Number" => "20205", + "Type" => "SYSTEM_ERROR"}, "FunctionResult" => "NOK", + "GuWID" => "C967464140265180577024", + "Info" => "THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED.", + "StatusType" => "INFO", "TimeStamp" => "2014-06-13 11:30:05"}, + "TransactionID" => "3A368E50D50B01310000000000009153"}, + "FunctionID" => %{}}, "JobID" => %{}}}, + "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + end + + def system_error_response_without_job do + {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"ERROR" => %{"Message" => "Job Refused", + "Number" => "10003", "Type" => "SYSTEM_ERROR"}}, + "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + end + + def transcript do + {:ok, %{"WIRECARD_BXML" => %{"W_REQUEST" => %{"W_JOB" => %{"BusinessCaseSignature" => "00000031629CAFD5", + "FNC_CC_PURCHASE" => %{"CC_TRANSACTION" => %{"Amount" => "100", + "CORPTRUSTCENTER_DATA" => %{"ADDRESS" => %{"Address1" => "456 My Street", + "Address2" => "Apt 1", "City" => "Ottawa", "Country" => "CA", + "Email" => "soleone@example.com", "State" => "ON", + "ZipCode" => "K1C2N6"}}, + "CREDIT_CARD_DATA" => %{"CVC2" => "123", + "CardHolderName" => "Longbob Longsen", + "CreditCardNumber" => "4200000000000000", + "ExpirationMonth" => "09", "ExpirationYear" => "2016"}, + "CountryCode" => "CA", "Currency" => "EUR", + "RECURRING_TRANSACTION" => %{"Type" => "Single"}, + "TransactionID" => "1"}, + "FunctionID" => "Wirecard remote test purchase"}, "JobID" => %{}}}}}} + end + + def scrubbed_transcript do + {:ok, %{"WIRECARD_BXML" => %{"W_REQUEST" => %{"W_JOB" => %{"BusinessCaseSignature" => "00000031629CAFD5", + "FNC_CC_PURCHASE" => %{"CC_TRANSACTION" => %{"Amount" => "100", + "CORPTRUSTCENTER_DATA" => %{"ADDRESS" => %{"Address1" => "456 My Street", + "Address2" => "Apt 1", "City" => "Ottawa", "Country" => "CA", + "Email" => "soleone@example.com", "State" => "ON", + "ZipCode" => "K1C2N6"}}, + "CREDIT_CARD_DATA" => %{"CVC2" => "[FILTERED]", + "CardHolderName" => "Longbob Longsen", + "CreditCardNumber" => "[FILTERED]", "ExpirationMonth" => "09", + "ExpirationYear" => "2016"}, "CountryCode" => "CA", + "Currency" => "EUR", + "RECURRING_TRANSACTION" => %{"Type" => "Single"}, + "TransactionID" => "1"}, + "FunctionID" => "Wirecard remote test purchase"}, "JobID" => %{}}}}}} + end +end From f5d9a416e9d9742c3973d6c66907f70b2c188810 Mon Sep 17 00:00:00 2001 From: voidzero Date: Wed, 27 Dec 2017 15:46:08 +0530 Subject: [PATCH 07/14] modify test case statements --- test/gateways/wire_card_test.exs | 66 ++++++++++++++++---------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/test/gateways/wire_card_test.exs b/test/gateways/wire_card_test.exs index 8d1d9a13..22ad4a2c 100644 --- a/test/gateways/wire_card_test.exs +++ b/test/gateways/wire_card_test.exs @@ -13,9 +13,9 @@ defmodule Gringotts.Gateways.WireCardTest do alias Gringotts.Gateways.WireCard, as: Gateway - @test_authorization_guwid "C822580121385121429927" - @test_purchase_guwid "C865402121385575982910" - @test_capture_guwid "C833707121385268439116" + @with authorization_guwid "C822580121385121429927" + @with purchase_guwid "C865402121385575982910" + @with capture_guwid "C833707121385268439116" @card %CreditCard{ number: "4200000000000000", @@ -61,140 +61,140 @@ defmodule Gringotts.Gateways.WireCardTest do describe "authorize/3" do @tag :pending - test "test_successful_authorization" do + test "with successful authorization" do end @tag :pending - test "test_successful_reference_authorization" do + test "with successful reference authorization" do end @tag :pending - test "test_wrong_credit_card_authorization" do + test "with wrong credit card authorization" do end end describe "purchase/3" do @tag :pending - test "test_successful_purchase" do + test "with successful purchase" do end @tag :pending - test "test_successful_reference_purchase" do + test "with successful reference purchase" do end end describe "authorize/3 and capture/3" do @tag :pending - test "test_successful_authorization_and_capture" do + test "with successful authorization and capture" do end @tag :pending - test "test_successful_authorization_and_partial_capture" do + test "with successful authorization and partial capture" do end @tag :pending - test "test_unauthorized_capture" do + test "with unauthorized capture" do end end describe "refund/3" do @tag :pending - test "test_successful_refund" do + test "with successful refund" do end @tag :pending - test "test_failed_refund" do + test "with failed refund" do end end describe "void/2" do @tag :pending - test "test_successful_void" do + test "with successful void" do end @tag :pending - test "test_failed_void" do + test "with failed void" do end end describe "store/2" do @tag :pending - test "test_store_sets_recurring_transaction_type_to_initial" do + test "with store sets recurring transaction type to initial" do end @tag :pending - test "test_store_sets_amount_to_100_by_default" do + test "with store sets amount to 100 by default" do end @tag :pending - test "test_store_sets_amount_to_amount_from_options" do + test "with store sets amount to amount from options" do end end describe "scrubbing/1" do @tag :pending - test "test_transcript_scrubbing" do + test "with transcript scrubbing" do end end describe "testing response for different request scenarios" do @tag :pending - test "test_no_error_if_no_state_is_provided_in_address" do + test "with no error if no state is provided in address" do end @tag :pending - test "test_no_error_if_no_address_provided" do + test "with no error if no address provided" do end @tag :pending - test "test_failed_avs_response_message" do + test "with failed avs response message" do end @tag :pending - test "test_failed_amex_avs_response_code" do + test "with failed amex avs response code" do end @tag :pending # Not sure what is this need to check - test "test_commerce_type_option" do + test "with commerce type option" do end @tag :pending - test "test_authorization_using_reference_sets_proper_elements" do + test "with authorization using reference sets proper elements" do end @tag :pending - test "test_purchase_using_reference_sets_proper_elements" do + test "with purchase using reference sets proper elements" do end @tag :pending - test "test_authorization_with_recurring_transaction_type_initial" do + test "with authorization with recurring transaction type initial" do end @tag :pending - test "test_purchase_using_with_recurring_transaction_type_initial" do + test "with purchase using with recurring transaction type initial" do end @tag :pending - test "test_description_trucated_to_32_chars_in_authorize" do + test "with description trucated to 32 chars in authorize" do end @tag :pending - test "test_description_trucated_to_32_chars_in_purchase" do + test "with description trucated to 32 chars in purchase" do end @tag :pending - test "test_description_is_ascii_encoded_since_wirecard_does_not_like_utf_8" do + test "with description is ascii encoded since wirecard does not like utf 8" do end end describe "system error in response in differnt request scenarios" do @tag :pending - test "test_system_error_response" do + test "with system error response" do end @tag :pending - test "test_system_error_response_without_job" do + test "with system error response without job" do end end end From c0f323b8f3b381e9951b39705f9476366b40d423 Mon Sep 17 00:00:00 2001 From: voidzero Date: Wed, 27 Dec 2017 16:40:03 +0530 Subject: [PATCH 08/14] modify wirecard response mocks --- test/gateways/wire_card_test.exs | 14 +- test/mocks/wirecard_mocks.exs | 468 +++++++++++++++++++++---------- 2 files changed, 332 insertions(+), 150 deletions(-) diff --git a/test/gateways/wire_card_test.exs b/test/gateways/wire_card_test.exs index 22ad4a2c..64da9960 100644 --- a/test/gateways/wire_card_test.exs +++ b/test/gateways/wire_card_test.exs @@ -3,15 +3,15 @@ defmodule Gringotts.Gateways.WireCardTest do import Mock - setup do - # TEST_AUTHORIZATION_GUWID = 'C822580121385121429927' - # TEST_PURCHASE_GUWID = 'C865402121385575982910' - # TEST_CAPTURE_GUWID = 'C833707121385268439116' + # TEST_AUTHORIZATION_GUWID = 'C822580121385121429927' + # TEST_PURCHASE_GUWID = 'C865402121385575982910' + # TEST_CAPTURE_GUWID = 'C833707121385268439116' + alias Gringotts.{ CreditCard, } - - alias Gringotts.Gateways.WireCard, as: Gateway + alias Gringotts.Gateways.WireCard, as: Wirecard + alias Gringotts.Gateways.AuthorizeNetMock, as: MockResponse @with authorization_guwid "C822580121385121429927" @with purchase_guwid "C865402121385575982910" @@ -188,7 +188,7 @@ defmodule Gringotts.Gateways.WireCardTest do end end - describe "system error in response in differnt request scenarios" do + describe "testing system error in response in differnt request scenarios" do @tag :pending test "with system error response" do end diff --git a/test/mocks/wirecard_mocks.exs b/test/mocks/wirecard_mocks.exs index 5597f16a..5282358c 100644 --- a/test/mocks/wirecard_mocks.exs +++ b/test/mocks/wirecard_mocks.exs @@ -1,193 +1,375 @@ defmodule Gringotts.Gateways.WireCardMock do # Authorization success def successful_authorization_response do - {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_PREAUTHORIZATION" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AVS" => %{"AuthorizationEntity" => "5", - "AuthorizationEntityMessage" => "Response provided by issuer processor.", - "Message" => "AVS Unavailable.", "ProviderResultCode" => "I", - "ProviderResultMessage" => "Address information is unavailable, or the Issuer does not support AVS. Acquirer has representment rights.", - "ResultCode" => "U"}, "AuthorizationCode" => "914683", - "CVCResponseCode" => "P", "FunctionResult" => "ACK", - "GuWID" => "C621878151436146500573", - "Info" => "THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED.", - "StatusType" => "INFO", "TimeStamp" => "2017-12-27 08:57:45"}, - "TransactionID" => "1"}, "FunctionID" => "dummy_description"}, - "JobID" => %{}}}, - "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + {:ok, + %HTTPoison.Response{body: ~s{ + + + + + test dummy data + + Wirecard remote test purchase + + 1 + + C822580121385121429927 + 709678 + THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED. + INFO + ACK + 2008-06-19 06:53:33 + + + + + + }, + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200}} end def wrong_creditcard_authorization_response do - {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_PREAUTHORIZATION" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => %{}, - "ERROR" => %{"Advice" => "Only demo card number is allowed for VISA in demo mode.", - "Message" => "Credit card number not allowed in demo mode.", - "Number" => "24997", "Type" => "DATA_ERROR"}, - "FunctionResult" => "NOK", "GuWID" => "C828112151436189571040", - "StatusType" => "INFO", "TimeStamp" => "2017-12-27 09:04:55"}, - "TransactionID" => "1"}, "FunctionID" => "dummy_description"}, - "JobID" => %{}}}, - "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + {:ok, + %HTTPoison.Response{body: "\n\n\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\t\tdummy_description\n\t\t\t\t\n\t\t\t\t\t1\n\t\t\t\t\t\n\t\t\t\t\t\tC784893151437179785993\n\t\t\t\t\t\t\n\t\t\t\t\t\tINFO\n\t\t\t\t\t\tNOK\n\t\t\t\t\t\t\n\t\t\t\t\t\t\tDATA_ERROR\n\t\t\t\t\t\t\t24997\n\t\t\t\t\t\t\tCredit card number not allowed in demo mode.\n\t\t\t\t\t\t\tOnly demo card number is allowed for VISA in demo mode.\n\t\t\t\t\t\t\n\t\t\t\t\t\t2017-12-27 11:49:57\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\n\t\n\n", + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200}} end # Capture success def successful_capture_response do - {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_CAPTURE" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => "600306", - "CVCResponseCode" => "P", "FunctionResult" => "PENDING", - "GuWID" => "C801119151436209066299", - "Info" => "THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED.", - "StatusType" => "INFO", "TimeStamp" => "2017-12-27 09:08:10"}, - "TransactionID" => "1"}, "FunctionID" => "dummy_description"}, - "JobID" => %{}}}, - "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + {:ok, + %HTTPoison.Response{body: ~s{ + + + + + test dummy data + + Wirecard remote test purchase + + 1 + + C833707121385268439116 + 915025 + THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED. + INFO + ACK + 2008-06-19 07:18:04 + + + + + + }, + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200}} end # Capture failure def unauthorized_capture_response do - {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_CAPTURE" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => %{}, - "ERROR" => %{"Message" => "Could not find referenced transaction for GuWID 1234567890123456789012.", - "Number" => "20080", "Type" => "DATA_ERROR"}, - "FunctionResult" => "NOK", "GuWID" => "C837754151436226322557", - "StatusType" => "INFO", "TimeStamp" => "2017-12-27 09:11:03"}, - "TransactionID" => "1"}, "FunctionID" => "dummy_description"}, - "JobID" => %{}}}, - "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + {:ok, %HTTPoison.Response{body: ~s{ + + + + + test dummy data + + Test dummy FunctionID + + a2783d471ccc98825b8c498f1a62ce8f + + C833707121385268439116 + + INFO + NOK + + DATA_ERROR + 20080 + Could not find referenced transaction for GuWID 1234567890123456789012. + + 2008-06-19 08:09:20 + + + + + + }, + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200}} end # Purchase success def successful_purchase_response do - {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_PURCHASE" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => "531750", - "FunctionResult" => "ACK", "GuWID" => "C865402121385575982910", - "Info" => "THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED.", - "StatusType" => "INFO", "TimeStamp" => "2008-06-19 08:09:19"}, - "TransactionID" => "1"}, - "FunctionID" => "Wirecard remote test purchase"}, - "JobID" => "test dummy data"}}, - "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + {:ok, %HTTPoison.Response{body: ~s{ + + + + + test dummy data + + Wirecard remote test purchase + + 1 + + C865402121385575982910 + 531750 + THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED. + INFO + ACK + 2008-06-19 08:09:19 + + + + + + }, + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200}} end # Refund success def successful_refund_response do - {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_BOOKBACK" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => "424492", - "FunctionResult" => "ACK", "GuWID" => "C898842138247065382261", - "Info" => "All good!", "StatusType" => "INFO", - "TimeStamp" => "2013-10-22 21:37:33"}, - "TransactionID" => "2a486b3ab747df694d5460c3cb444591"}, - "FunctionID" => %{}}, "JobID" => %{}}}, - "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + {:ok, %HTTPoison.Response{body: ~s{ + + + + + + + + + 2a486b3ab747df694d5460c3cb444591 + + C898842138247065382261 + 424492 + All good! + INFO + ACK + 2013-10-22 21:37:33 + + + + + + }, + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200}} end # Refund Failed def failed_refund_response do - {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_BOOKBACK" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => %{}, - "ERROR" => %{"Message" => "Not prudent", "Number" => "20080", - "Type" => "DATA_ERROR"}, "FunctionResult" => "NOK", - "GuWID" => "C999187138247102291030", "StatusType" => "INFO", - "TimeStamp" => "2013-10-22 21:43:42"}, - "TransactionID" => "98680cbeee81d32e94a2b71397ffdf88"}, - "FunctionID" => %{}}, "JobID" => %{}}}, - "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + {:ok, %HTTPoison.Response{body: ~s{ + + + + + + + + + 98680cbeee81d32e94a2b71397ffdf88 + + C999187138247102291030 + + INFO + NOK + + DATA_ERROR + 20080 + Not prudent + + 2013-10-22 21:43:42 + + + + + + }, + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200}} + end # Void Success def successful_void_response do - {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_REVERSAL" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => "802187", - "FunctionResult" => "ACK", "GuWID" => "C907807138247383379288", - "Info" => "Nice one!", "StatusType" => "INFO", - "TimeStamp" => "2013-10-22 22:30:33"}, - "TransactionID" => "5f1a2ab3fb2ed7a6aaa0eea74dc109e2"}, - "FunctionID" => %{}}, "JobID" => %{}}}, - "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + {:ok, %HTTPoison.Response{body: ~s{ + + + + + + + + + 5f1a2ab3fb2ed7a6aaa0eea74dc109e2 + + C907807138247383379288 + 802187 + Nice one! + INFO + ACK + 2013-10-22 22:30:33 + + + + + + }, + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200}} end # Void Failed def failed_void_response do - {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_REVERSAL" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => %{}, - "ERROR" => %{"Message" => "Not gonna do it", "Number" => "20080", - "Type" => "DATA_ERROR"}, "FunctionResult" => "NOK", - "GuWID" => "C941776138247400010330", "StatusType" => "INFO", - "TimeStamp" => "2013-10-22 22:33:20"}, - "TransactionID" => "c11154e9395cf03c49bd68ec5c7087cc"}, - "FunctionID" => %{}}, "JobID" => %{}}}, - "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + {:ok, %HTTPoison.Response{body: ~s{ + + + + + + + + + c11154e9395cf03c49bd68ec5c7087cc + + C941776138247400010330 + + INFO + NOK + + DATA_ERROR + 20080 + Not gonna do it + + 2013-10-22 22:33:20 + + + + + + }, + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200}} end # Purchase failure def wrong_creditcard_purchase_response do - {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_PURCHASE" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => %{}, - "ERROR" => %{"Advice" => "Only demo card number '4200000000000000' is allowed for VISA in demo mode.", - "Message" => "Credit card number not allowed in demo mode.", - "Number" => "24997", "Type" => "DATA_ERROR"}, - "FunctionResult" => "NOK", "GuWID" => "C824697121385153203112", - "StatusType" => "INFO", "TimeStamp" => "2008-06-19 06:58:51"}, - "TransactionID" => "1"}, - "FunctionID" => "Wirecard remote test purchase"}, - "JobID" => "test dummy data"}}, - "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + {:ok, %HTTPoison.Response{body: ~s{ + + + + + test dummy data + + Wirecard remote test purchase + + 1 + + C824697121385153203112 + + INFO + NOK + + DATA_ERROR 24997 + Credit card number not allowed in demo mode. + Only demo card number '4200000000000000' is allowed for VISA in demo mode. + + 2008-06-19 06:58:51 + + + + + + }, + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200}} end # AVS failure def failed_avs_response do - {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_PURCHASE" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AVS" => %{"AuthorizationEntity" => "5", - "AuthorizationEntityMessage" => "Response provided by issuer processor.", - "Message" => "AVS Unavailable.", "ProviderResultCode" => "A", - "ProviderResultMessage" => "Address information is unavailable, or the Issuer does not support AVS. Acquirer has representment rights.", - "ResultCode" => "U"}, "AuthorizationCode" => "732129", - "FunctionResult" => "PENDING", - "GuWID" => "C997753139988691610455", - "Info" => "THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED.", - "StatusType" => "INFO", "TimeStamp" => "2014-05-12 11:28:36"}, - "TransactionID" => "E0BCBF30B82D0131000000000000E4CF"}, - "FunctionID" => %{}}, "JobID" => %{}}}, - "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} + {:ok, %HTTPoison.Response{body: ~s{ + + + + + + + + + E0BCBF30B82D0131000000000000E4CF + + C997753139988691610455 + 732129 + THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED. + INFO + PENDING + + U + AVS Unavailable. + 5 + Response provided by issuer processor. + A + Address information is unavailable, or the Issuer does not support AVS. Acquirer has representment rights. + + 2014-05-12 11:28:36 + + + + + + }, + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200}} end def system_error_response do - {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"W_JOB" => %{"FNC_CC_PURCHASE" => %{"CC_TRANSACTION" => %{"PROCESSING_STATUS" => %{"AuthorizationCode" => %{}, - "ERROR" => %{"Message" => %{}, "Number" => "20205", - "Type" => "SYSTEM_ERROR"}, "FunctionResult" => "NOK", - "GuWID" => "C967464140265180577024", - "Info" => "THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED.", - "StatusType" => "INFO", "TimeStamp" => "2014-06-13 11:30:05"}, - "TransactionID" => "3A368E50D50B01310000000000009153"}, - "FunctionID" => %{}}, "JobID" => %{}}}, - "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} - end - - def system_error_response_without_job do - {:ok, %{"WIRECARD_BXML" => %{"W_RESPONSE" => %{"ERROR" => %{"Message" => "Job Refused", - "Number" => "10003", "Type" => "SYSTEM_ERROR"}}, - "{http://www.w3.org/1999/XMLSchema-instance}noNamespaceSchemaLocation" => "wirecard.xsd"}}} - end + {:ok, %HTTPoison.Response{body: ~s{ + + + + + + + + + 3A368E50D50B01310000000000009153 + + C967464140265180577024 + + THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED. + INFO + NOK + + SYSTEM_ERROR + 20205 + + + 2014-06-13 11:30:05 + + + + + + }, + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200}} - def transcript do - {:ok, %{"WIRECARD_BXML" => %{"W_REQUEST" => %{"W_JOB" => %{"BusinessCaseSignature" => "00000031629CAFD5", - "FNC_CC_PURCHASE" => %{"CC_TRANSACTION" => %{"Amount" => "100", - "CORPTRUSTCENTER_DATA" => %{"ADDRESS" => %{"Address1" => "456 My Street", - "Address2" => "Apt 1", "City" => "Ottawa", "Country" => "CA", - "Email" => "soleone@example.com", "State" => "ON", - "ZipCode" => "K1C2N6"}}, - "CREDIT_CARD_DATA" => %{"CVC2" => "123", - "CardHolderName" => "Longbob Longsen", - "CreditCardNumber" => "4200000000000000", - "ExpirationMonth" => "09", "ExpirationYear" => "2016"}, - "CountryCode" => "CA", "Currency" => "EUR", - "RECURRING_TRANSACTION" => %{"Type" => "Single"}, - "TransactionID" => "1"}, - "FunctionID" => "Wirecard remote test purchase"}, "JobID" => %{}}}}}} end - def scrubbed_transcript do - {:ok, %{"WIRECARD_BXML" => %{"W_REQUEST" => %{"W_JOB" => %{"BusinessCaseSignature" => "00000031629CAFD5", - "FNC_CC_PURCHASE" => %{"CC_TRANSACTION" => %{"Amount" => "100", - "CORPTRUSTCENTER_DATA" => %{"ADDRESS" => %{"Address1" => "456 My Street", - "Address2" => "Apt 1", "City" => "Ottawa", "Country" => "CA", - "Email" => "soleone@example.com", "State" => "ON", - "ZipCode" => "K1C2N6"}}, - "CREDIT_CARD_DATA" => %{"CVC2" => "[FILTERED]", - "CardHolderName" => "Longbob Longsen", - "CreditCardNumber" => "[FILTERED]", "ExpirationMonth" => "09", - "ExpirationYear" => "2016"}, "CountryCode" => "CA", - "Currency" => "EUR", - "RECURRING_TRANSACTION" => %{"Type" => "Single"}, - "TransactionID" => "1"}, - "FunctionID" => "Wirecard remote test purchase"}, "JobID" => %{}}}}}} + def system_error_response_without_job do + {:ok, %HTTPoison.Response{body: ~s{ + + + + + SYSTEM_ERROR + 10003 + Job Refused + + + }, + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200}} end end From 9501f5f738dbb0f96e3614791097b07d22c9a17e Mon Sep 17 00:00:00 2001 From: voidzero Date: Wed, 27 Dec 2017 18:51:23 +0530 Subject: [PATCH 09/14] added success failure test cases for wirecard authorize --- test/gateways/wire_card_test.exs | 41 +++++++++++++------ .../{wirecard_mocks.exs => wirecard_mock.exs} | 0 2 files changed, 29 insertions(+), 12 deletions(-) rename test/mocks/{wirecard_mocks.exs => wirecard_mock.exs} (100%) diff --git a/test/gateways/wire_card_test.exs b/test/gateways/wire_card_test.exs index 64da9960..5c144c9d 100644 --- a/test/gateways/wire_card_test.exs +++ b/test/gateways/wire_card_test.exs @@ -1,6 +1,6 @@ defmodule Gringotts.Gateways.WireCardTest do use ExUnit.Case, async: false - + Code.require_file "../mocks/wirecard_mock.exs", __DIR__ import Mock # TEST_AUTHORIZATION_GUWID = 'C822580121385121429927' @@ -10,12 +10,13 @@ defmodule Gringotts.Gateways.WireCardTest do alias Gringotts.{ CreditCard, } - alias Gringotts.Gateways.WireCard, as: Wirecard - alias Gringotts.Gateways.AuthorizeNetMock, as: MockResponse + alias Gringotts.Gateways.WireCard + alias Gringotts.Gateways.WireCardMock, as: MockResponse - @with authorization_guwid "C822580121385121429927" - @with purchase_guwid "C865402121385575982910" - @with capture_guwid "C833707121385268439116" + @test_authorization_guwid "C822580121385121429927" + @test_purchase_guwid "C865402121385575982910" + @test_capture_guwid "C833707121385268439116" + @amount 100 @card %CreditCard{ number: "4200000000000000", @@ -60,16 +61,32 @@ defmodule Gringotts.Gateways.WireCardTest do ] describe "authorize/3" do - @tag :pending test "with successful authorization" do + with_mock HTTPoison, + [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_authorization_response end] do + {:ok, response} = WireCard.authorize(@amount, @card, @options) + response_guwid = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["GuWID"] + assert response_guwid == @test_authorization_guwid + end end - @tag :pending test "with successful reference authorization" do - end - - @tag :pending - test "with wrong credit card authorization" do + with_mock HTTPoison, + [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_authorization_response end] do + {:ok, response} = WireCard.authorize(@amount, "709678", @options) + response_guwid = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["GuWID"] + assert response_guwid == @test_authorization_guwid + end + end + + test "with wrong credit card authorization" do + with_mock HTTPoison, + [request: fn(_method, _url, _body, _headers) -> MockResponse.wrong_creditcard_authorization_response end] do + {:ok, response} = WireCard.authorize(@amount, @declined_card, @options) + response_error = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["ERROR"] + assert "24997" === response_error["Number"] + assert "DATA_ERROR" === response_error["Type"] + end end end diff --git a/test/mocks/wirecard_mocks.exs b/test/mocks/wirecard_mock.exs similarity index 100% rename from test/mocks/wirecard_mocks.exs rename to test/mocks/wirecard_mock.exs From 1f6701da162f3f15fbac30ca7bc91bdf91c88bb3 Mon Sep 17 00:00:00 2001 From: voidzero Date: Wed, 27 Dec 2017 19:45:34 +0530 Subject: [PATCH 10/14] add test case for authorize and capture for success response --- test/gateways/wire_card_test.exs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/test/gateways/wire_card_test.exs b/test/gateways/wire_card_test.exs index 5c144c9d..cf53242a 100644 --- a/test/gateways/wire_card_test.exs +++ b/test/gateways/wire_card_test.exs @@ -91,18 +91,44 @@ defmodule Gringotts.Gateways.WireCardTest do end describe "purchase/3" do - @tag :pending test "with successful purchase" do + with_mock HTTPoison, + [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_purchase_response end] do + {:ok, response} = WireCard.purchase(@amount, @card, @options) + response_guwid = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PURCHASE"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["GuWID"] + assert response_guwid == @test_purchase_guwid + end end - @tag :pending test "with successful reference purchase" do + with_mock HTTPoison, + [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_purchase_response end] do + {:ok, response} = WireCard.purchase(@amount, "12345", @options) + response_guwid = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PURCHASE"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["GuWID"] + assert response_guwid == @test_purchase_guwid + end end end describe "authorize/3 and capture/3" do - @tag :pending + # This is Integration testing test "with successful authorization and capture" do + # Authorize first + response_guwid = with_mock HTTPoison, + [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_authorization_response end] do + {:ok, response} = WireCard.authorize(@amount, @card, @options) + response_guwid = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["GuWID"] + assert response_guwid == @test_authorization_guwid + response_guwid + end + + # capture + with_mock HTTPoison, + [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_authorization_response end] do + {:ok, response} = WireCard.capture(response_guwid, @amount, @options) + response_message = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["Info"] + assert response_message =~ "THIS IS A DEMO TRANSACTION" + end end @tag :pending From bbed54c89e53d3a478959ec1939ba5923a092fc9 Mon Sep 17 00:00:00 2001 From: voidzero Date: Thu, 28 Dec 2017 19:08:57 +0530 Subject: [PATCH 11/14] test cases for wirecard refund scenario --- test/gateways/wire_card_test.exs | 42 +++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/test/gateways/wire_card_test.exs b/test/gateways/wire_card_test.exs index cf53242a..348924fd 100644 --- a/test/gateways/wire_card_test.exs +++ b/test/gateways/wire_card_test.exs @@ -17,7 +17,7 @@ defmodule Gringotts.Gateways.WireCardTest do @test_purchase_guwid "C865402121385575982910" @test_capture_guwid "C833707121385268439116" @amount 100 - + @card %CreditCard{ number: "4200000000000000", month: 12, @@ -131,22 +131,52 @@ defmodule Gringotts.Gateways.WireCardTest do end end - @tag :pending test "with successful authorization and partial capture" do + # Authorize first + response_guwid = with_mock HTTPoison, + [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_authorization_response end] do + {:ok, response} = WireCard.authorize(@amount, @card, @options) + response_guwid = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["GuWID"] + assert response_guwid == @test_authorization_guwid + response_guwid + end + + # capture + with_mock HTTPoison, + [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_authorization_response end] do + {:ok, response} = WireCard.capture(response_guwid, (@amount - 10), @options) + response_message = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["Info"] + assert response_message =~ "THIS IS A DEMO TRANSACTION" + end end - @tag :pending - test "with unauthorized capture" do + test "with unauthorized capture" do + with_mock HTTPoison, + [request: fn(_method, _url, _body, _headers) -> MockResponse.unauthorized_capture_response end] do + {:ok, response} = WireCard.capture("1234567890123456789012", @amount, @options) + response_message = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_CAPTURE"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["ERROR"]["Message"] + assert response_message =~ "Could not find referenced transaction for GuWID 1234567890123456789012." + end end end describe "refund/3" do - @tag :pending test "with successful refund" do + with_mock HTTPoison, + [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_refund_response end] do + {:ok, response} = WireCard.refund(@amount - 10, @test_purchase_guwid, @options) + response_message = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_BOOKBACK"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["Info"] + assert response_message =~ "All good!" + end end - @tag :pending test "with failed refund" do + with_mock HTTPoison, + [request: fn(_method, _url, _body, _headers) -> MockResponse.failed_refund_response end] do + {:ok, response} = WireCard.capture(@test_capture_guwid, @amount - 10, @options) + response_message = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_BOOKBACK"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["ERROR"]["Message"] + assert response_message =~ "Not prudent" + end end end From 6fbf28ef0e0ce52bfe58e161b81df1bd71d84015 Mon Sep 17 00:00:00 2001 From: voidzero Date: Thu, 28 Dec 2017 19:32:58 +0530 Subject: [PATCH 12/14] added test cases for wirecard void function --- test/gateways/wire_card_test.exs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/test/gateways/wire_card_test.exs b/test/gateways/wire_card_test.exs index 348924fd..9075614e 100644 --- a/test/gateways/wire_card_test.exs +++ b/test/gateways/wire_card_test.exs @@ -173,7 +173,7 @@ defmodule Gringotts.Gateways.WireCardTest do test "with failed refund" do with_mock HTTPoison, [request: fn(_method, _url, _body, _headers) -> MockResponse.failed_refund_response end] do - {:ok, response} = WireCard.capture(@test_capture_guwid, @amount - 10, @options) + {:ok, response} = WireCard.refund("TheIdentifcation", @amount - 10, @options) response_message = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_BOOKBACK"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["ERROR"]["Message"] assert response_message =~ "Not prudent" end @@ -181,12 +181,22 @@ defmodule Gringotts.Gateways.WireCardTest do end describe "void/2" do - @tag :pending test "with successful void" do + with_mock HTTPoison, + [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_void_response end] do + {:ok, response} = WireCard.void(@test_purchase_guwid, @options) + response_message = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_REVERSAL"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["Info"] + assert response_message =~ "Nice one!" + end end - @tag :pending test "with failed void" do + with_mock HTTPoison, + [request: fn(_method, _url, _body, _headers) -> MockResponse.failed_void_response end] do + {:ok, response} = WireCard.void(@test_purchase_guwid, @options) + response_message = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_REVERSAL"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["ERROR"]["Message"] + assert response_message =~ "Not gonna do it" + end end end From 20f6118c3edf48b1251e7f1df02a447ddaf06b2f Mon Sep 17 00:00:00 2001 From: voidzero Date: Thu, 28 Dec 2017 19:34:46 +0530 Subject: [PATCH 13/14] fix test case for refund in wirecard --- test/gateways/wire_card_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/gateways/wire_card_test.exs b/test/gateways/wire_card_test.exs index 9075614e..285dc6b0 100644 --- a/test/gateways/wire_card_test.exs +++ b/test/gateways/wire_card_test.exs @@ -173,7 +173,7 @@ defmodule Gringotts.Gateways.WireCardTest do test "with failed refund" do with_mock HTTPoison, [request: fn(_method, _url, _body, _headers) -> MockResponse.failed_refund_response end] do - {:ok, response} = WireCard.refund("TheIdentifcation", @amount - 10, @options) + {:ok, response} = WireCard.refund(@amount - 10, "TheIdentifcation", @options) response_message = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_BOOKBACK"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["ERROR"]["Message"] assert response_message =~ "Not prudent" end From 81cfa2e352b8e04cf6ea01e3c15cc65391625ff4 Mon Sep 17 00:00:00 2001 From: Ananya Bahadur Date: Fri, 19 Jan 2018 17:27:09 +0530 Subject: [PATCH 14/14] Adapts WireCard with the Money protocol * Updated XmlBuilder calls, `doc/1` is now deprecated. * Removed various annoying warnings --- lib/gringotts/gateways/wire_card.ex | 265 ++++++++++++---------- lib/gringotts/utils/flatten_nested_map.ex | 21 -- test/gateways/wire_card_test.exs | 254 ++++++++++++++------- test/mocks/wirecard_mock.exs | 160 ++++++++----- 4 files changed, 427 insertions(+), 273 deletions(-) delete mode 100644 lib/gringotts/utils/flatten_nested_map.ex diff --git a/lib/gringotts/gateways/wire_card.ex b/lib/gringotts/gateways/wire_card.ex index 84f5c506..ef4b5a28 100644 --- a/lib/gringotts/gateways/wire_card.ex +++ b/lib/gringotts/gateways/wire_card.ex @@ -1,127 +1,156 @@ defmodule Gringotts.Gateways.WireCard do - @moduledoc ~S""" - An API client for the [WireCard](http://www.wirecard.com) gateway. + @moduledoc """ + An API client for the [WireCard][home] gateway. - For reference see [WireCard's CEE integration documentation](https://guides.wirecard.com/_export/pdf/wcp:test_mode) + For reference see [WireCard's CEE integration documentation][docs]. - The Following Features of WireCard are implemented: + The following features of WireCard are implemented: - | `type` | Action | Method | - | ------ | ------ | ------ | - | `PA` | Pre-authorize | `authorize/3` | - | `CP` | Capture | `capture/3` | - | `DB` | Debit | `purchase/3` | - | `RF` | Refund | `refund/3` | - | `RV` | Reversal | `void/2` | - | | Tokenization / Registrations | `store/2` | + | `type` | Action | Method | + | ------ | ------ | ------ | + **[citation-needed]** ## The `opts` argument - Most `Gringotts` API calls accept an optional `Keyword` list `opts` to supply - optional arguments for transactions with the WireCard gateway. The following keys - are supported: - - | Key | Remark | Status | - | ---- | --- | ---- | - | `order_id` | | implemented | - | `billing_address` | [Address Format](#address-format)| implemented | - | `description` | | Not implemented | - | `email` | | implemented | - | `ip` | | implemented | - | `test` | | implemented | - - ## - Address in `opts` should be `Map` with following keys: - - | Key | Remark | Status | - | ---- | --- | ---- | - | `name` | | implemented | - | `address1` | | implemented | - | `address2` | | implemented | - | `company` | | implemented | - | `city` | | implemented | - | `zip` | | implemented | - | `country` | | implemented | - | `phone` | | implemented | - | `fax` | | implemented | - - ## WireCard _quirks_ - * WireCard does not process money in cents, and the `amount` is by default considered to be cents. + Most `Gringotts` API calls accept an optional `keyword` list `opts` to supply + optional arguments for transactions with the WireCard gateway. The following + keys are supported **[citation-needed]** + + | Key | Remark | + | ---- | --- | + | `order_id` | | + | `billing_address` | [Address Format] | + | `description` | **Not implemented** | + | `email` | | + | `ip` | | + | `test` | | + + ### Schema + + 1. `billing_address` is a `map` containing the keys `[:name, :address1, + :address2, :company, :city, :zip, :country, :phone, :fax]` + - `:phone` must match `~r[\+\\d{1,3}(\(?\\d{3}\)?)?\\d{3}-\\d{4}-\\d{3}]`, + like so `+xxx(yyy)zzz-zzzz-ppp`, where: + + | Key | Value | + | --- | ----- | + | `xxx` | Country code | + | `yyy` | Area or city code | + | `zzz-zzzz` | Local number | + | `ppp` | PBX extension | + + ## Registering your WireCard account at `Gringotts` + + After [making an account on WireCard][dashboard], head to the dashboard and + find your account "secrets" in the appropriate section **[citation-needed]**. + + Here's how the secrets map to the required configuration parameters for + WireCard: + + | Config parameter | WireCard secret | + | ------- | ---- | + | `:username` | Username | + | `:password` | Password | + | `:signature` | Signature | + + Your Application config **must include the `:usename`, `:password`, `:signature` + fields** and would look something like this: + + config :gringotts, Gringotts.Gateways.WireCard, + adapter: Gringotts.Gateways.WireCard, + login: "your_secret_login", + password: "your_secret_password", + signature: "your_secret_signature" + + ## Scope of this module + + * WireCard processes money in the currenciy's divided units. For example, it + operates in cents as opposed to dollars in case of `USD`. + + ## Supported countries + + **[citation-needed]** + + ## Supported currencies + + **[citation-needed]** + + ## Following the examples + + 1. First, set up a sample application and configure it to work with MONEI. + - You could do that from scratch by following our [Getting Started](#) guide. + - To save you time, we recommend [cloning our example repo][example-repo] + that gives you a pre-configured sample app ready-to-go. + + You could use the same config or update it the with your "secrets" as + described + [above](#module-registering-your-wirecard-account-at-gringotts). + + 2. Run an `iex` session with `iex -S mix` and add some variable bindings and + aliases to it (to save some time): + ``` + iex> alias Gringotts.{Response, CreditCard, Gateways.WireCard} + iex> amount = Money.new(420, :EUR) + iex> card = %CreditCard{first_name: "Harry", + last_name: "Potter", + number: "4200000000000000", + year: 2099, month: 12, + verification_code: "123", + brand: "VISA"} + iex> address = %{ + name: "Hermione Granger", + address1: "301, Gryffindor", + address2: "Hogwarts Castle", + company: "Widgets Inc", + city: "Highlands", + state: "ON", + zip: "K1C2N6", + country: "CA", + phone: "(555)555-5555", + fax: "(555)555-6666"} + iex> opts = [order_id: 2018, + billing_address: address, + description: 'Wirecard remote test purchase', + email: "masterofdeath@ministryofmagic.gov", + ip: "127.0.0.1", + test: true] + ``` + + We'll be using these in the examples below. + + [example-repo]: https://github.com/aviabird/gringotts_example + + ## TODO + + * Docs + + [home]: http://www.wirecard.com + [docs]: https://guides.wirecard.com/_export/pdf/wcp:test_mode """ @test_url "https://c3-test.wirecard.com/secure/ssl-gateway" @live_url "https://c3.wirecard.com/secure/ssl-gateway" - @homepage_url "http://www.wirecard.com" - - @doc """ - Wirecard only allows phone numbers with a format like this: +xxx(yyy)zzz-zzzz-ppp, where: - xxx = Country code - yyy = Area or city code - zzz-zzzz = Local number - ppp = PBX extension - For example, a typical U.S. or Canadian number would be "+1(202)555-1234-739" indicating PBX extension 739 at phone - number 5551234 within area code 202 (country code 1). - """ @valid_phone_format ~r/\+\d{1,3}(\(?\d{3}\)?)?\d{3}-\d{4}-\d{3}/ - @default_currency "EUR" - @default_amount 100 + use Gringotts.Gateways.Base - use Gringotts.Adapter, required_config: [:login, :password, :signature] + use Gringotts.Adapter, required_config: [:username, :password, :signature] alias Gringotts.{ - CreditCard + CreditCard, + Money } - + import XmlBuilder @doc """ - Performs a (pre) Authorize operation. - - Authorization - the second parameter may be a CreditCard or - a String which represents a GuWID reference to an earlier - transaction. If a GuWID is given, rather than a CreditCard, - then then the :recurring option will be forced to "Repeated" - - ## Examples - Run this in your `iex -S mix` - ``` - creditcard = %CreditCard{ - number: "4200000000000000", - month: 12, - year: 2018, - first_name: "Longbob", - last_name: "Longsen", - verification_code: "123", - brand: "visa" - } + Performs a (pre) Authorize operation. - address = %{ - name: "Jim Smith", - address1: "456 My Street", - address2: "Apt 1", - company: "Widgets Inc", - city: "Ottawa", - state: "ON", - zip: "K1C2N6", - country: "CA", - phone: "(555)555-5555", - fax: "(555)555-6666" - } + The authorization validates the `card` details with the banking network, + places a hold on the transaction `amount` in the customer’s issuing bank and + also triggers risk management. Funds are not transferred. - options = [ - config: %{ - login: "00000031629CA9FA", - password: "TestXAPTER", - signature: "00000031629CAFD5", - }, - order_id: 1, - billing_address: address, - description: 'Wirecard remote test purchase', - email: "soleone@example.com", - ip: "127.0.0.1", - test: true - ] + If a GuWID reference to an earlier transaction is provided instead of a + `CreditCard.t`, then then the `:recurring` option will be set to "Repeated". """ - @spec authorize(Integer | Float, CreditCard.t() | String.t(), Keyword) :: {:ok, Map} + @spec authorize(Money.t(), CreditCard.t() | String.t(), keyword) :: {:ok | :error, map} def authorize(money, payment_method, options \\ []) def authorize(money, %CreditCard{} = creditcard, options) do @@ -138,7 +167,7 @@ defmodule Gringotts.Gateways.WireCard do Capture - the first paramter here should be a GuWid/authorization. Authorization is obtained by authorizing the creditcard. """ - @spec capture(String.t(), Float, Keyword) :: {:ok, Map} + @spec capture(String.t(), Money.t(), keyword) :: {:ok | :error, map} def capture(authorization, money, options \\ []) when is_binary(authorization) do options = Keyword.put(options, :preauthorization, authorization) commit(:post, :capture, money, options) @@ -150,7 +179,7 @@ defmodule Gringotts.Gateways.WireCard do transaction. If a GuWID is given, rather than a CreditCard, then then the :recurring option will be forced to "Repeated" """ - @spec purchase(Float | Integer, CreditCard | String.t(), Keyword) :: {:ok, Map} + @spec purchase(Money.t(), CreditCard.t() | String.t(), keyword) :: {:ok | :error, map} def purchase(money, payment_method, options \\ []) def purchase(money, %CreditCard{} = creditcard, options) do @@ -174,7 +203,7 @@ defmodule Gringotts.Gateways.WireCard do identification - The authorization string returned from the initial authorization or purchase. """ - @spec void(String.t(), Keyword) :: {:ok, Map} + @spec void(String.t(), keyword) :: {:ok | :error, map} def void(identification, options \\ []) when is_binary(identification) do options = Keyword.put(options, :preauthorization, identification) commit(:post, :reversal, nil, options) @@ -190,7 +219,7 @@ defmodule Gringotts.Gateways.WireCard do as an Integer value in cents. identification -- GuWID """ - @spec refund(Float, String.t(), Keyword) :: {:ok, Map} + @spec refund(Money.t(), String.t(), keyword) :: {:ok | :error, map} def refund(money, identification, options \\ []) when is_binary(identification) do options = Keyword.put(options, :preauthorization, identification) commit(:post, :bookback, money, options) @@ -227,14 +256,14 @@ defmodule Gringotts.Gateways.WireCard do the returned authorization/GuWID usable in later transactions with +options[:recurring] = 'Repeated'+. """ - @spec store(CreditCard.t(), Keyword) :: {:ok, Map} + @spec store(CreditCard.t(), keyword) :: {:ok | :error, map} def store(%CreditCard{} = creditcard, options \\ []) do options = options |> Keyword.put(:credit_card, creditcard) |> Keyword.put(:recurring, "Initial") - money = options[:amount] || @default_amount + money = options[:amount] # Amex does not support authorization_check case creditcard.brand do "american_express" -> commit(:post, :preauthorization, money, options) @@ -254,7 +283,7 @@ defmodule Gringotts.Gateways.WireCard do "Content-Type" => "text/xml", "Authorization" => encoded_credentials( - options[:config][:login], + options[:config][:usename], options[:config][:password] ) } @@ -267,7 +296,7 @@ defmodule Gringotts.Gateways.WireCard do {:ok, response} end - defp respond({:ok, %{body: body, status_code: status_code}}) do + defp respond({:ok, %{body: body}}) do {:error, "Some Error Occurred: \n #{inspect(body)}"} end @@ -283,7 +312,7 @@ defmodule Gringotts.Gateways.WireCard do options = Keyword.put(options, :action, action) request = - doc( + generate( element(:WIRECARD_BXML, [ element(:W_REQUEST, [ element(:W_JOB, [ @@ -292,7 +321,8 @@ defmodule Gringotts.Gateways.WireCard do add_transaction_data(action, money, options) ]) ]) - ]) + ]), + format: :none ) request @@ -410,7 +440,7 @@ defmodule Gringotts.Gateways.WireCard do defp add_invoice(money, options) do [ add_amount(money, options), - element(:Currency, currency(options)), + element(:Currency, Money.currency(money)), element(:CountryCode, options[:billing_address][:country]), element(:RECURRING_TRANSACTION, [ element(:Type, options[:recurring] || "Single") @@ -421,7 +451,10 @@ defmodule Gringotts.Gateways.WireCard do # Include the amount in the transaction-xml # TODO: check for localized currency or currency # localized_amount(money, options[:currency] || currency(money)) - defp add_amount(money, _options), do: element(:Amount, money) + defp add_amount(money, _options) do + {_, int_value, _} = Money.to_integer(money) + element(:Amount, int_value) + end defp atom_to_upcase_string(atom) do atom @@ -443,6 +476,4 @@ defmodule Gringotts.Gateways.WireCard do defp regex_match(regex, string), do: Regex.match?(regex, string) defp base_url(opts), do: if(opts[:test], do: @test_url, else: @live_url) - - defp currency(opts), do: opts[:currency] || @default_currency end diff --git a/lib/gringotts/utils/flatten_nested_map.ex b/lib/gringotts/utils/flatten_nested_map.ex deleted file mode 100644 index 7a18db6b..00000000 --- a/lib/gringotts/utils/flatten_nested_map.ex +++ /dev/null @@ -1,21 +0,0 @@ -defmodule Utils.Json do - def flatten(map) when is_map(map) do - map - |> to_list_of_tuples - |> Enum.into(%{}) - end - - defp to_list_of_tuples(m) do - m - |> Enum.map(&process/1) - |> List.flatten - end - - defp process({key, sub_map}) when is_map(sub_map) do - for { sub_key, value } <- flatten(sub_map) do - { "#{key}.#{sub_key}", value } - end - end - - defp process(next), do: next -end diff --git a/test/gateways/wire_card_test.exs b/test/gateways/wire_card_test.exs index 285dc6b0..fa4157a9 100644 --- a/test/gateways/wire_card_test.exs +++ b/test/gateways/wire_card_test.exs @@ -1,23 +1,22 @@ defmodule Gringotts.Gateways.WireCardTest do use ExUnit.Case, async: false - Code.require_file "../mocks/wirecard_mock.exs", __DIR__ + Code.require_file("../mocks/wirecard_mock.exs", __DIR__) import Mock # TEST_AUTHORIZATION_GUWID = 'C822580121385121429927' # TEST_PURCHASE_GUWID = 'C865402121385575982910' # TEST_CAPTURE_GUWID = 'C833707121385268439116' - alias Gringotts.{ - CreditCard, - } + alias Gringotts.CreditCard alias Gringotts.Gateways.WireCard alias Gringotts.Gateways.WireCardMock, as: MockResponse @test_authorization_guwid "C822580121385121429927" - @test_purchase_guwid "C865402121385575982910" - @test_capture_guwid "C833707121385268439116" - @amount 100 - + @test_purchase_guwid "C865402121385575982910" + + @amount Money.new(1, :EUR) + @bad_amount Money.new("0.9", :EUR) + @card %CreditCard{ number: "4200000000000000", month: 12, @@ -39,16 +38,16 @@ defmodule Gringotts.Gateways.WireCardTest do } @address %{ - name: "Jim Smith", + name: "Jim Smith", address1: "456 My Street", address2: "Apt 1", - company: "Widgets Inc", - city: "Ottawa", - state: "ON", - zip: "K1C2N6", - country: "CA", - phone: "(555)555-5555", - fax: "(555)555-6666" + company: "Widgets Inc", + city: "Ottawa", + state: "ON", + zip: "K1C2N6", + country: "CA", + phone: "(555)555-5555", + fax: "(555)555-6666" } @options [ @@ -62,29 +61,50 @@ defmodule Gringotts.Gateways.WireCardTest do describe "authorize/3" do test "with successful authorization" do - with_mock HTTPoison, - [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_authorization_response end] do - {:ok, response} = WireCard.authorize(@amount, @card, @options) - response_guwid = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["GuWID"] + with_mock HTTPoison, + request: fn _method, _url, _body, _headers -> + MockResponse.successful_authorization_response() + end do + {:ok, response} = WireCard.authorize(@amount, @card, @options) + + response_guwid = + response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"][ + "CC_TRANSACTION" + ]["PROCESSING_STATUS"]["GuWID"] + assert response_guwid == @test_authorization_guwid end end test "with successful reference authorization" do - with_mock HTTPoison, - [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_authorization_response end] do + with_mock HTTPoison, + request: fn _method, _url, _body, _headers -> + MockResponse.successful_authorization_response() + end do {:ok, response} = WireCard.authorize(@amount, "709678", @options) - response_guwid = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["GuWID"] + + response_guwid = + response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"][ + "CC_TRANSACTION" + ]["PROCESSING_STATUS"]["GuWID"] + assert response_guwid == @test_authorization_guwid end end test "with wrong credit card authorization" do - with_mock HTTPoison, - [request: fn(_method, _url, _body, _headers) -> MockResponse.wrong_creditcard_authorization_response end] do + with_mock HTTPoison, + request: fn _method, _url, _body, _headers -> + MockResponse.wrong_creditcard_authorization_response() + end do {:ok, response} = WireCard.authorize(@amount, @declined_card, @options) - response_error = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["ERROR"] - assert "24997" === response_error["Number"] + + response_error = + response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"][ + "CC_TRANSACTION" + ]["PROCESSING_STATUS"]["ERROR"] + + assert "24997" === response_error["Number"] assert "DATA_ERROR" === response_error["Type"] end end @@ -92,19 +112,33 @@ defmodule Gringotts.Gateways.WireCardTest do describe "purchase/3" do test "with successful purchase" do - with_mock HTTPoison, - [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_purchase_response end] do + with_mock HTTPoison, + request: fn _method, _url, _body, _headers -> + MockResponse.successful_purchase_response() + end do {:ok, response} = WireCard.purchase(@amount, @card, @options) - response_guwid = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PURCHASE"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["GuWID"] + + response_guwid = + response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PURCHASE"]["CC_TRANSACTION"][ + "PROCESSING_STATUS" + ]["GuWID"] + assert response_guwid == @test_purchase_guwid end end test "with successful reference purchase" do - with_mock HTTPoison, - [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_purchase_response end] do + with_mock HTTPoison, + request: fn _method, _url, _body, _headers -> + MockResponse.successful_purchase_response() + end do {:ok, response} = WireCard.purchase(@amount, "12345", @options) - response_guwid = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PURCHASE"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["GuWID"] + + response_guwid = + response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PURCHASE"]["CC_TRANSACTION"][ + "PROCESSING_STATUS" + ]["GuWID"] + assert response_guwid == @test_purchase_guwid end end @@ -114,67 +148,117 @@ defmodule Gringotts.Gateways.WireCardTest do # This is Integration testing test "with successful authorization and capture" do # Authorize first - response_guwid = with_mock HTTPoison, - [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_authorization_response end] do - {:ok, response} = WireCard.authorize(@amount, @card, @options) - response_guwid = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["GuWID"] - assert response_guwid == @test_authorization_guwid - response_guwid - end + response_guwid = + with_mock HTTPoison, + request: fn _method, _url, _body, _headers -> + MockResponse.successful_authorization_response() + end do + {:ok, response} = WireCard.authorize(@amount, @card, @options) + + response_guwid = + response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"][ + "CC_TRANSACTION" + ]["PROCESSING_STATUS"]["GuWID"] + + assert response_guwid == @test_authorization_guwid + response_guwid + end # capture - with_mock HTTPoison, - [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_authorization_response end] do + with_mock HTTPoison, + request: fn _method, _url, _body, _headers -> + MockResponse.successful_authorization_response() + end do {:ok, response} = WireCard.capture(response_guwid, @amount, @options) - response_message = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["Info"] + + response_message = + response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"][ + "CC_TRANSACTION" + ]["PROCESSING_STATUS"]["Info"] + assert response_message =~ "THIS IS A DEMO TRANSACTION" end end test "with successful authorization and partial capture" do # Authorize first - response_guwid = with_mock HTTPoison, - [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_authorization_response end] do - {:ok, response} = WireCard.authorize(@amount, @card, @options) - response_guwid = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["GuWID"] - assert response_guwid == @test_authorization_guwid - response_guwid - end + response_guwid = + with_mock HTTPoison, + request: fn _method, _url, _body, _headers -> + MockResponse.successful_authorization_response() + end do + {:ok, response} = WireCard.authorize(@amount, @card, @options) + + response_guwid = + response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"][ + "CC_TRANSACTION" + ]["PROCESSING_STATUS"]["GuWID"] + + assert response_guwid == @test_authorization_guwid + response_guwid + end # capture - with_mock HTTPoison, - [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_authorization_response end] do - {:ok, response} = WireCard.capture(response_guwid, (@amount - 10), @options) - response_message = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["Info"] + with_mock HTTPoison, + request: fn _method, _url, _body, _headers -> + MockResponse.successful_authorization_response() + end do + {:ok, response} = WireCard.capture(response_guwid, @bad_amount, @options) + + response_message = + response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_PREAUTHORIZATION"][ + "CC_TRANSACTION" + ]["PROCESSING_STATUS"]["Info"] + assert response_message =~ "THIS IS A DEMO TRANSACTION" end end test "with unauthorized capture" do - with_mock HTTPoison, - [request: fn(_method, _url, _body, _headers) -> MockResponse.unauthorized_capture_response end] do + with_mock HTTPoison, + request: fn _method, _url, _body, _headers -> + MockResponse.unauthorized_capture_response() + end do {:ok, response} = WireCard.capture("1234567890123456789012", @amount, @options) - response_message = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_CAPTURE"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["ERROR"]["Message"] - assert response_message =~ "Could not find referenced transaction for GuWID 1234567890123456789012." + + response_message = + response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_CAPTURE"]["CC_TRANSACTION"][ + "PROCESSING_STATUS" + ]["ERROR"]["Message"] + + assert response_message =~ + "Could not find referenced transaction for GuWID 1234567890123456789012." end end end describe "refund/3" do test "with successful refund" do - with_mock HTTPoison, - [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_refund_response end] do - {:ok, response} = WireCard.refund(@amount - 10, @test_purchase_guwid, @options) - response_message = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_BOOKBACK"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["Info"] + with_mock HTTPoison, + request: fn _method, _url, _body, _headers -> + MockResponse.successful_refund_response() + end do + {:ok, response} = WireCard.refund(@bad_amount, @test_purchase_guwid, @options) + + response_message = + response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_BOOKBACK"]["CC_TRANSACTION"][ + "PROCESSING_STATUS" + ]["Info"] + assert response_message =~ "All good!" end end test "with failed refund" do - with_mock HTTPoison, - [request: fn(_method, _url, _body, _headers) -> MockResponse.failed_refund_response end] do - {:ok, response} = WireCard.refund(@amount - 10, "TheIdentifcation", @options) - response_message = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_BOOKBACK"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["ERROR"]["Message"] + with_mock HTTPoison, + request: fn _method, _url, _body, _headers -> MockResponse.failed_refund_response() end do + {:ok, response} = WireCard.refund(@bad_amount, "TheIdentifcation", @options) + + response_message = + response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_BOOKBACK"]["CC_TRANSACTION"][ + "PROCESSING_STATUS" + ]["ERROR"]["Message"] + assert response_message =~ "Not prudent" end end @@ -182,19 +266,29 @@ defmodule Gringotts.Gateways.WireCardTest do describe "void/2" do test "with successful void" do - with_mock HTTPoison, - [request: fn(_method, _url, _body, _headers) -> MockResponse.successful_void_response end] do + with_mock HTTPoison, + request: fn _method, _url, _body, _headers -> MockResponse.successful_void_response() end do {:ok, response} = WireCard.void(@test_purchase_guwid, @options) - response_message = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_REVERSAL"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["Info"] + + response_message = + response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_REVERSAL"]["CC_TRANSACTION"][ + "PROCESSING_STATUS" + ]["Info"] + assert response_message =~ "Nice one!" end end test "with failed void" do - with_mock HTTPoison, - [request: fn(_method, _url, _body, _headers) -> MockResponse.failed_void_response end] do + with_mock HTTPoison, + request: fn _method, _url, _body, _headers -> MockResponse.failed_void_response() end do {:ok, response} = WireCard.void(@test_purchase_guwid, @options) - response_message = response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_REVERSAL"]["CC_TRANSACTION"]["PROCESSING_STATUS"]["ERROR"]["Message"] + + response_message = + response["WIRECARD_BXML"]["W_RESPONSE"]["W_JOB"]["FNC_CC_REVERSAL"]["CC_TRANSACTION"][ + "PROCESSING_STATUS" + ]["ERROR"]["Message"] + assert response_message =~ "Not gonna do it" end end @@ -205,10 +299,6 @@ defmodule Gringotts.Gateways.WireCardTest do test "with store sets recurring transaction type to initial" do end - @tag :pending - test "with store sets amount to 100 by default" do - end - @tag :pending test "with store sets amount to amount from options" do end @@ -245,15 +335,15 @@ defmodule Gringotts.Gateways.WireCardTest do @tag :pending test "with authorization using reference sets proper elements" do end - + @tag :pending test "with purchase using reference sets proper elements" do end - + @tag :pending test "with authorization with recurring transaction type initial" do end - + @tag :pending test "with purchase using with recurring transaction type initial" do end @@ -267,17 +357,17 @@ defmodule Gringotts.Gateways.WireCardTest do end @tag :pending - test "with description is ascii encoded since wirecard does not like utf 8" do + test "with description is ascii encoded since wirecard does not like utf 8" do end end describe "testing system error in response in differnt request scenarios" do @tag :pending - test "with system error response" do + test "with system error response" do end @tag :pending - test "with system error response without job" do + test "with system error response without job" do end end end diff --git a/test/mocks/wirecard_mock.exs b/test/mocks/wirecard_mock.exs index 5282358c..ebbe6cc1 100644 --- a/test/mocks/wirecard_mock.exs +++ b/test/mocks/wirecard_mock.exs @@ -2,7 +2,8 @@ defmodule Gringotts.Gateways.WireCardMock do # Authorization success def successful_authorization_response do {:ok, - %HTTPoison.Response{body: ~s{ + %HTTPoison.Response{ + body: ~s{ @@ -15,7 +16,8 @@ defmodule Gringotts.Gateways.WireCardMock do C822580121385121429927 709678 - THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED. + THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. + NO REAL MONEY WILL BE TRANSFERED. INFO ACK 2008-06-19 06:53:33 @@ -25,21 +27,26 @@ defmodule Gringotts.Gateways.WireCardMock do }, - request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", - status_code: 200}} + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200 + }} end def wrong_creditcard_authorization_response do {:ok, - %HTTPoison.Response{body: "\n\n\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\t\tdummy_description\n\t\t\t\t\n\t\t\t\t\t1\n\t\t\t\t\t\n\t\t\t\t\t\tC784893151437179785993\n\t\t\t\t\t\t\n\t\t\t\t\t\tINFO\n\t\t\t\t\t\tNOK\n\t\t\t\t\t\t\n\t\t\t\t\t\t\tDATA_ERROR\n\t\t\t\t\t\t\t24997\n\t\t\t\t\t\t\tCredit card number not allowed in demo mode.\n\t\t\t\t\t\t\tOnly demo card number is allowed for VISA in demo mode.\n\t\t\t\t\t\t\n\t\t\t\t\t\t2017-12-27 11:49:57\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\n\t\n\n", - request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", - status_code: 200}} + %HTTPoison.Response{ + body: + "\n\n\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\t\tdummy_description\n\t\t\t\t\n\t\t\t\t\t1\n\t\t\t\t\t\n\t\t\t\t\t\tC784893151437179785993\n\t\t\t\t\t\t\n\t\t\t\t\t\tINFO\n\t\t\t\t\t\tNOK\n\t\t\t\t\t\t\n\t\t\t\t\t\t\tDATA_ERROR\n\t\t\t\t\t\t\t24997\n\t\t\t\t\t\t\tCredit card number not allowed in demo mode.\n\t\t\t\t\t\t\tOnly demo card number is allowed for VISA in demo mode.\n\t\t\t\t\t\t\n\t\t\t\t\t\t2017-12-27 11:49:57\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\n\t\n\n", + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200 + }} end # Capture success def successful_capture_response do {:ok, - %HTTPoison.Response{body: ~s{ + %HTTPoison.Response{ + body: ~s{ @@ -52,7 +59,8 @@ defmodule Gringotts.Gateways.WireCardMock do C833707121385268439116 915025 - THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED. + THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. + NO REAL MONEY WILL BE TRANSFERED. INFO ACK 2008-06-19 07:18:04 @@ -62,13 +70,16 @@ defmodule Gringotts.Gateways.WireCardMock do }, - request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", - status_code: 200}} + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200 + }} end # Capture failure def unauthorized_capture_response do - {:ok, %HTTPoison.Response{body: ~s{ + {:ok, + %HTTPoison.Response{ + body: ~s{ @@ -86,7 +97,9 @@ defmodule Gringotts.Gateways.WireCardMock do DATA_ERROR 20080 - Could not find referenced transaction for GuWID 1234567890123456789012. + + Could not find referenced transaction for GuWID 1234567890123456789012. + 2008-06-19 08:09:20 @@ -95,13 +108,16 @@ defmodule Gringotts.Gateways.WireCardMock do }, - request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", - status_code: 200}} + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200 + }} end # Purchase success def successful_purchase_response do - {:ok, %HTTPoison.Response{body: ~s{ + {:ok, + %HTTPoison.Response{ + body: ~s{ @@ -114,7 +130,10 @@ defmodule Gringotts.Gateways.WireCardMock do C865402121385575982910 531750 - THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED. + + THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. + NO REAL MONEY WILL BE TRANSFERED. + INFO ACK 2008-06-19 08:09:19 @@ -124,13 +143,16 @@ defmodule Gringotts.Gateways.WireCardMock do }, - request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", - status_code: 200}} + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200 + }} end # Refund success def successful_refund_response do - {:ok, %HTTPoison.Response{body: ~s{ + {:ok, + %HTTPoison.Response{ + body: ~s{ @@ -153,13 +175,16 @@ defmodule Gringotts.Gateways.WireCardMock do }, - request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", - status_code: 200}} + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200 + }} end # Refund Failed def failed_refund_response do - {:ok, %HTTPoison.Response{body: ~s{ + {:ok, + %HTTPoison.Response{ + body: ~s{ @@ -186,14 +211,16 @@ defmodule Gringotts.Gateways.WireCardMock do }, - request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", - status_code: 200}} - + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200 + }} end # Void Success def successful_void_response do - {:ok, %HTTPoison.Response{body: ~s{ + {:ok, + %HTTPoison.Response{ + body: ~s{ @@ -216,13 +243,16 @@ defmodule Gringotts.Gateways.WireCardMock do }, - request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", - status_code: 200}} + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200 + }} end - - # Void Failed + + # Void Failed def failed_void_response do - {:ok, %HTTPoison.Response{body: ~s{ + {:ok, + %HTTPoison.Response{ + body: ~s{ @@ -249,13 +279,16 @@ defmodule Gringotts.Gateways.WireCardMock do }, - request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", - status_code: 200}} + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200 + }} end # Purchase failure def wrong_creditcard_purchase_response do - {:ok, %HTTPoison.Response{body: ~s{ + {:ok, + %HTTPoison.Response{ + body: ~s{ @@ -271,9 +304,12 @@ defmodule Gringotts.Gateways.WireCardMock do INFO NOK - DATA_ERROR 24997 + DATA_ERROR + 24997 Credit card number not allowed in demo mode. - Only demo card number '4200000000000000' is allowed for VISA in demo mode. + + Only demo card number '4200000000000000' is allowed for VISA in demo mode. + 2008-06-19 06:58:51 @@ -282,13 +318,16 @@ defmodule Gringotts.Gateways.WireCardMock do }, - request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", - status_code: 200}} + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200 + }} end # AVS failure def failed_avs_response do - {:ok, %HTTPoison.Response{body: ~s{ + {:ok, + %HTTPoison.Response{ + body: ~s{ @@ -301,16 +340,24 @@ defmodule Gringotts.Gateways.WireCardMock do C997753139988691610455 732129 - THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED. + + THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. + NO REAL MONEY WILL BE TRANSFERED. + INFO PENDING U AVS Unavailable. 5 - Response provided by issuer processor. + + Response provided by issuer processor. + A - Address information is unavailable, or the Issuer does not support AVS. Acquirer has representment rights. + + Address information is unavailable, or the Issuer does not support AVS. + Acquirer has representment rights. + 2014-05-12 11:28:36 @@ -319,12 +366,15 @@ defmodule Gringotts.Gateways.WireCardMock do }, - request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", - status_code: 200}} + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200 + }} end def system_error_response do - {:ok, %HTTPoison.Response{body: ~s{ + {:ok, + %HTTPoison.Response{ + body: ~s{ @@ -337,7 +387,8 @@ defmodule Gringotts.Gateways.WireCardMock do C967464140265180577024 - THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED. + THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. + NO REAL MONEY WILL BE TRANSFERED. INFO NOK @@ -352,13 +403,15 @@ defmodule Gringotts.Gateways.WireCardMock do }, - request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", - status_code: 200}} - + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200 + }} end def system_error_response_without_job do - {:ok, %HTTPoison.Response{body: ~s{ + {:ok, + %HTTPoison.Response{ + body: ~s{ @@ -369,7 +422,8 @@ defmodule Gringotts.Gateways.WireCardMock do }, - request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", - status_code: 200}} + request_url: "https://c3-test.wirecard.com/secure/ssl-gateway", + status_code: 200 + }} end end