Exemplo n.º 1
0
        def test_charge_sync(self):
            # Initialize stripe
            import stripe
            stripe.api_key = settings.STRIPE_SECRET_KEY

            customer = sync_subscriber(self.user)
            charges = Charge.objects.filter(customer=customer)

            # There shouldn't be any items attached to the customer
            self.assertEqual(0, len(charges), "Charges are unexpectedly associated with a new customer object.")

            token = stripe.Token.create(
                card={
                    "number": '4242424242424242',
                    "exp_month": 12,
                    "exp_year": 2016,
                    "cvc": '123'
                },
            )

            customer.update_card(token.id)

            stripe.Charge.create(
                amount=int(10 * 100),  # Convert dollars into cents
                currency="USD",
                customer=customer.stripe_id,
                description="Test Charge in test_charge_sync",
            )

            customer = sync_subscriber(self.user)
            charges = Charge.objects.filter(customer=customer)
            self.assertEqual(1, len(charges), "Unexpected number of charges associated with a new customer object.")
Exemplo n.º 2
0
	def test_sync_fail(self, stripe_customer_create_mock, api_retrieve_mock, _sync_mock):
		_sync_mock.side_effect = InvalidRequestError("No such customer:", "blah")

		with capture_stdout() as stdout:
			sync_subscriber(self.user)

		self.assertEqual("ERROR: No such customer:", stdout.getvalue().strip())
Exemplo n.º 3
0
        def test_bad_sync(self):
            customer = sync_subscriber(self.user)
            customer.stripe_id = "fake_customer_id"
            customer.save()

            sync_subscriber(self.user)

            self.assertEqual("ERROR: No such customer: fake_customer_id", sys.stdout.getvalue().strip())
Exemplo n.º 4
0
        def test_existing_customer(self):
            customerA = sync_subscriber(self.user)
            customerB = sync_subscriber(self.user)

            self.assertEqual(customerA, customerB, "Customers returned are not equal.")

            customerA.purge()
            customerB.purge()
Exemplo n.º 5
0
    def test_sync_success(self, stripe_customer_create_mock, api_retrieve_mock, _sync_subscriptions_mock,
                          _sync_invoices_mock, _sync_charges_mock):

        sync_subscriber(self.user)
        self.assertEqual(1, Customer.objects.count())
        self.assertEqual(FAKE_CUSTOMER, Customer.objects.get(subscriber=self.user).api_retrieve())

        _sync_subscriptions_mock.assert_called_once_with()
        _sync_invoices_mock.assert_called_once_with()
        _sync_charges_mock.assert_called_once_with()
Exemplo n.º 6
0
    def test_sync_success(self, stripe_customer_create_mock, api_retrieve_mock,
                          _sync_subscriptions_mock, _sync_invoices_mock,
                          _sync_charges_mock):

        sync_subscriber(self.user)
        self.assertEqual(1, Customer.objects.count())
        self.assertEqual(
            FAKE_CUSTOMER,
            Customer.objects.get(subscriber=self.user).api_retrieve())

        _sync_subscriptions_mock.assert_called_once_with()
        _sync_invoices_mock.assert_called_once_with()
        _sync_charges_mock.assert_called_once_with()
Exemplo n.º 7
0
    def test_sync_success(
        self,
        stripe_customer_create_mock,
        stripe_customer_mock,
        sync_mock,
        sync_current_subscription_mock,
        sync_invoices_mock,
        sync_charges_mock,
    ):

        sync_subscriber(self.user)

        sync_mock.assert_called_once_with(cu=self.fake_stripe_customer)
        sync_current_subscription_mock.assert_called_once_with(cu=self.fake_stripe_customer)
        sync_invoices_mock.assert_called_once_with(cu=self.fake_stripe_customer)
        sync_charges_mock.assert_called_once_with(cu=self.fake_stripe_customer)
Exemplo n.º 8
0
        def test_new_customer(self):
            customer = sync_subscriber(self.user)
            charges = Charge.objects.filter(customer=customer)

            # There shouldn't be any items attached to the customer
            self.assertEqual(0, len(charges), "Charges are unexpectedly associated with a new customer object.")
            customer.purge()
Exemplo n.º 9
0
 def sync_stripe(self):
     """sync all payment data (customer,card,charge,invoice) from stripe"""
     from djstripe.sync import sync_subscriber
     sync_subscriber(self.subscriber)
Exemplo n.º 10
0
    def test_sync_fail(self, stripe_customer_create_mock, stripe_customer_mock, sync_mock):
        sync_mock.side_effect = stripe.InvalidRequestError("No such customer:", "blah")

        sync_subscriber(self.user)

        self.assertEqual("ERROR: No such customer:", sys.stdout.getvalue().strip())
Exemplo n.º 11
0
def customer_receiver(sender, instance, created, *args, **kwargs):
    if created:
        customer = sync_subscriber(subscriber=instance)
        logger.info(f"[dj-stripe]: Customer created locally - {customer}")
Exemplo n.º 12
0
 def post(self, request, *args, **kwargs):
     context = dict(customer=sync_subscriber(
         settings.subscriber_request_callback(request)))
     return render(request, self.template_name, context)