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


Python Charge.sync_from_stripe_data方法代码示例

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


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

示例1: test_sync_from_stripe_data_no_customer

# 需要导入模块: from djstripe.models import Charge [as 别名]
# 或者: from djstripe.models.Charge import sync_from_stripe_data [as 别名]
	def test_sync_from_stripe_data_no_customer(
		self, charge_retrieve_mock, balance_transaction_retrieve_mock, default_account_mock
	):
		from djstripe.settings import STRIPE_SECRET_KEY

		default_account_mock.return_value = self.account

		fake_charge_copy = deepcopy(FAKE_CHARGE)

		fake_charge_copy.pop("customer", None)
		# remove invoice since it requires a customer
		fake_charge_copy.pop("invoice", None)

		Charge.sync_from_stripe_data(fake_charge_copy)
		assert Charge.objects.count() == 1
		charge = Charge.objects.get()
		assert charge.customer is None

		charge_retrieve_mock.assert_not_called()
		balance_transaction_retrieve_mock.assert_called_once_with(
			api_key=STRIPE_SECRET_KEY, expand=[], id=FAKE_BALANCE_TRANSACTION["id"]
		)

		self.assert_fks(
			charge,
			expected_blank_fks={
				"djstripe.Account.business_logo",
				"djstripe.Charge.customer",
				"djstripe.Charge.dispute",
				"djstripe.Charge.invoice",
				"djstripe.Charge.transfer",
				"djstripe.Customer.coupon",
				"djstripe.Plan.product",
			},
		)
开发者ID:,项目名称:,代码行数:37,代码来源:

示例2: test_sync_from_stripe_data_no_customer

# 需要导入模块: from djstripe.models import Charge [as 别名]
# 或者: from djstripe.models.Charge import sync_from_stripe_data [as 别名]
    def test_sync_from_stripe_data_no_customer(self, default_account_mock):
        default_account_mock.return_value = self.account

        fake_charge_copy = deepcopy(FAKE_CHARGE)
        fake_charge_copy.pop("customer", None)

        Charge.sync_from_stripe_data(fake_charge_copy)
        assert Charge.objects.count() == 1
        charge = Charge.objects.get()
        assert charge.customer is None
开发者ID:cloudsmith-io,项目名称:dj-stripe,代码行数:12,代码来源:test_charge.py

示例3: test_sync_from_stripe_data_max_amount

# 需要导入模块: from djstripe.models import Charge [as 别名]
# 或者: from djstripe.models.Charge import sync_from_stripe_data [as 别名]
	def test_sync_from_stripe_data_max_amount(
		self,
		default_account_mock,
		subscription_retrieve_mock,
		product_retrieve_mock,
		invoice_retrieve_mock,
		charge_retrieve_mock,
		balance_transaction_retrieve_mock,
	):
		default_account_mock.return_value = self.account

		fake_charge_copy = deepcopy(FAKE_CHARGE)
		# https://support.stripe.com/questions/what-is-the-maximum-amount-i-can-charge-with-stripe
		fake_charge_copy.update({"amount": 99999999})

		charge = Charge.sync_from_stripe_data(fake_charge_copy)

		self.assertEqual(Decimal("999999.99"), charge.amount)
		self.assertEqual(True, charge.paid)
		self.assertEqual(False, charge.refunded)
		self.assertEqual(True, charge.captured)
		self.assertEqual(False, charge.disputed)
		self.assertEqual(0, charge.amount_refunded)

		charge_retrieve_mock.assert_not_called()

		self.assert_fks(
			charge,
			expected_blank_fks={
				"djstripe.Account.business_logo",
				"djstripe.Charge.dispute",
				"djstripe.Charge.transfer",
				"djstripe.Customer.coupon",
			},
		)
开发者ID:,项目名称:,代码行数:37,代码来源:

示例4: sync_charges

# 需要导入模块: from djstripe.models import Charge [as 别名]
# 或者: from djstripe.models.Charge import sync_from_stripe_data [as 别名]
def sync_charges(apps, schema_editor):
    # This is okay, since we're only doing a forward migration.
    from djstripe.models import Charge

    from djstripe.context_managers import stripe_temporary_api_version

    with stripe_temporary_api_version("2016-03-07"):
        if Charge.objects.count():
            print("syncing charges. This may take a while.")

            for charge in tqdm(Charge.objects.all(), desc="Sync", unit=" charges"):
                try:
                    Charge.sync_from_stripe_data(charge.api_retrieve())
                except InvalidRequestError:
                    tqdm.write("There was an error while syncing charge ({charge_id}).".format(charge_id=charge.stripe_id))

            print("Charge sync complete.")
