Ejemplo n.º 1
0
def test_receive_merchant_order_request(mock_mqtt, payproc):
    request = MerchantOrderRequestMessage(
        amount=Decimal("1000"), session_id="1423", fiat_currency="eur",
    )

    expected = AckMessage(txid="0", url="manta://localhost/1423", status=Status.NEW)

    mock_mqtt.push("merchant_order_request/device1", request.to_json())

    mock_mqtt.publish.assert_any_call("acks/1423", JsonContains(expected))
    mock_mqtt.subscribe.assert_any_call("payments/1423")
    mock_mqtt.subscribe.assert_any_call("payment_requests/1423/+")
Ejemplo n.º 2
0
def test_receive_merchant_order_request_legacy(mock_mqtt, payproc):
    request = MerchantOrderRequestMessage(
        amount=Decimal("1000"),
        session_id="1423",
        fiat_currency="eur",
        crypto_currency="btc",
    )

    expected = AckMessage(txid="0",
                          url="bitcoin:btc_daddress?amount=5",
                          status=Status.NEW)

    mock_mqtt.push("merchant_order_request/device1", request.to_json())
    mock_mqtt.publish.assert_any_call("acks/1423", JsonContains(expected))
Ejemplo n.º 3
0
def test_receive_merchant_order_request_unkwnown_field(mock_mqtt, payproc):
    request = MerchantOrderRequestMessage(
        amount=Decimal("1000"), session_id="1423", fiat_currency="eur"
    )

    expected = AckMessage(txid="0", url="manta://localhost/1423", status=Status.NEW)

    request_json = request.unstructure()
    request_json["extra_field"] = "extra"

    mock_mqtt.push("merchant_order_request/device1", json.dumps(request_json))

    mock_mqtt.publish.assert_any_call("acks/1423", JsonContains(expected))
    mock_mqtt.subscribe.assert_any_call("payments/1423")
    mock_mqtt.subscribe.assert_any_call("payment_requests/1423/+")
Ejemplo n.º 4
0
def test_generate_payment_request():
    pp = PayProc(KEY_FILENAME, cert_file=CERTIFICATE_FILENAME)
    pp.get_merchant = lambda x: MERCHANT
    pp.get_destinations = lambda device, payment_request: [
        Destination(amount=Decimal(5),
                    destination_address="xrb123",
                    crypto_currency="NANO")
    ]
    pp.get_supported_cryptos = lambda device, payment_request: [
        "BTC", "XMR", "NANO"
    ]

    payment_request = MerchantOrderRequestMessage(
        amount=Decimal(10),
        fiat_currency="EURO",
        session_id="123",
        crypto_currency="NANO",
    )

    envelope = pp.generate_payment_request("device1", payment_request)

    expected_message = PaymentRequestMessage(
        merchant=MERCHANT,
        amount=Decimal(10),
        fiat_currency="EURO",
        destinations=[
            Destination(amount=Decimal(5),
                        destination_address="xrb123",
                        crypto_currency="NANO")
        ],
        supported_cryptos={"BTC", "XMR", "NANO"},
    )

    assert expected_message == envelope.unpack()
Ejemplo n.º 5
0
    def test_create(self, tx_storage: TXStorageMemory):
        ack = AckMessage(amount=Decimal("10"), status=Status.NEW, txid="0")
        order = MerchantOrderRequestMessage(amount=Decimal("10"),
                                            session_id="123",
                                            fiat_currency="EUR")

        tx_storage.create(0, "123", "app0@user0", order, ack)

        assert 1 == len(tx_storage)
Ejemplo n.º 6
0
def reply(topic, payload):
    order = MerchantOrderRequestMessage.from_json(payload)
    tokens = topic.split("/")
    device = tokens[1]

    r = AckMessage(txid="0",
                   status=Status.NEW,
                   url="manta://testpp.com/{}".format(order.session_id))

    return "acks/{}".format(device), r.to_json()
Ejemplo n.º 7
0
    def se(topic, payload):
        nonlocal mock_mqtt

        if topic == "merchant_order_request/device1":
            order = MerchantOrderRequestMessage.from_json(payload)
            reply = AckMessage(status=Status.NEW,
                               url="manta://testpp.com/{}".format(
                                   order.session_id),
                               txid="0")

            topic = "acks/{}".format(order.session_id)

            mock_mqtt.push(topic, reply.to_json())
Ejemplo n.º 8
0
    def test_ack_paid(self, tx_storage):
        self.test_create(tx_storage)
        ack = AckMessage(amount=Decimal("10"), status=Status.NEW, txid="1")
        order = MerchantOrderRequestMessage(amount=Decimal("10"),
                                            session_id="321",
                                            fiat_currency="EUR")

        tx_storage.create(1, "321", "app0@user0", order, ack)

        state = tx_storage.get_state_for_session("123")
        new_ack = attr.evolve(state.ack, status=Status.PAID)

        state.ack = new_ack

        assert 1 == len(tx_storage)
        assert Status.NEW == tx_storage.get_state_for_session("321").ack.status
Ejemplo n.º 9
0
def test_serialize():
    payload = '{"amount": 10, "session_id": "pXbNKx8YRJ2dsIjJIfEuQA==", "fiat_currency": "eur", "crypto_currency": null}'
    order = MerchantOrderRequestMessage.from_json(payload)