Ejemplo n.º 1
0
    def setUp(self):
        super(TestPayoutApi, self).setUp()
        self.client = JSONAPITestClient()
        self.plain_user = BlueBottleUserFactory.create()
        self.plain_token = Token.objects.create(user=self.plain_user)
        self.finance_user = BlueBottleUserFactory.create()
        self.token = Token.objects.create(user=self.finance_user)
        financial = Group.objects.get(name='Financial')
        financial.user_set.add(self.finance_user)

        yesterday = now() - timedelta(days=1)
        payout_account = StripePayoutAccountFactory.create(status='verified')
        self.bank_account = ExternalAccountFactory.create(
            connect_account=payout_account)

        self.funding = FundingFactory.create(deadline=yesterday, status='open')

        self.funding.bank_account = self.bank_account
        self.funding.save()

        donations = DonationFactory.create_batch(4,
                                                 activity=self.funding,
                                                 amount=Money(35, 'EUR'),
                                                 status='succeeded')
        for donation in donations:
            StripePaymentFactory.create(status='succeeded', donation=donation)

        self.funding.states.succeed(save=True)
        self.payout = self.funding.payouts.first()
        self.payout_url = reverse('payout-details',
                                  kwargs={'pk': self.payout.id})
Ejemplo n.º 2
0
    def setUp(self):
        self.initiative = InitiativeFactory.create()
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)
        self.funding = FundingFactory.create(
            initiative=self.initiative,
            duration=30,
            target=Money(1000, 'EUR')
        )
        BudgetLineFactory.create(activity=self.funding)
        payout_account = StripePayoutAccountFactory.create(reviewed=True, status='verified')
        self.bank_account = ExternalAccountFactory.create(connect_account=payout_account, status='verified')
        self.funding.bank_account = self.bank_account
        self.funding.states.submit()
        self.funding.states.approve(save=True)

        for donation in DonationFactory.create_batch(
                3,
                amount=Money(150, 'EUR'),
                activity=self.funding,
                status='succeeded'):
            StripePaymentFactory.create(donation=donation)

        for donation in DonationFactory.create_batch(
                2,
                amount=Money(200, 'USD'),
                payout_amount=(150, 'EUR'),
                activity=self.funding,
                status='succeeded'):
            StripePaymentFactory.create(donation=donation)

        for donation in DonationFactory.create_batch(
                5,
                amount=Money(100, 'USD'),
                activity=self.funding,
                status='succeeded'):
            StripePaymentFactory.create(donation=donation)

        donation = DonationFactory.create(
            amount=Money(750, 'EUR'),
            activity=self.funding,
            status='succeeded')
        PledgePaymentFactory.create(donation=donation)

        self.donation = donation

        for donation in DonationFactory.create_batch(
                5,
                amount=Money(150, 'EUR'),
                activity=self.funding,
                status='succeeded'):
            StripePaymentFactory.create(donation=donation)

        for donation in DonationFactory.create_batch(
                5,
                amount=Money(100, 'USD'),
                activity=self.funding,
                status='succeeded'):
            StripePaymentFactory.create(donation=donation)
Ejemplo n.º 3
0
 def test_request_refund(self, mock_retrieve):
     donation = DonationFactory.create(activity=self.funding)
     payment = StripePaymentFactory.create(donation=donation)
     payment.states.succeed(save=True)
     self.assertEqual(payment.status, 'succeeded')
     payment.states.request_refund(save=True)
     self.assertEqual(payment.status, 'refund_requested')
Ejemplo n.º 4
0
 def test_refund_donation_refunded(self):
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     payment = StripePaymentFactory.create(donation=donation)
     payment.states.succeed(save=True)
     payment.states.refund(save=True)
     self.assertEqual(donation.status, 'refunded')
