From cdac2e0997a919c72890f113c8e68cb8fe44a9e2 Mon Sep 17 00:00:00 2001 From: David Penner Date: Fri, 7 Apr 2017 09:29:09 -0500 Subject: [PATCH 1/7] Fixed ISubscriptionRequest so it does not depend on Subscription Request. --- Authorize.NET/ARB/ISubscriptionRequest.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Authorize.NET/ARB/ISubscriptionRequest.cs b/Authorize.NET/ARB/ISubscriptionRequest.cs index 6d68b479..6aa6546b 100644 --- a/Authorize.NET/ARB/ISubscriptionRequest.cs +++ b/Authorize.NET/ARB/ISubscriptionRequest.cs @@ -15,7 +15,7 @@ public interface ISubscriptionRequest { BankAccount eCheckBankAccount { get; set; } string CustomerEmail { get; set; } string CustomerID { get; set; } - AuthorizeNet.SubscriptionRequest SetTrialPeriod(short trialBillingCycles, decimal trialAmount); + AuthorizeNet.ISubscriptionRequest SetTrialPeriod(short trialBillingCycles, decimal trialAmount); AuthorizeNet.Address ShippingAddress { get; set; } DateTime StartsOn { get; set; } string SubscriptionID { get; set; } @@ -26,8 +26,8 @@ public interface ISubscriptionRequest { ARBSubscriptionType ToUpdateableAPI(); decimal TrialAmount { get; set; } short TrialBillingCycles { get; set; } - AuthorizeNet.SubscriptionRequest UsingCreditCard(string firstName, string lastName, string cardNumber, int cardExpirationYear, int cardExpirationMonth); - AuthorizeNet.SubscriptionRequest WithBillingAddress(AuthorizeNet.Address add); - AuthorizeNet.SubscriptionRequest WithShippingAddress(AuthorizeNet.Address add); + AuthorizeNet.ISubscriptionRequest UsingCreditCard(string firstName, string lastName, string cardNumber, int cardExpirationYear, int cardExpirationMonth); + AuthorizeNet.ISubscriptionRequest WithBillingAddress(AuthorizeNet.Address add); + AuthorizeNet.ISubscriptionRequest WithShippingAddress(AuthorizeNet.Address add); } } From 82a10bbaae25a89273493f0e402257dad277b60f Mon Sep 17 00:00:00 2001 From: David Penner Date: Fri, 7 Apr 2017 09:53:57 -0500 Subject: [PATCH 2/7] Added Support for Creating a Subscription from Customer Profile --- Authorize.NET/ARB/SubscriptionGateway.cs | 8 +- Authorize.NET/ARB/SubscriptionRequest.cs | 168 ++++++++++++++++------- 2 files changed, 117 insertions(+), 59 deletions(-) diff --git a/Authorize.NET/ARB/SubscriptionGateway.cs b/Authorize.NET/ARB/SubscriptionGateway.cs index 1cb8ecf3..c1586c93 100644 --- a/Authorize.NET/ARB/SubscriptionGateway.cs +++ b/Authorize.NET/ARB/SubscriptionGateway.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Xml.Serialization; -using System.IO; -using AuthorizeNet.APICore; +using AuthorizeNet.APICore; namespace AuthorizeNet { public class SubscriptionGateway : ISubscriptionGateway { diff --git a/Authorize.NET/ARB/SubscriptionRequest.cs b/Authorize.NET/ARB/SubscriptionRequest.cs index 58b61d25..fdb97683 100644 --- a/Authorize.NET/ARB/SubscriptionRequest.cs +++ b/Authorize.NET/ARB/SubscriptionRequest.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Text; using AuthorizeNet.APICore; @@ -119,7 +117,7 @@ public static SubscriptionRequest CreateWeekly(string email, string subscription /// The card expiration year. /// The card expiration month. /// - public SubscriptionRequest UsingCreditCard(string firstName, string lastName, string cardNumber, int cardExpirationYear, int cardExpirationMonth) { + public ISubscriptionRequest UsingCreditCard(string firstName, string lastName, string cardNumber, int cardExpirationYear, int cardExpirationMonth) { this.CardNumber = cardNumber; this.CardExpirationYear = cardExpirationYear; this.CardExpirationMonth = cardExpirationMonth; @@ -132,12 +130,22 @@ public SubscriptionRequest UsingCreditCard(string firstName, string lastName, st return this; } + public ISubscriptionRequest UsingPaymentProfile(string customerProfileId, string customerPaymentProfileId, string customerAddressId) + { + this.CustomerProfileId = customerProfileId; + this.CustomerPaymentProfileId = customerPaymentProfileId; + this.CustomerAddressId = customerAddressId; + + return this; + } + /// /// Adds a full billing address - which is required for a credit card. /// /// The add. /// - public SubscriptionRequest WithBillingAddress(Address add) { + public ISubscriptionRequest WithBillingAddress(Address add) + { this.BillingAddress = add; return this; } @@ -148,7 +156,8 @@ public SubscriptionRequest WithBillingAddress(Address add) { /// /// The address to ship to /// - public SubscriptionRequest WithShippingAddress(Address add) { + public ISubscriptionRequest WithShippingAddress(Address add) + { this.ShippingAddress = add; return this; } @@ -159,7 +168,8 @@ public SubscriptionRequest WithShippingAddress(Address add) { /// The trial billing cycles. /// The trial amount. /// - public SubscriptionRequest SetTrialPeriod(short trialBillingCycles, decimal trialAmount) { + public ISubscriptionRequest SetTrialPeriod(short trialBillingCycles, decimal trialAmount) + { this.TrialBillingCycles = trialBillingCycles; this.TrialAmount = trialAmount; @@ -178,7 +188,7 @@ public SubscriptionRequest SetTrialPeriod(short trialBillingCycles, decimal tria public decimal Amount { get; set; } public decimal TrialAmount { get; set; } - //CreditCard + // CreditCard public string CardNumber { get; set; } public int CardExpirationYear { get; set; } public int CardExpirationMonth { get; set; } @@ -187,6 +197,11 @@ public SubscriptionRequest SetTrialPeriod(short trialBillingCycles, decimal tria // eCheck public BankAccount eCheckBankAccount { get; set; } + // Customer Profile + public string CustomerProfileId { get; set; } + public string CustomerPaymentProfileId { get; set; } + public string CustomerAddressId { get; set; } + public Address BillingAddress { get; set; } public Address ShippingAddress { get; set; } @@ -202,25 +217,38 @@ public ARBSubscriptionType ToAPI(){ var sub = new ARBSubscriptionType(); sub.name = this.SubscriptionName; - bool isCard = true; + bool isCardValid = false; + bool isBankValid = false; + bool isProfileValid = false; StringBuilder sbError = new StringBuilder(""); bool bError = false; - if (String.IsNullOrEmpty(this.CardNumber) || (this.CardNumber.Trim().Length == 0)) + + + if (!String.IsNullOrEmpty(this.CardNumber) && + this.CardNumber.Trim().Length == 0) { - if ((null == this.eCheckBankAccount) || String.IsNullOrEmpty(this.eCheckBankAccount.accountNumber) || - (this.eCheckBankAccount.accountNumber.Trim().Length == 0)) - { - sbError.Append("Need a credit card number or a bank account number to set up this subscription"); - bError = true; - } - else - { - isCard = false; - } + isCardValid = true; + } + else if (this.eCheckBankAccount != null && + !String.IsNullOrEmpty(this.eCheckBankAccount.accountNumber) && + this.eCheckBankAccount.accountNumber.Trim().Length != 0) + { + isBankValid = true; + } + else if (!String.IsNullOrEmpty(this.CustomerProfileId) && + !String.IsNullOrEmpty(this.CustomerPaymentProfileId)) + { + isProfileValid = true; } + if (!(isCardValid || isBankValid || isProfileValid)) + { + sbError.Append("Need a credit card number or a bank account number to set up this subscription"); + bError = true; + } + DateTime dt = new DateTime(); - if ( isCard && !CommonFunctions.ParseDateTime(this.CardExpirationYear, this.CardExpirationMonth, 1, out dt)) + if (isCardValid && !CommonFunctions.ParseDateTime(this.CardExpirationYear, this.CardExpirationMonth, 1, out dt)) { sbError.Append("Need a valid CardExpirationMonth and CardExpirationYear to set up this subscription"); bError = true; @@ -231,15 +259,17 @@ public ARBSubscriptionType ToAPI(){ throw new InvalidOperationException(sbError.ToString()); } - if (isCard) + if (isCardValid) { - var creditCard = new creditCardType(); - creditCard.cardNumber = this.CardNumber; - creditCard.expirationDate = dt.ToString("yyyy-MM"); // required format for API is YYYY-MM - sub.payment = new paymentType(); - sub.payment.Item = creditCard; + var creditCard = new creditCardType + { + cardNumber = this.CardNumber, + // required format for API is YYYY-MM + expirationDate = dt.ToString("yyyy-MM") + }; + sub.payment = new paymentType { Item = creditCard }; } - else + else if (isBankValid) { var eCheck = new bankAccountType() { @@ -255,18 +285,31 @@ public ARBSubscriptionType ToAPI(){ }; sub.payment = new paymentType {Item = eCheck}; } + else if (isProfileValid) + { + var customerProfile = new customerProfileIdType + { + customerProfileId = this.CustomerProfileId, + customerPaymentProfileId = this.CustomerPaymentProfileId, + customerAddressId = this.CustomerAddressId + }; + + sub.profile = customerProfile; + } if(this.BillingAddress!=null) sub.billTo = this.BillingAddress.ToAPINameAddressType(); if (this.ShippingAddress != null) sub.shipTo = this.ShippingAddress.ToAPINameAddressType(); - sub.paymentSchedule = new paymentScheduleType(); - sub.paymentSchedule.startDate = this.StartsOn; - sub.paymentSchedule.startDateSpecified = true; + sub.paymentSchedule = new paymentScheduleType + { + startDate = this.StartsOn, + startDateSpecified = true, + totalOccurrences = this.BillingCycles, + totalOccurrencesSpecified = true + }; - sub.paymentSchedule.totalOccurrences = this.BillingCycles; - sub.paymentSchedule.totalOccurrencesSpecified = true; // free 1 month trial if (this.TrialBillingCycles >= 0) { @@ -290,12 +333,13 @@ public ARBSubscriptionType ToAPI(){ } else { sub.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.days; } - sub.customer = new customerType(); - sub.customer.email = this.CustomerEmail; + sub.customer = new customerType {email = this.CustomerEmail}; - sub.order = new orderType(); - sub.order.description = this.Description; - sub.order.invoiceNumber = this.Invoice; + sub.order = new orderType + { + description = this.Description, + invoiceNumber = this.Invoice + }; sub.customer.id = this.CustomerID; @@ -321,11 +365,13 @@ public ARBSubscriptionType ToUpdateableAPI() { throw new InvalidOperationException("Need a valid CardExpirationMonth and CardExpirationYear to set up this subscription"); } - var creditCard = new creditCardType(); - creditCard.cardNumber = this.CardNumber; - creditCard.expirationDate = dt.ToString("yyyy-MM");//string.Format("{0}-{1}", this.CardExpirationYear, this.CardExpirationMonth); // required format for API is YYYY-MM - sub.payment = new paymentType(); - sub.payment.Item = creditCard; + var creditCard = new creditCardType + { + cardNumber = this.CardNumber, + expirationDate = dt.ToString("yyyy-MM") + }; + //string.Format("{0}-{1}", this.CardExpirationYear, this.CardExpirationMonth); // required format for API is YYYY-MM + sub.payment = new paymentType { Item = creditCard }; } if ((this.eCheckBankAccount != null) && !String.IsNullOrEmpty(this.eCheckBankAccount.accountNumber) && @@ -346,26 +392,44 @@ public ARBSubscriptionType ToUpdateableAPI() { sub.payment = new paymentType { Item = eCheck }; } + if (!String.IsNullOrEmpty(this.CustomerProfileId) && !String.IsNullOrEmpty(this.CustomerPaymentProfileId)) + { + var customerProfile = new customerProfileIdType + { + customerProfileId = this.CustomerProfileId, + customerPaymentProfileId = this.CustomerPaymentProfileId, + customerAddressId = this.CustomerAddressId + }; + + sub.profile = customerProfile; + } + if (this.BillingAddress != null) sub.billTo = this.BillingAddress.ToAPINameAddressType(); if (this.ShippingAddress != null) sub.shipTo = this.ShippingAddress.ToAPINameAddressType(); - sub.paymentSchedule = new paymentScheduleType(); - sub.paymentSchedule.totalOccurrences = this.BillingCycles; - sub.paymentSchedule.totalOccurrencesSpecified = true; + sub.paymentSchedule = new paymentScheduleType + { + totalOccurrences = this.BillingCycles, + totalOccurrencesSpecified = true + }; sub.amount = this.Amount; sub.amountSpecified = true; - sub.customer = new customerType(); - sub.customer.email = this.CustomerEmail; - sub.customer.id = this.CustomerID; + sub.customer = new customerType + { + email = this.CustomerEmail, + id = this.CustomerID + }; + + sub.order = new orderType + { + description = this.Description, + invoiceNumber = this.Invoice + }; - sub.order = new orderType(); - sub.order.description = this.Description; - sub.order.invoiceNumber = this.Invoice; - return sub; } From 5a9f74a88b2b44efc3648b792b734515f6d59e83 Mon Sep 17 00:00:00 2001 From: David Penner Date: Fri, 7 Apr 2017 17:05:50 -0500 Subject: [PATCH 3/7] Exclude the Customer Email / ID when doing a profile subscription. --- Authorize.NET/ARB/SubscriptionRequest.cs | 27 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Authorize.NET/ARB/SubscriptionRequest.cs b/Authorize.NET/ARB/SubscriptionRequest.cs index fdb97683..a20bdbd6 100644 --- a/Authorize.NET/ARB/SubscriptionRequest.cs +++ b/Authorize.NET/ARB/SubscriptionRequest.cs @@ -333,16 +333,21 @@ public ARBSubscriptionType ToAPI(){ } else { sub.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.days; } - sub.customer = new customerType {email = this.CustomerEmail}; - + if (!isProfileValid) + { + sub.customer = new customerType + { + email = this.CustomerEmail, + id = this.CustomerID + }; + } + sub.order = new orderType { description = this.Description, invoiceNumber = this.Invoice }; - sub.customer.id = this.CustomerID; - return sub; } @@ -403,6 +408,14 @@ public ARBSubscriptionType ToUpdateableAPI() { sub.profile = customerProfile; } + else + { + sub.customer = new customerType + { + email = this.CustomerEmail, + id = this.CustomerID + }; + } if (this.BillingAddress != null) sub.billTo = this.BillingAddress.ToAPINameAddressType(); @@ -418,11 +431,7 @@ public ARBSubscriptionType ToUpdateableAPI() { sub.amount = this.Amount; sub.amountSpecified = true; - sub.customer = new customerType - { - email = this.CustomerEmail, - id = this.CustomerID - }; + sub.order = new orderType { From 8cbae98295e4b30b61f5099da3405930d2fa0784 Mon Sep 17 00:00:00 2001 From: David Penner Date: Fri, 7 Apr 2017 09:29:09 -0500 Subject: [PATCH 4/7] Fixed ISubscriptionRequest so it does not depend on Subscription Request. --- Authorize.NET/ARB/ISubscriptionRequest.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Authorize.NET/ARB/ISubscriptionRequest.cs b/Authorize.NET/ARB/ISubscriptionRequest.cs index 6d68b479..6aa6546b 100644 --- a/Authorize.NET/ARB/ISubscriptionRequest.cs +++ b/Authorize.NET/ARB/ISubscriptionRequest.cs @@ -15,7 +15,7 @@ public interface ISubscriptionRequest { BankAccount eCheckBankAccount { get; set; } string CustomerEmail { get; set; } string CustomerID { get; set; } - AuthorizeNet.SubscriptionRequest SetTrialPeriod(short trialBillingCycles, decimal trialAmount); + AuthorizeNet.ISubscriptionRequest SetTrialPeriod(short trialBillingCycles, decimal trialAmount); AuthorizeNet.Address ShippingAddress { get; set; } DateTime StartsOn { get; set; } string SubscriptionID { get; set; } @@ -26,8 +26,8 @@ public interface ISubscriptionRequest { ARBSubscriptionType ToUpdateableAPI(); decimal TrialAmount { get; set; } short TrialBillingCycles { get; set; } - AuthorizeNet.SubscriptionRequest UsingCreditCard(string firstName, string lastName, string cardNumber, int cardExpirationYear, int cardExpirationMonth); - AuthorizeNet.SubscriptionRequest WithBillingAddress(AuthorizeNet.Address add); - AuthorizeNet.SubscriptionRequest WithShippingAddress(AuthorizeNet.Address add); + AuthorizeNet.ISubscriptionRequest UsingCreditCard(string firstName, string lastName, string cardNumber, int cardExpirationYear, int cardExpirationMonth); + AuthorizeNet.ISubscriptionRequest WithBillingAddress(AuthorizeNet.Address add); + AuthorizeNet.ISubscriptionRequest WithShippingAddress(AuthorizeNet.Address add); } } From a11dbc9f1dd5f292eeb3a50cea3f8152a9b56293 Mon Sep 17 00:00:00 2001 From: David Penner Date: Fri, 7 Apr 2017 09:53:57 -0500 Subject: [PATCH 5/7] Added Support for Creating a Subscription from Customer Profile --- Authorize.NET/ARB/SubscriptionGateway.cs | 8 +- Authorize.NET/ARB/SubscriptionRequest.cs | 168 ++++++++++++++++------- 2 files changed, 117 insertions(+), 59 deletions(-) diff --git a/Authorize.NET/ARB/SubscriptionGateway.cs b/Authorize.NET/ARB/SubscriptionGateway.cs index 1cb8ecf3..c1586c93 100644 --- a/Authorize.NET/ARB/SubscriptionGateway.cs +++ b/Authorize.NET/ARB/SubscriptionGateway.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Xml.Serialization; -using System.IO; -using AuthorizeNet.APICore; +using AuthorizeNet.APICore; namespace AuthorizeNet { public class SubscriptionGateway : ISubscriptionGateway { diff --git a/Authorize.NET/ARB/SubscriptionRequest.cs b/Authorize.NET/ARB/SubscriptionRequest.cs index 58b61d25..fdb97683 100644 --- a/Authorize.NET/ARB/SubscriptionRequest.cs +++ b/Authorize.NET/ARB/SubscriptionRequest.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Text; using AuthorizeNet.APICore; @@ -119,7 +117,7 @@ public static SubscriptionRequest CreateWeekly(string email, string subscription /// The card expiration year. /// The card expiration month. /// - public SubscriptionRequest UsingCreditCard(string firstName, string lastName, string cardNumber, int cardExpirationYear, int cardExpirationMonth) { + public ISubscriptionRequest UsingCreditCard(string firstName, string lastName, string cardNumber, int cardExpirationYear, int cardExpirationMonth) { this.CardNumber = cardNumber; this.CardExpirationYear = cardExpirationYear; this.CardExpirationMonth = cardExpirationMonth; @@ -132,12 +130,22 @@ public SubscriptionRequest UsingCreditCard(string firstName, string lastName, st return this; } + public ISubscriptionRequest UsingPaymentProfile(string customerProfileId, string customerPaymentProfileId, string customerAddressId) + { + this.CustomerProfileId = customerProfileId; + this.CustomerPaymentProfileId = customerPaymentProfileId; + this.CustomerAddressId = customerAddressId; + + return this; + } + /// /// Adds a full billing address - which is required for a credit card. /// /// The add. /// - public SubscriptionRequest WithBillingAddress(Address add) { + public ISubscriptionRequest WithBillingAddress(Address add) + { this.BillingAddress = add; return this; } @@ -148,7 +156,8 @@ public SubscriptionRequest WithBillingAddress(Address add) { /// /// The address to ship to /// - public SubscriptionRequest WithShippingAddress(Address add) { + public ISubscriptionRequest WithShippingAddress(Address add) + { this.ShippingAddress = add; return this; } @@ -159,7 +168,8 @@ public SubscriptionRequest WithShippingAddress(Address add) { /// The trial billing cycles. /// The trial amount. /// - public SubscriptionRequest SetTrialPeriod(short trialBillingCycles, decimal trialAmount) { + public ISubscriptionRequest SetTrialPeriod(short trialBillingCycles, decimal trialAmount) + { this.TrialBillingCycles = trialBillingCycles; this.TrialAmount = trialAmount; @@ -178,7 +188,7 @@ public SubscriptionRequest SetTrialPeriod(short trialBillingCycles, decimal tria public decimal Amount { get; set; } public decimal TrialAmount { get; set; } - //CreditCard + // CreditCard public string CardNumber { get; set; } public int CardExpirationYear { get; set; } public int CardExpirationMonth { get; set; } @@ -187,6 +197,11 @@ public SubscriptionRequest SetTrialPeriod(short trialBillingCycles, decimal tria // eCheck public BankAccount eCheckBankAccount { get; set; } + // Customer Profile + public string CustomerProfileId { get; set; } + public string CustomerPaymentProfileId { get; set; } + public string CustomerAddressId { get; set; } + public Address BillingAddress { get; set; } public Address ShippingAddress { get; set; } @@ -202,25 +217,38 @@ public ARBSubscriptionType ToAPI(){ var sub = new ARBSubscriptionType(); sub.name = this.SubscriptionName; - bool isCard = true; + bool isCardValid = false; + bool isBankValid = false; + bool isProfileValid = false; StringBuilder sbError = new StringBuilder(""); bool bError = false; - if (String.IsNullOrEmpty(this.CardNumber) || (this.CardNumber.Trim().Length == 0)) + + + if (!String.IsNullOrEmpty(this.CardNumber) && + this.CardNumber.Trim().Length == 0) { - if ((null == this.eCheckBankAccount) || String.IsNullOrEmpty(this.eCheckBankAccount.accountNumber) || - (this.eCheckBankAccount.accountNumber.Trim().Length == 0)) - { - sbError.Append("Need a credit card number or a bank account number to set up this subscription"); - bError = true; - } - else - { - isCard = false; - } + isCardValid = true; + } + else if (this.eCheckBankAccount != null && + !String.IsNullOrEmpty(this.eCheckBankAccount.accountNumber) && + this.eCheckBankAccount.accountNumber.Trim().Length != 0) + { + isBankValid = true; + } + else if (!String.IsNullOrEmpty(this.CustomerProfileId) && + !String.IsNullOrEmpty(this.CustomerPaymentProfileId)) + { + isProfileValid = true; } + if (!(isCardValid || isBankValid || isProfileValid)) + { + sbError.Append("Need a credit card number or a bank account number to set up this subscription"); + bError = true; + } + DateTime dt = new DateTime(); - if ( isCard && !CommonFunctions.ParseDateTime(this.CardExpirationYear, this.CardExpirationMonth, 1, out dt)) + if (isCardValid && !CommonFunctions.ParseDateTime(this.CardExpirationYear, this.CardExpirationMonth, 1, out dt)) { sbError.Append("Need a valid CardExpirationMonth and CardExpirationYear to set up this subscription"); bError = true; @@ -231,15 +259,17 @@ public ARBSubscriptionType ToAPI(){ throw new InvalidOperationException(sbError.ToString()); } - if (isCard) + if (isCardValid) { - var creditCard = new creditCardType(); - creditCard.cardNumber = this.CardNumber; - creditCard.expirationDate = dt.ToString("yyyy-MM"); // required format for API is YYYY-MM - sub.payment = new paymentType(); - sub.payment.Item = creditCard; + var creditCard = new creditCardType + { + cardNumber = this.CardNumber, + // required format for API is YYYY-MM + expirationDate = dt.ToString("yyyy-MM") + }; + sub.payment = new paymentType { Item = creditCard }; } - else + else if (isBankValid) { var eCheck = new bankAccountType() { @@ -255,18 +285,31 @@ public ARBSubscriptionType ToAPI(){ }; sub.payment = new paymentType {Item = eCheck}; } + else if (isProfileValid) + { + var customerProfile = new customerProfileIdType + { + customerProfileId = this.CustomerProfileId, + customerPaymentProfileId = this.CustomerPaymentProfileId, + customerAddressId = this.CustomerAddressId + }; + + sub.profile = customerProfile; + } if(this.BillingAddress!=null) sub.billTo = this.BillingAddress.ToAPINameAddressType(); if (this.ShippingAddress != null) sub.shipTo = this.ShippingAddress.ToAPINameAddressType(); - sub.paymentSchedule = new paymentScheduleType(); - sub.paymentSchedule.startDate = this.StartsOn; - sub.paymentSchedule.startDateSpecified = true; + sub.paymentSchedule = new paymentScheduleType + { + startDate = this.StartsOn, + startDateSpecified = true, + totalOccurrences = this.BillingCycles, + totalOccurrencesSpecified = true + }; - sub.paymentSchedule.totalOccurrences = this.BillingCycles; - sub.paymentSchedule.totalOccurrencesSpecified = true; // free 1 month trial if (this.TrialBillingCycles >= 0) { @@ -290,12 +333,13 @@ public ARBSubscriptionType ToAPI(){ } else { sub.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.days; } - sub.customer = new customerType(); - sub.customer.email = this.CustomerEmail; + sub.customer = new customerType {email = this.CustomerEmail}; - sub.order = new orderType(); - sub.order.description = this.Description; - sub.order.invoiceNumber = this.Invoice; + sub.order = new orderType + { + description = this.Description, + invoiceNumber = this.Invoice + }; sub.customer.id = this.CustomerID; @@ -321,11 +365,13 @@ public ARBSubscriptionType ToUpdateableAPI() { throw new InvalidOperationException("Need a valid CardExpirationMonth and CardExpirationYear to set up this subscription"); } - var creditCard = new creditCardType(); - creditCard.cardNumber = this.CardNumber; - creditCard.expirationDate = dt.ToString("yyyy-MM");//string.Format("{0}-{1}", this.CardExpirationYear, this.CardExpirationMonth); // required format for API is YYYY-MM - sub.payment = new paymentType(); - sub.payment.Item = creditCard; + var creditCard = new creditCardType + { + cardNumber = this.CardNumber, + expirationDate = dt.ToString("yyyy-MM") + }; + //string.Format("{0}-{1}", this.CardExpirationYear, this.CardExpirationMonth); // required format for API is YYYY-MM + sub.payment = new paymentType { Item = creditCard }; } if ((this.eCheckBankAccount != null) && !String.IsNullOrEmpty(this.eCheckBankAccount.accountNumber) && @@ -346,26 +392,44 @@ public ARBSubscriptionType ToUpdateableAPI() { sub.payment = new paymentType { Item = eCheck }; } + if (!String.IsNullOrEmpty(this.CustomerProfileId) && !String.IsNullOrEmpty(this.CustomerPaymentProfileId)) + { + var customerProfile = new customerProfileIdType + { + customerProfileId = this.CustomerProfileId, + customerPaymentProfileId = this.CustomerPaymentProfileId, + customerAddressId = this.CustomerAddressId + }; + + sub.profile = customerProfile; + } + if (this.BillingAddress != null) sub.billTo = this.BillingAddress.ToAPINameAddressType(); if (this.ShippingAddress != null) sub.shipTo = this.ShippingAddress.ToAPINameAddressType(); - sub.paymentSchedule = new paymentScheduleType(); - sub.paymentSchedule.totalOccurrences = this.BillingCycles; - sub.paymentSchedule.totalOccurrencesSpecified = true; + sub.paymentSchedule = new paymentScheduleType + { + totalOccurrences = this.BillingCycles, + totalOccurrencesSpecified = true + }; sub.amount = this.Amount; sub.amountSpecified = true; - sub.customer = new customerType(); - sub.customer.email = this.CustomerEmail; - sub.customer.id = this.CustomerID; + sub.customer = new customerType + { + email = this.CustomerEmail, + id = this.CustomerID + }; + + sub.order = new orderType + { + description = this.Description, + invoiceNumber = this.Invoice + }; - sub.order = new orderType(); - sub.order.description = this.Description; - sub.order.invoiceNumber = this.Invoice; - return sub; } From d116f78c7c2845a3773acf121af6e86386f6688a Mon Sep 17 00:00:00 2001 From: David Penner Date: Fri, 7 Apr 2017 17:05:50 -0500 Subject: [PATCH 6/7] Exclude the Customer Email / ID when doing a profile subscription. --- Authorize.NET/ARB/SubscriptionRequest.cs | 27 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Authorize.NET/ARB/SubscriptionRequest.cs b/Authorize.NET/ARB/SubscriptionRequest.cs index fdb97683..a20bdbd6 100644 --- a/Authorize.NET/ARB/SubscriptionRequest.cs +++ b/Authorize.NET/ARB/SubscriptionRequest.cs @@ -333,16 +333,21 @@ public ARBSubscriptionType ToAPI(){ } else { sub.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.days; } - sub.customer = new customerType {email = this.CustomerEmail}; - + if (!isProfileValid) + { + sub.customer = new customerType + { + email = this.CustomerEmail, + id = this.CustomerID + }; + } + sub.order = new orderType { description = this.Description, invoiceNumber = this.Invoice }; - sub.customer.id = this.CustomerID; - return sub; } @@ -403,6 +408,14 @@ public ARBSubscriptionType ToUpdateableAPI() { sub.profile = customerProfile; } + else + { + sub.customer = new customerType + { + email = this.CustomerEmail, + id = this.CustomerID + }; + } if (this.BillingAddress != null) sub.billTo = this.BillingAddress.ToAPINameAddressType(); @@ -418,11 +431,7 @@ public ARBSubscriptionType ToUpdateableAPI() { sub.amount = this.Amount; sub.amountSpecified = true; - sub.customer = new customerType - { - email = this.CustomerEmail, - id = this.CustomerID - }; + sub.order = new orderType { From a9771a3b61d2bf00318648e4454f999b715bdf8c Mon Sep 17 00:00:00 2001 From: David Penner Date: Wed, 10 May 2017 16:52:35 -0500 Subject: [PATCH 7/7] Added GetSubscriptionList method --- Authorize.NET/ARB/ISubscriptionGateway.cs | 5 +++ Authorize.NET/ARB/ISubscriptionRequest.cs | 1 + Authorize.NET/ARB/SubscriptionGateway.cs | 49 ++++++++++++++++++++- Authorize.NET/Reporting/ReportingGateway.cs | 20 ++++++++- Authorize.NET/Reporting/Transaction.cs | 2 +- Authorize.NET/Utility/HttpXmlUtility.cs | 10 +++++ AuthorizeNET.sln | 24 +++++----- 7 files changed, 96 insertions(+), 15 deletions(-) diff --git a/Authorize.NET/ARB/ISubscriptionGateway.cs b/Authorize.NET/ARB/ISubscriptionGateway.cs index a4b67fca..4a92b40e 100644 --- a/Authorize.NET/ARB/ISubscriptionGateway.cs +++ b/Authorize.NET/ARB/ISubscriptionGateway.cs @@ -6,5 +6,10 @@ public interface ISubscriptionGateway { ISubscriptionRequest CreateSubscription(ISubscriptionRequest subscription); ARBSubscriptionStatusEnum GetSubscriptionStatus(string subscriptionID); bool UpdateSubscription(ISubscriptionRequest subscription); + + System.Collections.Generic.List GetSubscriptionList( + ARBGetSubscriptionListSearchTypeEnum searchType = ARBGetSubscriptionListSearchTypeEnum.subscriptionActive, + int page = 0, + int pageSize = 100); } } diff --git a/Authorize.NET/ARB/ISubscriptionRequest.cs b/Authorize.NET/ARB/ISubscriptionRequest.cs index 6aa6546b..b09c22d1 100644 --- a/Authorize.NET/ARB/ISubscriptionRequest.cs +++ b/Authorize.NET/ARB/ISubscriptionRequest.cs @@ -27,6 +27,7 @@ public interface ISubscriptionRequest { decimal TrialAmount { get; set; } short TrialBillingCycles { get; set; } AuthorizeNet.ISubscriptionRequest UsingCreditCard(string firstName, string lastName, string cardNumber, int cardExpirationYear, int cardExpirationMonth); + AuthorizeNet.ISubscriptionRequest UsingPaymentProfile(string customerProfileId, string customerPaymentProfileId, string customerAddressId); AuthorizeNet.ISubscriptionRequest WithBillingAddress(AuthorizeNet.Address add); AuthorizeNet.ISubscriptionRequest WithShippingAddress(AuthorizeNet.Address add); } diff --git a/Authorize.NET/ARB/SubscriptionGateway.cs b/Authorize.NET/ARB/SubscriptionGateway.cs index c1586c93..0187aeb1 100644 --- a/Authorize.NET/ARB/SubscriptionGateway.cs +++ b/Authorize.NET/ARB/SubscriptionGateway.cs @@ -1,4 +1,6 @@ -using AuthorizeNet.APICore; +using System.Collections.Generic; +using System.Linq; +using AuthorizeNet.APICore; namespace AuthorizeNet { public class SubscriptionGateway : ISubscriptionGateway { @@ -82,7 +84,50 @@ public ARBSubscriptionStatusEnum GetSubscriptionStatus(string subscriptionID) { return response.status; } - + /// + /// Gets the subscription details. + /// + /// The subscription ID. + /// + public ARBGetSubscriptionResponse GetSubscription(string subscriptionID) + { + var req = new ARBGetSubscriptionRequest(); + req.subscriptionId = subscriptionID; + var response = (ARBGetSubscriptionResponse)_gateway.Send(req); + + return response; + } + /// + /// Gets a list of all subscriptions + /// + /// + public List GetSubscriptionList( + ARBGetSubscriptionListSearchTypeEnum searchType = ARBGetSubscriptionListSearchTypeEnum.subscriptionActive, + int page = 0, + int pageSize = 100) + { + var req = new ARBGetSubscriptionListRequest(); + req.searchType = searchType; + req.paging = new Paging + { + limit = pageSize, + offset = page + }; + req.sorting = new ARBGetSubscriptionListSorting + { + orderBy = ARBGetSubscriptionListOrderFieldEnum.createTimeStampUTC, + orderDescending = true + }; + + var response = (ARBGetSubscriptionListResponse)_gateway.Send(req); + + if (response == null || response.subscriptionDetails == null) + { + return null; + } + + return response.subscriptionDetails.ToList(); + } } } diff --git a/Authorize.NET/Reporting/ReportingGateway.cs b/Authorize.NET/Reporting/ReportingGateway.cs index 050ab666..7c03c1cc 100644 --- a/Authorize.NET/Reporting/ReportingGateway.cs +++ b/Authorize.NET/Reporting/ReportingGateway.cs @@ -142,7 +142,25 @@ public List GetTransactionList(DateTime from, DateTime to) { result.AddRange(GetTransactionList(batch.ID.ToString())); } return result; - } + } + + /// + /// Returns all transactions for a given customerProfileId + /// + public List GetTransactionList(string customerProfileId) + { + + var request = new getTransactionListForCustomerRequest(); + request.customerProfileId = "1811474252"; + + var batches = GetSettledBatchList(from, to); + var result = new List(); + foreach (var batch in batches) + { + result.AddRange(GetTransactionList(batch.ID.ToString())); + } + return result; + } } } diff --git a/Authorize.NET/Reporting/Transaction.cs b/Authorize.NET/Reporting/Transaction.cs index b1b9d30d..2469a3d1 100644 --- a/Authorize.NET/Reporting/Transaction.cs +++ b/Authorize.NET/Reporting/Transaction.cs @@ -299,12 +299,12 @@ public static Transaction NewFromResponse(transactionDetailsType trans) { /// /// The transaction ID. public string TransactionID { get; set; } + /// /// Gets or sets the ref transaction ID. /// /// The transaction ID of the original transaction. This appears only for linked credits (transaction type refundTransaction). public string RefTransactionID { get; set; } /// - /// /// Gets or sets the date submitted. /// /// The date submitted. diff --git a/Authorize.NET/Utility/HttpXmlUtility.cs b/Authorize.NET/Utility/HttpXmlUtility.cs index 63e9f044..2c8cbb6d 100644 --- a/Authorize.NET/Utility/HttpXmlUtility.cs +++ b/Authorize.NET/Utility/HttpXmlUtility.cs @@ -254,6 +254,16 @@ ANetApiResponse DecideResponse(XmlDocument xmldoc) { apiResponse = (ARBGetSubscriptionStatusResponse)serializer.Deserialize(reader); break; + case "ARBGetSubscriptionResponse": + serializer = new XmlSerializer(typeof(ARBGetSubscriptionResponse)); + apiResponse = (ARBGetSubscriptionResponse)serializer.Deserialize(reader); + break; + + case "ARBGetSubscriptionListResponse": + serializer = new XmlSerializer(typeof(ARBGetSubscriptionListResponse)); + apiResponse = (ARBGetSubscriptionListResponse)serializer.Deserialize(reader); + break; + case "ErrorResponse": serializer = new XmlSerializer(typeof(ANetApiResponse)); apiResponse = (ANetApiResponse)serializer.Deserialize(reader); diff --git a/AuthorizeNET.sln b/AuthorizeNET.sln index a1c1a7b8..cd60cb57 100644 --- a/AuthorizeNET.sln +++ b/AuthorizeNET.sln @@ -1,6 +1,8 @@  -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AuthorizeNET", "Authorize.NET\AuthorizeNET.csproj", "{5D52EAEC-42FB-4313-83B8-69E2F55EBF14}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AuthorizeNETtest", "AuthorizeNETtest\AuthorizeNETtest.csproj", "{CDA0D4D8-E4AA-4BEA-8839-04D69607D914}" @@ -16,9 +18,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProjectSection EndProject Global - GlobalSection(TestCaseManagementSettings) = postSolution - CategoryFile = AuthorizeNET.vsmdi - EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU @@ -29,22 +28,25 @@ Global {5D52EAEC-42FB-4313-83B8-69E2F55EBF14}.Debug|Any CPU.Build.0 = Debug|Any CPU {5D52EAEC-42FB-4313-83B8-69E2F55EBF14}.Release|Any CPU.ActiveCfg = Release|Any CPU {5D52EAEC-42FB-4313-83B8-69E2F55EBF14}.Release|Any CPU.Build.0 = Release|Any CPU - {5D52EAEC-42FB-4313-83B8-69E2F55EBF14}.USELOCAL|Any CPU.ActiveCfg = USELOCAL|Any CPU - {5D52EAEC-42FB-4313-83B8-69E2F55EBF14}.USELOCAL|Any CPU.Build.0 = USELOCAL|Any CPU + {5D52EAEC-42FB-4313-83B8-69E2F55EBF14}.USELOCAL|Any CPU.ActiveCfg = Release|Any CPU + {5D52EAEC-42FB-4313-83B8-69E2F55EBF14}.USELOCAL|Any CPU.Build.0 = Release|Any CPU {CDA0D4D8-E4AA-4BEA-8839-04D69607D914}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CDA0D4D8-E4AA-4BEA-8839-04D69607D914}.Debug|Any CPU.Build.0 = Debug|Any CPU {CDA0D4D8-E4AA-4BEA-8839-04D69607D914}.Release|Any CPU.ActiveCfg = Release|Any CPU {CDA0D4D8-E4AA-4BEA-8839-04D69607D914}.Release|Any CPU.Build.0 = Release|Any CPU - {CDA0D4D8-E4AA-4BEA-8839-04D69607D914}.USELOCAL|Any CPU.ActiveCfg = USELOCAL|Any CPU - {CDA0D4D8-E4AA-4BEA-8839-04D69607D914}.USELOCAL|Any CPU.Build.0 = USELOCAL|Any CPU + {CDA0D4D8-E4AA-4BEA-8839-04D69607D914}.USELOCAL|Any CPU.ActiveCfg = Release|Any CPU + {CDA0D4D8-E4AA-4BEA-8839-04D69607D914}.USELOCAL|Any CPU.Build.0 = Release|Any CPU {79796297-BA7B-4F22-8C53-D9B6EFDD7EB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {79796297-BA7B-4F22-8C53-D9B6EFDD7EB7}.Debug|Any CPU.Build.0 = Debug|Any CPU {79796297-BA7B-4F22-8C53-D9B6EFDD7EB7}.Release|Any CPU.ActiveCfg = Release|Any CPU {79796297-BA7B-4F22-8C53-D9B6EFDD7EB7}.Release|Any CPU.Build.0 = Release|Any CPU - {79796297-BA7B-4F22-8C53-D9B6EFDD7EB7}.USELOCAL|Any CPU.ActiveCfg = USELOCAL|Any CPU - {79796297-BA7B-4F22-8C53-D9B6EFDD7EB7}.USELOCAL|Any CPU.Build.0 = USELOCAL|Any CPU + {79796297-BA7B-4F22-8C53-D9B6EFDD7EB7}.USELOCAL|Any CPU.ActiveCfg = Release|Any CPU + {79796297-BA7B-4F22-8C53-D9B6EFDD7EB7}.USELOCAL|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(TestCaseManagementSettings) = postSolution + CategoryFile = AuthorizeNET.vsmdi + EndGlobalSection EndGlobal