Gibt es eine Probe für PayPal IPN

Ich habe ein Asp.Net WEB API 2-Projekt und möchte einen IPN-Listener-Controller (Instant Payment Notification) implementieren.

Ich kann kein Beispiel- und Nuget-Paket finden. Alles was ich brauche ist zu bestätigen, dass der Benutzer mit dem Standard-HTML-Button auf Paypal bezahlt hat. Es ist ganz einfach

Alle Nuget-Pakete dienen zum Erstellen von Rechnungen oder benutzerdefinierten Schaltflächen. Es ist nicht das, was ich brauche

Die Beispiele auf Paypal gelten für klassisches asp.net und nicht für MVC oder WEB API MVC

Ich bin mir sicher, dass jemand das schon getan hat und als ich mit dem Codieren anfing, hatte ich das Gefühl, das Rad neu zu erfinden.

Gibt es ein Beispiel für einen IPN-Listener-Controller?

Zumindest ein PaypalIPNBindingModel, um die Paypal-Abfrage zu binden.

    [Route("IPN")]
    [HttpPost]
    public IHttpActionResult IPN(PaypalIPNBindingModel model)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest();
        }

        return Ok();
    }

BEARBEITE

So weit ich habe den folgenden Code

        [Route("IPN")]
        [HttpPost]
        public void IPN(PaypalIPNBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                // if you want to use the PayPal sandbox change this from false to true
                string response = GetPayPalResponse(model, true);

                if (response == "VERIFIED")
                {

                }
            }
        }

        string GetPayPalResponse(PaypalIPNBindingModel model, bool useSandbox)
        {
            string responseState = "INVALID";

            // Parse the variables
            // Choose whether to use sandbox or live environment
            string paypalUrl = useSandbox ? "https://www.sandbox.paypal.com/"
            : "https://www.paypal.com/";

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(paypalUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));

                //STEP 2 in the paypal protocol
                //Send HTTP CODE 200
                HttpResponseMessage response = client.PostAsJsonAsync("cgi-bin/webscr", "").Result;

                if (response.IsSuccessStatusCode)
                {
                    //STEP 3
                    //Send the paypal request back with _notify-validate
                    model.cmd = "_notify-validate";
                    response = client.PostAsync("cgi-bin/webscr", THE RAW PAYPAL REQUEST in THE SAME ORDER ).Result;

                    if(response.IsSuccessStatusCode)
                    {
                        responseState = response.Content.ReadAsStringAsync().Result;
                    }
                }
            }

            return responseState;
        }

Aber für Schritt 3 habe ich versucht, mein Modell als json zu veröffentlichen, aber paypal gibt eine HTML-Seite anstelle von VALIDATED oder INVALID zurück. Ich habe herausgefunden, dass ich @ verwenden muapplication/x-www-form-urlencoded und es sind die Parameter in der gleichen Reihenfolge.

Wie kann ich die Anforderungs-URL erhalten?

Ich würde die Abfrage-URL verwenden und @ hinzufüg&cmd=_notify-validate dazu

Antworten auf die Frage(5)

Ihre Antwort auf die Frage