class TestOrder(TestCase): def setUp(self): self.order = PayerOrder(order_id="123456") self.buyer_details = PayerBuyerDetails( first_name="John", last_name="Doe", address_line_1="1234 Main Street", postal_code="12345", city="Anywhere", phone_mobile="012345678", email="*****@*****.**", ) self.order_items = [ PayerOrderItem( description='A product', price_including_vat=123.50, vat_percentage=25, quantity=4, ), PayerOrderItem( description='Another product', price_including_vat=123.0, vat_percentage=12.5, quantity=2, ), ] self.info_lines = [ "Shipping with 5 work days", "Additional line of order info", ] def test_add_order_item(self): for order_item in self.order_items: self.order.add_order_item(order_item) self.assertTrue(order_item in self.order.order_items) self.assertEqual(self.order.order_items, self.order_items) def test_add_info_line(self): for info_line in self.info_lines: self.order.add_info_line(info_line) self.assertTrue(info_line in self.order.info_lines) self.assertEqual(self.order.info_lines, self.info_lines) def test_set_buyer_details(self): self.order.set_buyer_details(self.buyer_details) self.assertEqual(self.order.buyer_details, self.buyer_details)
def payer_redirect_view(self, request): """ This view generates the order XML data and other key-value pairs needed, outputs the as hidden input elemens in a form and redirects to Payer. """ order = self.shop.get_order(request) description = self.shop.get_order_short_name(order) order_id = self.shop.get_order_unique_id(order) user = None if request.user.is_authenticated(): user = request.user payer_order = PayerOrder( order_id=order_id, description=description, ) payer_order.set_buyer_details(buyer_details_from_user(user=user, order=order)) for order_item in order.items.all(): payer_order.add_order_item(payer_order_item_from_order_item(order_item)) for extra_order_price in order.extraorderpricefield_set.all(): payer_order.add_order_item(payer_order_item_from_extra_order_price(extra_order_price)) for info in order.extra_info.all(): for t in list(string_chunks(info.text, 255)): payer_order.add_info_line(t) self.api.set_processing_control(self.get_processing_control(request)) self.api.set_order(payer_order) redirect_data = self.api.get_post_data() form = PayerRedirectForm(redirect_data=redirect_data) ctx_data = { 'order': order, 'redirect_data': redirect_data, 'form_action': self.api.get_post_url(), 'form': form, } if settings.DEBUG: ctx_data['xml_data'] = self.api.get_xml_data(pretty_print=True) context = RequestContext(request, ctx_data) return render_to_response(self.template, context)