# StartWorkflow API

## Example implementation:

```php
    namespace BillinkGateway;

    // To start the payment workflow in Billink, create a list of
    // Billink\Order instances and put them in an Order\OrderList collection.
    $orderList = Order\OrderList::collect([
        (new Converters\Order(wc_get_order(123)))->parse(),
        (new Converters\Order(wc_get_order(456)))->parse(),
    ]);

    // Use the OrderListinstance on the StartWorkflow endpoint class 
    // and inject the AuthenticationHeader into it.
    $workflowEndpoint = new Endpoint\StartWorkflow($orderList);
    $workflowEndpoint->setAuthenticationHeader(App::get('auth.header'));

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

        $workflowResponse = App::get('serializer')
            ->unserialize($response->getBody(), Endpoint\StartWorkflow::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 ($workflowResponse->isInvalid()) {
        var_dump(
            $workflowResponse->isValid(),
            $workflowResponse->getCode(),
            $workflowResponse->getError(),
            $workflowResponse->getErrorLabel(),
            $workflowResponse
        );

        exit('Order is invalid');
    }

    // Get a list of Workflow\Invoice instances, which have methods to figure
    // out the status of an Invoice. The list itself is a Collection.
    $invoices = $workflowResponse->getInvoices();
    foreach ($invoices as $invoice) {
        var_dump(
            $invoice->exists(),
            $invoice->notExists(),
            $invoice->success(),
            $invoice->alreadyStarted(),
            $invoice->description,
            $invoice->invoiceNumber,
            $invoice->status
        );
    }
```
