Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofix committed Jan 21, 2025
1 parent 0f2969f commit 53a7ca9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 71 deletions.
18 changes: 4 additions & 14 deletions docs/django-payments.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
# Integración de Django-Payments con Flow

Django-Payments es un sistema universal de manejo de pagos para Django. Este documento detalla los pasos para integrar Flow con Django-Payments utilizando la librería `pyflowcl`.
Django-Payments es un sistema universal de manejo de pagos para Django. Este documento detalla los pasos para integrar Flow con Django-Payments utilizando la librería `django-payments-chile`.

## Instalación

Existen dos métodos principales para instalar `django-payments-flow`:

### Usando Poetry

```shell
poetry add django-payments-flow
```

### Usando pip

```shell
pip install django-payments-flow
pip install django-payments-chile
```

## Configuración Básica
Expand All @@ -24,7 +14,7 @@ Configura el proveedor de Flow en tu archivo `settings.py`:

```python
PAYMENT_VARIANTS = {
"flow": ("django_payments_flow.FlowProvider", {
"flow": ("django_payments_chile.FlowProvider", {
"key": "ApiKey",
"secret": "ApiSecret",
"sandbox": True, # Usar True para pruebas, False para producción
Expand Down Expand Up @@ -60,4 +50,4 @@ payment = Payment.objects.create(

## Configuración Avanzada

Para opciones de configuración más avanzadas, consulta la [documentación oficial de django-payments-flow](https://mariofix.github.io/django-payments-flow/uso/#variables-de-configuracion).
Para opciones de configuración más avanzadas, consulta la [documentación oficial de django-payments-chile](https://mariofix.github.io/django-payments-chile).
10 changes: 0 additions & 10 deletions docs/merchants.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ Merchants es un sistema universal de manejo de pagos para Starlette/FastAPI. Est

## Instalación

Existen dos métodos principales para instalar `merchants`:

### Usando Poetry

```shell
poetry add merchants
```

### Usando pip

```shell
pip install merchants
```
Expand Down
75 changes: 28 additions & 47 deletions tests/test_apiclient.py
Original file line number Diff line number Diff line change
@@ -1,116 +1,97 @@
import pytest
from unittest.mock import patch, Mock
import hashlib
import hmac
from pyflowcl.Clients import ApiClient
from unittest.mock import Mock, patch

import pytest
import requests

from pyflowcl.Clients import ApiClient


@pytest.fixture
def api_client():
return ApiClient(
api_key="test_key",
api_secret="test_secret"
)
return ApiClient(api_key="test_key", api_secret="test_secret")


@pytest.fixture
def mock_response():
mock = Mock()
mock.json.return_value = {"status": "success"}
return mock


def test_init_default_values():
client = ApiClient()
assert client.api_url == "https://www.flow.cl/api"
assert client.api_key is None
assert client.api_secret is None


def test_init_custom_values():
client = ApiClient(
api_url="https://custom.api.url",
api_key="custom_key",
api_secret="custom_secret"
)
client = ApiClient(api_url="https://custom.api.url", api_key="custom_key", api_secret="custom_secret")
assert client.api_url == "https://custom.api.url"
assert client.api_key == "custom_key"
assert client.api_secret == "custom_secret"


def test_make_signature(api_client):
params = {
"apiKey": "test_key",
"amount": 1000,
"subject": "Test Payment",
"empty": None
}
params = {"apiKey": "test_key", "amount": 1000, "subject": "Test Payment", "empty": None}

# Calculate expected signature manually
string = "apiKeytest_keyamount1000subjectTest Payment"
expected_signature = hmac.new(
"test_secret".encode(),
string.encode(),
hashlib.sha256
).hexdigest()
expected_signature = hmac.new(b"test_secret", string.encode(), hashlib.sha256).hexdigest()

assert api_client.make_signature(params) == expected_signature


def test_make_signature_empty_params(api_client):
params = {}
expected_signature = hmac.new(
"test_secret".encode(),
"".encode(),
hashlib.sha256
).hexdigest()
expected_signature = hmac.new(b"test_secret", b"", hashlib.sha256).hexdigest()

assert api_client.make_signature(params) == expected_signature

@patch('requests.get')

@patch("requests.get")
def test_get_request(mock_get, api_client, mock_response):
mock_get.return_value = mock_response
url = "https://api.example.com/endpoint"
query_params = {"param1": "value1", "param2": "value2"}

response = api_client.get(url, query_params)

mock_get.assert_called_once_with(
url,
params=query_params,
timeout=5
)
mock_get.assert_called_once_with(url, params=query_params, timeout=5)
assert response == mock_response

@patch('requests.post')

@patch("requests.post")
def test_post_request(mock_post, api_client, mock_response):
mock_post.return_value = mock_response
url = "https://api.example.com/endpoint"
post_data = {"field1": "value1", "field2": "value2"}

response = api_client.post(url, post_data)

mock_post.assert_called_once_with(
url,
data=post_data,
timeout=5
)
mock_post.assert_called_once_with(url, data=post_data, timeout=5)
assert response == mock_response


def test_make_signature_with_special_chars(api_client):
params = {
"apiKey": "test_key",
"subject": "Test & Payment",
"description": "Payment for item #123"
}
params = {"apiKey": "test_key", "subject": "Test & Payment", "description": "Payment for item #123"}

# The signature should handle special characters correctly
signature = api_client.make_signature(params)
assert len(signature) == 64 # SHA256 produces 64 character hex string

@patch('requests.get')

@patch("requests.get")
def test_get_request_timeout(mock_get, api_client):
mock_get.side_effect = requests.Timeout()

with pytest.raises(requests.Timeout):
api_client.get("https://api.example.com/endpoint", {})

@patch('requests.post')

@patch("requests.post")
def test_post_request_timeout(mock_post, api_client):
mock_post.side_effect = requests.Timeout()

Expand Down

0 comments on commit 53a7ca9

Please sign in to comment.