def test_invoice(self): account = Account(account_code='invoice%s' % self.test_id) with self.mock_request('invoice/account-created.xml'): account.save() try: with self.mock_request('invoice/account-has-no-invoices.xml'): invoices = account.invoices() self.assertEqual(invoices, []) with self.mock_request('invoice/error-no-charges.xml'): try: account.invoice() except ValidationError as exc: error = exc else: self.fail("Invoicing an account with no charges did not raise a ValidationError") self.assertEqual(error.symbol, 'will_not_invoice') charge = Adjustment(unit_amount_in_cents=1000, currency='USD', description='test charge', type='charge') with self.mock_request('invoice/charged.xml'): account.charge(charge) with self.mock_request('invoice/invoiced.xml'): account.invoice() with self.mock_request('invoice/account-has-invoices.xml'): invoices = account.invoices() self.assertEqual(len(invoices), 1) finally: with self.mock_request('invoice/account-deleted.xml'): account.delete()
def test_charge(self): account = Account(account_code='charge%s' % self.test_id) with self.mock_request('adjustment/account-created.xml'): account.save() try: with self.mock_request('adjustment/account-has-no-charges.xml'): charges = account.adjustments() self.assertEqual(charges, []) charge = Adjustment(unit_amount_in_cents=1000, currency='USD', description='test charge', type='charge') with self.mock_request('adjustment/charged.xml'): account.charge(charge) with self.mock_request('adjustment/account-has-adjustments.xml'): charges = account.adjustments() self.assertEqual(len(charges), 1) same_charge = charges[0] self.assertEqual(same_charge.unit_amount_in_cents, 1000) self.assertEqual(same_charge.currency, 'USD') self.assertEqual(same_charge.description, 'test charge') self.assertEqual(same_charge.type, 'charge') with self.mock_request('adjustment/account-has-charges.xml'): charges = account.adjustments(type='charge') self.assertEqual(len(charges), 1) with self.mock_request('adjustment/account-has-no-credits.xml'): credits = account.adjustments(type='credit') self.assertEqual(len(credits), 0) finally: with self.mock_request('adjustment/account-deleted.xml'): account.delete()
def test_invoice(self): account = Account(account_code='invoice%s' % self.test_id) with self.mock_request('invoice/account-created.xml'): account.save() try: with self.mock_request('invoice/account-has-no-invoices.xml'): invoices = account.invoices() self.assertEqual(invoices, []) with self.mock_request('invoice/error-no-charges.xml'): try: account.invoice() except ValidationError as exc: error = exc else: self.fail( "Invoicing an account with no charges did not raise a ValidationError" ) self.assertEqual(error.symbol, 'will_not_invoice') charge = Adjustment(unit_amount_in_cents=1000, currency='USD', description='test charge', type='charge') with self.mock_request('invoice/charged.xml'): account.charge(charge) with self.mock_request('invoice/invoiced.xml'): account.invoice() with self.mock_request('invoice/account-has-invoices.xml'): invoices = account.invoices() self.assertEqual(len(invoices), 1) finally: with self.mock_request('invoice/account-deleted.xml'): account.delete() """Test taxed invoice""" with self.mock_request('invoice/show-taxed.xml'): invoice = account.invoices()[0] self.assertEqual(invoice.tax_type, 'usst') """Test invoice with prefix""" with self.mock_request('invoice/show-with-prefix.xml'): invoice = account.invoices()[0] self.assertEqual(invoice.invoice_number, 1001) self.assertEqual(invoice.invoice_number_prefix, 'GB') self.assertEqual(invoice.invoice_number_with_prefix(), 'GB1001')
invoices = account.invoices() self.assertEqual(invoices, []) with self.mock_request('invoice/error-no-charges.xml'): try: account.invoice() except ValidationError, exc: error = exc else: self.fail( "Invoicing an account with no charges did not raise a ValidationError" ) self.assertEqual(error.symbol, 'will_not_invoice') charge = Adjustment(unit_amount_in_cents=1000, currency='USD', description='test charge', type='charge') with self.mock_request('invoice/charged.xml'): account.charge(charge) with self.mock_request('invoice/invoiced.xml'): account.invoice() with self.mock_request('invoice/account-has-invoices.xml'): invoices = account.invoices() self.assertEqual(len(invoices), 1) finally: with self.mock_request('invoice/account-deleted.xml'): account.delete() def test_pages(self):
def test_transaction_with_balance(self): transaction = Transaction( amount_in_cents=1000, currency='USD', account=Account(), ) error = None with self.mock_request('transaction-balance/transaction-no-account.xml'): try: transaction.save() except ValidationError as _error: error = _error else: self.fail("Posting a transaction without an account code did not raise a ValidationError") # Make sure there really were errors. self.assertTrue(len(error.errors) > 0) account_code = 'transbalance%s' % self.test_id account = Account(account_code=account_code) with self.mock_request('transaction-balance/account-created.xml'): account.save() try: # Try to charge without billing info, should break. transaction = Transaction( amount_in_cents=1000, currency='USD', account=account, ) error = None with self.mock_request('transaction-balance/transaction-no-billing-fails.xml'): try: transaction.save() except ValidationError as _error: error = _error else: self.fail("Posting a transaction without billing info did not raise a ValidationError") # Make sure there really were errors. self.assertTrue(len(error.errors) > 0) binfo = BillingInfo( first_name='Verena', last_name='Example', address1='123 Main St', city=six.u('San Jos\xe9'), state='CA', zip='94105', country='US', type='credit_card', number='4111 1111 1111 1111', verification_value='7777', year='2015', month='12', ) with self.mock_request('transaction-balance/set-billing-info.xml'): account.update_billing_info(binfo) # Try to charge now, should be okay. transaction = Transaction( amount_in_cents=1000, currency='USD', account=account, ) with self.mock_request('transaction-balance/transacted.xml'): transaction.save() # Give the account a credit. credit = Adjustment(unit_amount_in_cents=-2000, currency='USD', description='transaction test credit') with self.mock_request('transaction-balance/credited.xml'): # TODO: maybe this should be adjust()? account.charge(credit) # Try to charge less than the account balance, which should fail (not a CC transaction). transaction = Transaction( amount_in_cents=500, currency='USD', account=account, ) with self.mock_request('transaction-balance/transacted-2.xml'): transaction.save() # The transaction doesn't actually save. self.assertTrue(transaction._url is None) # Try to charge more than the account balance, which should work. transaction = Transaction( amount_in_cents=3000, currency='USD', account=account, ) with self.mock_request('transaction-balance/transacted-3.xml'): transaction.save() # This transaction should be recorded. self.assertTrue(transaction._url is not None) finally: with self.mock_request('transaction-balance/account-deleted.xml'): account.delete()
def test_charge(self): account = Account(account_code="charge%s" % self.test_id) with self.mock_request("adjustment/account-created.xml"): account.save() try: with self.mock_request("adjustment/account-has-no-charges.xml"): charges = account.adjustments() self.assertEqual(charges, []) charge = Adjustment(unit_amount_in_cents=1000, currency="USD", description="test charge", type="charge") with self.mock_request("adjustment/charged.xml"): account.charge(charge) with self.mock_request("adjustment/account-has-adjustments.xml"): charges = account.adjustments() self.assertEqual(len(charges), 1) same_charge = charges[0] self.assertEqual(same_charge.unit_amount_in_cents, 1000) self.assertEqual(same_charge.tax_in_cents, 5000) self.assertEqual(same_charge.tax_type, "usst") self.assertEqual(same_charge.tax_rate, 0.0875) self.assertEqual(same_charge.tax_region, "CA") self.assertEqual(same_charge.currency, "USD") self.assertEqual(same_charge.description, "test charge") self.assertEqual(same_charge.type, "charge") tax_details = same_charge.tax_details state, county = tax_details self.assertEqual(len(tax_details), 2) self.assertEqual(state.name, "california") self.assertEqual(state.type, "state") self.assertEqual(state.tax_rate, 0.065) self.assertEqual(state.tax_in_cents, 3000) self.assertEqual(county.name, "san francisco") self.assertEqual(county.type, "county") self.assertEqual(county.tax_rate, 0.02) self.assertEqual(county.tax_in_cents, 2000) with self.mock_request("adjustment/account-has-charges.xml"): charges = account.adjustments(type="charge") self.assertEqual(len(charges), 1) with self.mock_request("adjustment/account-has-no-credits.xml"): credits = account.adjustments(type="credit") self.assertEqual(len(credits), 0) finally: with self.mock_request("adjustment/account-deleted.xml"): account.delete() """Test taxed adjustments""" with self.mock_request("adjustment/show-taxed.xml"): charge = account.adjustments()[0] self.assertFalse(charge.tax_exempt) """Test original adjustment""" with self.mock_request("adjustment/original-adjustment.xml"): charge = Adjustment.get("2c06b94abe047189b225d94dd0adb71f") with self.mock_request("adjustment/original-adjustment-lookup.xml"): original_charge = charge.original_adjustment() self.assertEqual(original_charge.total_in_cents, -charge.total_in_cents) """Test original adjustment lookup by UUID""" with self.mock_request("adjustment/original-adjustment-uuid.xml"): charge = Adjustment.get("2c06b94abe047189b225d94dd0adb71f") with self.mock_request("adjustment/original-adjustment-lookup.xml"): original_charge = charge.original_adjustment() self.assertEqual(original_charge.total_in_cents, -charge.total_in_cents)
def test_charge(self): account = Account(account_code='charge%s' % self.test_id) with self.mock_request('adjustment/account-created.xml'): account.save() try: with self.mock_request('adjustment/account-has-no-charges.xml'): charges = account.adjustments() self.assertEqual(charges, []) charge = Adjustment(unit_amount_in_cents=1000, currency='USD', description='test charge', type='charge') with self.mock_request('adjustment/charged.xml'): account.charge(charge) with self.mock_request('adjustment/account-has-adjustments.xml'): charges = account.adjustments() self.assertEqual(len(charges), 1) same_charge = charges[0] self.assertEqual(same_charge.unit_amount_in_cents, 1000) self.assertEqual(same_charge.tax_in_cents, 5000) self.assertEqual(same_charge.tax_type, 'usst') self.assertEqual(same_charge.tax_rate, 0.0875) self.assertEqual(same_charge.tax_region, 'CA') self.assertEqual(same_charge.currency, 'USD') self.assertEqual(same_charge.description, 'test charge') self.assertEqual(same_charge.type, 'charge') tax_details = same_charge.tax_details state, county = tax_details self.assertEqual(len(tax_details), 2) self.assertEqual(state.name, 'california') self.assertEqual(state.type, 'state') self.assertEqual(state.tax_rate, 0.065) self.assertEqual(state.tax_in_cents, 3000) self.assertEqual(county.name, 'san francisco') self.assertEqual(county.type, 'county') self.assertEqual(county.tax_rate, 0.02) self.assertEqual(county.tax_in_cents, 2000) with self.mock_request('adjustment/account-has-charges.xml'): charges = account.adjustments(type='charge') self.assertEqual(len(charges), 1) with self.mock_request('adjustment/account-has-no-credits.xml'): credits = account.adjustments(type='credit') self.assertEqual(len(credits), 0) finally: with self.mock_request('adjustment/account-deleted.xml'): account.delete() """Test taxed adjustments""" with self.mock_request('adjustment/show-taxed.xml'): charge = account.adjustments()[0] self.assertFalse(charge.tax_exempt) """Test original adjustment""" with self.mock_request('adjustment/original-adjustment.xml'): charge = Adjustment.get('2c06b94abe047189b225d94dd0adb71f') with self.mock_request( 'adjustment/original-adjustment-lookup.xml'): original_charge = charge.original_adjustment() self.assertEqual(original_charge.total_in_cents, -charge.total_in_cents) """Test original adjustment lookup by UUID""" with self.mock_request('adjustment/original-adjustment-uuid.xml'): charge = Adjustment.get('2c06b94abe047189b225d94dd0adb71f') with self.mock_request( 'adjustment/original-adjustment-lookup.xml'): original_charge = charge.original_adjustment() self.assertEqual(original_charge.total_in_cents, -charge.total_in_cents)