0
votes

I am developing web application on ASP.NET. In application users can purchase article for money. For work with PayPal I using PayPal Merchant SDK for .NET package. Application work good with sandbox but with live display error: "This transaction is invalid". Please return to the recipient's website to complete your transaction using their regular checkout flow." When user click on purchase button I execute code:

// only for live
var paypalConfig = new Dictionary<string, string> { 
                {"account1.applicationId", "<APP-LIVEID>"},

                {"account1.apiUsername", "<username>"},
                {"account1.apiPassword", "<pass>"},
                {"account1.apiSignature", "<signature>"},
                {"mode", "live"}};

try
        {
            var currency = CurrencyCodeType.USD;
            var paymentItem = new PaymentDetailsItemType
            {
                Name = "item",
                Amount = new BasicAmountType(currency, amount.ToString()),
                ItemCategory = ItemCategoryType.DIGITAL,
            };

            var paymentItems = new List<PaymentDetailsItemType>();
            paymentItems.Add(paymentItem);

            var paymentDetail = new PaymentDetailsType();
            paymentDetail.PaymentDetailsItem = paymentItems;
            paymentDetail.PaymentAction = PaymentActionCodeType.SALE;
            paymentDetail.OrderTotal = new BasicAmountType(currency, amount.ToString());
            paymentDetail.SellerDetails = new SellerDetailsType {
                PayPalAccountID= sellerEmail
            };
            var paymentDetails = new List<PaymentDetailsType>();
            paymentDetails.Add(paymentDetail);

            var ecDetails = new SetExpressCheckoutRequestDetailsType { 
                ReturnURL = returnUrl,
                CancelURL = cancelUrl,
                PaymentDetails = paymentDetails,

            };


            var request = new SetExpressCheckoutRequestType
            {
                Version = "104.0",
                SetExpressCheckoutRequestDetails = ecDetails,
            };

            var wrapper = new SetExpressCheckoutReq
            {
                SetExpressCheckoutRequest = request
            };

            var service = new PayPalAPIInterfaceServiceService(paypalConfig);
            var setECResponse = service.SetExpressCheckout(wrapper);

            if (sandbox)
                return "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={0}".FormatWith(setECResponse.Token);

            return "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&TOKEN={0}".FormatWith(setECResponse.Token);

        }
        // # Exception log    
        catch (System.Exception ex)
        {
            // Log the exception message       

            Console.WriteLine("Error Message : " + ex.Message);
        }

After all I redirect user to url with received TOKEN.

For my application, registered on PayPal, I set in options only "Adaptive Payments > Basic Payments > Checkout, Send Money or Parallel Payments"

Why live paypal payments can not work? What is the reason?

2
What EC token are you getting back? The error This transaction is invalid is usually returned when you use a sandbox token on live or vice versa.Jason Z
token is null. thanks. I found error.KregHEk

2 Answers

0
votes

Removed

ItemCategory = ItemCategoryType.DIGITAL,

and all work

0
votes

From previous experiences this problem usually comes from having a "null" token because of some mistake in the "setExpressCheckout" request (where, in the express checkout flow, you ask paypal for a transaction token).

Basically, you ask paypal for a token so you can build the redirect URL, but you make some mistake and paypal gives you an error but no token, so you build the URL with no token (or a wrong one).

If you try to redirect the user to the checkout URL ( https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={...}&useraction={...}) with an empty token you will get this error.

Actually I'm trying to know of there can be other causes...