def test_failed_order_transaction_created(self): """Tests a failed paypal transaction """ def fake_postback(self, test=True): """Perform a Fake PayPal IPN Postback request.""" return 'INVALID' PayPalIPN._postback = fake_postback country = Country(code="ie", name="Ireland") country.save() order = Order(invoice_country=country, shipping_country=country, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) order.save() self.assertEqual(len(PayPalIPN.objects.all()), 0) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 0) post_params = self.IPN_POST_PARAMS payment_status_update = {"payment_status": ST_PP_DENIED} post_params.update(payment_status_update) response = self.client.post(reverse('paypal-ipn'), post_params) self.assertEqual(response.status_code, 200) self.assertEqual(len(PayPalIPN.objects.all()), 1) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 1) ipn_obj = PayPalIPN.objects.all()[0] self.assertEqual(ipn_obj.payment_status, ST_PP_DENIED) self.assertEqual(ipn_obj.flag, True) order = Order.objects.all()[0] self.assertEqual(order.state, PAYMENT_FAILED)
def test_successful_order_transaction_created(self): """Tests we have a transaction associated with an order after payment """ def fake_postback(self, test=True): """Perform a Fake PayPal IPN Postback request.""" return 'VERIFIED' PayPalIPN._postback = fake_postback country = Country(code="ie", name="Ireland") country.save() order = Order(invoice_country=country, shipping_country=country, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) order.save() self.assertEqual(len(PayPalIPN.objects.all()), 0) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 0) post_params = self.IPN_POST_PARAMS response = self.client.post(reverse('paypal-ipn'), post_params) self.assertEqual(response.status_code, 200) self.assertEqual(len(PayPalIPN.objects.all()), 1) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 1) ipn_obj = PayPalIPN.objects.all()[0] self.assertEqual(ipn_obj.flag, False) order = Order.objects.all()[0] self.assertEqual(order.state, PAID)
def test_succesful_order_with_flagged_payment_invalid_receiver_email(self): """Tests a succesful paypal transaction that is flagged with an invalide receiver email """ def fake_postback(self, test=True): """Perform a Fake PayPal IPN Postback request.""" return 'VERIFIED' PayPalIPN._postback = fake_postback country = Country(code="ie", name="Ireland") country.save() order = Order(invoice_country=country, shipping_country=country, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) order.save() self.assertEqual(len(PayPalIPN.objects.all()), 0) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 0) post_params = self.IPN_POST_PARAMS incorrect_receiver_email_update = {"receiver_email": "*****@*****.**"} post_params.update(incorrect_receiver_email_update) response = self.client.post(reverse('paypal-ipn'), post_params) self.assertEqual(response.status_code, 200) self.assertEqual(len(PayPalIPN.objects.all()), 1) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 1) ipn_obj = PayPalIPN.objects.all()[0] self.assertEqual(ipn_obj.payment_status, ST_PP_COMPLETED) self.assertEqual(ipn_obj.flag, True) self.assertEqual(ipn_obj.flag_info, u'Invalid receiver_email ([email protected]).') order = Order.objects.all()[0] self.assertEqual(order.state, PAYMENT_FLAGGED)
def test_succesful_order_with_flagged_payment_invalid_receiver_email(self): """Tests a succesful paypal transaction that is flagged with an invalide receiver email """ def fake_postback(self, test=True): """Perform a Fake PayPal IPN Postback request.""" return 'VERIFIED' PayPalIPN._postback = fake_postback country = Country(code="ie", name="Ireland") country.save() order = Order(invoice_country=country, shipping_country=country, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) order.save() self.assertEqual(len(PayPalIPN.objects.all()), 0) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 0) post_params = self.IPN_POST_PARAMS incorrect_receiver_email_update = { "receiver_email": "*****@*****.**" } post_params.update(incorrect_receiver_email_update) response = self.client.post(reverse('paypal-ipn'), post_params) self.assertEqual(response.status_code, 200) self.assertEqual(len(PayPalIPN.objects.all()), 1) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 1) ipn_obj = PayPalIPN.objects.all()[0] self.assertEqual(ipn_obj.payment_status, ST_PP_COMPLETED) self.assertEqual(ipn_obj.flag, True) self.assertEqual( ipn_obj.flag_info, u'Invalid receiver_email ([email protected]).') order = Order.objects.all()[0] self.assertEqual(order.state, PAYMENT_FLAGGED)