我在使用 Paypal 的 Payflow 托管页面时遇到问题。我收到一条错误消息,指出令牌丢失。我认为我的问题是安全令牌 ID。我在代码中创建了一个安全令牌 ID,但我不知道如何在请求中将其传递给 PayPal。我得到 0 的响应并返回令牌,但是当我重定向到托管页面时如果失败。我进行了广泛的搜索,似乎无法找到我的问题的答案。我正在使用https://developer.paypal.com/docs/classic/payflow/gs_ppa_hosted_pa ges/ 上的贝宝指南 来解决这个问题。任何帮助是极大的赞赏。下面是我的代码
//Controller that gets some data from a database table and passes it to the paypal utility class
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult RedirectInstruct(PayPalModel Submit)
{
bool recordRetrieved = false;
bool secureTokenRetrieved = false;
string orderId = "A3420-789632-15115151935";
string secureToken = "";
string secureTokenId = "";
string[,] InvoiceArray = new string[9, 2];
dbConnect = new SQLDatabaseUtility(orderId);
//Here I get some data from a database table that is used as the information passed to the inventor object
recordRetrieved = dbConnect.QryCustOrderDetails();
if (recordRetrieved)
{
InvoiceArray = dbConnect.RetrieveCustOrder();
paymentProcessing = new PaymentProcessingUtility(InvoiceArray);
//Here I call the method in the paypal utility class to get the secure token
paymentProcessing.GetSecureToken();
secureToken = paymentProcessing.PassSecureToken();
secureTokenId = paymentProcessing.PassSecureTokenId();
if (secureTokenRetrieved)
{
//Here I insert the token information into the url string and then redirect user to paypal website
string url = "https://payflowlink.paypal.com?MODE=TEST&SECURETOKENID=" + secureTokenId + "&SECURETOKEN=" + secureToken;
Response.Redirect(url);
}
else
{
//secure token retrieval failed
}
}
//Method in the paypal utility class that creates the securitytokenid and gets the security token from paypal
public void GetSecureToken()
{
decimal total = 0;
string licenseNo = "";
string orderID = "";
string requestType = "";
//set the values
orderID = InvoiceArray[0, 1];
total = Convert.ToDecimal(InvoiceArray[8, 1]);
requestType = InvoiceArray[2, 1];
//Here I create the securitytokenid
Guid id = Guid.NewGuid();
SECURETOKENID = Convert.ToString(id).Replace("-", "");
// create the user object
UserInfo User = new UserInfo("myuserid", "vender",
"partner", "password");
// Create the Payflow Connection data object with the required connection details.
PayflowConnectionData Connection = new PayflowConnectionData();
// Create a new Invoice data object with the Amount, Billing Address etc. details.
Invoice Inv = new Invoice();
//Here I place some transaction details into the inventory object
Currency Amt = new Currency(total, "USD");
Inv.Amt = Amt;
Inv.InvoiceDate = DateTime.Now.ToShortDateString();
Inv.Comment1 = licenseNo;
Inv.CustRef = orderID;
Inv.OrderDesc = requestType;
//create a new express checkout request
ECSetRequest setRequest = new ECSetRequest(ConfigurationManager.AppSettings["ReturnURL"], ConfigurationManager.AppSettings["CancelURL"]);
PayPalTender Tender = new PayPalTender(setRequest);
// Create a new Auth Transaction.
SaleTransaction Trans = new SaleTransaction(User, Connection, Inv, Tender, 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;
ExpressCheckoutResponse eResponse = Resp.ExpressCheckoutSetResponse;
if ((TrxnResponse != null) && (eResponse != null))
{
//get the token
SECURETOKEN = eResponse.Token;
//Below I have tested to see if the requestid or correlationid is the securetokenid I need...
//SECURETOKENID = Trans.Response.RequestId;
//SECURETOKENID = Trans.Response.TransactionResponse.CorrelationId;
}
}
}
//Here I am passing the values back to the calling class
public string PassSecureToken()
{
return SECURETOKEN;
}
public string PassSecureTokenId()
{
return SECURETOKENID;
}