This document outlines the payment gateway system implementation in the Sjoppie API.
The payment gateway system is designed to be modular and extensible, allowing for easy integration of multiple payment providers. The system currently supports Mollie as a payment gateway, with the architecture in place to add more providers in the future.
app/
├── Modules/
│ └── PaymentGateways/
│ ├── Contracts/
│ │ └── PaymentGatewayInterface.php
│ ├── AbstractPaymentGateway.php
│ └── Mollie/
│ └── MolliePaymentGateway.php
├── Models/
│ └── PaymentGateway.php
├── Services/
│ └── PaymentGatewayService.php
└── Http/
└── Controllers/
└── Api/
└── PaymentGatewayController.php
The payment_gateways table contains the following fields:
| Field | Type | Description |
|---|---|---|
| id | bigint | Primary key |
| name | string | Display name of the payment gateway |
| module_name | string | Name of the module implementing the gateway |
| is_active | boolean | Whether the gateway is active |
| is_test_mode | boolean | Whether the gateway is in test mode |
| configuration | json | Gateway-specific configuration |
| created_at | timestamp | Creation timestamp |
| updated_at | timestamp | Last update timestamp |
| deleted_at | timestamp | Soft delete timestamp |
GET /api/payment-gateways/modules
Returns a list of available payment gateway modules that can be configured.
Response:
[
{
"name": "Mollie",
"module_name": "Mollie",
"description": "Mollie Payment Gateway Integration",
"configuration": {
"test_api_key": {
"type": "string",
"required": true,
"label": "Test API Key",
"description": "Your Mollie test API key"
},
"live_api_key": {
"type": "string",
"required": true,
"label": "Live API Key",
"description": "Your Mollie live API key"
},
"customer_id": {
"type": "string",
"required": true,
"label": "Customer ID",
"description": "Your Mollie customer ID"
}
}
}
]GET /api/payment-gateways
Returns a list of all configured payment gateways.
Response:
[
{
"id": 1,
"name": "Mollie Gateway",
"module_name": "Mollie",
"is_active": true,
"is_test_mode": true,
"configuration": {
"test_api_key": "test_...",
"live_api_key": "live_...",
"customer_id": "cst_..."
},
"created_at": "2024-04-25T21:34:53.000000Z",
"updated_at": "2024-04-25T21:34:53.000000Z"
}
]POST /api/payment-gateways
Creates a new payment gateway configuration.
Request:
{
"name": "Mollie Gateway",
"module_name": "Mollie",
"is_active": true,
"is_test_mode": true,
"configuration": {
"test_api_key": "test_...",
"live_api_key": "live_...",
"customer_id": "cst_..."
}
}PUT /api/payment-gateways/{id}
Updates an existing payment gateway configuration.
Request:
{
"name": "Updated Mollie Gateway",
"is_active": false,
"is_test_mode": false,
"configuration": {
"test_api_key": "new_test_...",
"live_api_key": "new_live_...",
"customer_id": "new_cst_..."
}
}DELETE /api/payment-gateways/{id}
Deletes a payment gateway configuration.
To add a new payment gateway module:
- Create a new directory under
app/Modules/PaymentGateways/with the module name - Create a class that extends
AbstractPaymentGateway - Implement the required methods from
PaymentGatewayInterface
Example module structure:
namespace App\Modules\PaymentGateways\NewProvider;
use App\Modules\PaymentGateways\AbstractPaymentGateway;
class NewProviderPaymentGateway extends AbstractPaymentGateway
{
public function getName(): string
{
return 'New Provider';
}
public function getDescription(): string
{
return 'New Provider Payment Gateway Integration';
}
public function getRequiredConfiguration(): array
{
return [
'api_key' => [
'type' => 'string',
'required' => true,
'label' => 'API Key',
'description' => 'Your API key'
]
];
}
public function initialize(array $configuration): void
{
parent::initialize($configuration);
// Initialize the provider's client
}
}-
Configuration
- Always validate configuration before saving
- Use appropriate field types (string, boolean, etc.)
- Provide clear labels and descriptions
- Mark required fields appropriately
-
Security
- Never log sensitive configuration data
- Use environment variables for sensitive data
- Validate all input data
- Use proper encryption for sensitive data
-
Error Handling
- Implement proper error handling
- Provide clear error messages
- Log errors appropriately
- Handle API failures gracefully
-
Testing
- Test both test and live modes
- Mock external API calls
- Test error scenarios
- Validate configuration handling
-
Additional Features
- Payment method management
- Transaction history
- Webhook handling
- Refund processing
-
New Providers
- Stripe
- PayPal
- Adyen
- Custom providers
-
Improvements
- Better error handling
- More detailed logging
- Enhanced security measures
- Performance optimizations