Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add receiptOptions & additionalSearchTerms to createInvoice & Add includeSensitive & onlyAccountedPayments to getPaymentMethods #131

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 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 Expand Up @@ -229,11 +233,17 @@ public function getAllInvoicesWithFilter(
/**
* @return InvoicePaymentMethod[]
*/
public function getPaymentMethods(string $storeId, string $invoiceId): array
{
public function getPaymentMethods(
string $storeId,
string $invoiceId,
bool $includeSensitive = false,
bool $onlyAccountedPayments = true
): array {
$method = 'GET';
$url = $this->getApiUrl() . 'stores/' . urlencode($storeId) . '/invoices/'
. urlencode($invoiceId) . '/payment-methods';
$url .= '?includeSensitive=' . ($includeSensitive ? 'true' : 'false');
$url .= '&onlyAccountedPayments=' . ($onlyAccountedPayments ? 'true' : 'false');
$headers = $this->getRequestHeaders();
$response = $this->getHttpClient()->request($method, $url, $headers);

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;
}
}
Loading