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 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 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']) return web.json_response("ok")