2012-07-07 84 views
3

有沒有人知道如何根據pnref或其他參數通過調用paypal返回退款(使用payflow API時)。 謝謝 MaciekPayflow退款

回答

3

如果交易尚未結算,您可以使用無效退款。對於長期交易,就像一個月前一樣,你需要做一筆信用。以下是無效代碼:

using System; 
    using PayPal.Payments.Common; 
    using PayPal.Payments.Common.Utility; 
    using PayPal.Payments.DataObjects; 
    using PayPal.Payments.Transactions; 

    namespace PayPal.Payments.Samples.CS.DataObjects.BasicTransactions 
    { 
/// <summary> 
/// This class uses the Payflow SDK Data Objects to do a simple Void transaction. 
/// The request is sent as a Data Object and the response received is also a Data  Object. 
/// </summary> 
public class DOVoid 
{ 
    public DOVoid() 
    { 
    } 

    public static void Main(string[] Args) 
    { 
     Console.WriteLine("------------------------------------------------------"); 
     Console.WriteLine("Executing Sample from File: DOVoid.cs"); 
     Console.WriteLine("------------------------------------------------------"); 

     // Create the Data Objects. 
     // Create the User data object with the required user details. 
     //UserInfo User = new UserInfo("<user>", "<vendor>", "<partner>", "<password>"); 

     UserInfo User = new UserInfo("xxx", Xxx", "paypal", "password"); 

     // Create the Payflow Connection data object with the required connection details. 
     // The PAYFLOW_HOST property is defined in the App config file. 
     PayflowConnectionData Connection = new PayflowConnectionData(); 
     /////////////////////////////////////////////////////////////////// 

     // Create a new Void Transaction. 
     // The ORIGID is the PNREF no. for a previous transaction. 
     //VoidTransaction Trans = new VoidTransaction("<ORIGINAL_PNREF>", 
     // User, Connection, PayflowUtility.RequestId); 

     VoidTransaction Trans = new VoidTransaction("V35A0A3E6E0C", 
      User, Connection, PayflowUtility.RequestId); 

     // Submit the Transaction 
     Response Resp = Trans.SubmitTransaction(); 

     // Display the transaction response parameters. 
     if (Resp != null) 
     { 
      // Get the Transaction Response parameters. 
      TransactionResponse TrxnResponse = Resp.TransactionResponse; 

      if (TrxnResponse != null) 
      { 
       Console.WriteLine("RESULT = " + TrxnResponse.Result); 
       Console.WriteLine("PNREF = " + TrxnResponse.Pnref); 
       Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg); 
       Console.WriteLine("AUTHCODE = " + TrxnResponse.AuthCode); 
       Console.WriteLine("AVSADDR = " + TrxnResponse.AVSAddr); 
       Console.WriteLine("AVSZIP = " + TrxnResponse.AVSZip); 
       Console.WriteLine("IAVS = " + TrxnResponse.IAVS); 
      } 

      // Get the Fraud Response parameters. 
      FraudResponse FraudResp = Resp.FraudResponse; 

      // Display Fraud Response parameter 
      if (FraudResp != null) 
      { 
       Console.WriteLine("PREFPSMSG = " + FraudResp.PreFpsMsg); 
       Console.WriteLine("POSTFPSMSG = " + FraudResp.PostFpsMsg); 
      } 

      // Display the response. 
      Console.WriteLine(Environment.NewLine + PayflowUtility.GetStatus(Resp));  

      // Get the Transaction Context and check for any contained SDK specific errors (optional code). 
      Context TransCtx = Resp.TransactionContext; 
      if (TransCtx != null && TransCtx.getErrorCount() > 0) 
      { 
       Console.WriteLine(Environment.NewLine + "Transaction Errors = " + TransCtx.ToString()); 
      } 
     } 
     Console.WriteLine("Press Enter to Exit ..."); 
     Console.ReadLine(); 
    } 
} 
    } 

這裏是信用代碼:

