def test_process_payment_raises_exception(self, purchased_callback): # pylint: disable=unused-argument self.order.clear() OrderItem.objects.create( order=self.order, user=self.user, unit_cost=self.COST, line_cost=self.COST, ) params = self._signed_callback_params(self.order.id, self.COST, self.COST) process_postpay_callback(params)
def test_process_payment_invalid_order(self): # Use an invalid order ID params = self._signed_callback_params("98272", self.COST, self.COST) result = process_postpay_callback(params) # Expect an error self.assertFalse(result['success']) self.assertIn(u"inconsistent data", result['error_html'])
def test_process_amount_paid_not_decimal(self): # Change the payment amount to a non-decimal params = self._signed_callback_params(self.order.id, self.COST, "abcd") result = process_postpay_callback(params) # Expect an error self.assertFalse(result['success']) self.assertIn(u"badly-typed value", result['error_html'])
def test_process_invalid_payment_amount(self): # Change the payment amount (no longer matches the database order record) params = self._signed_callback_params(self.order.id, "145.00", "145.00") result = process_postpay_callback(params) # Expect an error self.assertFalse(result['success']) self.assertIn(u"different amount than the order total", result['error_html'])
def test_process_payment_rejected(self): # Simulate a callback from CyberSource indicating that the payment was rejected params = self._signed_callback_params(self.order.id, self.COST, self.COST, accepted=False) result = process_postpay_callback(params) # Expect that we get an error message self.assertFalse(result['success']) self.assertIn(u"did not accept your payment", result['error_html'])
def test_process_payment_invalid_signature(self): # Simulate a callback from CyberSource indicating that the payment was rejected params = self._signed_callback_params(self.order.id, self.COST, self.COST, signature="invalid!") result = process_postpay_callback(params) # Expect that we get an error message self.assertFalse(result['success']) self.assertIn(u"corrupted message regarding your charge", result['error_html'])
def test_process_payment_declined(self): # Simulate a callback from CyberSource indicating that the payment was declined params = self._signed_callback_params(self.order.id, self.COST, self.COST, decision='DECLINE') result = process_postpay_callback(params) # Expect that we get an error message self.assertFalse(result['success']) self.assertIn(u"payment was declined", result['error_html'])
def test_process_user_cancelled(self): # Change the payment amount to a non-decimal params = self._signed_callback_params(self.order.id, self.COST, "abcd") params['decision'] = u'CANCEL' result = process_postpay_callback(params) # Expect an error self.assertFalse(result['success']) self.assertIn(u"you have cancelled this transaction", result['error_html'])
def test_process_payment_rejected(self): # Simulate a callback from CyberSource indicating that the payment was rejected params = self._signed_callback_params(self.order.id, self.COST, self.COST, decision='REJECT') result = process_postpay_callback(params) # Expect that we get an error message self.assertFalse(result['success']) self.assertIn(u"did not accept your payment", result['error_html']) self.assert_dump_recorded(result['order'])
def test_sign_then_verify_unicode(self, purchased_callback): params = self._signed_callback_params( self.order.id, self.COST, self.COST, first_name=u'\u2699' ) # Verify that this executes without a unicode error result = process_postpay_callback(params) self.assertTrue(result['success'])
def test_sign_then_verify_unicode(self, purchased_callback): params = self._signed_callback_params(self.order.id, self.COST, self.COST, first_name=u'\u2699') # Verify that this executes without a unicode error result = process_postpay_callback(params) self.assertTrue(result['success'])
def test_sign_then_verify_unicode(self, pdf_receipt_display_name, purchased_callback): # pylint: disable=unused-argument params = self._signed_callback_params( self.order.id, self.COST, self.COST, first_name=u'\u2699' ) # Verify that this executes without a unicode error result = process_postpay_callback(params) self.assertTrue(result['success']) self.assert_dump_recorded(result['order'])
def test_process_no_credit_card_digits(self, callback): # Use a credit card number with no digits provided params = self._signed_callback_params(self.order.id, self.COST, self.COST, card_number="nodigits") result = process_postpay_callback(params) # Expect that we processed the payment successfully self.assertTrue( result["success"], msg="Payment was not successful: {error}".format(error=result.get("error_html")) ) self.assertEqual(result["error_html"], "") # Expect that the order has placeholders for the missing credit card digits self.assertEqual(result["order"].bill_to_ccnum, "####")
def test_process_missing_parameters(self, missing_param): # Remove a required parameter params = self._signed_callback_params(self.order.id, self.COST, self.COST) del params[missing_param] # Recalculate the signature with no signed fields so we can get past # signature validation. params['signed_field_names'] = 'reason_code,message' params['signature'] = self._signature(params) result = process_postpay_callback(params) # Expect an error self.assertFalse(result['success']) self.assertIn(u"did not return a required parameter", result['error_html'])
def test_process_payment_success(self, purchased_callback): # Simulate a callback from CyberSource indicating that payment was successful params = self._signed_callback_params(self.order.id, self.COST, self.COST) result = process_postpay_callback(params) # Expect that we processed the payment successfully self.assertTrue( result["success"], msg="Payment was not successful: {error}".format(error=result.get("error_html")) ) self.assertEqual(result["error_html"], "") # Expect that the item's purchased callback was invoked purchased_callback.assert_called_with() # Expect that the order has been marked as purchased self.assertEqual(result["order"].status, "purchased")
def test_process_no_credit_card_digits(self, callback): # Use a credit card number with no digits provided params = self._signed_callback_params(self.order.id, self.COST, self.COST, card_number='nodigits') result = process_postpay_callback(params) # Expect that we processed the payment successfully self.assertTrue(result['success'], msg="Payment was not successful: {error}".format( error=result.get('error_html'))) self.assertEqual(result['error_html'], '') # Expect that the order has placeholders for the missing credit card digits self.assertEqual(result['order'].bill_to_ccnum, '####')
def test_process_payment_success(self, purchased_callback): # Simulate a callback from CyberSource indicating that payment was successful params = self._signed_callback_params(self.order.id, self.COST, self.COST) result = process_postpay_callback(params) # Expect that we processed the payment successfully self.assertTrue(result['success'], msg="Payment was not successful: {error}".format( error=result.get('error_html'))) self.assertEqual(result['error_html'], '') # Expect that the item's purchased callback was invoked purchased_callback.assert_called_with() # Expect that the order has been marked as purchased self.assertEqual(result['order'].status, 'purchased')
def test_process_no_credit_card_digits(self, pdf_receipt_display_name, purchased_callback): # pylint: disable=unused-argument # Use a credit card number with no digits provided params = self._signed_callback_params( self.order.id, self.COST, self.COST, card_number='nodigits' ) result = process_postpay_callback(params) # Expect that we processed the payment successfully self.assertTrue( result['success'], msg="Payment was not successful: {error}".format(error=result.get('error_html')) ) self.assertEqual(result['error_html'], '') self.assert_dump_recorded(result['order']) # Expect that the order has placeholders for the missing credit card digits self.assertEqual(result['order'].bill_to_ccnum, '####')
def test_process_payment_success(self, pdf_receipt_display_name, purchased_callback): # pylint: disable=unused-argument # Simulate a callback from CyberSource indicating that payment was successful params = self._signed_callback_params(self.order.id, self.COST, self.COST) result = process_postpay_callback(params) # Expect that we processed the payment successfully self.assertTrue( result['success'], msg="Payment was not successful: {error}".format(error=result.get('error_html')) ) self.assertEqual(result['error_html'], '') # Expect that the item's purchased callback was invoked purchased_callback.assert_called_with() # Expect that the order has been marked as purchased self.assertEqual(result['order'].status, 'purchased') self.assert_dump_recorded(result['order'])