I’ve been able to get my shopping cart working fine with PayPal when it’s unencrypted but I’m having trouble making the updates when moving to an encrypted form.
[This is all using the sandbox site at the moment]
I’ve uploaded my secure certificates and such and the encryption of the values seems to be okay.
My unencrypted form uses _cart as the cmd. Using this I get the error message “We have detected a problem with this shopping cart. If the problem persists, please contact the merchant.”.
So, since the ‘normal’ checkout command changes from _xclick to _s-xclick when moving to encrypted payments, I next tried _s-cart as the command. This results in an error message of “You have requested an outdated version of PayPal. This error often results from the use of bookmarks.” Which is useful.
The encrypted values of my cart contains the cmd value _cart as is shown in the documentation for cart checkouts.
Does anyone know what the correct values should be for this? PayPal developer documentation has samples for cart checkouts and single item encrypted checkouts but none (that I’ve been able to find) for cart encrypted checkouts.
My encrypted form looks like this at the moment:
<form id="Paypal" name="Paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-cart">
<input type="hidden" name="encrypted" value="@ViewBag.EncryptedBasket" />
<button type="submit" id="paypal-checkout-button" value="PayPal">Checkout</button>
</form>
My encrypted values are:
var valuePairs = (new[]
{
new KeyValuePair<string, string>("cmd", "_cart"),
new KeyValuePair<string, string>("upload", "1"),
new KeyValuePair<string, string>("business", Globals.Settings.PayPal.AccountEmail),
new KeyValuePair<string, string>("currency_code", Globals.Settings.PayPal.CurrencyCode),
new KeyValuePair<string, string>("return", returnUrl),
new KeyValuePair<string, string>("cancel_return", cancelUrl),
new KeyValuePair<string, string>("cert_id", Globals.Settings.PayPal.CertificateId),
}).ToList();
for (int i = 0; i < ShoppingCart.Items.Count; i++)
{
var index = i + 1;
var item = ShoppingCart.Items[i];
valuePairs.Add(new KeyValuePair<string, string>("amount_" + index, item.Product.FinalUnitPrice.ToString("N2")));
valuePairs.Add(new KeyValuePair<string, string>("item_name_" + index, item.Product.Title));
valuePairs.Add(new KeyValuePair<string, string>("item_number_" + index, item.Product.ProductId.ToString()));
valuePairs.Add(new KeyValuePair<string, string>("quantity_" + index, item.Quantity.ToString()));
}
In case anyone else is wondering, every time you use encrypted payments you should use the _s-xclick command, you may then encrypt your items using the _cart command and making sure to add the parameter upload=1 to the request.