using System; 
    using PayPal.Payments.Common; 
    using PayPal.Payments.Common.Utility; 
    using PayPal.Payments.DataObjects; 
    using PayPal.Payments.Transactions; 

    namespace PayPal.Payments.Samples.CS.DataObjects.BasicTransactions 
    { 
/// <summary> 
/// This class uses the Payflow SDK Data Objects to do a simple independent Credit transaction. 
/// The request is sent as a Data Object and the response received is also a Data Object. 
/// </summary> 
public class DOCredit 
{ 
    public DOCredit() 
    { 
    } 

    public static void Main(string[] Args) 
    { 
     Console.WriteLine("------------------------------------------------------"); 
     Console.WriteLine("Executing Sample from File: DOCredit.cs"); 
     Console.WriteLine("------------------------------------------------------"); 

     // Create the Data Objects. 
     // Create the User data object with the required user details. 
     UserInfo User = new UserInfo("xxx", "xxx", "paypal", "a12"); 

     // Create the Payflow Connection data object with the required connection details. 
     // The PAYFLOW_HOST property is defined in the App config file. 
     PayflowConnectionData Connection = new PayflowConnectionData(); 

     // Create a new Invoice data object with the Amount, Billing Address etc. details. 
     Invoice Inv = new Invoice(); 

     // Set Amount. 
     Currency Amt = new Currency(new decimal(1)); 
     Inv.Amt = Amt; 
     Inv.PoNum = "PO12345"; 
     Inv.InvNum = "INV12345"; 

     // Set the Billing Address details. 
     BillTo Bill = new BillTo(); 
     Bill.Street = "123 Main St."; 
     Bill.Zip = "12345"; 
     Inv.BillTo = Bill; 

     // Create a new Payment Device - Credit Card data object. 
     // The input parameters are Credit Card Number and Expiration Date of the Credit Card. 
     CreditCard CC = new CreditCard("5105105105105100", "0112"); 

     // Create a new Tender - Card Tender data object. 
     CardTender Card = new CardTender(CC); 
     /////////////////////////////////////////////////////////////////// 

     // Create a new Credit Transaction. 
     // Following is an example of a independent credit type of transaction. 
     CreditTransaction Trans = new CreditTransaction(User, Connection, Inv, Card, 
      PayflowUtility.RequestId); 

     // Submit the Transaction 
     Response Resp = Trans.SubmitTransaction(); 

     // Display the transaction response parameters. 
     if (Resp != null) 
     { 
      // Get the Transaction Response parameters. 
      TransactionResponse TrxnResponse = Resp.TransactionResponse; 

      if (TrxnResponse != null) 
      { 
       Console.WriteLine("RESULT = " + TrxnResponse.Result); 
       Console.WriteLine("PNREF = " + TrxnResponse.Pnref); 
       Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg); 
       Console.WriteLine("AUTHCODE = " + TrxnResponse.AuthCode); 
       Console.WriteLine("AVSADDR = " + TrxnResponse.AVSAddr); 
       Console.WriteLine("AVSZIP = " + TrxnResponse.AVSZip); 
       Console.WriteLine("IAVS = " + TrxnResponse.IAVS); 
       Console.WriteLine("CVV2MATCH = " + TrxnResponse.CVV2Match); 
       // If value is true, then the Request ID has not been changed and the original response 
       // of the original transction is returned. 
       Console.WriteLine("DUPLICATE = " + TrxnResponse.Duplicate); 
      } 

      // Get the Fraud Response parameters. 
      FraudResponse FraudResp = Resp.FraudResponse; 
      // Display Fraud Response parameter 
      if (FraudResp != null) 
      { 
       Console.WriteLine("PREFPSMSG = " + FraudResp.PreFpsMsg); 
       Console.WriteLine("POSTFPSMSG = " + FraudResp.PostFpsMsg); 
      } 

      // Display the response. 
      Console.WriteLine(Environment.NewLine + PayflowUtility.GetStatus(Resp));  

      // Get the Transaction Context and check for any contained SDK specific errors (optional code). 
      Context TransCtx = Resp.TransactionContext; 
      if (TransCtx != null && TransCtx.getErrorCount() > 0) 
      { 
       Console.WriteLine(Environment.NewLine + "Transaction Errors = " + TransCtx.ToString()); 
      } 
     } 
     Console.WriteLine("Press Enter to Exit ..."); 
     Console.ReadLine(); 
    } 
} 
} 
+0

非常感謝約瑟夫。但是我還有一個問題,因爲我不確定解決方案。當我在付款過程中首先進行授權呼叫「&TRXTYPE = A&AMT = 199.00&」時,我必須使用信用或無效,並且在此之後我再撥打另一個電話「TRXTYPE = D&AMT = 199.00&」 - 因爲稍後我想打電話基於ORIGID。此外哪些pnref選擇退款 - 授權通話或延遲捕獲的pnref。最好的問候,Maciek – user1401308 2012-07-08 08:08:49

+0

不客氣。您可以使用授權和捕獲或授權與延遲捕獲。開始時使用哪種付款並不重要。如果付款已被授權,則使用void。我認爲你可以使用任何pnref,因爲我相信它們是一樣的。定製解決方案可將pnref保存到數據庫,並可通過訂單ID進行引用。如果您仍有問題,請在您的帖子中添加一些代碼。 – 2012-07-08 14:52:39

+0

未來的讀者注意:只要您指定了PNREF值,您就不需要指定信用卡號碼(至少在我的經驗中)。 – Josh1billion 2014-04-07 19:28:46