-
Notifications
You must be signed in to change notification settings - Fork 175
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
Showing
7 changed files
with
109 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
include 'basics.php'; | ||
|
||
use unreal4u\TelegramAPI\Telegram\Methods\SendInvoice; | ||
use unreal4u\TelegramAPI\Telegram\Types\LabeledPrice; | ||
use unreal4u\TelegramAPI\Telegram\Types\Message; | ||
use unreal4u\TelegramAPI\TgLog; | ||
|
||
$sendInvoice = new SendInvoice(); | ||
$sendInvoice->chat_id = A_USER_CHAT_ID; | ||
$sendInvoice->title = 'My Special Invoice'; | ||
$sendInvoice->description = 'This is the description of the invoice'; | ||
$sendInvoice->payload = 'specialItem-001'; | ||
$sendInvoice->provider_token = PAYMENT_TOKEN; | ||
$sendInvoice->start_parameter = 'u4u-invoice-0001'; | ||
$sendInvoice->currency = 'EUR'; | ||
$sendInvoice->prices = [ new LabeledPrice(['amount' => 975, 'label' => 'That special item']) ]; | ||
|
||
var_dump($sendInvoice); | ||
|
||
$tgLog = new TgLog(BOT_TOKEN); | ||
/** @var Message $result */ | ||
$result = $tgLog->performApiRequest($sendInvoice); | ||
|
||
var_dump($result); |
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
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
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 @@ | ||
{"ok":true,"result":[{"update_id":816722710,"pre_checkout_query":{"id":"47054498177565117","from":{"id":10955729,"first_name":"Camilo","last_name":"Sperberg","username":"unreal4u","language_code":"en-NL"},"currency":"EUR","total_amount":975,"invoice_payload":"specialItem-001"}}]} |
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 @@ | ||
{"ok":true,"result":{"message_id":2796,"from":{"id":167423524,"first_name":"unreal4uBot","username":"unreal4uBot"},"chat":{"id":10955729,"first_name":"Camilo","last_name":"Sperberg","username":"unreal4u","type":"private"},"date":1497903034,"invoice":{"title":"My Special Invoice","description":"This is the description of the invoice","start_parameter":"u4u-invoice-0001","currency":"EUR","total_amount":975}}} |
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
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,57 @@ | ||
<?php | ||
|
||
namespace unreal4u\TelegramAPI\tests\Telegram\Methods; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use unreal4u\TelegramAPI\Telegram\Methods\SendInvoice; | ||
use unreal4u\TelegramAPI\Telegram\Types\Invoice; | ||
use unreal4u\TelegramAPI\Telegram\Types\LabeledPrice; | ||
use unreal4u\TelegramAPI\tests\Mock\MockTgLog; | ||
use unreal4u\TelegramAPI\Telegram\Types\Message; | ||
|
||
class SendInvoiceTest extends TestCase | ||
{ | ||
/** | ||
* @var MockTgLog | ||
*/ | ||
private $tgLog; | ||
|
||
/** | ||
* Prepares the environment before running a test. | ||
*/ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->tgLog = new MockTgLog('TEST-TEST'); | ||
} | ||
|
||
/** | ||
* Cleans up the environment after running a test. | ||
*/ | ||
protected function tearDown() | ||
{ | ||
$this->tgLog = null; | ||
parent::tearDown(); | ||
} | ||
|
||
public function testSendInvoice() | ||
{ | ||
$sendInvoice = new SendInvoice(); | ||
$sendInvoice->chat_id = 12341234; | ||
$sendInvoice->title = 'My Special Invoice'; | ||
$sendInvoice->description = 'This is the description of the invoice'; | ||
$sendInvoice->payload = 'specialItem-001'; | ||
$sendInvoice->provider_token = 'TEST-TOKEN-TEST'; | ||
$sendInvoice->start_parameter = 'u4u-invoice-0001'; | ||
$sendInvoice->currency = 'EUR'; | ||
$sendInvoice->prices = [ new LabeledPrice(['amount' => 975, 'label' => 'That special item']) ]; | ||
|
||
/** @var Message $result */ | ||
$result = $this->tgLog->performApiRequest($sendInvoice); | ||
$this->assertInstanceOf(Message::class, $result); | ||
$this->assertInstanceOf(Invoice::class, $result->invoice); | ||
$this->assertSame(975, $result->invoice->total_amount); | ||
$this->assertSame('EUR', $result->invoice->currency); | ||
$this->assertSame('u4u-invoice-0001', $result->invoice->start_parameter); | ||
} | ||
} |