Inhalte aufrufen

Profilbild

Session appears to be null after PayPal redirect back to site


  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
1 Antwort zu diesem Thema

#1 altmoola

altmoola

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 66 Beiträge

Geschrieben: 16 January 2021 - 00:50

For some reason when you attempt to complete a PayPal payment on my site, when it redirects back to my site from PayPal it is getting a null OrderPaymentInfo from the session. This causes the order to fail with a server error, as it then calls processor.SetCheckoutDetails.

var paymentInfo = this.Session["OrderPaymentInfo"] as ProcessPaymentRequest;

I threw in some hacky statements into the code and despite there being a SessionID, when I try something like this inside GetDetails

throw new ArgumentNullException(this.Session.SessionID);

It actually is returning blank/null even though I can see that it exists in the browser console. I can't seem to figure out what is happening. At first I thought it was because the SessionID cookie was not set with Secure = true, but even after fixing that it still doesn't want to work. What could be happening?

 

This is all occurring within the PayPalExpressController.GetDetails method. In summary: everything works properly during checkout until you confirm the PayPal payment, once you do, it redirects back to the site and cannot get the OrderPaymentInfo it stored previously and then just fails and for some reason a call to this.Session.SessionID inside GetDetails returns empty.

 

vDHOMln.png



#2 altmoola

altmoola

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 66 Beiträge

Geschrieben: 16 January 2021 - 01:35

I've found a workaround, although I'm not sure the implications. I save the processPaymentRequest as JSON in the generic attributes using the PayPal Token as the key:

_genericAttributeService.SaveAttribute<string>(resp.Token.GetHashCode(), resp.Token, "Session", Newtonsoft.Json.JsonConvert.SerializeObject(processPaymentRequest));

Then later in GetDetails I retrieve it if the session fails to get it:

if (paymentInfo == null)
{
    // didn't save session details, try to pull from attribute service
    // as a backup
    var jsonPaymentInfo = _genericAttributeService.GetAttributes(token, "Session").ToList().SingleOrDefault();
    if (jsonPaymentInfo != null)
    {
        var attrPaymentInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ProcessPaymentRequest>(jsonPaymentInfo.Value);
        paymentInfo = attrPaymentInfo;
    }
}

Obviously I'd prefer it to work properly, but at least I can accept a PayPal payment this way and it seems somewhat secure still.