[feat] Add stripe payments (#3184)
This commit is contained in:
parent
5c9511ccfe
commit
695e9b6471
51 changed files with 2014 additions and 175 deletions
|
|
@ -8,10 +8,12 @@ from pytest_mock.plugin import MockerFixture
|
|||
from lnbits import bolt11
|
||||
from lnbits.core.models import CreateInvoice, Payment
|
||||
from lnbits.core.views.payment_api import api_payment
|
||||
from lnbits.fiat.base import FiatInvoiceResponse
|
||||
from lnbits.settings import Settings
|
||||
|
||||
from ..helpers import (
|
||||
get_random_invoice_data,
|
||||
get_random_string,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -155,6 +157,60 @@ async def test_create_invoice_fiat_amount(client, inkey_headers_to):
|
|||
assert extra["fiat_rate"]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_create_fiat_invoice(
|
||||
client, inkey_headers_to, settings: Settings, mocker: MockerFixture
|
||||
):
|
||||
data = await get_random_invoice_data()
|
||||
data["unit"] = "EUR"
|
||||
data["fiat_provider"] = "stripe"
|
||||
|
||||
settings.stripe_enabled = True
|
||||
settings.stripe_api_secret_key = "mock_sk_test_4eC39HqLyjWDarjtT1zdp7dc"
|
||||
|
||||
fiat_payment_request = "https://stripe.com/pay/session_123"
|
||||
fiat_mock_response = FiatInvoiceResponse(
|
||||
ok=True,
|
||||
checking_id=f"session_123_{get_random_string(10)}",
|
||||
payment_request=fiat_payment_request,
|
||||
)
|
||||
|
||||
mocker.patch(
|
||||
"lnbits.fiat.StripeWallet.create_invoice",
|
||||
AsyncMock(return_value=fiat_mock_response),
|
||||
)
|
||||
mocker.patch(
|
||||
"lnbits.utils.exchange_rates.get_fiat_rate_satoshis",
|
||||
AsyncMock(return_value=1000), # 1 BTC = 100 000 EUR, so 1 EUR = 1000 sats
|
||||
)
|
||||
response = await client.post(
|
||||
"/api/v1/payments", json=data, headers=inkey_headers_to
|
||||
)
|
||||
assert response.status_code == 201
|
||||
invoice = response.json()
|
||||
decode = bolt11.decode(invoice["bolt11"])
|
||||
assert decode.amount_msat == 10_000_000
|
||||
assert decode.payment_hash
|
||||
assert invoice["fiat_provider"] == "stripe"
|
||||
assert invoice["status"] == "pending"
|
||||
assert invoice["extra"]["fiat_checking_id"]
|
||||
assert invoice["extra"]["fiat_payment_request"] == fiat_payment_request
|
||||
|
||||
response = await client.get(
|
||||
f"/api/v1/payments/{decode.payment_hash}", headers=inkey_headers_to
|
||||
)
|
||||
assert response.is_success
|
||||
data = response.json()
|
||||
assert data["status"] == "pending"
|
||||
invoice = data["details"]
|
||||
|
||||
assert invoice["fiat_provider"] == "stripe"
|
||||
assert invoice["status"] == "pending"
|
||||
assert invoice["amount"] == 10_000_000
|
||||
assert invoice["extra"]["fiat_checking_id"]
|
||||
assert invoice["extra"]["fiat_payment_request"] == fiat_payment_request
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.parametrize("currency", ("msat", "RRR"))
|
||||
async def test_create_invoice_validates_used_currency(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue