• Namespace
  • Class

Namespaces

  • Klarna
    • Exceptions
    • Rest
      • Checkout
      • CustomerToken
      • HostedPaymentPage
      • InstantShopping
      • MerchantCardService
      • OrderManagement
      • Payments
      • Settlements
      • Transport
        • Exception

Classes

  • ApiResponse
  • Connector
  • CURLConnector
  • GuzzleConnector
  • Method
  • ResponseValidator
  • UserAgent

Interfaces

  • ConnectorInterface
  • UserAgentInterface

Class ResponseValidator

HTTP response validator helper class.

Namespace: Klarna\Rest\Transport
Located at Klarna/Rest/Transport/ResponseValidator.php

Methods summary

public
# __construct( Klarna\Rest\Transport\ApiResponse $response )

Constructs a response validator instance.

Constructs a response validator instance.

Parameters

$response
Response to validate
public Klarna\Rest\Transport\ApiResponse
# getResponse( )

Gets the response object.

Gets the response object.

Returns

Klarna\Rest\Transport\ApiResponse
public Klarna\Rest\Transport\ResponseValidator
# status( string|string[] $status )

Asserts the HTTP response status code.

Asserts the HTTP response status code.

Parameters

$status
Expected status code(s)

Returns

Klarna\Rest\Transport\ResponseValidator

Throws

RuntimeException
If status code does not match
public Klarna\Rest\Transport\ResponseValidator
# contentType( string $mediaType )

Asserts the Content-Type header. Checks partial matching. Validation PASSES in the following cases: Content-Type: application/json $mediaType = 'application/json'

Asserts the Content-Type header. Checks partial matching. Validation PASSES in the following cases: Content-Type: application/json $mediaType = 'application/json'

Content-Type: application/json; charset=utf-8 $mediaType = 'application/json'

Validation FAILS in the following cases: Content-Type: plain/text $mediaType = 'application/json' Content-Type: application/json; charset=utf-8 $mediaType = 'application/json; charset=cp-1251'

Parameters

$mediaType
Expected media type. RegExp rules can be used.

Returns

Klarna\Rest\Transport\ResponseValidator

Throws

RuntimeException
If Content-Type header is missing
RuntimeException
If Content-Type header does not match
public array
# getJson( )

Gets the decoded JSON response.

Gets the decoded JSON response.

Returns

array

Throws

RuntimeException
If the response body is not in JSON format
InvalidArgumentException
If the JSON cannot be parsed
public StreamInterface
# getBody( )

Gets response body.

Gets response body.

Returns

StreamInterface
the body as a stream

Throws

RuntimeException
If the response body is not in JSON format
InvalidArgumentException
If the JSON cannot be parsed
public string
# getLocation( )

Gets the Location header.

Gets the Location header.

Returns

string

Throws

RuntimeException
If the Location header is missing
public
# expectSuccessfull( )

Asserts and analyze the response. Checks if the reponse has SUCCESSFULL family and try to parse the Klarna error message if possbile.

Asserts and analyze the response. Checks if the reponse has SUCCESSFULL family and try to parse the Klarna error message if possbile.

Throws

Klarna\Rest\Transport\Exception\ConnectorException

if response has non-2xx HTTP CODE and contains a Error


RuntimeException
if response has non-2xx HTTP CODE and body is not parsable
public
# isSuccessfull( )

Magic methods summary

Properties summary

protected Klarna\Rest\Transport\ApiResponse $response

HTTP response to validate against.

HTTP response to validate against.

#
API documentation generated by ApiGen