Using the SDK

Making calls

Task-based Asynchronous Pattern

The C# SDK utilizes the Task-based Asynchronous Pattern (TAP) for handling asynchronous operations. This means that you can call API methods within functions that are declared with the async keyword and use the await operator, as demonstrated in the example below.

Using the TAP allows for efficient handling of asynchronous operations, improving the performance and scalability of your application.

 async Task listPaymentOrders()
 {
   var response = await api.PaymentOrder.V1.List();
 }


Handel responses

Response object

The response object provides valuable information and useful functions for handling responses. It includes the following properties and methods:

response.StatusCode //  The HTTP status code of the response.
response.RawBody // The raw body of the response as a string.
response.ParsingError // A boolean indicating any error that occurred while parsing the response.
response.Body.SuccessfulResponseBody // The body of the response, if the response was successful.
response.Body.ErrorResponseBody // The body of the response, if the response was an error.
response.IsFailure // A boolean indicating whether the response was a failure.
response.IsSuccessful //  A boolean indicating whether the response was successful.
response.Match() // Allows you pattern match based on the success or failure of the response.
response.MatchAsync() //  An async version of Match() for handling responses asynchronously.

Check if the call is successful

Use if/else statment

if(response.IsSuccessful)
{
    await ShowDialog("Open Swish on your device...");
} 
else
{
    await ShowError(response.Body.ErrorResponseBody);
}

Or use pattern match on response (if you like a functional programming approach)

await response.MatchAsync
(
    OnSuccess: async (SwishECommerceResponse ipr) => await ShowDialog("Open Swish on your device..."),
    OnFailure: async (ErrorResponseBody error) => await ShowError(error)
);


Successful responses

200 OK

A status 200 HTTP response is a standard response to a successful HTTP request. It indicates that the client's request was received, understood, and accepted by the server. This is the most common and general successful status code, indicating that the request was fulfilled without any errors or issues.

Example value

{
  "url": "string"
}

201 Created

A status 201 HTTP response is a standard response to a successful HTTP request that results in the creation of a new resource on the server. This response indicates that the request was received and processed successfully, and that a new resource has been created as a result. The newly created resource is typically returned in the response body, along with additional information about its location and other metadata. This status code is often used in response to POST requests that create a new resource on the server.

Example value

{
  "merchant_id": "string"
}

204 No content

A status 204 HTTP response is a standard response to a successful HTTP request that does not require a response body to be sent by the server. This response indicates that the request was received and processed successfully, but that there is no additional information to be sent in the response body.

Example value

{}


Error responses

400 Bad Request

A HTTP response status code 400 Bad Request indicates that the server cannot or will not process the request due to something that is perceived to be a client error (for example, malformed request syntax, invalid request message framing, or deceptive request routing).

Example value

{
  "errors": [
    {
      "reason": "person_already_exists",
      "description": "This person is already registered"
    }
  ]
}

403 Forbidden

A status 403 HTTP response is a standard response to a request that is not authorized or is otherwise not allowed to be performed by the client. This response indicates that the client's request was understood by the server, but the server is refusing to fulfill it. This status code is typically used when the client does not have the necessary permissions or credentials to access the requested resource.

Example value

{
  "errors": [
    {
      "additional_information": null,
      "description": "This operation cannot be completed under certain conditions",
      "error": "operation_forbidden"
    }
  ]
}

404 NotFound

A status 404 HTTP response is a standard response to a request that cannot be fulfilled by the server. This response indicates that the server was unable to find the requested resource, and that it does not have any further information on where the resource might be located. This status code is typically used when the client has requested a resource that does not exist on the server, or when the server is unable to locate the requested resource.

Example value

{
  "errors": [
    {
      "additional_information": null,
      "description": " Requested object not found in our system",
      "error": "not_found"
    }
  ]
}

422 UnprocessableEntity

A status 422 HTTP response is a standard response to a request that cannot be processed by the server due to a semantic error in the request. This response indicates that the server was able to understand the request and the client's intentions, but that the request was not well-formed or otherwise unable to be processed. This status code is typically used when the server is able to understand the request, but the request is missing required parameters or includes invalid data.

Example value

{
  "errors": [
    {
      "additional_information": null,
      "description": "null value where string expected",
      "error": "null_value",
      "property": "open_banking.success_url"
    }
  ]
}

500 InternalServerError

A 500 HTTP response indicates that an error occurred on the server while processing the request, and as such, it should be considered unusual for our API. These responses should only happen in exceptional cases, such as when the server is experiencing a crash or other unexpected error.

Example value

{}