2016-11-11 41 views
0

對於具有現有付款配置文件ID(保存的信用卡)的客戶,我們使用「createCustomerProfileTransactionController」作爲授權。Authorized.net - 可以createTransactionRequest用於授權,捕獲和使現有付款配置文件ID的交易無效

public createCustomerProfileTransactionResponse AuthorizePaymentProfile(int customerProfileId, int customerPaymentProfileId, decimal amount) 
     { 
      createCustomerProfileTransactionResponse response = null; 

      ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = environment; 

      // define the merchant information (authentication/transaction id) 
      ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType() 
      { 
       name = apiLoginID, 
       ItemElementName = ItemChoiceType.transactionKey, 
       Item = apiTransactionKey, 
      }; 

      //construct request 
      var request = new createCustomerProfileTransactionRequest 
      { 
       merchantAuthentication = new merchantAuthenticationType 
       { 
        name = apiLoginID, 
        ItemElementName = ItemChoiceType.transactionKey, 
        Item = apiTransactionKey 
       }, 
       transaction = new profileTransactionType 
       { 
        Item = new profileTransAuthOnlyType 
        { 
         customerProfileId = customerProfileId.ToString(), 
         customerPaymentProfileId = customerPaymentProfileId.ToString(), 
         amount = amount 
        } 
       }, 
       extraOptions = "x_duplicate_window=1" 
      }; 

      //Prepare Request 
      var controller = new createCustomerProfileTransactionController(request); 
      controller.Execute(); 

      //Send Request to EndPoint 
      response = controller.GetApiResponse(); 

      return response; 

     } 

而對於客戶不使用現有的我們「createTransactionRequest」爲遵循授權付款資料ID。

public createTransactionResponse AuthorizeOneTimePayment(Card cardInfo, decimal amount) 
     { 
      createTransactionResponse response = null; 
      ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = environment; 

      //define the merchant information (authentication/transaction id) 
      ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType() 
      { 
       name = apiLoginID, 
       ItemElementName = ItemChoiceType.transactionKey, 
       Item = apiTransactionKey, 
      }; 

      var creditCard = new creditCardType 
      { 
       cardNumber = cardInfo.CardNumber,// "4111111111111111", 
       expirationDate = cardInfo.ExpirationDate// "0718" 
       //cardCode=cardInfo.VerificationCode 
      }; 

      //standard api call to retrieve response 
      var paymentType = new paymentType { Item = creditCard }; 

      string firstName = string.Empty; 
      string lastName = string.Empty; 

      if (!string.IsNullOrWhiteSpace(cardInfo.BillingName)) 
      { 
       string[] name = GetBillName(cardInfo.BillingName); 
       firstName = name[0]; 
       lastName = name[1]; 
      } 

      var transactionRequest = new transactionRequestType 
      { 
       transactionType = transactionTypeEnum.authOnlyTransaction.ToString(), // authorize only 
       amount = amount, 
       payment = paymentType, 
       billTo = new customerAddressType 
       { 
        firstName = firstName, 
        lastName = lastName, 
        address = cardInfo.BillingAddress, 
        city = cardInfo.BillingCity, 
        state = cardInfo.BillingState, 
        zip = cardInfo.BillingZipCode 
       } 
      }; 

      var request = new createTransactionRequest { transactionRequest = transactionRequest }; 

      // instantiate the controller that will call the service 
      var controller = new createTransactionController(request); 
      controller.Execute(); 

      // get the response from the service (errors contained if any) 
      response = controller.GetApiResponse(); 

      return response; 

     } 

並遵循相同的技術捕獲和無效的交易。

我的問題是,我們可以使用「createTransactionRequest」進行所有交易,例如爲具有付款資料ID和一次性客戶的客戶授權,獲取和使交易無效。

我能找到的在線文檔中authorize.net任何線索。請指導我們如何做到這一點。

回答

1

是的,您可以通過更改transactionRequestType和paymentType來使用createTransactionRequest進行Auth/Capture,Auth Only,Prior Auth和Capture,Void和Refund。

+0

謝謝,可以將其用於現有付款資料的ID,怎麼樣? –

相關問題