开发者ID:cloudsmith-io,项目名称:dj-stripe,代码行数:19,代码来源:0012_model_sync.py

示例5: test_sync_from_stripe_data_refunded

# 需要导入模块: from djstripe.models import Charge [as 别名]
# 或者: from djstripe.models.Charge import sync_from_stripe_data [as 别名]
	def test_sync_from_stripe_data_refunded(
		self,
		subscription_retrieve_mock,
		product_retrieve_mock,
		invoice_retrieve_mock,
		charge_retrieve_mock,
		balance_transaction_retrieve_mock,
		default_account_mock,
	):
		from djstripe.settings import STRIPE_SECRET_KEY

		default_account_mock.return_value = self.account
		fake_charge_copy = deepcopy(FAKE_CHARGE_REFUNDED)

		charge = Charge.sync_from_stripe_data(fake_charge_copy)

		self.assertEqual(Decimal("22"), charge.amount)
		self.assertEqual(True, charge.paid)
		self.assertEqual(True, charge.refunded)
		self.assertEqual(True, charge.captured)
		self.assertEqual(False, charge.disputed)
		self.assertEqual("VideoDoc consultation for ivanp0001 berkp0001", charge.description)
		self.assertEqual(charge.amount, charge.amount_refunded)

		charge_retrieve_mock.assert_not_called()

		# We expect two calls - for charge and then for charge.refunds
		balance_transaction_retrieve_mock.assert_has_calls(
			[
				call(api_key=STRIPE_SECRET_KEY, expand=[], id=FAKE_BALANCE_TRANSACTION["id"]),
				call(
					api_key=STRIPE_SECRET_KEY, expand=[], id=FAKE_BALANCE_TRANSACTION_REFUND["id"]
				),
			]
		)

		refunds = list(charge.refunds.all())
		self.assertEqual(len(refunds), 1)

		refund = refunds[0]

		self.assertEqual(refund.id, FAKE_REFUND["id"])

		self.assertNotEqual(charge.balance_transaction.id, refund.balance_transaction.id)
		self.assertEqual(charge.balance_transaction.id, FAKE_BALANCE_TRANSACTION["id"])
		self.assertEqual(refund.balance_transaction.id, FAKE_BALANCE_TRANSACTION_REFUND["id"])

		self.assert_fks(
			charge,
			expected_blank_fks={
				"djstripe.Account.business_logo",
				"djstripe.Charge.dispute",
				"djstripe.Charge.transfer",
				"djstripe.Customer.coupon",
			},
		)
开发者ID:,项目名称:,代码行数:58,代码来源:

示例6: test_sync_from_stripe_data_unsupported_source

# 需要导入模块: from djstripe.models import Charge [as 别名]
# 或者: from djstripe.models.Charge import sync_from_stripe_data [as 别名]
    def test_sync_from_stripe_data_unsupported_source(self, default_account_mock):
        default_account_mock.return_value = self.account

        fake_charge_copy = deepcopy(FAKE_CHARGE)
        fake_charge_copy.update({"source": {"id": "test_id", "object": "unsupported"}})

        charge = Charge.sync_from_stripe_data(fake_charge_copy)
        self.assertEqual("test_id", charge.source_stripe_id)
        self.assertEqual("unsupported", charge.source_type)
        self.assertEqual(charge.source, PaymentMethod.objects.get(id="test_id"))
开发者ID:cloudsmith-io,项目名称:dj-stripe,代码行数:12,代码来源:test_charge.py

示例7: test_sync_from_stripe_data

# 需要导入模块: from djstripe.models import Charge [as 别名]
# 或者: from djstripe.models.Charge import sync_from_stripe_data [as 别名]
    def test_sync_from_stripe_data(self):
        charge = Charge.sync_from_stripe_data(FAKE_CHARGE)

        self.assertEqual(self.invoice, charge.invoice)
        self.assertEqual("9999", charge.card_last_4)
        self.assertEqual("Visa", charge.card_kind)
        self.assertEqual(Decimal("9.95"), charge.amount)
        self.assertEqual(True, charge.paid)
        self.assertEqual(False, charge.refunded)
        self.assertEqual(True, charge.captured)
        self.assertEqual(Decimal("0"), charge.fee)
        self.assertEqual(False, charge.disputed)
        self.assertEqual("test_description", charge.description)
        self.assertEqual(None, charge.amount_refunded)
开发者ID:areski,项目名称:dj-stripe,代码行数:16,代码来源:test_charge.py

示例8: test_sync_from_stripe_data_max_amount

