2012-06-11 29 views
29

Authorize.Net CIM XML API C# sample code ile oynadıktan sonra Authorize.Net C# SDK'u kullanmaya başladım. CIM XML API örnek kodunu kullanarak kredi kartı ve banka hesaplarını müşteri profillerine ekleyebiliyorum. SDK'yı kullanarak banka hesaplarını nasıl ekleyeceğimi bilmiyorum. Yalnızca bir .AddCreditCard() yöntemine bakın SDK kullanarakAuthorize.Net ile Banka Hesaplarını Kullanma C# SDK

... 
customerPaymentProfileType new_payment_profile = new customerPaymentProfileType(); 
paymentType new_payment = new paymentType(); 

bankAccountType new_bank = new bankAccountType(); 
new_bank.nameOnAccount = "xyz"; 
new_bank.accountNumber = "4111111"; 
new_bank.routingNumber = "325070760"; 
new_payment.Item = new_bank; 

new_payment_profile.payment = new_payment; 

createCustomerPaymentProfileRequest request = new createCustomerPaymentProfileRequest(); 
XmlAPIUtilities.PopulateMerchantAuthentication((ANetApiRequest)request); 

request.customerProfileId = profile_id.ToString(); 
request.paymentProfile = new_payment_profile; 
request.validationMode = validationModeEnum.testMode; 
... 

ancak bir banka hesabı eklemek için bir yol:

CIM XML API ile banka hesabı ekleme. Çok bir banka hesabı genelinde geldiğinde bütün PaymentProfiles boyunca ben döngü O bir istisna atar zaman:

CustomerGateway cg = new CustomerGateway("xxx", "yyy"); 

foreach (string cid in cg.GetCustomerIDs()) 
{ 
    Customer c = cg.GetCustomer(cid); 
    foreach (PaymentProfile pp in c.PaymentProfiles) 
    { 
     Console.WriteLine(pp.ToString()); 
    } 
} 

İstisna: Bir için bir banka hesabı nasıl eklerim

Unable to cast object of type 'AuthorizeNet.APICore.bankAccountMaskedType' to type 'AuthorizeNet.APICore.creditCardMaskedType'. 

enter image description here

Cize profil Authorize.Net C# SDK kullanarak?

Güncelleme: CIM banka hesap bilgilerini saklayabilir olduğunu

Kanıtı: Test edilen aşağıdakiler

enter image description here

+0

@Ramhound Yani banka hesap bilgilerini CIM kullanarak depolayamayacağımı mı söylüyorsunuz? – Greg

+0

@Ramhound, sitelerinde CIM örnek kodunu kullanarak, müşterileriniz için ödeme profilleri oluşturmanıza izin veriyor, böylece tekrar giriş yaptıkları zaman, ödeme bilgilerini tekrar girmek zorunda kalmıyorlar (çünkü Authorize.Net CIM kaydediyor) Uygulamamla onu kaydetmem ya da hatta doğrudan erişim hakkına sahip olmalısın – Greg

+2

@Ramhound Bunu açıkla: https://dl.dropbox.com/u/3115379/ProofThatCIMStoresBankAccountInformation.png – Greg

cevap

9

ancak bugüne kadar orijinal soru kadar ne getirdi (daha test edin olarak Benim için?), sağlanan XML örneğini kullanarak ve AddCreditCard kodunun kodunu kopyalayarak yazdım. Tüm Aşağıdaki kod çalışacaktır güncelleme yapılır

:

 var cg = new CustomerGateway("login", "transkey", ServiceMode.Test); 
     var c = cg.CreateCustomer("[email protected]", "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()); 
     } 

Birincisi, http://developer.authorize.net/downloads/ gelen API için C# kaynak kodu indirmek.

"CreditCardType" kullanan 4 dosyayı görebiliyorum, bunlar SubscriptionRequest.cs, CustomerGateway.cs, PaymentProfile.cs ve AnetApiSchema.cs (bu sonuncusu dokunmaya gerek yok). Ayrıca, PaymentProfile.cs, Transaction.cs ve AnetApiSchema.cs'de kullanılan 'creditCardMaskedType' için de dikkatli olmamız gerekiyor. Bu dosyaların ortaya çıktığı herhangi bir yer, bankAccount denklemlerini de desteklediğimizden emin olmalıyız.

AuthorizeNET çözümünü açın. Yukarıda listelenen dosyalardan biraz geçeceğiz. PaymentProfile yılında

/// <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; 
    } 

: CustomerGateway.cs olarak

aşağıdaki kod bloğunu ekleyin.

 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; 
     } 

için aşağıdaki kamu özellikleri ekleyin:

 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() yöntemine bu bloğu ekleyin: cs bazı kamu özelliklerini

public string BankNameOnAccount {get; set; } 
    public string BankAccountNumber { get; set; } 
    public string BankRoutingNumber { get; set; } 

PaymentProfile(customerPaymentProfileMaskedType apiType) yapıcı aşağıdaki bloğu değiştirin

eklemek SubscriptionRequest.cs> SubscriptionRequest sınıfı (satır 187 civarında)

public string BankNameOnAccount {get; set; } 
    public string BankAccountNumber { get; set; } 
    public string BankRoutingNumber { get; set; } 

Abonelik Sıfırlaması'na TWICE numaralı bloğu ekleyin. İlk kez ToAPI yönteminde, ikincisi ToUpdateableAPI yöntemindedir, her iki durumda da CC numarası null kontrolünden sonra gider.

 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; 
     } 

statik NewFromResponse (transactionDetailsType trans) yöntemi Transaction.cs olarak

public string BankNameOnAccount { get; set; } 
    public string BankAccountNumber { get; set; } 
    public string BankRoutingNumber { get; set; } 

Transaction.cs trans.payment != null kontrol eder bloğu bulmak ve gösterilen çimdik aşağıdaki genel özellikleri ekleyin:

 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; 
      } 
     } 
+0

Güzel! Ben bir kaynak indirme olduğunu tamamen özledim: -/ – Rup

+0

@Peter çok teşekkür ederim, bu harika çalışıyor – Greg

+0

Bu örnek kod için çok teşekkür ederim. Authorize.net'de, CIM'i uygulamak için SDK içinde açıkça yöntemlerin olduğunu işaret etsem de, C# SDK'nın SOAP/XML ile yapılmadıkça CIM kullanamadığını söyledim. – Ricky

İlgili konular