Unable to make payment using c# SDK


#1

Hello,
I’m trying to request a payment using the C# SDK and Express Mobile Transaction mode.
I’m using this code:

var paynow = new Webdev.Payments.Paynow(integrationID, integrationKey);

paynow.ResultUrl = notifyURL;

// Create a new payment
var payment = paynow.CreatePayment(reference_id,opMail);

// Add items to the payment
payment.Add(“deposit”, amount);

// Send payment to paynow
var response = paynow.SendMobileAsync(payment, mobile, “ecocash”);

string pollUrl = “”;

// Check if payment was sent without error
if (response.Result.Success())
{
pollUrl = response.Result.PollUrl();
}

But the code is timing out when trying to get the result of the payment request at this part of the code:
if (response.Result.Success())

Is there anything wrong?
Thanks


#2

Good day @sarkis

Calling .Result on a Task returned from an async method in C# can cause thread starvation, particularly in ASP.NET applications or UI-based applications (like WPF or WinForms). This happens because .Result blocks the calling thread, potentially leading to deadlocks if the synchronization context is captured.

A better approach is to use await , which allows the method to asynchronously wait for the result without blocking the thread.

var response = await paynow.SendMobileAsync(payment, mobile, "ecocash");
// Check if payment was sent without error
if (response.Success())
{
pollUrl = response.PollUrl();
}