PayPal in ASP.NET Core

I had the same issue with you. Looked for weeks and found there is just no way to get the SDK API working with .Net Core

You have a few options, first recreate your project using 4.6 or something. Secondly using the URL API based call from your app if you are wanting to do single item sales. (Which is what I wanted to do)

How I did it was attaching a javascript to the button click that did the following:

function PayPalPaymentEvent(eventid) {

    var URL = 'https://www.paypal.com/cgi-bin/webscr?';
    var cmd = '_xclick';
    var business = Your Business Email;
    var currency_code = 'AUD';
    var amount = 100;
    var item_name = Name Of Your Item;
    var item_number = Some Identifier;
    var returnurl = 'http://somepage?info=success';
    var cancel_return = 'http://somepage?info=failed';
    var notify_url = 'http://WebFacingSite/API/PayPalReg';
    var tax = (amount * 0.10);

    var fullURL = URL + 'cmd=' + cmd + '&business=' + business + '&currency_code=' + currency_code + '&amount=' + amount + '&tax=' + tax + '&item_name=' + item_name + '&item_number=' + item_number + '&return=' + returnurl + '&cancel_return=' + cancel_return + '&notify_url=' + notify_url;

    ///// this ajax bit I use to record the transaction has started
    $.ajax({
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        url: '/API/PaymentStarted?eventid=' + eventid + '&UserID=' + UserID + '&paymentID' + paymentID,
        error: function () {
            SetMessage('error', 'Something has gone horribly, horribly wrong')
        },
        success: function (data) {

            window.location.href = fullURL;

        },
        type: 'POST'
    });


  }

Once you have done this you will need to set up a IPN URL in your paypal account Your account must be a business account, go to your profile, click seller tools and you will see IPN Settings. In there add your web facing URL without a port (Localhost won't work unless you use something like ngrok)

Structuring your Item_code right becomes important here. The IPN will send list of variables back to your exposed API and then you can do some matching and such. This won't suit you but this is how I catch that message and deal with it. My scenario is that I have a user who signs up for an event:

[HttpPost]
    [Route("API/PayPalReg")]
    public JsonResult ReceiveInput(string txn_id, string payment_date,
                                string payer_email, string payment_status, 
                                string first_name, string last_name, 
                                string item_number, string item_name, 
                                string payer_id, string verify_sign)
    {

        var paypaltypes = item_name.Split('-');


        var result = item_number.Split('-');
        var userid = int.Parse(result[1]);
        var TransPaymentString = result[1].ToString() + result[0].ToString();
        var TransPayment = int.Parse(TransPaymentString);
        var user = _context.Person.Include(p => p.Payments).Where(p => p.UserID == userid).Single();
        var payment = user.Payments.Where(p => p.TransPaymentID == TransPayment).Single();

        if (paypaltypes[0] == "Event")
        {
            var eventid = int.Parse(result[0]);

            payment.PaymentReceipt = txn_id;
            payment.PaymentReceived = true;
            payment.PaymentReceivedDate = DateTime.Now;
            payment.PaymentNotes = payer_email + " " + first_name + " " + last_name + " " + item_number + " " + payer_id + " " + verify_sign + " " + item_name;

            _context.Payments.Update(payment);
            _context.SaveChanges();

            var userevent = _context.Person.Include(p => p.EventRegistry).Where(p => p.UserID == userid).Single();
            var eventreg = userevent.EventRegistry.Where(er => er.EventID == eventid).Single();
            eventreg.EventPaid = true;

            _context.EventRegistry.Update(eventreg);
            _context.SaveChanges();
            Response.StatusCode = (int)HttpStatusCode.OK;
            return Json("Json Result");

        }

Hope this helps a bit

Caz


In case somebody finds this question I'll post an update.

As of now, there is no official release of a .net core sdk for Paypal but looking on github there has been a lot of progress since this question was asked.

The developper have currently released an official beta version of the sdk that is available for fork or download here : https://github.com/paypal/PayPal-NET-SDK/tree/2.0-beta

They even have a migration guide if you were previously using the first version of their sdk.


So maybe,it's too late when i am posting this and you've moved out of that problem,but it's for the ease of any person who may need this in future.

So as we knew that PayPal had earlier not provided any nuget package for supporting PayPal payments in .Net Core. But putting an end to this pain, it has finally come out with a solution- by buying BrainTreepayments.com to provide better dev support.

Here's a link for reference.