Skip to content

Commit c4b7c6e

Browse files
committed
fix(SalesInvoices): Fixed that a empty body was send
1 parent c97c9d7 commit c4b7c6e

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/Moneybird/Resource/SalesInvoices.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,13 @@ public function send($invoice = NULL) {
110110

111111
$body = [];
112112
if (!empty($this->contact)) {
113-
if (empty($this->contact->email))
113+
if (empty($this->contact->email)) {
114114
throw new Exception("Contact has no email address!");
115+
}
115116

116-
if (empty($this->contact->delivery_method))
117+
if (empty($this->contact->delivery_method)) {
117118
throw new Exception("Contact has no delivery method!");
119+
}
118120

119121
$body[ "email_address" ] = $this->contact->email;
120122
$body[ "delivery_method" ] = $this->contact->delivery_method;
@@ -129,7 +131,14 @@ public function send($invoice = NULL) {
129131
$body[ "email_message" ] = $this->emailMessage;
130132
}
131133

132-
return $this->restUpdate($this->getResourcePath(), "send_invoice", [ "sales_invoice_sending" => $body ]);
134+
if (count($body) > 0) {
135+
$body = [ "sales_invoice_sending" => $body ];
136+
137+
} else {
138+
$body = NULL;
139+
}
140+
141+
return $this->restUpdate($this->getResourcePath(), "send_invoice", $body);
133142
}
134143

135144
/**

0 commit comments

Comments
 (0)