Skip to content

Cannot send an invoice using the 'default' method #316

@markvds

Description

@markvds

The API docs say:

This endpoint provides two options: sending the invoice and scheduling sending in the future. When sending now, you can provide a send method, email address and message. If you don't provide any arguments, the defaults from the contact and workflow will be used.

So, if you don't provide a delivery method, the default method of the Moneybird contact is used. For example, some of my clients use Peppol as delivery method. But that preference is stored only in Moneybird, not in any external system.

The way \Picqer\Financials\Moneybird\Entities\SalesInvoice::sendInvoice acts right now, doesn't support using an empty delivery method:

public function sendInvoice($deliveryMethodOrOptions = SendInvoiceOptions::METHOD_EMAIL)
{
if (is_string($deliveryMethodOrOptions)) {
$options = new SendInvoiceOptions($deliveryMethodOrOptions);
} else {
$options = $deliveryMethodOrOptions;
}
unset($deliveryMethodOrOptions);
if (! $options instanceof SendInvoiceOptions) {
$options = is_object($options) ? get_class($options) : gettype($options);
throw new InvalidArgumentException("Expected string or options instance. Received: '$options'");
}
$response = $this->connection->patch($this->endpoint . '/' . $this->id . '/send_invoice', json_encode([
'sales_invoice_sending' => $options->jsonSerialize(),
]));
if (is_array($response)) {
$this->selfFromResponse($response);
}
return $this;
}

public function setMethod($method)
{
$validMethods = self::getValidMethods();
if (! in_array($method, $validMethods)) {
$method = is_object($method) ? get_class($method) : $method;
$validMethodNames = implode(',', $validMethods);
throw new InvalidArgumentException("Invalid method: '$method'. Expected one of: '$validMethodNames'");
}
$this->method = $method;
}

I'll solve it and create a pull request later tonight.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions