def __init__(self, model): self.URL = model.endpoint self.USERNAME = model.merchant self.PASSWORD = model.password self.SUCCESS_CALLBACK = model.success_callback self.ERROR_CALLBACK = model.error_callback self.PENDING_CALLBACK = model.pending_callback self.MONEY = 100 self.CURRENCY = 'EUR' self.order = compute_uuid() self.gw = model self.gateways_manager = PaymentGatewayManager() self.payment_method_process = PaymentMethodProcess()
class PaymentMethodManager: payment_method_process = PaymentMethodProcess() def get_payment_methods(self, account, status): return PaymentMethod.objects.filter(account=account, status=status) def get_payment_methods_by_order_code(self, order_code, status): return PaymentMethod.objects.get(recurrent_order_code=order_code, status=status) def get_valid_payment_methods(self, account): return PaymentMethod.objects.filter(account=account, status='VALIDATED') def get_valid_payment_method(self, pm_id, account): try: return PaymentMethod.objects.get(id=pm_id, account=account, status='VALIDATED') except PaymentMethod.DoesNotExist: return None def store_payment_method(self, account, recurrent_order_code, gateway): # Creating PaymentMethod payment_method = PaymentMethod( account=account, recurrent_order_code=recurrent_order_code, gateway=gateway) payment_method.save() return payment_method def start_new_payment_method_notification_process(self, payment_method, fn): fn = self.payment_method_process._start_standalone_new_payment_method_process # Async. Starting notification process self.payment_method_process.start_new_payment_method_notification_process( payment_method, fn)
class PaymentGateway(object): def __init__(self, model): self.URL = model.endpoint self.USERNAME = model.merchant self.PASSWORD = model.password self.SUCCESS_CALLBACK = model.success_callback self.ERROR_CALLBACK = model.error_callback self.PENDING_CALLBACK = model.pending_callback self.MONEY = 100 self.CURRENCY = 'EUR' self.order = compute_uuid() self.gw = model self.gateways_manager = PaymentGatewayManager() self.payment_method_process = PaymentMethodProcess() def get_order(self): return self.order def get_gateway(self): return self.gw ########################################################### # Common data flows ########################################################### def identify_successful_flow(self, order_code, mask, month, year, status): try: payment_method = PaymentMethod.objects.get( recurrent_order_code=order_code, status='PENDING') except PaymentMethod.DoesNotExist: payment_method = None # Distinguising flows if payment_method: return self._data_acquisition_flow(payment_method, mask, month, year, status) # Callback of recurrent payment flow try: order = Order.objects.get(order_code=order_code, status='PENDING') except Order.DoesNotExist: order = None if order: return self._recurrent_payment_flow(order, status) # Neither data acquistion flow nor recurrent payment flow, this is an error! print "ERROR: NEITHER ACQUISITION NOR RECURRENT FLOW IN ADYEN CALLBACK" return False def _data_acquisition_flow(self, payment_method, mask, month, year, status): # Callback of payment data acquisition flow print "DATA ACQUISITION FLOW" print status payment_method.mask = mask payment_method.month = month payment_method.year = year payment_method.status = status payment_method.save() fn = self.payment_method_process._start_standalone_new_payment_method_process # Start Async notify process self.payment_method_process.start_new_payment_method_notification_process( payment_method, fn) def _recurrent_payment_flow(self, order, status): # Callback of recuerrent payment flow print "RECURRENT ORDER FLOW" order.status = status order.save() ########################################################### # Should be overwritten by specific implementations of Payment Gateways ########################################################### # account: customers.models.BillingAddress def get_redirect_url(self, billing_address): pass # order: customers.models.Order # payment_method: payment_gateways.models.PaymentMethod def recurrent_payment(self, order, payment_method): pass # data: dict. Data from the callback from the Payment Gateway def update_order_status(self, data): pass
class PaymentGateway(object): def __init__(self, model): self.URL = model.endpoint self.USERNAME = model.merchant self.PASSWORD = model.password self.SUCCESS_CALLBACK = model.success_callback self.ERROR_CALLBACK = model.error_callback self.PENDING_CALLBACK = model.pending_callback self.MONEY = 100 self.CURRENCY = 'EUR' self.order = compute_uuid() self.gw = model self.gateways_manager = PaymentGatewayManager() self.payment_method_process = PaymentMethodProcess() def get_order(self): return self.order def get_gateway(self): return self.gw ########################################################### # Common data flows ########################################################### def identify_successful_flow(self, order_code, mask, month, year, status): try: payment_method = PaymentMethod.objects.get(recurrent_order_code=order_code, status='PENDING') except PaymentMethod.DoesNotExist: payment_method = None # Distinguising flows if payment_method: return self._data_acquisition_flow(payment_method, mask, month, year, status) # Callback of recurrent payment flow try: order = Order.objects.get(order_code=order_code, status='PENDING') except Order.DoesNotExist: order = None if order: return self._recurrent_payment_flow(order, status) # Neither data acquistion flow nor recurrent payment flow, this is an error! print "ERROR: NEITHER ACQUISITION NOR RECURRENT FLOW IN ADYEN CALLBACK" return False def _data_acquisition_flow(self, payment_method, mask, month, year, status): # Callback of payment data acquisition flow print "DATA ACQUISITION FLOW" print status payment_method.mask = mask payment_method.month = month payment_method.year = year payment_method.status = status payment_method.save() fn = self.payment_method_process._start_standalone_new_payment_method_process # Start Async notify process self.payment_method_process.start_new_payment_method_notification_process(payment_method, fn) def _recurrent_payment_flow(self, order, status): # Callback of recuerrent payment flow print "RECURRENT ORDER FLOW" order.status = status order.save() ########################################################### # Should be overwritten by specific implementations of Payment Gateways ########################################################### # account: customers.models.BillingAddress def get_redirect_url(self, billing_address): pass # order: customers.models.Order # payment_method: payment_gateways.models.PaymentMethod def recurrent_payment(self, order, payment_method): pass # data: dict. Data from the callback from the Payment Gateway def update_order_status(self, data): pass
def __init__(self): self.payment_method_process = PaymentMethodProcess() self.customer_manager = CustomerManager() self.payment_method_manager = PaymentMethodManager()