-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a9c359
commit 6023da3
Showing
19 changed files
with
1,066 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitPaySDKexamples; | ||
|
||
use BitPaySDK\Client; | ||
use BitPaySDK\PosClient; | ||
|
||
class ClientProvider | ||
{ | ||
public static function create(): Client | ||
{ | ||
// to create private key, tokens & private key secret run setup/ConfigGenerator.php from CLI before | ||
|
||
return Client::createWithFile(__DIR__ . '/myConfigFile.json'); | ||
} | ||
|
||
public static function createPos(): Client | ||
{ | ||
return new PosClient('myPosToken'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitPaySDKexamples\General; | ||
|
||
use BitPaySDK\Logger\BitPayLogger; | ||
use BitPaySDK\Logger\LoggerProvider; | ||
use BitPaySDKexamples\ClientProvider; | ||
|
||
final class UseLogger | ||
{ | ||
/** | ||
* @throws \BitPaySDK\Exceptions\BitPayApiException | ||
* @throws \BitPaySDK\Exceptions\BitPayGenericException | ||
*/ | ||
public function execute(): void | ||
{ | ||
LoggerProvider::setLogger( | ||
new class() implements BitPayLogger | ||
{ | ||
public function logRequest(string $method, string $endpoint, ?string $json): void | ||
{ | ||
echo $this->getLogMessage('Request', $method, $endpoint, $json); | ||
$this->newLine(); | ||
} | ||
|
||
public function logResponse(string $method, string $endpoint, ?string $json): void | ||
{ | ||
echo $this->getLogMessage('Response', $method, $endpoint, $json); | ||
$this->newLine(); | ||
} | ||
|
||
public function logError(?string $message): void | ||
{ | ||
echo $message; | ||
$this->newLine(); | ||
} | ||
|
||
private function getLogMessage(string $type, string $method, string $endpoint, ?string $json): string | ||
{ | ||
$array = [ | ||
'type' => $type, | ||
'method' => $method, | ||
'endpoint' => $endpoint, | ||
'json' => $json | ||
]; | ||
|
||
return json_encode($array, JSON_THROW_ON_ERROR | JSON_ERROR_NONE); | ||
} | ||
|
||
private function newLine(): void | ||
{ | ||
echo "\r\n"; | ||
} | ||
} | ||
); | ||
|
||
// for monolog implementation you can use code from src/BitPaySDK/Logger/MonologLoggerExample.php | ||
|
||
$client = ClientProvider::create(); | ||
|
||
$invoice = $client->getInvoiceByGuid("someGuid"); // requests/response will be logged | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitPaySDKexamples\Merchant; | ||
|
||
use BitPaySDK\Model\Bill\Bill; | ||
use BitPaySDK\Model\Bill\Item; | ||
use BitPaySDKexamples\ClientProvider; | ||
|
||
final class BillRequests | ||
{ | ||
/** | ||
* @throws \BitPaySDK\Exceptions\BitPayApiException | ||
* @throws \BitPaySDK\Exceptions\BitPayGenericException | ||
*/ | ||
public function createBill(): void | ||
{ | ||
$client = ClientProvider::create(); | ||
|
||
$bill = new Bill(null, 'USD'); | ||
$bill->setName('someName'); | ||
$bill->setEmail('[email protected]'); | ||
$bill->setAddress1('SomeAddress'); | ||
$bill->setCity('MyCity'); | ||
// ... | ||
|
||
$client->createBill($bill); | ||
} | ||
|
||
/** | ||
* @throws \BitPaySDK\Exceptions\BitPayApiException | ||
* @throws \BitPaySDK\Exceptions\BitPayGenericException | ||
*/ | ||
public function getBill(): void | ||
{ | ||
$client = ClientProvider::create(); | ||
|
||
$bill = $client->getBill('someBillId'); | ||
|
||
$bills = $client->getBills('draft'); | ||
} | ||
|
||
/** | ||
* @throws \BitPaySDK\Exceptions\BitPayApiException | ||
* @throws \BitPaySDK\Exceptions\BitPayGenericException | ||
*/ | ||
public function updateBill(): void | ||
{ | ||
$client = ClientProvider::create(); | ||
|
||
$item = new Item(); | ||
$item->setPrice(12.34); | ||
$item->setQuantity(5); | ||
$item->setDescription('someDecription'); | ||
|
||
$bill = new Bill(); | ||
$bill->setEmail('[email protected]'); | ||
$bill->setItems([$item]); | ||
|
||
$client->updateBill($bill, $bill->getId()); | ||
} | ||
|
||
/** | ||
* @throws \BitPaySDK\Exceptions\BitPayApiException | ||
* @throws \BitPaySDK\Exceptions\BitPayGenericException | ||
*/ | ||
public function deliverBillViaEmail(): void | ||
{ | ||
$client = ClientProvider::create(); | ||
|
||
$client->deliverBill('someBillId', 'myBillToken'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitPaySDKexamples\Merchant; | ||
|
||
use BitPaySDK\Model\Invoice\Buyer; | ||
use BitPaySDK\Model\Invoice\Invoice; | ||
use BitPaySDKexamples\ClientProvider; | ||
|
||
final class InvoiceRequests | ||
{ | ||
/** | ||
* @throws \BitPaySDK\Exceptions\BitPayApiException | ||
* @throws \BitPaySDK\Exceptions\BitPayGenericException | ||
*/ | ||
public function createInvoice(): void | ||
{ | ||
$invoice = new Invoice(10.0, "USD"); | ||
$invoice->setFullNotifications(true); | ||
$invoice->setExtendedNotifications(true); | ||
$invoice->setNotificationURL("https://test/lJnJg9WW7MtG9GZlPVdj"); | ||
$invoice->setRedirectURL("https://test/lJnJg9WW7MtG9GZlPVdj"); | ||
$invoice->setNotificationEmail("[email protected]"); | ||
$invoice->setBuyerSms('+12223334445'); | ||
|
||
$buyer = new Buyer(); | ||
$buyer->setName("Test"); | ||
$buyer->setEmail("[email protected]"); | ||
$buyer->setAddress1("168 General Grove"); | ||
$buyer->setCountry("AD"); | ||
$buyer->setLocality("Port Horizon"); | ||
$buyer->setNotify(true); | ||
$buyer->setPhone("+990123456789"); | ||
$buyer->setPostalCode("KY7 1TH"); | ||
$buyer->setRegion("New Port"); | ||
|
||
$invoice->setBuyer($buyer); | ||
|
||
$client = ClientProvider::create(); | ||
|
||
$createdInvoice = $client->createInvoice($invoice); | ||
} | ||
|
||
/** | ||
* @throws \BitPaySDK\Exceptions\BitPayApiException | ||
* @throws \BitPaySDK\Exceptions\BitPayGenericException | ||
*/ | ||
public function getInvoice(): void | ||
{ | ||
$client = ClientProvider::create(); | ||
|
||
$invoiceById = $client->getInvoice("myInvoiceId"); | ||
$invoiceByGuid = $client->getInvoiceByGuid("someGuid"); // we can add a GUID during the invoice creation | ||
$invoices = $client->getInvoices("2023-04-14", "2023-04-17"); | ||
} | ||
|
||
/** | ||
* @throws \BitPaySDK\Exceptions\BitPayApiException | ||
* @throws \BitPaySDK\Exceptions\BitPayGenericException | ||
*/ | ||
public function updateInvoice(): void | ||
{ | ||
$client = ClientProvider::create(); | ||
|
||
$invoice = $client->updateInvoice("someId", "123321312", null, null); | ||
} | ||
|
||
/** | ||
* @throws \BitPaySDK\Exceptions\BitPayApiException | ||
* @throws \BitPaySDK\Exceptions\BitPayGenericException | ||
*/ | ||
public function cancelInvoice(): void | ||
{ | ||
$client = ClientProvider::create(); | ||
|
||
$client->cancelInvoice('invoiceId'); | ||
|
||
$client->cancelInvoiceByGuid('invoiceGuid'); | ||
} | ||
|
||
/** | ||
* @throws \BitPaySDK\Exceptions\BitPayApiException | ||
* @throws \BitPaySDK\Exceptions\BitPayGenericException | ||
*/ | ||
public function requestInvoiceWebhookToBeResent(): void | ||
{ | ||
$client = ClientProvider::create(); | ||
|
||
$client->requestInvoiceNotification('someInvoiceId'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitPaySDKexamples\Ledger; | ||
|
||
use BitPaySDKexamples\ClientProvider; | ||
|
||
final class LedgerRequests | ||
{ | ||
/** | ||
* @throws \BitPaySDK\Exceptions\BitPayApiException | ||
* @throws \BitPaySDK\Exceptions\BitPayGenericException | ||
*/ | ||
public function getLedgers(): void | ||
{ | ||
$client = ClientProvider::create(); | ||
|
||
$ledgers = $client->getLedgers(); | ||
} | ||
|
||
/** | ||
* @throws \BitPaySDK\Exceptions\BitPayApiException | ||
* @throws \BitPaySDK\Exceptions\BitPayGenericException | ||
*/ | ||
public function getLedgerEntries(): void | ||
{ | ||
$client = ClientProvider::create(); | ||
|
||
$ledgerEntries = $client->getLedgerEntries('USD', '2023-08-14', '2023-08-22'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitPaySDKexamples\Merchant; | ||
|
||
use BitPaySDKexamples\ClientProvider; | ||
|
||
final class RefundRequests | ||
{ | ||
/** | ||
* @throws \BitPaySDK\Exceptions\BitPayApiException | ||
* @throws \BitPaySDK\Exceptions\BitPayGenericException | ||
*/ | ||
public function createRefund(): void | ||
{ | ||
$client = ClientProvider::create(); | ||
|
||
$refund = $client->createRefund("myInvoiceId", 12.34, "USD"); | ||
} | ||
|
||
/** | ||
* @throws \BitPaySDK\Exceptions\BitPayApiException | ||
*/ | ||
public function updateRefund(): void | ||
{ | ||
$client = ClientProvider::create(); | ||
|
||
$updatedRefund = $client->updateRefund('myRefundId','created'); | ||
$updatedRefundByGuid = $client->updateRefundByGuid('myRefundId','created'); | ||
} | ||
|
||
/** | ||
* @throws \BitPaySDK\Exceptions\BitPayApiException | ||
* @throws \BitPaySDK\Exceptions\BitPayGenericException | ||
*/ | ||
public function getRefund(): void | ||
{ | ||
$client = ClientProvider::create(); | ||
|
||
$refund = $client->getRefund('someRefundId'); | ||
$refundByGuid = $client->getRefundByGuid('someGuid'); | ||
} | ||
|
||
/** | ||
* @throws \BitPaySDK\Exceptions\BitPayApiException | ||
*/ | ||
public function cancelRefund(): void | ||
{ | ||
$client = ClientProvider::create(); | ||
|
||
$cancelRefund = $client->cancelRefund('myRefundId'); | ||
$cancelRefundByGuid = $client->cancelRefundByGuid('someGuid'); | ||
} | ||
|
||
public function requestRefundNotificationToBeResent(): void | ||
{ | ||
$client = ClientProvider::create(); | ||
|
||
$client->sendRefundNotification('someRefundId'); | ||
} | ||
} |
Oops, something went wrong.