Does anybody know how to make a refund (when using payflow api) basing on pnref or others parameteres returned by call to paypal. Thanks Maciek
Asked
Active
Viewed 2,812 times
1 Answers
4
You can refund using a Void if the transaction hasn't settled. For longer term transactions, like a month ago, you need to do a credit. Here is the void code:
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();
}
}
}
Here is the credit code:
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();
}
}
}

Joseph Anderson
- 4,114
- 4
- 45
- 99
-
Thanks a lot Joseph. However I've got one more question since I'm not sure about solution. Do I have to use credit or void when during payment process I first make a authorisation call "&TRXTYPE=A&AMT=199.00&" and right after this I make another call "TRXTYPE=D&AMT=199.00&"- because later I want to make call basing on ORIGID. Moreover which pnref choose to make a refund - pnref of authorization call or delayed capture. Best Regards, Maciek – user1401308 Jul 08 '12 at 08:08
-
You are welcome. You can use auth and capture or auth with delayed capture. It does not matter which payment you use in the beginning. Use void, if the payment has been authorized only. I think you can use any pnref, since I believe they are the same. Custom solutions save the pnref to the database and can be referenced by the order id. If you still have issues, please add some code to your post. – Joseph Anderson Jul 08 '12 at 14:52
-
Note for future readers: you do not need to specify the credit card number (in my experience, at least), so long as you have the PNREF value specified. – Josh1billion Apr 07 '14 at 19:28