I am trying to integrate payapl through sandbox for my website.
I am able to send multiple items to paypal and it works fine. however i want to set CART-WIDE shipping cost and send it to paypal.
I am getting error code:
10413 ("ErrorCode=10413&Desc=Transaction refused because of an invalid argument. See additional error messages for details.& Desc2=The totals of the cart item amounts do not match order amounts.")
My CART:
Item: Mens Jackets
Price: 14.99
DESC: "SAMPLE"
QTY: 1
ITEM TOTAL: 14.99
SHIPPING: 5.99
CART TOTAL: 20.94
I am setting the following variables and i dont know what i am doing wrong.
NVPCodec encoder = new NVPCodec();
encoder["METHOD"] = "SetExpressCheckout";
encoder["RETURNURL"] = returnURL;
encoder["CANCELURL"] = cancelURL;
encoder["BRANDNAME"] = "Mountain Warehouse Sample Application";
encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "GBP";
// Get the Shopping Cart Products
int i = 0;
Decimal totalItemAmt = 0.00M;
string cartShippingAmt = "";
foreach (BasketItem item in basket.Items)
{
if (item.OrderItemType == OrderItemType.Product)
{
encoder["L_PAYMENTREQUEST_0_NAME" + i] = item.Name.ToString();
encoder["L_PAYMENTREQUEST_0_AMT" + i] = item.Price.ToString("0.00");
encoder["L_PAYMENTREQUEST_0_QTY" + i] = item.Quantity.ToString();
i++;
totalItemAmt += Convert.ToDecimal(item.Price.ToString("0.00"));
}
if (item.OrderItemType == OrderItemType.Shipping)
{
cartShippingAmt = item.Price.ToString("0.00");
}
}
encoder["PAYMENTREQUEST_0_ITEMAMT"] = totalItemAmt.ToString();
encoder["PAYMENTREQUEST_0_AMT"] = amt;
encoder["HANDLING_CART"] = cartShippingAmt;
Here is the query that gets send to paypal
METHOD=SetExpressCheckout&
RETURNURL=http%3a%2f%2flocalhost%3a1234%2fCheckout%2fCheckoutReview.aspx&
CANCELURL=http%3a%2f%2flocalhost%3a1234%2fCheckout%2fCheckoutCancel.aspx&
BRANDNAME=Sample+Application&
PAYMENTREQUEST_0_PAYMENTACTION=Sale&
PAYMENTREQUEST_0_CURRENCYCODE=GBP&
L_PAYMENTREQUEST_0_NAME0=MENS+JACKETS&
L_PAYMENTREQUEST_0_AMT0=14.99&
L_PAYMENTREQUEST_0_QTY0=1&
PAYMENTREQUEST_0_ITEMAMT=14.99&
HANDLING_CART=5.95&
PAYMENTREQUEST_0_AMT=20.94
I think i am assigning wrong variable Shipping cost for entire cart.
You’ve got a few things wrong here.
First, some of the request parameters you’re using aren’t right. HANDLING_CART is not a valid request parameter. I think what you’re looking for there is HANDLINGAMT (which would actually be PAYMENTREQUEST_0_HANDLINGAMT).
In each payment, the total of ITEMAMT + SHIPPINGAMT + HANDLINGAMT + TAXAMT needs to equal AMT. In your case, PayPal is ignoring the invalid parameter you’re sending, so it ends up seeing the following…
PAYMENTREQUEST_0_ITEMAMT = 14.99
PAYMENTREQUEST_0_AMT = 20.94
It’s not seeing your handling amount because that parameter is invalid, therefore, the totals don’t match up according to what they’re seeing. You just need to change HANDLING_CART to PAYMENTREQUEST_0_HANDLINGAMT and that should fix your issue.
Here’s a sample of a working SetExpressCheckout request with multiple items and some additional options included…