-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from ThePay/v2.x-4729-merge-v1.x
V2.x 4729 merge v1.x
- Loading branch information
Showing
6 changed files
with
160 additions
and
0 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,29 @@ | ||
# Generating a confirmation PDF for paid payment | ||
|
||
If a merchant needs confirmation for someone that they received payment through our services. | ||
They can generate a confirmation PDF document for payment in ThePay administration. | ||
|
||
The generating confirmation can be also integrated into merchant application as describe example below. | ||
|
||
```php | ||
|
||
/** @var \ThePay\ApiClient\TheClient $thePayClient */ | ||
|
||
$payment = $thePayClient->getPayment('exampleUID'); | ||
// make detection if payment was really paid | ||
// and inform user that for not paid payment is confirmation unavailable, | ||
// because call method generatePaymentConfirmationPdf for unpaid payments will fail | ||
if($payment->wasPaid()) { | ||
|
||
// we recommend asking user for language of receiver who confirmation wants, so he can understand it, | ||
// if we not support given language, we return confirmation in english | ||
$confirmationLanguageCode = 'cs'; | ||
|
||
$confirmationPdfContent = $thePayClient->generatePaymentConfirmationPdf('exampleUID', $confirmationLanguageCode); | ||
|
||
header('Content-type:application/pdf'); | ||
|
||
echo $confirmationPdfContent; | ||
} | ||
|
||
``` |
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
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,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ThePay\ApiClient\Tests; | ||
|
||
use GuzzleHttp\Psr7\HttpFactory; | ||
use GuzzleHttp\Psr7\Response; | ||
use Psr\Http\Client\ClientInterface; | ||
use Psr\Http\Message\RequestInterface; | ||
use ThePay\ApiClient\Service\ApiService; | ||
use ThePay\ApiClient\Service\SignatureService; | ||
use ThePay\ApiClient\TheClient; | ||
|
||
final class GeneratePaymentConfirmationTest extends BaseTestCase | ||
{ | ||
public function testSuccess(): void | ||
{ | ||
$httpFactory = new HttpFactory(); | ||
|
||
$httpClient = $this->createMock(ClientInterface::class); | ||
$httpClient->expects(self::once())->method('sendRequest') | ||
->willReturnCallback(function (RequestInterface $request): Response { | ||
self::assertSame('GET', $request->getMethod()); | ||
self::assertSame( | ||
$this->config->getApiUrl() . 'projects/1/payments/testUID/generate_confirmation?language=cs&merchant_id=' . self::MERCHANT_ID, | ||
$request->getUri()->__toString() | ||
); | ||
|
||
return new Response(200, [], 'test pdf content'); | ||
}) | ||
; | ||
|
||
$theClient = new TheClient( | ||
$this->config, | ||
new ApiService( | ||
$this->config, | ||
$this->createMock(SignatureService::class), | ||
$httpClient, | ||
$httpFactory, | ||
$httpFactory | ||
) | ||
); | ||
|
||
$pdfContent = $theClient->generatePaymentConfirmationPdf('testUID', 'cs'); | ||
|
||
self::assertSame('test pdf content', $pdfContent); | ||
} | ||
|
||
public function testFailed(): void | ||
{ | ||
$httpFactory = new HttpFactory(); | ||
|
||
$httpClient = $this->createMock(ClientInterface::class); | ||
$httpClient->expects(self::once())->method('sendRequest') | ||
->willReturn(new Response(400)); | ||
|
||
$theClient = new TheClient( | ||
$this->config, | ||
new ApiService( | ||
$this->config, | ||
$this->createMock(SignatureService::class), | ||
$httpClient, | ||
$httpFactory, | ||
$httpFactory | ||
) | ||
); | ||
|
||
$this->expectException(\RuntimeException::class); | ||
|
||
$theClient->generatePaymentConfirmationPdf('testUID', 'cs'); | ||
} | ||
} |