From f84375f23231284159329a57365735a504bc3937 Mon Sep 17 00:00:00 2001 From: Lydia Koller Date: Wed, 15 Aug 2018 13:24:10 -0400 Subject: [PATCH 1/3] Create customer profile from transaction --- lib/elixir_authorizenet/customer.ex | 14 ++++++++++++++ test/resources/AnetApiSchema.xsd | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/elixir_authorizenet/customer.ex b/lib/elixir_authorizenet/customer.ex index 059023a..a6464f7 100644 --- a/lib/elixir_authorizenet/customer.ex +++ b/lib/elixir_authorizenet/customer.ex @@ -140,6 +140,20 @@ defmodule AuthorizeNet.Customer do %AuthorizeNet.Customer{profile | profile_id: profile_id} end + @spec create_from_transaction( + String.t, String.t, String.t, String.t + ) :: AuthorizeNet.Customer.t | no_return + def create_from_transaction(id, transaction_id, description, email) do + profile = new id, nil, description, email + profile_xml = to_xml profile + doc = Main.req :createCustomerProfileFromTransactionRequest, [ + customer: profile_xml, + transId: transaction_id, + ] + profile_id = xml_one_value_int doc, "//customerProfileId" + %AuthorizeNet.Customer{profile | profile_id: profile_id} + end + @doc """ Deletes a customer profile by customer profile ID. See: http://developer.authorize.net/api/reference/index.html#manage-customer-profiles-delete-customer-profile diff --git a/test/resources/AnetApiSchema.xsd b/test/resources/AnetApiSchema.xsd index ad8501b..1493030 100644 --- a/test/resources/AnetApiSchema.xsd +++ b/test/resources/AnetApiSchema.xsd @@ -2411,7 +2411,10 @@ @@ -2420,6 +2423,7 @@ + From 39aa3fe547bffacfa8a6de3452cc9b204e5fc772 Mon Sep 17 00:00:00 2001 From: Lydia Koller Date: Thu, 16 Aug 2018 10:03:57 -0400 Subject: [PATCH 2/3] Add BaseCustomer module --- lib/elixir_authorizenet/base_customer.ex | 42 ++++++++++++++++++++++++ lib/elixir_authorizenet/customer.ex | 29 ++++++++++++---- test/resources/AnetApiSchema.xsd | 26 +++++++-------- 3 files changed, 77 insertions(+), 20 deletions(-) create mode 100644 lib/elixir_authorizenet/base_customer.ex diff --git a/lib/elixir_authorizenet/base_customer.ex b/lib/elixir_authorizenet/base_customer.ex new file mode 100644 index 0000000..9ced11c --- /dev/null +++ b/lib/elixir_authorizenet/base_customer.ex @@ -0,0 +1,42 @@ +defmodule AuthorizeNet.BaseCustomer do + @moduledoc """ + Handles customer profiles (http://developer.authorize.net/api/reference/index.html#manage-customer-profiles). + + Copyright 2015 Marcelo Gornstein + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + """ + use AuthorizeNet.Helper.XML + defstruct id: nil, + email: nil, + description: nil + + @type t :: %AuthorizeNet.BaseCustomer{} + + @spec new( String.t, String.t, String.t + ) :: AuthorizeNet.BaseCustomer.t | no_return + def new( id, description, email) do + %AuthorizeNet.BaseCustomer{ + id: id, + description: description, + email: email + } + end + + def to_xml(customer) do + [ + merchantCustomerId: customer.id, + description: customer.description, + email: customer.email, + ] + end +end diff --git a/lib/elixir_authorizenet/customer.ex b/lib/elixir_authorizenet/customer.ex index a6464f7..29949db 100644 --- a/lib/elixir_authorizenet/customer.ex +++ b/lib/elixir_authorizenet/customer.ex @@ -19,6 +19,7 @@ defmodule AuthorizeNet.Customer do alias AuthorizeNet, as: Main alias AuthorizeNet.PaymentProfile, as: PaymentProfile alias AuthorizeNet.Address, as: Address + alias AuthorizeNet.BaseCustomer, as: BaseCustomer defstruct description: nil, email: nil, id: nil, @@ -141,17 +142,31 @@ defmodule AuthorizeNet.Customer do end @spec create_from_transaction( - String.t, String.t, String.t, String.t + String.t, String.t, String.t, String.t, String.t ) :: AuthorizeNet.Customer.t | no_return - def create_from_transaction(id, transaction_id, description, email) do - profile = new id, nil, description, email - profile_xml = to_xml profile + def create_from_transaction(id, nil, transaction_id, description, email) do + profile = BaseCustomer.new(id, description, email) + profile_xml = BaseCustomer.to_xml(profile) doc = Main.req :createCustomerProfileFromTransactionRequest, [ - customer: profile_xml, transId: transaction_id, + customer: profile_xml ] - profile_id = xml_one_value_int doc, "//customerProfileId" - %AuthorizeNet.Customer{profile | profile_id: profile_id} + customer_profile = new id, nil, description, email + customer_profile_id = xml_one_value_int doc, "//customerProfileId" + payment_profile_id = xml_one_value_int doc, "//numericString" + + %AuthorizeNet.Customer{customer_profile | profile_id: customer_profile_id, payment_profiles: [payment_profile_id]} + end + + def create_from_transaction(_id, profile_id, transaction_id, _description, _email) do + doc = Main.req :createCustomerProfileFromTransactionRequest, [ + transId: transaction_id, + customerProfileId: profile_id, + ] + customer_profile = get profile_id + payment_profile_id = xml_one_value_int doc, "//numericString" + + %AuthorizeNet.Customer{customer_profile | payment_profiles: [payment_profile_id]} end @doc """ diff --git a/test/resources/AnetApiSchema.xsd b/test/resources/AnetApiSchema.xsd index 1493030..3bab3b8 100644 --- a/test/resources/AnetApiSchema.xsd +++ b/test/resources/AnetApiSchema.xsd @@ -2417,19 +2417,19 @@ The merchant must be signed up for the CIM service to use it. =================================================================== --> - - - - - - - - - - - - - + + + + + + + + + + + + +