Ejemplo n.º 5
0
    def test_generate_payouts(self):
        Payout.generate(self.funding)
        self.assertEqual(self.funding.payouts.count(), 3)
        payout_amounts = [p.total_amount for p in self.funding.payouts.all()]
        self.assertTrue(Money(1000, 'USD') in payout_amounts)
        self.assertTrue(Money(1500, 'EUR') in payout_amounts)
        self.assertTrue(Money(750, 'EUR') in payout_amounts)

        # More donations
        for donation in DonationFactory.create_batch(5,
                                                     amount=Money(150, 'EUR'),
                                                     activity=self.funding,
                                                     status='succeeded'):
            StripePaymentFactory.create(donation=donation)

        # Recalculate should generate new payouts. One should be higher now.
        Payout.generate(self.funding)
        self.assertEqual(self.funding.payouts.count(), 3)
        payout_amounts = [p.total_amount for p in self.funding.payouts.all()]
        self.assertTrue(Money(1000, 'USD') in payout_amounts)
        self.assertTrue(Money(2250, 'EUR') in payout_amounts)
        self.assertTrue(Money(750, 'EUR') in payout_amounts)

        with mock.patch('bluebottle.payouts_dorado.adapters.DoradoPayoutAdapter.trigger_payout'):
            for payout in self.funding.payouts.all():
                payout.states.approve()
                payout.save()

        # More donations after approved payouts
        for donation in DonationFactory.create_batch(8,
                                                     amount=Money(250, 'EUR'),
                                                     activity=self.funding,
                                                     status='succeeded'):
            StripePaymentFactory.create(donation=donation)

        # Recalculate should generate an additional payout
        Payout.generate(self.funding)
        self.assertEqual(self.funding.payouts.count(), 4)
        payout_amounts = [p.total_amount for p in self.funding.payouts.all()]
        self.assertTrue(Money(1000, 'USD') in payout_amounts)
        self.assertTrue(Money(2000, 'EUR') in payout_amounts)
        self.assertTrue(Money(2250, 'EUR') in payout_amounts)
        self.assertTrue(Money(750, 'EUR') in payout_amounts)
Ejemplo n.º 6
0
    def test_donation_admin_pledge_filter(self):
        for donation in DonationFactory.create_batch(2, activity=self.funding):
            PledgePaymentFactory.create(donation=donation)

        for donation in DonationFactory.create_batch(7, activity=self.funding):
            StripePaymentFactory.create(donation=donation)

        self.client.force_login(self.superuser)

        response = self.client.get(self.admin_url, {'status__exact': 'all'})
        self.assertContains(response, '9 Donations')

        response = self.client.get(self.admin_url, {
            'status__exact': 'all',
            'pledge': 'paid'
        })
        self.assertContains(response, '7 Donations')

        response = self.client.get(self.admin_url, {
            'status__exact': 'all',
            'pledge': 'pledged'
        })
        self.assertContains(response, '2 Donations')
Ejemplo n.º 7
0
    def setUp(self):
        self.initiative = InitiativeFactory.create()
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)
        self.funding = FundingFactory.create(initiative=self.initiative,
                                             duration=30,
                                             target=Money(1000, 'EUR'))
        BudgetLineFactory.create(activity=self.funding)
        payout_account = StripePayoutAccountFactory.create(reviewed=True,
                                                           status='verified')
        self.bank_account = ExternalAccountFactory.create(
            connect_account=payout_account, status='verified')
        self.funding.bank_account = self.bank_account
        self.funding.states.submit()
        self.funding.states.approve(save=True)

        donation = DonationFactory.create(amount=Money(150, 'EUR'),
                                          activity=self.funding,
                                          status='succeeded')

        self.payment = StripePaymentFactory.create(donation=donation)
        super(StripePaymentTransitionsTestCase, self).setUp()
Ejemplo n.º 8
0
 def test_authorize_donation_success(self):
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     payment = StripePaymentFactory.create(donation=donation)
     payment.states.authorize(save=True)
     self.assertEqual(donation.status, 'succeeded')
Ejemplo n.º 9
0
 def test_fail(self):
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     payment = StripePaymentFactory.create(donation=donation)
     payment.states.fail(save=True)
     self.assertEqual(payment.status, 'failed')
Ejemplo n.º 10
0
 def test_initiate(self):
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     payment = StripePaymentFactory.create(donation=donation)
     self.assertEqual(payment.status, 'new')