def test_key_from_keydata():
    key = PayProc.key_from_keydata(PRIV_KEY_DATA)
    assert PRIV_KEY_DATA == key.private_bytes(
        encoding=serialization.Encoding.PEM,
        format=serialization.PrivateFormat.TraditionalOpenSSL,
        encryption_algorithm=serialization.NoEncryption(),
    )
def payproc():
    # noinspection PyUnusedLocal
    def get_destinations(device, merchant_order: MerchantOrderRequestMessage):
        if merchant_order.crypto_currency:
            destination = next(
                x for x in DESTINATIONS
                if x.crypto_currency == merchant_order.crypto_currency)
            return [destination]
        else:
            return DESTINATIONS

    pp = PayProc(KEY_FILENAME, cert_file=CERTIFICATE_FILENAME)
    pp.get_merchant = lambda x: MERCHANT

    pp.get_destinations = get_destinations
    pp.get_supported_cryptos = lambda device, payment_request: {
        "btc", "xmr", "nano"
    }
    return pp
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()
def test_sign():
    pp = PayProc(KEY_FILENAME)
    print(pp.sign(b"Hello"))
    assert HELLO_SIGNED == pp.sign(b"Hello")
Example #5
0
MERCHANT = Merchant(name="Merchant 1", address="5th Avenue")


def get_destinations(application_id,
                     merchant_order: MerchantOrderRequestMessage):
    if merchant_order.crypto_currency:
        destination = next(
            x for x in DESTINATIONS
            if x.crypto_currency == merchant_order.crypto_currency)
        return [destination]
    else:
        return DESTINATIONS


pp = PayProc(KEYFILE)
pp.get_merchant = lambda x: MERCHANT
pp.get_destinations = get_destinations
pp.get_supported_cryptos = lambda device, payment_request: {
    'btc', 'xmr', 'nano'
}

routes = web.RouteTableDef()


@routes.post("/confirm")
async def merchant_order(request: web.Request):
    try:
        logger.info("Got confirm request")
        json = await request.json()
        pp.confirm(json['session_id'])