Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6182823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:15:50+00:00 2026-05-24T01:15:50+00:00

I am trying to set up a mocking scenario for my payment processor on

  • 0

I am trying to set up a mocking scenario for my payment processor on a web site. Normally, my site redirects to the processor site, where the user pays. The processor then redirects back to my site, and I wait for an immediate payment notification (IPN) from the processor. The processor then posts to my NotifyUrl, which routes to the Notify action on my payments controller (PayFastController). To mock, I redirect to a local action, which after a conformation click, spawns a thread to post the IPN, as if posted by the processor, and redirects back to my registration process.

My mock processor controller uses the following two methods to simulate the processor’s response:

[HttpGet]
public RedirectResult Pay(string returnUrl, string notifyUrl, int paymentId)
{
    var waitThread = new Thread(Notify);
    waitThread.Start(new { paymentId, ipnDelay = 1000 });

    return new RedirectResult(returnUrl);
}

public void Notify(dynamic data)
{
    // Simulate a delay before PayFast 
    Thread.Sleep(1000);

    // Delegate URL determination to the model, vs. directly to the config.
    var notifyUrl = new PayFastPaymentModel().NotifyUrl;
    if (_payFastConfig.UseMock)
    {
        // Need an absoluate URL here just for the WebClient.
        notifyUrl = Url.Action("Notify", "PayFast", new {data.paymentId}, "http");
    }

    // Use a canned IPN message.
    Dictionary<string, string> dict = _payFastIntegration.GetMockIpn(data.paymentId);
    var values = dict.ToNameValueCollection();
    using (var wc = new WebClient())
    {
        // Just a reminder we are posting to Trocrates here, from PayFast.
        wc.UploadValues(notifyUrl, "POST", values);
    }
}

However, I get an ‘Object reference not set to an instance of an object.’ exception on the following line:

notifyUrl = Url.Action("Notify", "PayFast", new {data.paymentId}, "http");

data.paymentId has a valid value, e.g. 112, so I’m not passing any null references to the Url.Action method. I suspect I have lost some sort of context somewhere by calling Notify on a new thread. However, if I use just notifyUrl = Url.Action("Notify", "PayFast");, I avoid the exception, but I get a relative action URL, where I need the overload that takes a protocol parameter, as only that overload gives me the absolute URL that WebClient.UploadValues says it needs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:15:52+00:00Added an answer on May 24, 2026 at 1:15 am

    When you are inside the thread you no longer have access to the HttpContext and the Request property which the Url helper relies upon. So you should never use anything that relies on HttpContext inside threads.

    You should pass all the information that’s needed to the thread when calling it, like this:

    waitThread.Start(new { 
        paymentId, 
        ipnDelay = 1000,
        notifyUrl = Url.Action("Notify", "PayFast", new { paymentId }, "http")
    });
    

    and then inside the thread callback:

    var notifyUrl = new PayFastPaymentModel().NotifyUrl;
    if (_payFastConfig.UseMock)
    {
        // Need an absoluate URL here just for the WebClient.
        notifyUrl = data.notifyUrl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to set it so if a certain condition is met then one of
I am trying set a button on a user control as defaultbutton on a
I am trying to set the mysql connection in web config file. Here is
Im trying set the single table inheritance model type in a form. So i
I am trying set up databinding as described in the title. The problem I
Trying to set up caching on our datasets - we're using clr stored procedures
Trying to set up a dependency in C++ with a parent-child relationship. The parent
Im trying to set up a session and i am getting a header error,
Im trying to set the certificate friendly name during the certificate request/acceptance process. I
When trying to set DoMatchParen I get the following error: E492: Not an editor

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.