Search code examples
c#paypal-sandboxpaypal-adaptive-paymentspaypal

Paypal payKey brings me to incorrect payment


I'm trying to create an API call to create a split payment. Upon creating the AdaptivePaymentService and calling the Pay method, it returns a PayResponse that shows SUCCESS. However, when I get the payKey and open the page at https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=, it brings me to some random page that usually says some error along the lines of "This transaction has already been approved. Please visit your PayPal Account Overview to see the details.", and in the top right, it'll show "Fiverr.com" or some other random webpage. I've verified that the payKey I am receiving is sent along with aSUCCESS message, so I don't understand why this is invalid. The following code is what I am using.

        ReceiverList receiverList = new ReceiverList();
        receiverList.receiver = new List<Receiver>();
        RequestEnvelope requestEnvelope = new RequestEnvelope("en_US");

        Dictionary<string, string> configurationMap = new Dictionary<string, string>();

        configurationMap.Add("account1.apiUsername", "----");
        configurationMap.Add("account1.apiPassword", "----");
        configurationMap.Add("account1.apiSignature", "----");
        configurationMap.Add("account1.applicationId", "APP-80W284485P519543T");

        configurationMap.Add("mode", "sandbox");

        Receiver receiver1 = new Receiver();
        receiver1.amount = ((decimal?)9.00);
        receiver1.email = "[email protected]";

        receiverList.receiver.Add(receiver1);

        Receiver receiver2 = new Receiver();
        receiver2.amount = ((decimal?)2.00);
        receiver2.email = "[email protected]";

        receiverList.receiver.Add(receiver2);

        PayRequest request = new PayRequest(requestEnvelope, "PAY", "https://devtools-paypal.com/guide/ap_parallel_payment/dotnet?cancel=true", "USD", receiverList, "https://devtools-paypal.com/guide/ap_parallel_payment/dotnet?success=true");

        AdaptivePaymentsService service = new AdaptivePaymentsService(configurationMap);
        PayResponse response = service.Pay(request);

        if (!response.responseEnvelope.ack.ToString().Trim().ToUpper().Equals(AckCode.FAILURE.ToString()) && !response.responseEnvelope.ack.ToString().Trim().ToUpper().Equals(AckCode.FAILUREWITHWARNING.ToString()))
        {
            Process.Start("https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=" + response.payKey); //opens the webpage
        }
        else
        {
            Console.WriteLine("E:" + String.Join("\n", response.error.Select((x) => x.message)));
        }

Solution

  • I am currently facing this problem in java.

    Try returning to this: "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey=" + paykey. It is supposed to work with this.

    It's all I found, but it DIDN'T work for me.