Add taxIncluded field

This commit is contained in:
nicolas.dorier 2019-01-26 13:56:34 +09:00
parent 958fd250ef
commit f34dba2448
6 changed files with 59 additions and 10 deletions

View File

@ -62,8 +62,9 @@ $invoiceId = $invoice->getId();
$invoiceStatus = $invoice->getStatus();
$invoiceExceptionStatus = $invoice->getExceptionStatus();
$invoicePrice = $invoice->getPrice();
$taxIncluded = $invoice->getTaxIncluded();
fwrite($myfile, $date . " : IPN received for BitPay invoice ".$invoiceId." . Status = " .$invoiceStatus." / exceptionStatus = " . $invoiceExceptionStatus." Price = ". $invoicePrice. "\n");
fwrite($myfile, $date . " : IPN received for BitPay invoice ".$invoiceId." . Status = " .$invoiceStatus." / exceptionStatus = " . $invoiceExceptionStatus." Price = ". $invoicePrice." Tax Included = ". $taxIncluded."\n");
fwrite($myfile, "Raw IPN: ". $raw_post_data."\n");
//Respond with HTTP 200, so BitPay knows the IPN has been received correctly

View File

@ -126,6 +126,7 @@ class Client implements ClientInterface
->setStatus($data['status'])
->setBtcPrice(array_key_exists('btcPrice', $data) ? $data['btcPrice'] : '')
->setPrice($data['price'])
->setPrice($data['taxIncluded'])
->setCurrency(new \Bitpay\Currency($data['currency']))
->setOrderId(array_key_exists('orderId', $data) ? $data['orderId'] : '')
->setInvoiceTime($invoiceTime)
@ -162,6 +163,7 @@ class Client implements ClientInterface
$body = array(
'price' => $item->getPrice(),
'taxIncluded' => $item->getTaxIncluded(),
'currency' => $currency->getCode(),
'posData' => $invoice->getPosData(),
'notificationURL' => $invoice->getNotificationUrl(),
@ -701,14 +703,5 @@ class Client implements ClientInterface
protected function checkPriceAndCurrency($price, $currency)
{
$decimalPosition = strpos($price, '.');
if ($decimalPosition == 0) {
$decimalPrecision = 0;
} else {
$decimalPrecision = strlen(substr($price, $decimalPosition + 1));
}
if (($decimalPrecision > 2 && $currency != 'BTC') || $decimalPrecision > 6) {
throw new \Exception('Incorrect price format or currency type.');
}
}
}

View File

@ -164,6 +164,14 @@ class Invoice implements InvoiceInterface
return $this->getItem()->getPrice();
}
/**
* @inheritdoc
*/
public function getTaxIncluded()
{
return $this->getItem()->getTaxIncluded();
}
/**
* @param float $price
*
@ -178,6 +186,20 @@ class Invoice implements InvoiceInterface
return $this;
}
/**
* @param float $taxIncluded
*
* @return InvoiceInterface
*/
public function setTaxIncluded($taxIncluded)
{
if (!empty($taxIncluded)) {
$this->getItem()->setTaxIncluded($taxIncluded);
}
return $this;
}
/**
* @inheritdoc
*/

View File

@ -84,6 +84,8 @@ interface InvoiceInterface
*/
public function getPrice();
public function getTaxIncluded();
/**
* This is the currency code set for the price setting.  The pricing currencies
* currently supported are USD, EUR, BTC, and all of the codes listed on this page:

View File

@ -29,6 +29,11 @@ class Item implements ItemInterface
*/
protected $price;
/**
* @var float
*/
protected $taxIncluded;
/**
* @var integer
*/
@ -96,6 +101,16 @@ class Item implements ItemInterface
return $this->price;
}
/**
* @inheritdoc
*
* @return float
*/
public function getTaxIncluded()
{
return $this->taxIncluded;
}
/**
* @param mixed $price A float, integer, or en_US formatted numeric string
*
@ -112,6 +127,17 @@ class Item implements ItemInterface
return $this;
}
public function setTaxIncluded($taxIncluded)
{
if (is_string($taxIncluded)) {
$this->checkPriceFormat($taxIncluded);
}
$this->taxIncluded = (float)$taxIncluded;
return $this;
}
/**
* @inheritdoc
*/

View File

@ -34,6 +34,11 @@ interface ItemInterface
*/
public function getPrice();
/**
* @return string
*/
public function getTaxIncluded();
/**
* @return string
*/