diff --git a/src/Infrastructure/Repository/InvoiceRepo.php b/src/Infrastructure/Repository/InvoiceRepo.php index 82b7578..494b7c5 100644 --- a/src/Infrastructure/Repository/InvoiceRepo.php +++ b/src/Infrastructure/Repository/InvoiceRepo.php @@ -11,7 +11,9 @@ declare(strict_types=1); namespace Singularity\HDK\Pay\Infrastructure\Repository; +use GuzzleHttp\Exception\GuzzleException; use Hyperf\Codec\Json; +use Singularity\HDK\Core\Exceptions\ValidateException; use Singularity\HDK\Pay\Application\Command\CreateInvoiceCmd; use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\Address; use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\Invoice; @@ -54,4 +56,17 @@ final class InvoiceRepo extends AbstractRepo implements InvoiceRepoInterface 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"); + } } \ No newline at end of file diff --git a/tests/Feature/Invoice/CreateInvoiceTest.php b/tests/Feature/Invoice/CreateInvoiceTest.php index ceeb58a..424ab26 100644 --- a/tests/Feature/Invoice/CreateInvoiceTest.php +++ b/tests/Feature/Invoice/CreateInvoiceTest.php @@ -34,3 +34,14 @@ it('should can create invoice', function () { expect($invoice) ->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); +});