This project is a PHP implementation for integrating with Tinkoff's payment gateway using a Domain-Driven Design (DDD) and SOLID principles. The package allows easy integration of Tinkoff's payment services into any PHP application.
- Create a payment (
InitPayment
) through the Tinkoff API.- Type-safe models using value objects for
Amount
,OrderId
, etc.- Mappers for converting API responses to corresponding entities.
- Abstract payment class to handle common payment attributes.
src/Domain: Contains the core domain entities and value objects.
- Entity: Contains abstract and concrete payment entities, such as
Payment
andInitPayment
.- Enum: Enumeration classes like
LanguageEnum
andPayTypeEnum
.- ValueObject: Value objects like
OrderId
andAmount
.src/Infrastructure: Contains infrastructure code for API communication.
- Mapper: Handles mapping between arrays and domain entities.
- TinkoffClient: Implements the communication with the Tinkoff API.
To install the package, navigate to your project directory and run:
composer require egorov/tinkoff-apiTo create a new payment, you need to create an instance of the
Order
entity and useTinkoffClient
to initiate the payment:require __DIR__ . '/../vendor/autoload.php'; use Egorov\TinkoffApi\Domain\Entity\Order; use Egorov\TinkoffApi\Domain\ValueObject\Amount; use Egorov\TinkoffApi\Domain\ValueObject\OrderId; use Egorov\TinkoffApi\Infrastructure\TinkoffClient; $orderId = new OrderId('12345'); $amount = new Amount(10000); $order = Order::build($orderId, $amount) ->withDescription('Payment for Order #12345'); $terminalKey = 'YourTerminalKey'; $password = 'YourPassword'; $tinkoffClient = new TinkoffClient($terminalKey, $password); $payment = $tinkoffClient->initiatePayment($order); if ($payment->isSuccess()) { echo "Payment successfully initiated. Payment URL: " . $payment->getPaymentUrl(); } else { echo "Failed to initiate payment. Error Code: " . $payment->getErrorCode(); }The API responses are mapped to specific payment entities like
InitPayment
. This allows for type-safe interaction with the data:use Egorov\TinkoffApi\Infrastructure\Mapper\InitPaymentMapper; $responseData = [ 'OrderId' => 'Order123', 'Amount' => 10000, 'Status' => 'NEW', 'TerminalKey' => 'TinkoffBankTest', 'PaymentURL' => 'https://securepayments.tinkoff.ru/dWCdXdBf', ]; $initPayment = InitPaymentMapper::fromArray($responseData); echo "Payment Status: " . $initPayment->getStatus() . "\n"; echo "Payment URL: " . $initPayment->getPaymentUrl() . "\n";
- Domain-Driven Design (DDD): The project follows DDD principles by clearly separating domain logic from infrastructure and application logic.
- SOLID Principles: Each class follows single responsibility and open/closed principles, making the codebase easier to extend and maintain.
Feel free to submit issues or pull requests if you encounter bugs or have suggestions for improvements.
This project is licensed under the MIT License.
-
Notifications
You must be signed in to change notification settings - Fork 0
maksimEgo/tinkoff-api
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published