def computed_signature(self): """ Compute the signature on the fly """ from mock import Mock from systempay.facade import Facade from django.http import QueryDict request = Mock() request.POST = QueryDict(self.raw_request) facade = Facade() form = facade.get_return_form_populated_with_request(request) return facade.gateway.compute_signature(form)
class TestForm(TestCase): def setUp(self): self.order = self.create_mock_order() self.facade = Facade() def create_mock_order(self): order = Mock() order.number = '100313' order.total_incl_tax = D('15.24') order.lines = Mock() order.lines.all = Mock(return_value=[]) order.total_discount = D('0.00') order.get_discounts = Mock(return_value=[]) return order def create_submit_form_with_order(self, order): form = self.facade.get_submit_form_populated_with_order(self.order) form.data['vads_trans_id'] = '654321' form.data['vads_trans_date'] = '20090501193530' form.data['vads_payment_config'] = 'SINGLE' # override to have the same hash self.facade.gateway._site_id = "12345678" self.facade.gateway._certificate = "1122334455667788" # we sign AGAIN the form because the data has been changed self.facade.gateway.sign(form) return form def printable_form_errors(self, form): return u' / '.join([u"%s: %s" % (f.name, '. '.join(f.errors)) for f in form])
class TestForm(TestCase): def setUp(self): self.order = self.create_mock_order() self.facade = Facade() def create_mock_order(self): order = Mock() order.number = '100313' order.total_incl_tax = D('15.24') order.lines = Mock() order.lines.all = Mock(return_value=[]) order.total_discount = D('0.00') order.get_discounts = Mock(return_value=[]) return order def create_submit_form_with_order(self, order): form = self.facade.get_submit_form_populated_with_order(self.order) form.data['vads_trans_id'] = '654321' form.data['vads_trans_date'] = '20090501193530' form.data['vads_payment_config'] = 'SINGLE' # override to have the same hash self.facade.gateway._site_id = "12345678" self.facade.gateway._certificate = "1122334455667788" # we sign AGAIN the form because the data has been changed self.facade.gateway.sign(form) return form def printable_form_errors(self, form): return u' / '.join( [u"%s: %s" % (f.name, '. '.join(f.errors)) for f in form])
def handle_ipn(self, request, **kwargs): """ Complete payment with PayPal - this calls the 'DoExpressCheckout' method to capture the money from the initial transaction. """ txn = None try: txn = Facade().handle_request(request) order = Order.objects.get(number=txn.order_number) # Record payment source source_type, is_created = SourceType.objects.get_or_create( code='systempay') if txn.operation_type == SystemPayTransaction.OPERATION_TYPE_DEBIT: source = Source(source_type=source_type, currency=txn.currency, amount_allocated=D(0), amount_debited=txn.amount, order=order) source.save() elif txn.operation_type == SystemPayTransaction.OPERATION_TYPE_CREDIT: source = Source(source_type=source_type, currency=txn.currency, amount_allocated=D(0), amount_refunded=txn.amount, order=order) source.save() else: raise PaymentError( _("Unknown operation type '%(operation_type)s'") % {'operation_type': txn.operation_type}) except SystemPayError, inst: logger.error(inst.message) raise PaymentError(inst.message)
def setUp(self): self.order = self.create_mock_order() self.facade = Facade()
def get(self, *args, **kwargs): # record the request order = self.get_object() form = self.get_form() Facade().record_submit_txn(order.number, order.total_incl_tax, form) return super(SecureRedirectView, self).get(*args, **kwargs)
def get_form(self): if self._form is not None: return self._form order = self.get_object() self._form = Facade().get_submit_form_populated_with_order(order) return self._form