# 需要导入模块: from djstripe.models import Charge [as 别名]
# 或者: from djstripe.models.Charge import sync_from_stripe_data [as 别名]
    def test_sync_from_stripe_data_max_amount(self, default_account_mock):
        default_account_mock.return_value = self.account

        fake_charge_copy = deepcopy(FAKE_CHARGE)
        # https://support.stripe.com/questions/what-is-the-maximum-amount-i-can-charge-with-stripe
        fake_charge_copy.update({"amount": 99999999})

        charge = Charge.sync_from_stripe_data(fake_charge_copy)

        self.assertEqual(Decimal("999999.99"), charge.amount)
        self.assertEqual(True, charge.paid)
        self.assertEqual(False, charge.refunded)
        self.assertEqual(True, charge.captured)
        self.assertEqual(False, charge.disputed)
        self.assertEqual(0, charge.amount_refunded)
开发者ID:cloudsmith-io,项目名称:dj-stripe,代码行数:17,代码来源:test_charge.py

示例9: test_sync_from_stripe_data

# 需要导入模块: from djstripe.models import Charge [as 别名]
# 或者: from djstripe.models.Charge import sync_from_stripe_data [as 别名]
    def test_sync_from_stripe_data(self, default_account_mock):
        default_account_mock.return_value = self.account

        fake_charge_copy = deepcopy(FAKE_CHARGE)
        fake_charge_copy.update({"application_fee": {"amount": 0}})

        charge = Charge.sync_from_stripe_data(FAKE_CHARGE)

        self.assertEqual(Decimal("22"), charge.amount)
        self.assertEqual(True, charge.paid)
        self.assertEqual(False, charge.refunded)
        self.assertEqual(True, charge.captured)
        self.assertEqual(False, charge.disputed)
        self.assertEqual("VideoDoc consultation for ivanp0001 berkp0001", charge.description)
        self.assertEqual(0, charge.amount_refunded)

        self.assertEqual("card_16YKQh2eZvKYlo2Cblc5Feoo", charge.source_stripe_id)
        self.assertEqual(charge.source_type, LegacySourceType.card)
开发者ID:cloudsmith-io,项目名称:dj-stripe,代码行数:20,代码来源:test_charge.py

示例10: test_sync_from_stripe_data

# 需要导入模块: from djstripe.models import Charge [as 别名]
# 或者: from djstripe.models.Charge import sync_from_stripe_data [as 别名]
	def test_sync_from_stripe_data(
		self,
		subscription_retrieve_mock,
		product_retrieve_mock,
		invoice_retrieve_mock,
		charge_retrieve_mock,
		balance_transaction_retrieve_mock,
		default_account_mock,
	):
		from djstripe.settings import STRIPE_SECRET_KEY

		default_account_mock.return_value = self.account

		fake_charge_copy = deepcopy(FAKE_CHARGE)
		fake_charge_copy.update({"application_fee": {"amount": 0}})

		charge = Charge.sync_from_stripe_data(fake_charge_copy)

		self.assertEqual(Decimal("22"), charge.amount)
		self.assertEqual(True, charge.paid)
		self.assertEqual(False, charge.refunded)
		self.assertEqual(True, charge.captured)
		self.assertEqual(False, charge.disputed)
		self.assertEqual("VideoDoc consultation for ivanp0001 berkp0001", charge.description)
		self.assertEqual(0, charge.amount_refunded)

		self.assertEqual("card_16YKQh2eZvKYlo2Cblc5Feoo", charge.source_id)
		self.assertEqual(charge.source.type, LegacySourceType.card)

		charge_retrieve_mock.assert_not_called()
		balance_transaction_retrieve_mock.assert_called_once_with(
			api_key=STRIPE_SECRET_KEY, expand=[], id=FAKE_BALANCE_TRANSACTION["id"]
		)

		self.assert_fks(
			charge,
			expected_blank_fks={
				"djstripe.Account.business_logo",
				"djstripe.Charge.dispute",
				"djstripe.Charge.transfer",
				"djstripe.Customer.coupon",
			},
		)
开发者ID:,项目名称:,代码行数:45,代码来源:

示例11: test_sync_from_stripe_data_unsupported_source

