Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split to Mirspay and Custom namespaces #13

Merged
merged 6 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,37 @@ The request will contain json data like this:
}
}
```

## How to debug payment gateway callbacks

In order to debug payment gateway callback responses, [expose](https://expose.dev/) tool can be used to create a tunnel
to your local development environment.
If you use docker, start `expose` with the following command:
```shell
expose share http://localhost
```

You will see external _Public HTTP_ and _Public HTTPS_ urls in output.
Use one of those urls and send Create Order request like this:
```
curl --location 'https://okdfskdfj126722jsnxz.sharedwithexpose.com/api/v1/order' \
--header 'Content-Type: application/json' \
--data '{
"order_num": "00001",
"payment_gateway": "liqpay",
"description": "Order #001",
"return_url": "https://super-site.com/thank-you",
"products": [
{
"sku": "A01001",
"price": 1900,
"qty": 1,
"name": "Beer"
}
]
}'
```
Make sure `status_check` in the response has an external url,
that means your host is shared and the payment gateway will send a callback via the external url.

If you still have localhost, check `trusted_proxies` settings in `config/packages/framework.yaml`.
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env php
<?php

use App\Kernel;
use Mirspay\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;

if (!is_dir(dirname(__DIR__).'/vendor')) {
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@
},
"autoload": {
"psr-4": {
"App\\": "src/"
"Mirspay\\": "src/Mirspay",
"Custom\\": "src/Custom"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
"Mirspay\\Tests\\": "tests/"
}
},
"replace": {
Expand Down
6 changes: 3 additions & 3 deletions config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ doctrine:
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
Mirspay:
type: attribute
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
dir: '%kernel.project_dir%/src/Mirspay/Entity'
prefix: 'Mirspay\Entity'
alias: App

when@test:
Expand Down
4 changes: 2 additions & 2 deletions config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ framework:
php_errors:
log: true

# expose.dev
trusted_proxies: '127.0.0.1'
# expose.dev (local and docker)
trusted_proxies: '127.0.0.0/8,172.16.0.0/12'
trusted_headers: [ 'x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', 'x-forwarded-port', 'x-forwarded-prefix' ]

when@test:
Expand Down
5 changes: 5 additions & 0 deletions config/packages/maker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# config/packages/maker.yaml

when@dev:
maker:
root_namespace: 'Mirspay'
2 changes: 1 addition & 1 deletion config/packages/messenger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ framework:

routing:
# Route your messages to the transports
App\Message\NotifySubscriber: async
Mirspay\Message\NotifySubscriber: async

when@test:
framework:
Expand Down
4 changes: 2 additions & 2 deletions config/routes.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
controllers:
resource:
path: ../src/Controller/
namespace: App\Controller
path: ../src/Mirspay/Controller/
namespace: Mirspay\Controller
type: attribute
24 changes: 13 additions & 11 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,36 @@ services:

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/'
Mirspay\:
resource: '../src/Mirspay'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
- '../src/Mirspay/DependencyInjection/'
- '../src/Mirspay/Entity/'
- '../src/Mirspay/Kernel.php'
Custom\:
resource: '../src/Custom'

# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
App\Payment\LiqPay\Gateway:
Mirspay\Payment\LiqPay\Gateway:
arguments:
$publicKey: '%env(LIQPAY_PUBLIC_KEY)%'
$privateKey: '%env(LIQPAY_PRIVATE_KEY)%'
$serverCallbackHandler: '@App\Payment\LiqPay\ServerCallbackHandler'
$serverCallbackHandler: '@Mirspay\Payment\LiqPay\ServerCallbackHandler'
tags: ['app.payment.gateway']

App\Payment\LiqPay\Signature:
Mirspay\Payment\LiqPay\Signature:
arguments:
$privateKey: '%env(LIQPAY_PRIVATE_KEY)%'

App\Order\OrderTotalAmountCalculator:
Mirspay\Order\OrderTotalAmountCalculator:
arguments:
$currencyCode: 'UAH'

App\Subscriber\Channel\HttpNotificationChannel:
Mirspay\Subscriber\Channel\HttpNotificationChannel:
tags:
- { name: 'app.subscriber.channel', type: 'http' }

App\Subscriber\Channel\SimpleArrayChannelMessage:
Mirspay\Subscriber\Channel\SimpleArrayChannelMessage:
tags:
- { name: 'app.subscriber.message', type: 'simple' }
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="9.6" />
<server name="KERNEL_CLASS" value="Mirspay\Kernel" />
</php>

<testsuites>
Expand Down
2 changes: 1 addition & 1 deletion public/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use App\Kernel;
use Mirspay\Kernel;

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions src/Custom/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Put your custom functionality here...

Use `Custom` namespace to add new payment gateways, API, etc.

For example:

`./src/Custom/Payment/MyCustomGateway.php`:

```php
namespace Custom\Payment;

use Mirspay\Payment\Common\AbstractGateway;

