wagtail-longclaw/longclaw/longclawcheckout/gateways/base.py

33 wiersze
1.1 KiB
Python
Czysty Zwykły widok Historia

2017-02-17 09:03:21 +00:00
from longclaw.longclawcheckout.utils import PaymentError
2017-02-06 08:04:04 +00:00
class BasePayment():
'''
Provides the interface for payment backends and
can function as a dummy backend for testing.
'''
2017-03-12 18:05:00 +00:00
def create_payment(self, request, amount, description=''):
2017-02-06 08:04:04 +00:00
'''
Dummy function for creating a payment through a payment gateway.
Should be overridden in gateway implementations.
Can be used for testing - to simulate a failed payment/error,
pass `error: true` in the request data.
'''
err = request.data.get("error", False)
if err:
raise PaymentError("Dummy error requested")
2017-03-11 21:55:58 +00:00
return 'fake_transaction_id'
2017-02-06 08:04:04 +00:00
def get_token(self, request):
'''
Dummy function for generating a client token through
a payment gateway. Most (all?) gateways have a flow which
involves requesting a token from the server (usually to
tokenize the payment method) and then passing that token
to another api endpoint to create the payment.
This function should be overriden in child classes
'''
return 'dummy_token'