manta.payproc.PayProc

This class can be used to create a Manta Payment Processor.

An example using the class is the manta.testing.payproc module.

Here is an example of the initialization of the PayProc class:

1
2
3
4
 pp = PayProc(KEYFILE, host="localhost")
 pp.get_merchant = lambda x: MERCHANT
 pp.get_destinations = get_destinations
 pp.get_supported_cryptos = lambda device, payment_request: {'btc', 'xmr', 'nano'}

The lines from 2 to 4 define the callbacks you need to implement.

The class will callback to request information about which Merchant information to provide, which is the destination address, which supported crypto currencies.

For example this is how get_destinations can be defined:

DESTINATIONS = [
    Destination(
        amount=Decimal("0.01"),
        destination_address="xrb_3d1ab61eswzsgx5arwqc3gw8xjcsxd7a5egtr69jixa5it9yu9fzct9nyjyx",
        crypto_currency="NANO"
    ),
]

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

Finally you need to start the MQTT processing loop which is started in another thread. To activate it just execute:

pp.run()

Reference

class manta.payproc.PayProc(key_file, cert_file=None, host='localhost', starting_txid=0, tx_storage=None, mqtt_options=None, port=1883)[source]

Manta Protocol Payment Processor Implementation

Parameters:
  • key_file (str) – File name of PEM private key of Payment Processor. This will be used to sign messages
  • certificate – File name of Manta Certificate Authority, IE mantaproto
  • host (str) – MQTT Broker host
  • starting_txid (int) – Transaction ID are progressive, starting from the one specified
  • tx_storage (Optional[TXStorage]) – TXStorage instance to store session information
  • mqtt_options (Optional[Dict[str, Any]]) – A Dict of options to be passed to MQTT Client (like username, password)
  • port (int) – MQTT Broker port number. Specified only if it’s different than the default of 1883
Attributes:
  • get_destinations – Callback function to retrieve list of Destination
  • get_supported_cryptos – Callback function to retrieve list of supported cryptos
ack(session_id, ack)[source]

Publish the given AckMessage.

Parameters:session_id (str) – id of the session where to send the messages
confirm(session_id, transaction_hash=None, transaction_currency=None)[source]

Change the status of the session with the given session_id to PAID and publish the AckMessage.

Parameters:session_id (str) – session to change
confirming(session_id)[source]

Change the status of the session with the given session_id to CONFIRMING and publish the AckMessage.

Parameters:session_id (str) – session to change
generate_payment_request(device, merchant_request)[source]

Create a PaymentRequestEnvelope containing the payment informations.

Parameters:
Return type:

PaymentRequestEnvelope

Returns:

an envelope containing a PaymentRequestMessage

invalidate(session_id, reason='')[source]

Change the status of the session with the given session_id to INVALID and publish the AckMessage.

Parameters:
  • session_id (str) – session to change
  • reason (str) – reason for INVALID status (ex. ‘Timeout’)
static key_from_keydata(key_data)[source]

Given a string containing the key encoded in PEM format, loads it.

Parameters:key_data (bytes) – string containing the key in PEM format
Return type:RSAPrivateKey
Returns:a ready key object
run()[source]

Start processing network requests. This starts the MQTT client processing loop in another thread.

sign(message)[source]

Sign the given string with the cryptographic key specified at creation time.

Parameters:message (bytes) – string to sign
Return type:bytes
Returns:signature text