我当前遇到错误(如标题中所述)。我不知道出了什么问题或我遇到的问题。我确定错误中提到的所有值都相同,但仍然会弹出相同的错误。
我的目的是使所有值相同以解决错误。
这是我的错误的完整说明:
{
"name": "https://stackoverflow.com/VALIDATION_ERROR",
"details": [
{
"field": "transactions[0]",
"issue": "Item amount must add up to specified amount subtotal (or total if amount details not specified)"
}
],
"message": "Invalid request - see details",
"information_link": "https://developer.paypal.com/docs/api/payments/#errors",
"debug_id": "67a354f1a8fc7"
}
请帮助!
以下是我的参考代码:
// scList has 2 values inside.
List<UserShoppingCartDAO> scList = UserShoppingCartDAO.GetCartOfUser(uID);
List<Item> itms = new List<Item>();
ItemList itemList = new ItemList();
decimal deliveryCharges = 0;
string deliveryChargesStr = "";
decimal postagePackingCost = 0;
decimal examPaperPrice = 0;
int quantityOfExamPapers = 0;
decimal subtotal = 0;
decimal total = 0;
var transactionDetails = new Details();
var transactionAmount = new Amount();
Transaction tran = new Transaction();
for (int iCounter = 0; iCounter < scList.Count; iCounter++)
{
Product p = Product.getProduct(scList[iCounter].ProductID.ToString());
deliveryCharges = p.price * 0.05m;
deliveryChargesStr = deliveryCharges.ToString();
postagePackingCost = 10m;
examPaperPrice = p.price;
quantityOfExamPapers = scList[iCounter].ProductQuantity;
subtotal = (quantityOfExamPapers * examPaperPrice);
total = subtotal + postagePackingCost;
var examPaperItem = new Item();
examPaperItem.name = p.productName;
examPaperItem.currency = "SGD";
examPaperItem.price = total.ToString();
examPaperItem.sku = p.productID.ToString();
examPaperItem.description = p.productDesc;
examPaperItem.quantity = quantityOfExamPapers.ToString();
itms.Add(examPaperItem);
itemList.items = itms;
// var transactionDetails = new Detail
transactionDetails.tax = "0";
if (transactionDetails.shipping == null)
{
transactionDetails.shipping = postagePackingCost.ToString();
}
else
{
decimal total2 = decimal.Parse(transactionDetails.shipping) + postagePackingCost;
transactionDetails.shipping = total2.ToString();
}
if (transactionDetails.subtotal == null)
{
transactionDetails.subtotal = subtotal.ToString();
}
else
{
decimal total2 = decimal.Parse(transactionDetails.subtotal) + subtotal;
transactionDetails.subtotal = total2.ToString();
}
//transactionDetails.shipping = postagePackingCost.ToString();
//transactionDetails.subtotal = subtotal.ToString("0.00");
// var transactionAmount = new Amount();
transactionAmount.currency = "SGD";
if (transactionAmount.total == null)
{
transactionAmount.total = total.ToString();
}
else
{
decimal total2 = decimal.Parse(transactionAmount.total) + total;
transactionAmount.total = total2.ToString();
}
transactionAmount.details = transactionDetails;
// Transaction tran = new Transaction();
tran.description = scList[0].ProductDescription;
tran.invoice_number = Guid.NewGuid().ToString();
tran.amount = transactionAmount;
// transaction.item_list = new List<Item>();
tran.item_list = itemList;
transactionList.Add(tran);
}
transactionList.Remove(transactionList[1]);
//Authenticate with paypal
var config = ConfigManager.Instance.GetProperties();
var accessToken = new OAuthTokenCredential(config).GetAccessToken();
//Get APIContent Object
var apiContext = new APIContext(accessToken);
var payer = new Payer();
payer.payment_method = "paypal";
var redirectUrls = new RedirectUrls();
redirectUrls.cancel_url = "http://localhost60681/Cancel.aspx";
redirectUrls.return_url = "http://localhost:60681/CompletePurchase.aspx";
var payment = Payment.Create(apiContext, new Payment
{
intent = "sale",
payer = payer,
transactions = transactionList,
redirect_urls = redirectUrls
});
Session["paymentId"] = payment.id;
foreach (var link in payment.links)
{
if (link.rel.ToLower().Trim().Equals("approval_url"))
{
Response.Redirect(link.href);
}
}