以下はテストされていますが、元の質問がもたらしたものについてのみ (もっとテストしてください?)、提供された XML の例を使用し、AddCreditCard コードのコードをコピーして作成しました。
すべての更新が完了すると、次のコードが機能します。
var cg = new CustomerGateway("login", "transkey", ServiceMode.Test);
var c = cg.CreateCustomer("peter@example.com", "test customer");
//just to show that we didn't break CC
cg.AddCreditCard(c.ProfileID, "cc#", 07, 2011);
cg.AddBankAccount(c.ProfileID, "Peter", "bankaccoung#", "routing#");
//tostring doesn't actually do much... but if you break on it you can see the details for both the CC and the bank info.
foreach (PaymentProfile pp in cg.GetCustomer(c.ProfileID).PaymentProfiles)
{
Console.WriteLine(pp.ToString());
}
まず、API の C# ソース コードをhttp://developer.authorize.net/downloads/からダウンロードします。
コードを確認すると、「creditCardType」を使用する 4 つのファイルが見つかります。これらは、SubscriptionRequest.cs、CustomerGateway.cs、PaymentProfile.cs、および AnetApiSchema.cs です (この最後のファイルについては、触れる必要はありません)。PaymentProfile.cs、Transaction.cs、および AnetApiSchema.cs で使用される「creditCardMaskedType」にも注意する必要があります。これらのファイルが表示される場所では、bankAccount と同等のものもサポートする必要があります。
AuthorizeNET ソリューションを開きます。上記のファイルを少し飛び回ります。
CustomerGateway.cs に、次のコード ブロックを追加します。
/// <summary>
/// Adds a bank account profile to the user and returns the profile ID
/// </summary>
/// <returns></returns>
public string AddBankAccount(string profileID, string nameOnAccount, string accountNumber, string routingNumber)
{
var req = new createCustomerPaymentProfileRequest();
req.customerProfileId = profileID;
req.paymentProfile = new customerPaymentProfileType();
req.paymentProfile.payment = new paymentType();
bankAccountType new_bank = new bankAccountType();
new_bank.nameOnAccount = nameOnAccount;
new_bank.accountNumber = accountNumber;
new_bank.routingNumber = routingNumber;
req.paymentProfile.payment.Item = new_bank;
var response = (createCustomerPaymentProfileResponse)_gateway.Send(req);
return response.customerPaymentProfileId;
}
PaymentProfile.cs で、いくつかのパブリック プロパティを追加します。
public string BankNameOnAccount {get; set; }
public string BankAccountNumber { get; set; }
public string BankRoutingNumber { get; set; }
PaymentProfile(customerPaymentProfileMaskedType apiType)
コンストラクターの次のブロックを変更します。
if (apiType.payment != null) {
if(apiType.payment.Item is bankAccountMaskedType) {
var bankAccount = (bankAccountMaskedType)apiType.payment.Item;
this.BankNameOnAccount = bankAccount.nameOnAccount;
this.BankAccountNumber = bankAccount.accountNumber;
this.BankRoutingNumber = bankAccount.routingNumber;
}
else if (apiType.payment.Item is creditCardMaskedType)
{
var card = (creditCardMaskedType)apiType.payment.Item;
this.CardType = card.cardType;
this.CardNumber = card.cardNumber;
this.CardExpiration = card.expirationDate;
}
}
PaymentProfile.ToAPI()
このブロックをメソッドに追加します。
if (!string.IsNullOrEmpty(this.BankAccountNumber))
{
bankAccountType new_bank = new bankAccountType();
new_bank.nameOnAccount = BankNameOnAccount;
new_bank.accountNumber = BankAccountNumber;
new_bank.routingNumber = BankRoutingNumber;
result.payment.Item = new_bank;
}
次のパブリック プロパティを SubscriptionRequest.cs > SubscriptionRequest クラスに追加します (187 行目あたり)。
public string BankNameOnAccount {get; set; }
public string BankAccountNumber { get; set; }
public string BankRoutingNumber { get; set; }
次の else if block TWICEを SubscriptionRequest に追加します。1 回目は ToAPI メソッドで、2 回目は ToUpdateableAPI メソッドで、どちらの場合も CC 番号の null チェックの後に行われます。
else if (!String.IsNullOrEmpty(this.BankAccountNumber))
{
bankAccountType new_bank = new bankAccountType();
new_bank.nameOnAccount = BankNameOnAccount;
new_bank.accountNumber = BankAccountNumber;
new_bank.routingNumber = BankRoutingNumber;
sub.payment = new paymentType();
sub.payment.Item = new_bank;
}
次のパブリック プロパティを Transaction.cs に追加します。
public string BankNameOnAccount { get; set; }
public string BankAccountNumber { get; set; }
public string BankRoutingNumber { get; set; }
静的な NewFromResponse(transactionDetailsType trans) メソッドの Transaction.cs で、次のtrans.payment != null
ようにチェックして微調整するブロックを見つけます。
if (trans.payment != null) {
if (trans.payment.Item.GetType() == typeof(creditCardMaskedType))
{
var cc = (creditCardMaskedType)trans.payment.Item;
result.CardNumber = cc.cardNumber;
result.CardExpiration = cc.expirationDate;
result.CardType = cc.cardType;
}
else if (trans.payment.Item.GetType() == typeof(bankAccountMaskedType))
{
var bankAccount = (bankAccountMaskedType)trans.payment.Item;
result.BankNameOnAccount = bankAccount.nameOnAccount;
result.BankAccountNumber = bankAccount.accountNumber;
result.BankRoutingNumber = bankAccount.routingNumber;
}
}