当前位置: 首页>>代码示例>>Python>>正文


Python Account.charge方法代码示例

本文整理汇总了Python中recurly.Account.charge方法的典型用法代码示例。如果您正苦于以下问题:Python Account.charge方法的具体用法?Python Account.charge怎么用?Python Account.charge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在recurly.Account的用法示例。


在下文中一共展示了Account.charge方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_invoice

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import charge [as 别名]
    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()
开发者ID:Captricity,项目名称:recurly-client-python,代码行数:34,代码来源:test_resources.py

示例2: test_charge

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import charge [as 别名]
    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()
开发者ID:mbeale,项目名称:recurly-client-python,代码行数:36,代码来源:test_resources.py

示例3: test_charge

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import charge [as 别名]
    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.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)
开发者ID:issuu,项目名称:recurly-client-python,代码行数:56,代码来源:test_resources.py

示例4: test_invoice

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import charge [as 别名]
    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")
开发者ID:tbartelmess,项目名称:recurly-client-python,代码行数:46,代码来源:test_resources.py

示例5: test_build_invoice

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import charge [as 别名]
    def test_build_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/preview-error-no-charges.xml"):
                try:
                    account.build_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/preview-invoice.xml"):
                account.build_invoice()
        finally:
            with self.mock_request("invoice/account-deleted.xml"):
                account.delete()
开发者ID:tbartelmess,项目名称:recurly-client-python,代码行数:26,代码来源:test_resources.py

示例6: Adjustment

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import charge [as 别名]
            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, 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):
        account_code = 'pages-%s-%%d' % self.test_id
        all_test_accounts = list()
开发者ID:mbeale,项目名称:recurly-client-python,代码行数:32,代码来源:test_resources.py

示例7: test_transaction_with_balance

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import charge [as 别名]
    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()
开发者ID:issuu,项目名称:recurly-client-python,代码行数:99,代码来源:test_resources.py

示例8: test_charge

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import charge [as 别名]
    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)
开发者ID:tbartelmess,项目名称:recurly-client-python,代码行数:77,代码来源:test_resources.py


注:本文中的recurly.Account.charge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。