# Check API

## Example implementation:

```php
    namespace Tussendoor\Billink;

    // The easiest way is to resolve the customer from a WooCommerce order.
    // Give the WC_Customer instance to the customer converter to easily 
    // create a Tussendoor\Billink\Customer\Customer instance. 
    $wcOrder = wc_get_order(123);
    $customerId = $wcOrder->get_customer_id();
    $wcCustomer = new \WC_Customer($customerId);

    $order = (new Converters\Order($wcOrder))->parse();
    $customer = (new Converters\Customer($wcCustomer))->parse();

    // Use the Customer instance on the Check endpoint class and inject the
    // AuthenticationHeader into it.
    $checkEndpoint = new Endpoint\Check($customer, $order);
    $checkEndpoint->setAuthenticationHeader(App::get('auth.header'));

    // Build the HTTP request through our HTTP client and serialize the 
    // Check instance into XML by calling the serialize() method.
    try {
        $response = App::get('http.client')
            ->post($checkEndpoint->getUrlEndpoint(), $checkEndpoint->serialize())
            ->send();

        $checkResponse = App::get('serializer')
            ->unserialize($response->getBody(), Endpoint\Check::class, 'xml');
    } catch (\Tussendoor\Http\RequestException $e) {
        // When the HTTP request fails, a RequestException is thrown.
        var_dump($e->getErrors());
        exit();
    } catch (\Exception $e) {
        var_dump($e);
        exit();
    }

    // The response will be invalid if a validation error occured over at Billink.
    if ($checkResponse->isInvalid()) {
        var_dump(
            $checkResponse->isValid(),
            $checkResponse->getCode(),
            $checkResponse->getError(),
            $checkResponse->getErrorLabel(),
            $checkResponse
        );

        exit();
    }

    // This is a CheckResponse specific method. If it is negative, this means the customer
    // cannot order through Billink as it did not pass the credit check.
    if ($checkResponse->isNegative()) {
        exit('did not pass credit check');
    }

    // At this point the customer did pass the credit check and an UUID is availble
    $uuid = $checkResponse->getUuid();
```
