Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c0bf5a5bf | ||
|
|
75bd0f95f5 | ||
|
|
d59411a396 | ||
|
|
16862d2ed6 | ||
|
|
3b161c5d00 | ||
|
|
ca9e77e5df | ||
|
|
01057e8da8 | ||
|
|
5522adcf5e | ||
|
|
c41360a6e2 | ||
|
|
7815bc0312 | ||
|
|
79ac751e54 | ||
|
|
3e0425497c | ||
|
|
1e08ee7c91 | ||
|
|
f04618c667 | ||
|
|
8b3f1663f1 | ||
|
|
43076fdd9b | ||
|
|
79d1f1e51b | ||
|
|
36578f803c | ||
|
|
dbc3aeec94 |
15
README.md
15
README.md
@ -1,3 +1,7 @@
|
||||
# === Warning ===
|
||||
|
||||
This is the old BitPay based PHP client and should be considered deprecated (even though it currently still works). If you are building something from scratch, [use the new Greenfield API](https://github.com/btcpayserver/btcpayserver-greenfield-php).
|
||||
|
||||
bitpay/php-bitpay-client
|
||||
=================
|
||||
|
||||
@ -33,8 +37,15 @@ Add to your composer.json file by hand.
|
||||
...
|
||||
"require": {
|
||||
...
|
||||
"bitpay/php-client": "~2.2"
|
||||
}
|
||||
"bitpay/php-client": "dev-master"
|
||||
},
|
||||
"repositories": [
|
||||
...
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "https://github.com/btcpayserver/php-bitpay-client"
|
||||
}
|
||||
],
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
@ -34,7 +34,7 @@ if (true === empty($ipn)) {
|
||||
throw new \Exception('Could not decode the JSON payload from BitPay.');
|
||||
}
|
||||
|
||||
if (true === empty($ipn -> id)) {
|
||||
if (true === empty($ipn->id)) {
|
||||
fwrite($myfile, $date . " : Error. Invalid Bitpay payment notification message received - did not receive invoice ID.\n");
|
||||
fclose($myfile);
|
||||
throw new \Exception('Invalid Bitpay payment notification message received - did not receive invoice ID.');
|
||||
@ -42,15 +42,20 @@ if (true === empty($ipn -> id)) {
|
||||
|
||||
// Now fetch the invoice from BitPay
|
||||
// This is needed, since the IPN does not contain any authentication
|
||||
|
||||
$storageEngine = new \Bitpay\Storage\EncryptedFilesystemStorage('YourTopSecretPassword');
|
||||
$privateKey = $storageEngine->load('/tmp/bitpay.pri');
|
||||
$publicKey = $storageEngine->load('/tmp/bitpay.pub');
|
||||
$client = new \Bitpay\Client\Client();
|
||||
$adapter = new \Bitpay\Client\Adapter\CurlAdapter();
|
||||
$client->setPrivateKey($privateKey);
|
||||
$client->setPublicKey($publicKey);
|
||||
$client->setUri('https://btcpay.server/');
|
||||
$client->setAdapter($adapter);
|
||||
|
||||
$token = new \Bitpay\Token();
|
||||
$token->setToken('UpdateThisValue'); // UPDATE THIS VALUE
|
||||
$client->setToken($token);
|
||||
$token->setFacade('merchant');
|
||||
|
||||
/**
|
||||
* This is where we will fetch the invoice object
|
||||
|
||||
@ -15,13 +15,19 @@ require __DIR__.'/../../vendor/autoload.php';
|
||||
|
||||
// Now fetch the invoice from BitPay
|
||||
|
||||
$storageEngine = new \Bitpay\Storage\EncryptedFilesystemStorage('YourTopSecretPassword');
|
||||
$privateKey = $storageEngine->load('/tmp/bitpay.pri');
|
||||
$publicKey = $storageEngine->load('/tmp/bitpay.pub');
|
||||
$client = new \Bitpay\Client\Client();
|
||||
$adapter = new \Bitpay\Client\Adapter\CurlAdapter();
|
||||
$client->setPrivateKey($privateKey);
|
||||
$client->setPublicKey($publicKey);
|
||||
$client->setUri('https://btcpay.server/');
|
||||
$client->setAdapter($adapter);
|
||||
|
||||
$token = new \Bitpay\Token();
|
||||
$token->setToken('UpdateThisValue'); // UPDATE THIS VALUE
|
||||
$token->setFacade('merchant');
|
||||
|
||||
$client->setToken($token);
|
||||
|
||||
|
||||
@ -103,7 +103,6 @@ class CurlAdapter implements AdapterInterface
|
||||
CURLOPT_TIMEOUT => 10,
|
||||
CURLOPT_SSL_VERIFYPEER => 1,
|
||||
CURLOPT_SSL_VERIFYHOST => 2,
|
||||
CURLOPT_CAINFO => __DIR__.'/ca-bundle.crt',
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_FORBID_REUSE => 1,
|
||||
CURLOPT_FRESH_CONNECT => 1,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -111,7 +111,7 @@ class Client implements ClientInterface
|
||||
$invoiceTime = is_numeric($data['invoiceTime']) ? intval($data['invoiceTime']/1000) : $data['invoiceTime'];
|
||||
$expirationTime = is_numeric($data['expirationTime']) ? intval($data['expirationTime']/1000) : $data['expirationTime'];
|
||||
$currentTime = is_numeric($data['currentTime']) ? intval($data['currentTime']/1000) : $data['currentTime'];
|
||||
|
||||
|
||||
$invoiceToken = new \Bitpay\Token();
|
||||
$invoice
|
||||
->setToken($invoiceToken->setToken($data['token']))
|
||||
@ -121,7 +121,7 @@ class Client implements ClientInterface
|
||||
->setBtcPrice(array_key_exists('btcPrice', $data) ? $data['btcPrice'] : '')
|
||||
->setPrice($data['price'])
|
||||
->setTaxIncluded($data['taxIncluded'])
|
||||
->setCurrency(new \Bitpay\Currency($data['currency']))
|
||||
->setCurrency(new \Bitpay\CurrencyUnrestricted($data['currency']))
|
||||
->setOrderId(array_key_exists('orderId', $data) ? $data['orderId'] : '')
|
||||
->setInvoiceTime($invoiceTime)
|
||||
->setExpirationTime($expirationTime)
|
||||
@ -183,8 +183,15 @@ class Client implements ClientInterface
|
||||
'guid' => Util::guid(),
|
||||
'nonce' => Util::nonce(),
|
||||
'token' => $this->token->getToken(),
|
||||
'paymentCurrencies' => $invoice->getPaymentCurrencies(),
|
||||
);
|
||||
|
||||
foreach(array_keys($body) as $key) {
|
||||
if(null === $body[$key]) {
|
||||
unset($body[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$request->setBody(json_encode($body));
|
||||
$this->addIdentityHeader($request);
|
||||
$this->addSignatureHeader($request);
|
||||
@ -598,7 +605,7 @@ class Client implements ClientInterface
|
||||
}
|
||||
|
||||
$data = $body['data'];
|
||||
|
||||
|
||||
$invoice = new \Bitpay\Invoice();
|
||||
$invoice = $this->fillInvoiceData($invoice, $data);
|
||||
|
||||
@ -606,7 +613,7 @@ class Client implements ClientInterface
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -25,8 +25,8 @@ interface ClientInterface
|
||||
*
|
||||
* @see RFC2616 section 14.43 for User-Agent Format
|
||||
*/
|
||||
const NAME = 'BitPay PHP-Client';
|
||||
const VERSION = '2.2.20';
|
||||
const NAME = 'BitPay PHP-Client BTCPAY';
|
||||
const VERSION = '2.2.23';
|
||||
|
||||
//public function createApplication(ApplicationInterface $application);
|
||||
|
||||
|
||||
16
src/Bitpay/CurrencyUnrestricted.php
Normal file
16
src/Bitpay/CurrencyUnrestricted.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Bitpay;
|
||||
|
||||
class CurrencyUnrestricted extends Currency
|
||||
{
|
||||
/**
|
||||
* Overrides the parent method to allow any currency symbol to be set.
|
||||
*/
|
||||
public function setCode($code)
|
||||
{
|
||||
$this->code = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@ -155,6 +155,10 @@ class Invoice implements InvoiceInterface
|
||||
*/
|
||||
protected $paymentTotals;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $paymentCurrencies;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -598,10 +602,7 @@ class Invoice implements InvoiceInterface
|
||||
*/
|
||||
public function setOrderId($orderId)
|
||||
{
|
||||
if (!empty($orderId) && ctype_print($orderId)) {
|
||||
$this->orderId = trim($orderId);
|
||||
}
|
||||
|
||||
$this->orderId = $orderId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -922,4 +923,21 @@ class Invoice implements InvoiceInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getPaymentCurrencies() {
|
||||
return $this->paymentCurrencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setPaymentCurrencies($paymentCurrencies) {
|
||||
$this->paymentCurrencies = $paymentCurrencies;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@ -379,4 +379,22 @@ interface InvoiceInterface
|
||||
* @return array|object
|
||||
*/
|
||||
public function getRefundAddresses();
|
||||
|
||||
/**
|
||||
* Get the enforced transaction currencies.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getPaymentCurrencies();
|
||||
|
||||
/**
|
||||
* Set specific invoice currencies and to enforce them on payment step.
|
||||
*
|
||||
* @param array $paymentCurrencies
|
||||
* The currencies need to match what is supported by BTCPay Server.
|
||||
* E.g. BTC, BTC_ONCHAIN, BTC_OFFCHAIN, LTC, XMR_MONEROLIKE etc.
|
||||
*
|
||||
* @return InvoiceInterface
|
||||
*/
|
||||
public function setPaymentCurrencies($paymentCurrencies);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user