# 需要导入模块: from djstripe.models import Charge [as 别名]
# 或者: from djstripe.models.Charge import sync_from_stripe_data [as 别名]
	def test_sync_from_stripe_data_unsupported_source(
		self,
		invoice_retrieve_mock,
		subscription_retrieve_mock,
		product_retrieve_mock,
		charge_retrieve_mock,
		balance_transaction_retrieve_mock,
		default_account_mock,
	):
		from djstripe.settings import STRIPE_SECRET_KEY

		default_account_mock.return_value = self.account

		fake_charge_copy = deepcopy(FAKE_CHARGE)
		fake_charge_copy.update({"source": {"id": "test_id", "object": "unsupported"}})

		charge = Charge.sync_from_stripe_data(fake_charge_copy)
		self.assertEqual("test_id", charge.source_id)
		self.assertEqual("unsupported", charge.source.type)
		self.assertEqual(charge.source, DjstripePaymentMethod.objects.get(id="test_id"))

		# alias to old model name should work the same
		self.assertEqual(charge.source, PaymentMethod.objects.get(id="test_id"))

		charge_retrieve_mock.assert_not_called()

		balance_transaction_retrieve_mock.assert_called_once_with(
			api_key=STRIPE_SECRET_KEY, expand=[], id=FAKE_BALANCE_TRANSACTION["id"]
		)

		self.assert_fks(
			charge,
			expected_blank_fks={
				"djstripe.Account.business_logo",
				"djstripe.Charge.dispute",
				"djstripe.Charge.transfer",
				"djstripe.Customer.coupon",
			},
		)
开发者ID:,项目名称:,代码行数:41,代码来源:

示例12: test_sync_from_stripe_data_refunded_on_update

# 需要导入模块: from djstripe.models import Charge [as 别名]
# 或者: from djstripe.models.Charge import sync_from_stripe_data [as 别名]
	def test_sync_from_stripe_data_refunded_on_update(
		self,
		subscription_retrieve_mock,
		product_retrieve_mock,
		invoice_retrieve_mock,
		charge_retrieve_mock,
		default_account_mock,
	):
		# first sync charge (as per test_sync_from_stripe_data) then sync refunded version,
		# to hit the update code-path instead of insert

		from djstripe.settings import STRIPE_SECRET_KEY

		default_account_mock.return_value = self.account

		fake_charge_copy = deepcopy(FAKE_CHARGE)

		with patch(
			"stripe.BalanceTransaction.retrieve", return_value=deepcopy(FAKE_BALANCE_TRANSACTION)
		):
			charge = Charge.sync_from_stripe_data(fake_charge_copy)

		self.assertEqual(Decimal("22"), charge.amount)
		self.assertEqual(True, charge.paid)
		self.assertEqual(False, charge.refunded)
		self.assertEqual(True, charge.captured)
		self.assertEqual(False, charge.disputed)

		self.assertEqual(len(charge.refunds.all()), 0)

		fake_charge_refunded_copy = deepcopy(FAKE_CHARGE_REFUNDED)

		with patch(
			"stripe.BalanceTransaction.retrieve",
			return_value=deepcopy(FAKE_BALANCE_TRANSACTION_REFUND),
		) as balance_transaction_retrieve_mock:
			charge_refunded = Charge.sync_from_stripe_data(fake_charge_refunded_copy)

		self.assertEqual(charge.id, charge_refunded.id)

		self.assertEqual(Decimal("22"), charge_refunded.amount)
		self.assertEqual(True, charge_refunded.paid)
		self.assertEqual(True, charge_refunded.refunded)
		self.assertEqual(True, charge_refunded.captured)
		self.assertEqual(False, charge_refunded.disputed)
		self.assertEqual(
			"VideoDoc consultation for ivanp0001 berkp0001", charge_refunded.description
		)
		self.assertEqual(charge_refunded.amount, charge_refunded.amount_refunded)

		charge_retrieve_mock.assert_not_called()
		balance_transaction_retrieve_mock.assert_called_once_with(
			api_key=STRIPE_SECRET_KEY, expand=[], id=FAKE_BALANCE_TRANSACTION_REFUND["id"]
		)

		refunds = list(charge_refunded.refunds.all())
		self.assertEqual(len(refunds), 1)

		refund = refunds[0]

		self.assertEqual(refund.id, FAKE_REFUND["id"])

		self.assertNotEqual(
			charge_refunded.balance_transaction.id, refund.balance_transaction.id
		)
		self.assertEqual(
			charge_refunded.balance_transaction.id, FAKE_BALANCE_TRANSACTION["id"]
		)
		self.assertEqual(refund.balance_transaction.id, FAKE_BALANCE_TRANSACTION_REFUND["id"])

		self.assert_fks(
			charge_refunded,
			expected_blank_fks={
				"djstripe.Account.business_logo",
				"djstripe.Charge.dispute",
				"djstripe.Charge.transfer",
				"djstripe.Customer.coupon",
			},
		)
开发者ID:,项目名称:,代码行数:81,代码来源:


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