Skip to content

Commit

Permalink
Add receiptOptions & additionalSearchTerms to createInvoice
Browse files Browse the repository at this point in the history
  • Loading branch information
smell-of-curry committed Nov 12, 2024
1 parent f4fac20 commit 21814f3
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Client/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public function createInvoice(
?string $orderId = null,
?string $buyerEmail = null,
?array $metaData = null,
?InvoiceCheckoutOptions $checkoutOptions = null
?InvoiceCheckoutOptions $checkoutOptions = null,
?InvoiceReceiptOptions $receiptOptions = null,
?array $additionalSearchTerms = null
): ResultInvoice {
$url = $this->getApiUrl() . 'stores/' . urlencode(
$storeId
Expand Down Expand Up @@ -55,7 +57,9 @@ public function createInvoice(
'amount' => $amount !== null ? $amount->__toString() : null,
'currency' => $currency,
'metadata' => !empty($metaDataMerged) ? $metaDataMerged : null,
'checkout' => $checkoutOptions ? $checkoutOptions->toArray() : null
'checkout' => $checkoutOptions ? $checkoutOptions->toArray() : null,
'receipt' => $receiptOptions ? $receiptOptions->toArray() : null,
'additionalSearchTerms' => $additionalSearchTerms
],
JSON_THROW_ON_ERROR
);
Expand Down
87 changes: 87 additions & 0 deletions src/Client/InvoiceReceiptOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

declare(strict_types=1);

namespace BTCPayServer\Client;

/**
* Additional settings to customize the public receipt
*/
class InvoiceReceiptOptions
{
/** @var bool */
protected $enabled;

/** @var bool */
protected $showQR;

/** @var bool */
protected $showPayments;

public static function create(
?bool $enabled,
?bool $showQR,
?bool $showPayments,
) {
$options = new InvoiceReceiptOptions();
$options->enabled = $enabled;
$options->showQR = $showQR ?? null;
$options->showPayments = $showPayments;
return $options;
}

public function isEnabled(): ?bool
{
return $this->enabled;
}


public function setEnabled(?bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}

public function showsQR(): ?bool
{
return $this->showQR;
}

public function setShowQR(?bool $showQR): self
{
$this->showQR = $showQR;
return $this;
}

public function showsPayments(): ?bool
{
return $this->showPayments;
}

public function setShowPayments(?bool $showPayments): self
{
$this->showPayments = $showPayments;
return $this;
}

/**
* Converts the whole object incl. protected and private properties to an array.
*/
public function toArray(): array
{
$array = [];
$objAsArray = (array) $this;
foreach ($objAsArray as $k => $v) {
$separator = "\0";
$k = rtrim($k, $separator);

$lastIndex = strrpos($k, $separator);
if ($lastIndex !== false) {
$k = substr($k, $lastIndex + 1);
}
$array[$k] = $v;
}

return $array;
}
}

0 comments on commit 21814f3

Please sign in to comment.