feat(invoice): 添加发票发送功能并进行测试

- 在 InvoiceRepo 中添加 send 方法,用于发送发票邮件
- 在 CreateInvoiceTest 中添加测试用例,验证发票发送功能
This commit is contained in:
李东云
2025-09-04 15:06:23 +08:00
parent 2a40b3b219
commit 72f7d37382
2 changed files with 26 additions and 0 deletions

View File

@@ -11,7 +11,9 @@ declare(strict_types=1);
namespace Singularity\HDK\Pay\Infrastructure\Repository; namespace Singularity\HDK\Pay\Infrastructure\Repository;
use GuzzleHttp\Exception\GuzzleException;
use Hyperf\Codec\Json; use Hyperf\Codec\Json;
use Singularity\HDK\Core\Exceptions\ValidateException;
use Singularity\HDK\Pay\Application\Command\CreateInvoiceCmd; use Singularity\HDK\Pay\Application\Command\CreateInvoiceCmd;
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\Address; use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\Address;
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\Invoice; use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\Invoice;
@@ -54,4 +56,17 @@ final class InvoiceRepo extends AbstractRepo implements InvoiceRepoInterface
receiver: $result['receiver'], receiver: $result['receiver'],
); );
} }
/**
* @param string $invoiceNo
* @return void
* @throws GuzzleException
*/
public function send(string $invoiceNo): void
{
if (empty($invoiceNo)) {
throw new ValidateException(message: 'invoice no is required.');
}
$this->requestService->requestGet(url: "/rpc/v2/invoice/invoices/$invoiceNo/email");
}
} }

View File

@@ -34,3 +34,14 @@ it('should can create invoice', function () {
expect($invoice) expect($invoice)
->toBeInstanceOf(Invoice::class); ->toBeInstanceOf(Invoice::class);
}); });
it('should can send invoice email to receiver', function () {
$repo = make(InvoiceRepo::class);
expect((function () use ($repo) {
$invoice_no = '517268';
$repo->send($invoice_no);
return true;
})())->not->toThrow(Throwable::class);
});