Esempio n. 1
0
    def bad_cc_scenario(self):
        """Goal of this scenario: enter a CC that will cause a charge.failed event, have user repledge succesfully"""

        card1 = card(number=ERROR_TESTING['BAD_ATTACHED_CARD'][0])

        (events, charge_exception) = self.pledge_to_work_with_cc(username="******", password="******", work_id=2, card=card1,
                               preapproval_amount='10', premium_id='150')

        # we should have an exception when the charge was attempted
        self.assertTrue(charge_exception is not None)

        # expect to have 3 events (there is a possibility that someone else could be running tests on this stripe account at the same time)
        # events returned sorted in reverse chronological order.

        evt_types = [event.type for event in events]
        self.assertTrue('charge.failed' in evt_types)
        self.assertTrue('customer.card.created' in evt_types)
        self.assertTrue('customer.created' in evt_types)

        # now feed each of the events to the IPN processor.
        ipn_url = reverse("HandleIPN", args=('stripelib',))

        for (i, event) in enumerate(events):
            r = self.client.post(ipn_url, data=json.dumps({"id": event.id}), content_type="application/json; charset=utf-8")
            self.assertEqual(r.status_code, 200)

        self.assertEqual(len(Notice.objects.filter(notice_type__label='pledge_you_have_pledged', recipient__username='******')), 1)
        self.assertEqual(len(Notice.objects.filter(notice_type__label='pledge_failed', recipient__username='******')), 1)
Esempio n. 2
0
    def recharge_with_new_card(self):

        # mark campaign as SUCCESSFUL -- campaign for work 2
        c = Work.objects.get(id=2).last_campaign()
        c.status = 'SUCCESSFUL'
        c.save()

        # set up a good card
        card1 = card(number=TEST_CARDS[0][0], exp_month=1, exp_year='2030', cvc='123', name='dataunbound',
          address_line1="100 Jackson St.", address_line2="", address_zip="94706", address_state="CA", address_country=None)  # good card

        sc = StripeClient()
        stripe_token = sc.create_token(card=card1)

        # track start time and end time of these stipe interactions so that we can limit the window of Events to look for
        time0 = stripe_token['created']

        r = self.client.post("/accounts/manage/", data={'stripe_token':stripe_token.id}, follow=True)

        #time1 = time.time()

        # retrieve events from this period -- need to pass in ints for event creation times
        events = list(sc._all_objs('Event', created={'gte': time0}))

        # now feed each of the events to the IPN processor.
        ipn_url = reverse("HandleIPN", args=('stripelib',))

        for (i, event) in enumerate(events):
            r = self.client.post(ipn_url, data=json.dumps({"id": event.id}), content_type="application/json; charset=utf-8")
            self.assertEqual(r.status_code, 200)

        # a charge should now go through
        self.assertEqual(len(Notice.objects.filter(notice_type__label='pledge_charged', recipient__username='******')), 1)
Esempio n. 3
0
    def good_cc_scenario(self):
        # how much of test.campaigntest.test_relaunch can be done here?

        card1 = card(number=TEST_CARDS[0][0], exp_month=1, exp_year='2030', cvc='123', name='Raymond Yee',
          address_line1="100 Jackson St.", address_line2="", address_zip="94706", address_state="CA", address_country=None)  # good card

        (events, charge_exception) = self.pledge_to_work_with_cc(username="******", password="******", work_id=1, card=card1,
                               preapproval_amount='10', premium_id='150')

        self.assertEqual(charge_exception, None)

        # expect to have 3 events (there is a possibility that someone else could be running tests on this stripe account at the same time)
        # events returned sorted in reverse chronological order.
        evt_types = [event.type for event in events]
        self.assertTrue('charge.succeeded' in evt_types)
        self.assertTrue('customer.card.created' in evt_types)
        self.assertTrue('customer.created' in evt_types)

        # now feed each of the events to the IPN processor.
        ipn_url = reverse("HandleIPN", args=('stripelib',))

        for (i, event) in enumerate(events):
            r = self.client.post(ipn_url, data=json.dumps({"id": event.id}), content_type="application/json; charset=utf-8")
            self.assertEqual(r.status_code, 200)

        # expected notices

        self.assertEqual(len(Notice.objects.filter(notice_type__label='pledge_you_have_pledged', recipient__username='******')), 1)
        self.assertEqual(len(Notice.objects.filter(notice_type__label='pledge_charged', recipient__username='******')), 1)
Esempio n. 4
0
 def handle(self, *args, **kwargs):
     # test card
     sc = stripelib.StripeClient()
     card = stripelib.card(number="4242424242424242", exp_month="01", exp_year="2013", cvc="123")
     cust = sc.create_customer(card=card, description="William Shakespeare XIV (via test_stripe_charge)", email="*****@*****.**")
     print(cust)
     # let's charge RY $1.00
     charge = sc.create_charge(D('1.00'), customer=cust.id, description="$1 TEST CHARGE for Will S. XIV")
     print(charge)
Esempio n. 5
0
    def test_paymentmanager_charge(self):
        """
        test regluit.payment.manager.PaymentManager.charge
        
        trying to simulate the conditions of having a bare transaction setup before we try to do
        an instant charge.
        
        """
        user = User.objects.create_user('pm_charge', '*****@*****.**',
                                        'payment_test')
        # need to create an Account to associate with user
        from regluit.payment.stripelib import StripeClient, card, Processor

        sc = StripeClient()

        # valid card and Account
        card0 = card()
        stripe_processor = Processor()
        account = stripe_processor.make_account(user=user, token=card0)

        w = Work()
        w.save()

        c = Campaign(target=D('1000.00'),
                     deadline=now() + timedelta(days=180),
                     work=w)
        c.save()

        t = Transaction(host='stripelib')

        t.max_amount = D('12.34')
        t.type = PAYMENT_TYPE_NONE
        t.status = TRANSACTION_STATUS_NONE
        t.campaign = c
        t.approved = False
        t.user = user

        t.save()

        pm = PaymentManager()
        response = pm.charge(t)

        self.assertEqual(t.status, TRANSACTION_STATUS_COMPLETE)
        self.assertEqual(t.type, EXECUTE_TYPE_CHAINED_INSTANT)
        self.assertEqual(t.amount, D('12.34'))