final class MyCustomGateway extends AbstractGateway
{
// implementation of your custom payment gateway
}
```

Don't forget to tag your custom payment gateway with `app.payment.gateway`.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace App\Command;
namespace Mirspay\Command;

use App\Payment\Common\GatewayInterface;
use App\Payment\Common\PaymentGatewayRegistryInterface;
use Mirspay\Payment\Common\GatewayInterface;
use Mirspay\Payment\Common\PaymentGatewayRegistryInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace App\Command;
namespace Mirspay\Command;

use App\Entity\OrderStatus;
use App\Subscriber\Action\AddHttpSubscriberAction;
use App\Subscriber\Channel\HttpNotificationChannel;
use Exception;
use Mirspay\Entity\OrderStatus;
use Mirspay\Subscriber\Action\AddHttpSubscriberAction;
use Mirspay\Subscriber\Channel\HttpNotificationChannel;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace App\Command;
namespace Mirspay\Command;

use App\Subscriber\Channel\NotificationChannelCollection;
use Mirspay\Subscriber\Channel\NotificationChannelCollection;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace App\Command;
namespace Mirspay\Command;

use App\Entity\OrderStatus;
use App\Repository\SubscriberRepository;
use Exception;
use Mirspay\Entity\OrderStatus;
use Mirspay\Repository\SubscriberRepository;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace App\Command;
namespace Mirspay\Command;

use App\Entity\Subscriber;
use App\Repository\SubscriberRepository;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Mirspay\Entity\Subscriber;
use Mirspay\Repository\SubscriberRepository;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

declare(strict_types=1);

namespace App\Controller\Api\V1;

use App\Dto\OrderDto;
use App\Entity\Order;
use App\Entity\OrderProduct;
use App\Entity\OrderStatus;
use App\Event\OrderWasCreated;
use App\Order\OrderTotalAmountCalculator;
use App\Order\Workflow\OrderWorkflowFactory;
use App\Payment\Common\Exception\PaymentGatewayIsNotRegisteredException;
use App\Payment\Common\PaymentGatewayRegistryInterface;
use App\Repository\OrderRepository;
namespace Mirspay\Controller\Api\V1;

use Doctrine\ORM\EntityManagerInterface;
use Mirspay\Dto\OrderDto;
use Mirspay\Entity\Order;
use Mirspay\Entity\OrderProduct;
use Mirspay\Entity\OrderStatus;
use Mirspay\Event\OrderWasCreated;
use Mirspay\Order\OrderTotalAmountCalculator;
use Mirspay\Order\Workflow\OrderWorkflowFactory;
use Mirspay\Payment\Common\Exception\PaymentGatewayIsNotRegisteredException;
use Mirspay\Payment\Common\PaymentGatewayRegistryInterface;
use Mirspay\Repository\OrderRepository;
use OpenApi\Attributes as OA;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

declare(strict_types=1);

namespace App\Controller\Api\V1;

use App\Dto\PaymentGatewayDto;
use App\Dto\PaymentStatusDto;
use App\Entity\Order;
use App\Entity\OrderStatus;
use App\Event\AfterPaymentCallbackHandlerEvent;
use App\Event\BeforePaymentCallbackHandlerEvent;
use App\Event\PaymentStatusEvent;
use App\Order\Workflow\OrderWorkflowFactory;
use App\Payment\Common\GatewayInterface;
use App\Payment\Common\PaymentGatewayRegistryInterface;
namespace Mirspay\Controller\Api\V1;

use Mirspay\Dto\PaymentGatewayDto;
use Mirspay\Dto\PaymentStatusDto;
use Mirspay\Entity\Order;
use Mirspay\Entity\OrderStatus;
use Mirspay\Event\AfterPaymentCallbackHandlerEvent;
use Mirspay\Event\BeforePaymentCallbackHandlerEvent;
use Mirspay\Event\PaymentStatusEvent;
use Mirspay\Order\Workflow\OrderWorkflowFactory;
use Mirspay\Payment\Common\GatewayInterface;
use Mirspay\Payment\Common\PaymentGatewayRegistryInterface;
use Nelmio\ApiDocBundle\Annotation\Model;
use OpenApi\Attributes as OA;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

declare(strict_types=1);

namespace App\DataFixtures;
namespace Mirspay\DataFixtures;

use App\Dto\OrderDto;
use App\Dto\ProductDto;
use App\Entity\Order;
use App\Order\OrderTotalAmountCalculator;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Mirspay\Dto\OrderDto;
use Mirspay\Dto\ProductDto;
use Mirspay\Entity\Order;
use Mirspay\Order\OrderTotalAmountCalculator;

final class OrderFixture extends Fixture
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace App\DataFixtures;
namespace Mirspay\DataFixtures;

use App\Entity\OrderStatus;
use App\Entity\Subscriber;
use App\Subscriber\Action\AddHttpSubscriberAction;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Mirspay\Entity\OrderStatus;
use Mirspay\Entity\Subscriber;
use Mirspay\Subscriber\Action\AddHttpSubscriberAction;

class SubscriberFixture extends Fixture
{
Expand Down
2 changes: 1 addition & 1 deletion src/Dto/OrderDto.php → src/Mirspay/Dto/OrderDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Dto;
namespace Mirspay\Dto;

use OpenApi\Attributes as OA;
use Symfony\Component\Serializer\Attribute\SerializedName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace App\Dto;
namespace Mirspay\Dto;

use App\Payment\Common\GatewayInterface;
use Symfony\Component\Serializer\Attribute\SerializedName;
use Mirspay\Payment\Common\GatewayInterface;
use OpenApi\Attributes as OA;
use Symfony\Component\Serializer\Attribute\SerializedName;

#[OA\Schema(
description: 'Payment Gateway object.'
Expand Down
Loading
Loading