Ejemplo n.º 1
0
    def test_authorization_action(self, mock_post, create_hash, get_current_host):
        """
        Play some posts that Vitepay might fire at us.
        """
        self.init_projects()
        order = OrderFactory.create()
        DonationFactory.create(amount=Money(2000, XOF), order=order)
        order_payment = OrderPaymentFactory.create(payment_method='vitepayOrangemoney', order=order)
        adapter = VitepayPaymentAdapter(order_payment)
        authorization_action = adapter.get_authorization_action()
        data = {
            u"api_key": u"123",
            u"hash": u"123123",
            u"redirect": 0,
            u"payment": {
                u"description": u"Thanks for your donation!",
                u"order_id": u"opc-{}".format(order_payment.id),
                u"decline_url": u"https://onepercentclub.com/orders/{}/failed".format(order_payment.order.id),
                u"p_type": u"orange_money",
                u"country_code": u"ML",
                u"language_code": u"fr",
                u"amount_100": 200000,
                u"cancel_url": u"https://onepercentclub.com/orders/{}/failed".format(order_payment.order.id),
                u"currency_code": u"XOF",
                u"callback_url": u"https://onepercentclub.com/payments_vitepay/status_update/",
                u"return_url": u"https://onepercentclub.com/orders/{}/success".format(order_payment.order.id)
            }
        }

        self.assertEqual(mock_post.call_args[0][0], 'https://api.vitepay.com/v1/prod/payments')
        self.assertEqual(json.loads(mock_post.call_args[1]['data']), data)
        self.assertEqual(mock_post.call_args[1]['headers'], {'Content-Type': 'application/json'})

        self.assertEqual(authorization_action['url'], 'https://vitepay.com/some-path-to-pay')
Ejemplo n.º 2
0
 def test_authorization_action(self, get_current_host, create_hash):
     """
     Play some posts that Vitepay might fire at us.
     """
     self.init_projects()
     order = OrderFactory.create()
     DonationFactory.create(amount=Money(2000, NGN), order=order)
     order_payment = OrderPaymentFactory.create(payment_method='interswitchWebpay', order=order)
     adapter = InterswitchPaymentAdapter(order_payment)
     authorization_action = adapter.get_authorization_action()
     redirect_url = 'https://onepercentclub.com/payments_interswitch/payment_response/{0}'.format(order_payment.id)
     data = {
         'hash': '123123',
         'product_id': '1234',
         'site_redirect_url': redirect_url,
         'local_date_time': None,
         'txn_ref': '-{0}'.format(order_payment.id),
         'cust_name': None,
         'currency': '566',
         'amount': 200000,
         'pay_item_name': None,
         'cust_id': None,
         'pay_item_id': '123',
         'site_name': 'testserver',
         'cust_id_desc': None,
         'cust_name_desc': None
     }
     self.assertEqual(authorization_action['url'], 'https://stageserv.interswitchng.com/test_paydirect/pay')
     self.assertEqual(authorization_action['payload'], data)
Ejemplo n.º 3
0
    def setUp(self):
        super(PaymentFeeTestCase, self).setUp()
        self.init_projects()

        self.order = OrderFactory.create()
        self.donation = DonationFactory(amount=60, order=self.order)
        self.order_payment = OrderPaymentFactory.create(order=self.order)
Ejemplo n.º 4
0
    def test_no_payment_method_change(self, mock_fetch_status,
                                      mock_transaction):
        self.assertEquals(PaymentLogEntry.objects.count(), 1)

        # Mock the status check with docdata
        mock_fetch_status.return_value = self.create_status_response(
            'AUTHORIZED')

        order = OrderFactory.create()
        order_payment = OrderPaymentFactory.create(
            order=order, payment_method='docdataCreditcard')
        docdata_payment = DocdataPaymentFactory.create(
            order_payment=order_payment,
            default_pm='mastercard',
            payment_cluster_id='1234',
            total_gross_amount=100)
        DocdataTransactionFactory.create(payment=docdata_payment,
                                         payment_method='VISA')
        c = Client()
        merchant_order_id = "{0}-1".format(order_payment.id)
        resp = c.get(reverse('docdata-payment-status-update',
                             kwargs={'merchant_order_id': merchant_order_id}))

        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp.content, 'success')

        # Reload the order payment
        order_payment = OrderPayment.objects.get(id=order_payment.id)
        self.assertEqual(order_payment.payment_method, 'docdataCreditcard')
Ejemplo n.º 5
0
    def test_incomplete_userdata(self, mock_client):
        # Mock response to creating the payment at docdata
        instance = mock_client.return_value
        instance.create.return_value = {'order_key': 123, 'order_id': 123}

        patch.object(DocdataPaymentAdapter, 'create_payment',
                     fake_create_payment)

        user = BlueBottleUserFactory()
        self.order = OrderFactory.create(user=user)
        self.order_payment = OrderPaymentFactory.create(
            order=self.order, payment_method='docdataIdeal',
            integration_data={'default_pm': 'ideal'})

        self.service = PaymentService(order_payment=self.order_payment)

        user_data = self.service.adapter.get_user_data()
        self.assertEqual(user_data['id'], user.id)
        self.assertEqual(user_data['first_name'], user.first_name)
        self.assertEqual(user_data['last_name'], user.last_name)
        self.assertEqual(user_data['email'], user.email)

        self.assertEqual(user_data['street'], 'Unknown')
        self.assertEqual(user_data['house_number'], 'Unknown')
        self.assertEqual(user_data['postal_code'], 'Unknown')
        self.assertEqual(user_data['city'], 'Unknown')
        self.assertEqual(user_data['country'], 'NL')

        self.assertEqual(user_data['company'], '')
        self.assertEqual(user_data['kvk_number'], '')
        self.assertEqual(user_data['vat_number'], '')
        self.assertEqual(user_data['house_number_addition'], '')
        self.assertEqual(user_data['state'], '')
Ejemplo n.º 6
0
    def setUp(self):
        super(TestRefund, self).setUp()

        self.init_projects()

        self.project = ProjectFactory.create(status=ProjectPhase.objects.get(
            slug='refunded'))

        self.order = OrderFactory.create()
        self.order_payment = OrderPaymentFactory.create(
            order=self.order,
            payment_method='docdataIdeal',
            integration_data={'default_pm': 'ideal'},
        )
        payment = DocdataPaymentFactory.create(
            order_payment=self.order_payment,
            payment_cluster_key='123-4',
            default_pm='ideal',
            total_gross_amount=100)

        DonationFactory.create(
            project=self.project,
            order=self.order,
            amount=Money(100, 'EUR'),
        )
        payment.status = 'authorized'
        payment.save()
        payment.status = 'settled'
        payment.save()

        self.project.refresh_from_db()
Ejemplo n.º 7
0
    def test_incomplete_userdata(self, mock_client):
        # Mock response to creating the payment at docdata
        instance = mock_client.return_value
        instance.create.return_value = {'order_key': 123, 'order_id': 123}

        patch.object(DocdataPaymentAdapter, 'create_payment',
                     fake_create_payment)

        user = BlueBottleUserFactory()
        self.order = OrderFactory.create(user=user)
        self.order_payment = OrderPaymentFactory.create(
            order=self.order,
            payment_method='docdataIdeal',
            integration_data={'default_pm': 'ideal'})

        self.service = PaymentService(order_payment=self.order_payment)

        user_data = self.service.adapter.get_user_data()
        self.assertEqual(user_data['id'], user.id)
        self.assertEqual(user_data['first_name'], user.first_name)
        self.assertEqual(user_data['last_name'], user.last_name)
        self.assertEqual(user_data['email'], user.email)

        self.assertEqual(user_data['street'], 'Unknown')
        self.assertEqual(user_data['house_number'], 'Unknown')
        self.assertEqual(user_data['postal_code'], 'Unknown')
        self.assertEqual(user_data['city'], 'Unknown')
        self.assertEqual(user_data['country'], 'NL')

        self.assertEqual(user_data['company'], '')
        self.assertEqual(user_data['kvk_number'], '')
        self.assertEqual(user_data['vat_number'], '')
        self.assertEqual(user_data['house_number_addition'], '')
        self.assertEqual(user_data['state'], '')
Ejemplo n.º 8
0
    def test_abnormal_address_data(self, mock_client):
        # Mock response to creating the payment at docdata
        instance = mock_client.return_value
        instance.create.return_value = {'order_key': 123, 'order_id': 123}

        patch.object(DocdataPaymentAdapter, 'create_payment',
                     fake_create_payment)

        user = BlueBottleUserFactory()
        CountryFactory(name='Netherlands', alpha2_code='NL')

        # Update user address with abnormal line1
        user.address.line1 = '1a'
        user.address.save()

        self.order = OrderFactory.create(user=user)
        self.order_payment = OrderPaymentFactory.create(
            order=self.order,
            payment_method='docdataIdeal',
            integration_data={'default_pm': 'ideal'})

        self.service = PaymentService(order_payment=self.order_payment)

        user_data = self.service.adapter.get_user_data()
        self.assertEqual(user_data['street'], 'Unknown')
Ejemplo n.º 9
0
    def test_no_payment_method_change(self, mock_fetch_status,
                                      mock_transaction):
        self.assertEquals(PaymentLogEntry.objects.count(), 1)

        # Mock the status check with docdata
        mock_fetch_status.return_value = self.create_status_response(
            'AUTHORIZED')

        order = OrderFactory.create()
        order_payment = OrderPaymentFactory.create(
            order=order, payment_method='docdataCreditcard')
        docdata_payment = DocdataPaymentFactory.create(
            order_payment=order_payment,
            default_pm='mastercard',
            payment_cluster_id='1234',
            total_gross_amount=100)
        DocdataTransactionFactory.create(payment=docdata_payment,
                                         payment_method='VISA')
        c = Client()
        merchant_order_id = "{0}-1".format(order_payment.id)
        resp = c.get(
            reverse('docdata-payment-status-update',
                    kwargs={'merchant_order_id': merchant_order_id}))

        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp.content, 'success')

        # Reload the order payment
        order_payment = OrderPayment.objects.get(id=order_payment.id)
        self.assertEqual(order_payment.payment_method, 'docdataCreditcard')
Ejemplo n.º 10
0
    def setUp(self):
        self.order = OrderFactory.create(total=Money(200, 'EUR'))
        self.order_payment = OrderPaymentFactory.create(
            payment_method='docdata', order=self.order)

        PaymentFactory.create(order_payment=self.order_payment)
        self.adapter = BasePaymentAdapter(self.order_payment)
Ejemplo n.º 11
0
    def test_create_payment_redirect(self, charge, get_current_host):
        """
        Test Flutterwave payment that turns to success without otp (one time pin)
        """
        self.init_projects()
        order = OrderFactory.create()
        DonationFactory.create(amount=Money(150000, NGN), order=order)
        order_payment = OrderPaymentFactory.create(
            payment_method='flutterwaveCreditcard',
            order=order,
            integration_data=integration_data)
        adapter = FlutterwaveCreditcardPaymentAdapter(order_payment)
        authorization_action = adapter.get_authorization_action()

        self.assertEqual(adapter.payment.amount, '150000.00')
        self.assertEqual(adapter.payment.status, 'started')
        self.assertEqual(adapter.payment.transaction_reference, 'FLW005')
        self.assertEqual(
            authorization_action, {
                'method': 'get',
                'payload': {
                    'method': 'flutterwave-otp',
                    'text': redirect_response['data']['responsemessage']
                },
                'type': 'redirect',
                'url': redirect_response['data']['authurl']
            })
Ejemplo n.º 12
0
    def setUp(self):
        super(PaymentFeeTestCase, self).setUp()
        self.init_projects()

        self.order = OrderFactory.create()
        self.donation = DonationFactory(amount=60, order=self.order)
        self.order_payment = OrderPaymentFactory.create(order=self.order)
Ejemplo n.º 13
0
    def setUp(self):
        super(PaymentMockTests, self).setUp()
        self.init_projects()

        self.order_payment = OrderPaymentFactory.create(status=StatusDefinition.CREATED, amount=100, payment_method='mock')
        self.user1 = BlueBottleUserFactory.create()
        self.user1_token = "JWT {0}".format(self.user1.get_jwt_token())
Ejemplo n.º 14
0
    def test_refund_created_payment(self):
        order = OrderFactory.create()
        order_payment = OrderPaymentFactory.create(
            order=order,
            payment_method='docdataIdeal',
            integration_data={'default_pm': 'ideal'},
        )
        DocdataPaymentFactory.create(order_payment=order_payment,
                                     payment_cluster_key='456-4',
                                     payment_cluster_id='test',
                                     default_pm='ideal',
                                     total_gross_amount=100)

        DonationFactory.create(
            project=self.project,
            order=order,
            amount=Money(100, 'EUR'),
        )

        with mock.patch.object(DocdataPaymentAdapter,
                               'refund_payment',
                               side_effect=self.mock_side_effect) as refund:
            refund_project(connection.tenant, self.project)

        self.order = Order.objects.get(pk=self.order.pk)
        self.assertEqual(refund.call_count, 1)
        self.assertEqual(self.order.status, 'refund_requested')

        self.order_payment.payment.status = 'refunded'
        self.order_payment.payment.save()

        self.order = Order.objects.get(pk=self.order.pk)
        self.assertEqual(self.order.status, 'cancelled')
Ejemplo n.º 15
0
    def setUp(self):
        super(TestPledgeMails, self).setUp()

        self.init_projects()

        self.user = BlueBottleUserFactory(can_pledge=True)
        self.project_owner = BlueBottleUserFactory(username='******',
                                                   email='*****@*****.**',
                                                   password='******')
        self.organization = OrganizationFactory.create(name='test_org',
                                                       slug='test_org')

        self.project = ProjectFactory(owner=self.project_owner,
                                      organization=self.organization,
                                      title='Project 1',
                                      amount_needed=1111,
                                      amount_asked=1111)
        self.order = OrderFactory.create(user=self.user)
        self.donation = DonationFactory(amount=60,
                                        order=self.order,
                                        project=self.project,
                                        fundraiser=None)

        self.order_payment = OrderPaymentFactory.create(
            order=self.order, payment_method='pledgeStandard')
        self.order_payment.pledged()
        self.order_payment.save()
Ejemplo n.º 16
0
    def setUp(self):
        self.user = BlueBottleUserFactory.create(can_pledge=True)

        self.order = OrderFactory.create(user=self.user)
        self.order_payment = OrderPaymentFactory.create(
            order=self.order, user=self.user, payment_method='pledgeStandard'
        )
Ejemplo n.º 17
0
    def test_normal_userdata(self, mock_client_create):
        mock_client_create.return_value = {'order_key': 123, 'order_id': 123}
        mock_create_payment = patch.object(DocdataPaymentAdapter, 'create_payment', fake_create_payment)

        user = BlueBottleUserFactory()
        holland = CountryFactory(name='Netherlands', alpha2_code='NL')

        address = BlueBottleAddressFactory(user=user, line1='Dam 1a', line2='Bovenste bel', city='Amsterdam',
                                           postal_code='1000AA', country=holland)

        self.order = OrderFactory.create(user=user)
        self.order_payment = OrderPaymentFactory.create(order=self.order, payment_method='docdataIdeal',
                                                        integration_data={'default_pm': 'ideal'})

        self.service = PaymentService(order_payment=self.order_payment)

        user_data = self.service.adapter.get_user_data()
        self.assertEqual(user_data['id'], user.id)
        self.assertEqual(user_data['first_name'], user.first_name)
        self.assertEqual(user_data['last_name'], user.last_name)
        self.assertEqual(user_data['email'], user.email)

        self.assertEqual(user_data['street'], 'Dam')
        self.assertEqual(user_data['house_number'], '1a')
        self.assertEqual(user_data['postal_code'], '1000AA')
        self.assertEqual(user_data['city'], 'Amsterdam')
        self.assertEqual(user_data['country'], 'NL')

        self.assertEqual(user_data['company'], '')
        self.assertEqual(user_data['kvk_number'], '')
        self.assertEqual(user_data['vat_number'], '')
        self.assertEqual(user_data['house_number_addition'], '')
        self.assertEqual(user_data['state'], '')
Ejemplo n.º 18
0
    def test_authorization_action(self, mock_post, create_hash, get_current_host):
        """
        Play some posts that Vitepay might fire at us.
        """
        self.init_projects()
        order = OrderFactory.create()
        DonationFactory.create(amount=Money(2000, XOF), order=order)
        order_payment = OrderPaymentFactory.create(payment_method="vitepayOrangemoney", order=order)
        adapter = VitepayPaymentAdapter(order_payment)
        authorization_action = adapter.get_authorization_action()
        data = {
            u"api_key": u"123",
            u"hash": u"123123",
            u"redirect": 0,
            u"payment": {
                u"description": u"Thanks for your donation!",
                u"order_id": u"opc-{}".format(order_payment.id),
                u"decline_url": u"https://onepercentclub.com/orders/{}/failed".format(order_payment.order.id),
                u"p_type": u"orange_money",
                u"country_code": u"ML",
                u"language_code": u"fr",
                u"amount_100": 200000,
                u"cancel_url": u"https://onepercentclub.com/orders/{}/failed".format(order_payment.order.id),
                u"currency_code": u"XOF",
                u"callback_url": u"https://onepercentclub.com/payments_vitepay/status_update/",
                u"return_url": u"https://onepercentclub.com/orders/{}/success".format(order_payment.order.id),
            },
        }

        self.assertEqual(mock_post.call_args[0][0], "https://api.vitepay.com/v1/prod/payments")
        self.assertEqual(json.loads(mock_post.call_args[1]["data"]), data)
        self.assertEqual(mock_post.call_args[1]["headers"], {"Content-Type": "application/json"})

        self.assertEqual(authorization_action["url"], "https://vitepay.com/some-path-to-pay")
Ejemplo n.º 19
0
    def setUp(self):
        super(PaymentsMockTestCase, self).setUp()

    	self.init_projects()

        self.order = OrderFactory.create(total=35)
        self.order_payment = OrderPaymentFactory.create(order=self.order, payment_method='mock')
        self.service = PaymentService(order_payment=self.order_payment)
Ejemplo n.º 20
0
    def setUp(self):
        super(PaymentMockTests, self).setUp()
        self.init_projects()

        self.order_payment = OrderPaymentFactory.create(
            status=StatusDefinition.CREATED, amount=100, payment_method='mock')
        self.user1 = BlueBottleUserFactory.create()
        self.user1_token = "JWT {0}".format(self.user1.get_jwt_token())
Ejemplo n.º 21
0
 def setUp(self):
     self.order = OrderFactory.create()
     self.donation = DonationFactory.create(amount=Money(1500, KES), order=self.order)
     self.order_payment = OrderPaymentFactory.create(
         payment_method='lipishaMpesa',
         order=self.order
     )
     self.adapter = LipishaPaymentAdapter(self.order_payment)
Ejemplo n.º 22
0
    def setUp(self):
        super(PaymentsMockTestCase, self).setUp()

        self.init_projects()

        self.order = OrderFactory.create(total=35)
        self.order_payment = OrderPaymentFactory.create(order=self.order,
                                                        payment_method='mock')
        self.service = PaymentService(order_payment=self.order_payment)
Ejemplo n.º 23
0
 def test_no_success_payment_status_check(self, mock_check_payment_status):
     self.order = OrderFactory.create(user=self.user1, total=15)
     self.order_payment = OrderPaymentFactory.create(order=self.order,
                                                     payment_method='mock')
     self.service = PaymentService(order_payment=self.order_payment)
     self.client.get(reverse('manage-order-detail',
                             kwargs={'pk': self.order.id}),
                     token=self.user1_token)
     self.assertEqual(mock_check_payment_status.called, True)
Ejemplo n.º 24
0
    def setUp(self, mock_client_create):
        super(TestPaymentLogger, self).setUp()

        mock_client_create.return_value = {'order_key': 123, 'order_id': 123}

        self.order = OrderFactory.create(total=35)
        self.order_payment = OrderPaymentFactory.create(payment_method='docdataIdeal', order=self.order,
                                                        integration_data={'default_pm': 'ideal'})
        self.service = PaymentService(self.order_payment)
Ejemplo n.º 25
0
 def test_create_only_one_payment(self, get_current_host):
     self.init_projects()
     order = OrderFactory.create()
     DonationFactory.create(amount=Money(2000, NGN), order=order)
     order_payment = OrderPaymentFactory.create(payment_method='interswitchWebpay', order=order)
     InterswitchPaymentAdapter(order_payment)
     self.assertEqual(InterswitchPayment.objects.count(), 1)
     InterswitchPaymentAdapter(order_payment)
     self.assertEqual(InterswitchPayment.objects.count(), 1)
Ejemplo n.º 26
0
 def test_no_success_payment_status_check(self, mock_check_payment_status):
     self.order = OrderFactory.create(user=self.user1, total=15)
     self.order_payment = OrderPaymentFactory.create(order=self.order,
                                                     payment_method='mock')
     self.service = PaymentService(order_payment=self.order_payment)
     self.client.get(reverse('order-manage-detail',
                             kwargs={'pk': self.order.id}),
                     token=self.user1_token)
     self.assertEqual(mock_check_payment_status.called, True)
Ejemplo n.º 27
0
    def setUp(self):
        self.order = OrderFactory.create(total=Money(200, 'EUR'))
        self.order_payment = OrderPaymentFactory.create(
            payment_method='docdata',
            order=self.order
        )

        PaymentFactory.create(order_payment=self.order_payment)
        self.adapter = BasePaymentAdapter(self.order_payment)
Ejemplo n.º 28
0
 def test_payment_country_without_profile(self, mock_client):
     # For anonymous donations the default from settings should be used.
     instance = mock_client.return_value
     instance.create.return_value = {'order_key': 123, 'order_id': 123}
     order_payment = OrderPaymentFactory(
         payment_method='docdataCreditcard',
         integration_data={'default_pm': 'mastercard'})
     self.adapter = DocdataPaymentAdapter(order_payment=order_payment)
     payment = self.adapter.payment
     self.assertEqual(payment.country, 'BG')
Ejemplo n.º 29
0
    def test_success_payment_status_check(self, mock_check_payment_status):
        self.order = OrderFactory.create(user=self.user1, total=15,
                                         status=StatusDefinition.SUCCESS)
        self.order_payment = OrderPaymentFactory.create(order=self.order,
                                                        payment_method='mock',
                                                        status=StatusDefinition.AUTHORIZED)

        self.client.get(reverse('manage-order-detail',
                                kwargs={'pk': self.order.id}),
                        token=self.user1_token)
        self.assertEqual(mock_check_payment_status.called, False)
Ejemplo n.º 30
0
    def setUp(self, mock_client_create):
        # Mock response to creating the payment at docdata
        mock_client_create.return_value = {'order_key': 123, 'order_id': 123}

        # Mock create payment
        mock_create_payment = patch.object(DocdataPaymentAdapter, 'create_payment', fake_create_payment)

        self.order = OrderFactory.create()
        self.order_payment = OrderPaymentFactory.create(order=self.order, payment_method='docdataIdeal',
                                                        integration_data={'default_pm': 'ideal'})
        self.service = PaymentService(order_payment=self.order_payment)
Ejemplo n.º 31
0
 def test_direct_debit_wrong_pm(self):
     """
     Test that a direct debit payments default_pm will be forced
     to 'sepa_direct_debit'.
     """
     order_payment = OrderPaymentFactory.create(amount=1000)
     docdata_payment = DocdataDirectdebitPaymentFactory.create(
         order_payment=order_payment,
         default_pm='ideal',
         total_gross_amount=1000)
     self.assertEqual(docdata_payment.default_pm, 'sepa_direct_debit')
Ejemplo n.º 32
0
 def setUp(self):
     super(TestProjectExport, self).setUp()
     self.project = ProjectFactory.create(amount_asked=5000)
     self.user = BlueBottleUserFactory.create()
     self.orders = OrderFactory.create_batch(7)
     for order in self.orders:
         DonationFactory.create(project=self.project, order=order)
         order_payment = OrderPaymentFactory(order=order)
         payment = PaymentFactory(order_payment=order_payment)
         payment.status = 'settled'
         payment.save()
Ejemplo n.º 33
0
    def test_status_without_order(self, mock_client):
        credentials = {
            'merchant_name': 'test',
            'merchant_password': '******',
        }
        self.gateway = DocdataClient(credentials)
        order_payment = OrderPaymentFactory()
        DocdataDirectdebitPaymentFactory(order_payment=order_payment)

        with self.assertRaisesMessage(PaymentException, 'Missing order_key!'):
            self.gateway.status(order_key=None)
Ejemplo n.º 34
0
    def test_start_remote_payment(self, mock_client):
        credentials = {
            'merchant_name': 'test',
            'merchant_password': '******',
        }
        self.gateway = DocdataClient(credentials)
        order_payment = OrderPaymentFactory()
        payment = DocdataDirectdebitPaymentFactory(order_payment=order_payment)

        result = self.gateway.start_remote_payment(order_key='123',
                                                   payment=payment)
        self.assertEqual(result, 'GHGHGHG')
Ejemplo n.º 35
0
 def test_direct_debit_wrong_pm(self):
     """
     Test that a direct debit payments default_pm will be forced
     to 'sepa_direct_debit'.
     """
     order_payment = OrderPaymentFactory.create(amount=1000)
     docdata_payment = DocdataDirectdebitPaymentFactory.create(
         order_payment=order_payment,
         default_pm='ideal',
         total_gross_amount=1000
     )
     self.assertEqual(docdata_payment.default_pm, 'sepa_direct_debit')
Ejemplo n.º 36
0
 def test_create_success_payment(self):
     """
     Test External payment
     """
     order = OrderFactory.create()
     DonationFactory.create(amount=Money(70, EUR), order=order)
     order_payment = OrderPaymentFactory.create(
         payment_method='externalMoney', order=order)
     order_payment.started()
     adapter = ExternalPaymentAdapter(order_payment)
     adapter.check_payment_status()
     self.assertEqual(adapter.payment.status, 'settled')
Ejemplo n.º 37
0
    def setUp(self, mock_client_create):
        super(TestPaymentLoggerAdapter, self).setUp()

        # Mock response to creating the payment at docdata
        mock_client_create.return_value = {'order_key': 123, 'order_id': 123}

        self.order = OrderFactory.create()
        self.order_payment = OrderPaymentFactory.create(payment_method='docdata', order=self.order,
                                                        integration_data={'default_pm': 'ideal'})
        self.service = PaymentService(self.order_payment)

        PaymentLogEntry.objects.all().delete()
Ejemplo n.º 38
0
    def test_status(self, mock_client):
        credentials = {
            'merchant_name': 'test',
            'merchant_password': '******',
        }
        self.gateway = DocdataClient(credentials)
        order_payment = OrderPaymentFactory()
        DocdataDirectdebitPaymentFactory(order_payment=order_payment)

        with self.assertRaisesMessage(PaymentException,
                                      'Payment not found here...'):
            self.gateway.status(order_key=123)
Ejemplo n.º 39
0
    def test_success_payment_status_check(self, mock_check_payment_status):
        self.order = OrderFactory.create(user=self.user1,
                                         total=15,
                                         status=StatusDefinition.SUCCESS)
        self.order_payment = OrderPaymentFactory.create(
            order=self.order,
            payment_method='mock',
            status=StatusDefinition.AUTHORIZED)

        self.client.get(reverse('order-manage-detail',
                                kwargs={'pk': self.order.id}),
                        token=self.user1_token)
        self.assertEqual(mock_check_payment_status.called, False)
Ejemplo n.º 40
0
    def test_order_status_cannot_pledge(self):
        """
        Normal user can not pledge
        """
        user = BlueBottleUserFactory()

        order = OrderFactory.create(user=user)
        order_payment = OrderPaymentFactory.create(
            order=order, user=user, payment_method='pledgeStandard'
        )

        with self.assertRaises(PaymentException):
            self.service = PaymentService(order_payment=order_payment)
Ejemplo n.º 41
0
 def test_payment_country_without_user(self, mock_client):
     # For donations without users some defaults should be used
     instance = mock_client.return_value
     instance.create.return_value = {'order_key': 123, 'order_id': 123}
     order_payment = OrderPaymentFactory(
         payment_method='docdataCreditcard',
         integration_data={'default_pm': 'ideal'})
     order_payment.order.user = None
     order_payment.order.save()
     self.adapter = DocdataPaymentAdapter(order_payment=order_payment)
     payment = self.adapter.payment
     self.assertEqual(payment.first_name, 'Nomen')
     self.assertEqual(payment.last_name, 'Nescio')
Ejemplo n.º 42
0
 def test_payment_country_with_profile_without_country(self, mock_client):
     # If no country specified in profile the default from settings should be used
     instance = mock_client.return_value
     instance.create.return_value = {'order_key': 123, 'order_id': 123}
     user = BlueBottleUserFactory()
     order_payment = OrderPaymentFactory(
         user=user,
         payment_method='docdataCreditcard',
         integration_data={'default_pm': 'mastercard'})
     order_payment.order.user = user
     self.adapter = DocdataPaymentAdapter(order_payment=order_payment)
     payment = self.adapter.payment
     self.assertEqual(payment.country, 'BG')
Ejemplo n.º 43
0
 def setUp(self):
     super(PaymentsDocdataAdapterRefundTestCase, self).setUp()
     self.order_payment = OrderPaymentFactory.create(
         status='started',
         payment_method='docdataIdeal',
         integration_data={'default_pm': 'ideal'},
         order=OrderFactory.create(status='locked'))
     DocdataPaymentFactory.create(order_payment=self.order_payment,
                                  payment_cluster_key='123-4',
                                  default_pm='ideal',
                                  total_gross_amount=100,
                                  status='settled')
     self.adapter = DocdataPaymentAdapter(self.order_payment)
Ejemplo n.º 44
0
    def test_start_remote_payment(self, mock_client):
        credentials = {
            'merchant_name': 'test',
            'merchant_password': '******',
        }
        self.gateway = DocdataClient(credentials)
        order_payment = OrderPaymentFactory()
        payment = DocdataDirectdebitPaymentFactory(order_payment=order_payment)

        with self.assertRaisesMessage(
                PaymentException, 'Received unknown reply from DocData. '
                'WebDirect payment not created.'):
            self.gateway.start_remote_payment(order_key='123', payment=payment)
Ejemplo n.º 45
0
 def test_create_payment_incomplete(self, charge, get_current_host):
     """
     Test Flutterwave payment throws an error when incomplete data is sent
     """
     self.init_projects()
     order = OrderFactory.create()
     DonationFactory.create(amount=Money(150000, NGN), order=order)
     order_payment = OrderPaymentFactory.create(
         payment_method='flutterwaveCreditcard',
         order=order,
         integration_data={'card_number': '123blabla'})
     with self.assertRaises(PaymentException):
         FlutterwaveCreditcardPaymentAdapter(order_payment)
Ejemplo n.º 46
0
    def test_get_fee_absolute(self):
        """
            Test that the correct fee is returned given the defined percentage. In this test case the
            amount is 100 and the fee percentage is 1.5%, so the result should be 100 * 0.015.
        """

        order_payment = OrderPaymentFactory.create(amount=1000)
        docdata_payment = DocdataPaymentFactory.create(order_payment=order_payment,
                                                       default_pm='ideal',
                                                       total_gross_amount=1000)
        order_payment.amount = 100
        fee_total = docdata_payment.get_fee()
        self.assertEqual(fee_total, 100 * 0.015)
Ejemplo n.º 47
0
    def test_order_status_can_pledge(self):
        """
        User with can_pledge setting enabled is allowed to pledge
        """
        user = BlueBottleUserFactory(can_pledge=True)

        order = OrderFactory.create(user=user)
        order_payment = OrderPaymentFactory.create(
            order=order, user=user, payment_method='pledgeStandard'
        )
        PaymentService(order_payment=order_payment)

        # Check that the status propagated through to order
        self.assert_status(order, StatusDefinition.PLEDGED)
Ejemplo n.º 48
0
    def setUp(self):
        super(TestOrderPermissions, self).setUp()

        self.user1 = BlueBottleUserFactory.create()
        self.user1_token = "JWT {0}".format(self.user1.get_jwt_token())

        self.user2 = BlueBottleUserFactory.create()
        self.user2_token = "JWT {0}".format(self.user2.get_jwt_token())

        self.order = OrderFactory.create(user=self.user1,
                                         status=StatusDefinition.SUCCESS)
        self.order_payment = OrderPaymentFactory.create(order=self.order,
                                                        payment_method='mock',
                                                        status=StatusDefinition.SUCCESS)
Ejemplo n.º 49
0
    def test_unknown_payment_method_change(self, mock_fetch_status,
                                           mock_transaction):
        self.skipTest('Skipping test until we update it.')

        # Two payment log entries already exist: 2x 'a new payment status "started" '
        self.assertEquals(PaymentLogEntry.objects.count(), 2)

        # Mock the status check with docdata
        mock_fetch_status.return_value = self.create_status_response(
            'AUTHORIZED')

        order = OrderFactory.create()
        # Ensure that we use an existing payment_method or the adapter throws an exception
        order_payment = OrderPaymentFactory.create(order=order,
                                                   payment_method='docdataPaypal')
        docdata_payment = DocdataPaymentFactory.create(
            order_payment=order_payment,
            default_pm='paypal',
            payment_cluster_id='1236',
            total_gross_amount=100)

        DocdataTransactionFactory.create(payment=docdata_payment,
                                         payment_method='BLABLABLA')
        c = Client()
        merchant_order_id = "{0}-1".format(order_payment.id)
        resp = c.get(reverse('docdata-payment-status-update',
                             kwargs={'merchant_order_id': merchant_order_id}))
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp.content, 'success')

        # Reload the order payment
        order_payment = OrderPayment.objects.get(id=order_payment.id)
        self.assertEqual(order_payment.payment_method, 'docdataPaypal')

        # Check that all is logged correctly
        self.assertEquals(
            PaymentLogEntry.objects.filter(payment=docdata_payment).count(), 5)
        log = PaymentLogEntry.objects.all()[0]
        self.assertEqual(log.message,
                         "{0} - Payment method '{1}' not found for payment "
                         "with id {2} and order payment with id {3}.".format(
                             docdata_payment,
                             'BLABLABLA',
                             docdata_payment.id,
                             docdata_payment.order_payment.id))
        self.assertEqual(log.payment.id, docdata_payment.id)
        self.assertEqual(log.level, 'WARNING')
Ejemplo n.º 50
0
    def test_abnormal_address_data(self, mock_client_create):
        mock_client_create.return_value = {'order_key': 123, 'order_id': 123}
        mock_create_payment = patch.object(DocdataPaymentAdapter, 'create_payment', fake_create_payment)

        user = BlueBottleUserFactory()
        holland = CountryFactory(name='Netherlands', alpha2_code='NL')

        # Update user address with abnormal line1
        user.address.line1 = '1a'
        user.address.save()

        self.order = OrderFactory.create(user=user)
        self.order_payment = OrderPaymentFactory.create(order=self.order, payment_method='docdataIdeal',
                                                        integration_data={'default_pm': 'ideal'})

        self.service = PaymentService(order_payment=self.order_payment)

        user_data = self.service.adapter.get_user_data()
        self.assertEqual(user_data['street'], 'Unknown')
Ejemplo n.º 51
0
    def setUp(self):
        super(TestPledgeMails, self).setUp()

        self.init_projects()

        self.user = BlueBottleUserFactory(can_pledge=True)
        self.project_owner = BlueBottleUserFactory(username="******", email="*****@*****.**", password="******")
        self.organization = OrganizationFactory.create(name="test_org", slug="test_org")

        self.project = ProjectFactory(
            owner=self.project_owner,
            organization=self.organization,
            title="Project 1",
            amount_needed=1111,
            amount_asked=1111,
        )
        self.order = OrderFactory.create(user=self.user)
        self.donation = DonationFactory(amount=60, order=self.order, project=self.project, fundraiser=None)

        self.order_payment = OrderPaymentFactory.create(order=self.order, payment_method="pledgeStandard")
        self.order_payment.pledged()
        self.order_payment.save()
    def test_statistics_more_complex_case(self):
        """
        Besides all orders, donations and transactions that are created in the SetUp,
        this test creates:

        - two more BankTransactions (one remotePayout and one remotePayment)
        - one extra donation that belongs to an failed order
        - one order payment that has no payment, its should appear in the invalid_order_payments
        - one transaction that has IntegretyStatus mismatch
        - one project_payouts with status = 'in_progress'
        - one project_payout with status = 'new'
        - one more bank transaction (not connected to any payout or payment) that is debit

        and all these cases are checked to appear correctly in the statistics ouput
        """
        # ##### EXTRA BANK TRANSACTIONS (RemotePayout and RemotePayment) ##### #
        remoteDDPayout1 = RemoteDocdataPayoutFactory.create(collected_amount=Decimal('1.11'),
                                                            payout_amount=Decimal('1.11'))
        BankTransactionFactory.create(amount=Decimal('1.11'), category=self.DOCDATA_PAYOUT,
                                      credit_debit=self.creditdebit.credit, status=self.status.Valid,
                                      payout=None,
                                      remote_payout=remoteDDPayout1,
                                      remote_payment=None)
        remoteDDPayout2 = RemoteDocdataPayoutFactory.create(collected_amount=Decimal('0.14'),
                                                                payout_amount=Decimal('0.14'))
        remoteDDPayment = RemoteDocdataPaymentFactory.create(remote_payout=remoteDDPayout2,
                                                             local_payment=self.payment,
                                                             amount_collected=Decimal('0.14'),
                                                             docdata_fee=Decimal('0.02'))
        BankTransactionFactory.create(amount=Decimal('0.14'), category=self.DOCDATA_PAYMENT,
                                      credit_debit=self.creditdebit.credit, status=self.status.Valid,
                                      payout=None,
                                      remote_payout=None,
                                      remote_payment=remoteDDPayment)

        # ##### EXTRA DONATION ##### #
        failed_order = OrderFactory.create(user=self.person2, status='failed')
        failed_donation = DonationFactory(order=failed_order, project=self.project1, amount=33000)

        # ##### EXTRA ORDER PAYMENT ##### #
        order = OrderFactory.create(user=self.person2)
        self.assertEqual(order.status, 'created')

        order_payment = OrderPaymentFactory.create(order=order, amount=Decimal('77'))
        self.assertEqual(OrderPayment.objects.filter(payment=None).first().pk, order_payment.pk)
        self.assertEqual(order_payment.amount.amount, 0.00) # because it has no payment

        # ##### EXTRA BANKTRANSACTIONS  ##### #
        BankTransactionFactory.create(amount=Decimal('77'),
                                      category=self.CAMPAIGN_PAYOUT,
                                      credit_debit=self.creditdebit.credit,
                                      status=self.status.UnknownTransaction,
                                      payout=None,
                                      remote_payout=None,
                                      remote_payment=None,
                                      )
        BankTransactionFactory.create(amount=Decimal('500'),
                                      category=self.CAMPAIGN_PAYOUT,
                                      credit_debit=self.creditdebit.debit,
                                      status=self.status.Valid,
                                      payout=None,
                                      remote_payout=None,
                                      remote_payment=None,
                                      )

        # ##### EXTRA PROJECT_PAYOUT ##### #
        ProjectPayoutFactory.create(
            completed=self.middle_date, status=StatusDefinition.IN_PROGRESS, project=self.project1,
            amount_raised=444, organization_fee=0, amount_payable=444)

        ProjectPayoutFactory.create(
            completed=self.middle_date, status=StatusDefinition.NEW, project=self.project1,
            amount_raised=Decimal('22.95'), organization_fee=0, amount_payable=Decimal('22.95'))

        #
        # #### TEST STATISTICS #### #
        #
        stats = get_accounting_statistics(self.last_year, self.today + timedelta(days=1))
        stats_keys = stats.keys()
        self.assertEqual(set(stats_keys), {'project_payouts', 'donations', 'docdata', 'bank', 'orders'})

        # ##### DONATIONS ##### #
        # only donations that have an order with status 'success' appear in the donations stats
        stats_donations = stats['donations']
        self.assertEqual(stats_donations.get('count'), 3) # 111 + 222 for project 1 and 1000 for project 2
        self.assertEqual(stats_donations.get('total_amount'), Decimal('1333'))

        # ##### ORDER PAYMENTS ##### #
        # only project 1 is added to an order payment
        stats_orders = stats['orders']
        self.assertEqual(stats_orders.get('count'), 1)
        self.assertEqual(stats_orders.get('total_amount'), Decimal('333.00'))
        self.assertEqual(stats_orders.get('transaction_fee'), Decimal())

        # ##### PROJECT PAYOUTS ##### #
        stats_project_payouts = stats['project_payouts']
        self.assertEqual(stats_project_payouts.get('count'), 4) # includes one in progress, and one pending
        self.assertEqual(stats_project_payouts.get('organization_fee'), Decimal('50'))
        self.assertEqual(stats_project_payouts.get('raised'), Decimal('1799.95')) # 1000 + 333 + 444 + 22.95
        self.assertEqual(stats_project_payouts.get('payable'),Decimal('1749.95')) # above - 50

        # ##### DOCDATA ##### #
        stats_docdata = stats['docdata']
        self.assertEqual(stats_docdata.get('pending_orders'), Decimal('311.75')) # = 333 - 20 - 1.11 - 0.14
        self.assertEqual(stats_docdata.get('pending_payout'), Decimal('122.48')) #  123.45 + 0.14 - 1.11
        self.assertEqual(stats_docdata.get('pending_service_fee'), Decimal('-0.35')) # 0.33 + 0.02

        stats_docdata_payment = stats_docdata['payment']
        self.assertEqual(stats_docdata_payment.get('count'), 2)
        self.assertEqual(stats_docdata_payment.get('docdata_fee'), Decimal('0.35')) # 0.33 + 0.02
        self.assertEqual(stats_docdata_payment.get('third_party'), Decimal())
        self.assertEqual(stats_docdata_payment.get('total_amount'), Decimal('123.59')) # 123.45 + 0.14

        stats_docdata_payout = stats_docdata['payout']
        self.assertEqual(stats_docdata_payout.get('count'), 3)
        self.assertEqual(stats_docdata_payout.get('other_costs'), Decimal('101.99')) # = 123.45 - (20 + 0.33) -(1.11 + 0.02)
        self.assertEqual(stats_docdata_payout.get('total_amount'),Decimal('21.25')) # 20 + 1.11 + 0.14

        # ##### BANK ##### #
        stats_bank = stats['bank']

        # ##### BANK ALL ##### #
        stats_bank_all = stats_bank[0]
        self.assertEqual(stats_bank_all.get('name'), 'All')
        self.assertEqual(stats_bank_all.get('account_number'), '')
        self.assertEqual(stats_bank_all.get('count'), 5)
        self.assertEqual(stats_bank_all.get('credit'), Decimal('1078.25')) # 1000 + 77 (mismatch) + 1.11 + 0.14
        self.assertEqual(stats_bank_all.get('debit'), Decimal('500'))
        self.assertEqual(stats_bank_all.get('balance'), Decimal('578.25'))

        per_category = stats_bank_all['per_category']
        for cat_dict in per_category:
            if cat_dict.get('category') == self.CAMPAIGN_PAYOUT:
                self.assertEqual(cat_dict.get('credit'), Decimal('1077')) # 1000 + 77 (mismatch)
                self.assertEqual(cat_dict.get('debit'), Decimal('500'))
                self.assertEqual(cat_dict.get('balance'), Decimal('577'))
            elif cat_dict.get('category') == self.DOCDATA_PAYOUT:
                self.assertEqual(cat_dict.get('credit'), Decimal('1.11'))
                self.assertEqual(cat_dict.get('debit'), Decimal())
                self.assertEqual(cat_dict.get('balance'), Decimal('1.11'))
            elif cat_dict.get('category') == self.DOCDATA_PAYMENT:
                self.assertEqual(cat_dict.get('credit'), Decimal('0.14'))
                self.assertEqual(cat_dict.get('debit'), Decimal())
                self.assertEqual(cat_dict.get('balance'), Decimal('0.14'))
            else: # all other categories should have zero
                self.assertEqual(cat_dict.get('credit'), 0)
                self.assertEqual(cat_dict.get('debit'), 0)
                self.assertEqual(cat_dict.get('balance'), 0)

        # ##### BANK CHECKINGS##### #
        stats_bank_checking = stats_bank[1]
        self.assertEqual(stats_bank_checking.get('name'), 'Checking account')
        self.assertEqual(stats_bank_checking.get('balance'), Decimal())
        self.assertEqual(stats_bank_checking.get('count'), 0)
        self.assertEqual(stats_bank_checking.get('credit'), Decimal())
        self.assertEqual(stats_bank_checking.get('debit'), 0)

        # ##### BANK SAVINGS##### #
        stats_bank_savings = stats_bank[2]
        self.assertEqual(stats_bank_savings.get('name'), 'Savings account')
        self.assertEqual(stats_bank_savings.get('balance'), Decimal())
        self.assertEqual(stats_bank_savings.get('count'), 0)
        self.assertEqual(stats_bank_savings.get('credit'), Decimal())
        self.assertEqual(stats_bank_savings.get('debit'), 0)

        #
        # ##### TEST DASHBOARD VALUES ##### #
        #
        values = get_dashboard_values(self.last_year, self.today + timedelta(days=1))

        # ##### DONATIONS ##### #
        donations = values.get('donations')
        donations_count = values.get('donations_count')
        donations_amount = values.get('donations_amount')
        self.assertTrue(donations.exists())
        self.assertEqual(donations_count, 4) # also includes failed order
        self.assertEqual(donations_amount, Decimal('34333')) # 33000 (failed order) + 1000 + 222 + 111

        donations_settled = values.get('donations_settled')
        donations_settled_count = values.get('donations_settled_count')
        donations_settled_amount = values.get('donations_settled_amount')
        self.assertTrue(donations_settled.exists())
        self.assertEqual(donations_settled_count, 3)
        self.assertEqual(donations_settled_amount, Decimal('1333'))

        donations_failed = values.get('donations_failed')
        donations_failed_count = values.get('donations_failed_count')
        donations_failed_amount = values.get('donations_failed_amount')
        self.assertTrue(donations_failed.exists())
        self.assertEqual(donations_failed_count, 1)
        self.assertEqual(donations_failed_amount, Decimal(33000))

        # ##### PROJECT PAYOUTS ##### #
        project_payouts = values.get('project_payouts')
        project_payouts_count = values.get('project_payouts_count')
        project_payouts_amount = values.get('project_payouts_amount')
        self.assertTrue(project_payouts.exists())
        self.assertEqual(project_payouts_count, 4) # includes in 'progress' and 'new' payout
        self.assertEqual(project_payouts_amount, Decimal('1799.95')) # 1000 + 333 + 444 + 22.95
        # PENDING
        project_payouts_pending = values.get('project_payouts_pending')
        project_payouts_pending_amount = values.get('project_payouts_pending_amount')
        self.assertTrue(project_payouts_pending.exists())
        self.assertEqual(project_payouts_pending_amount, Decimal('466.95')) # 444 + 22.95
        # PENDING NEW
        project_payouts_pending_new = values.get('project_payouts_pending_new')
        project_payouts_pending_new_count = values.get('project_payouts_pending_new_count')
        project_payouts_pending_new_amount = values.get('project_payouts_pending_new_amount')
        self.assertTrue(project_payouts_pending_new.exists())
        self.assertEqual(project_payouts_pending_new_count, 1)
        self.assertEqual(project_payouts_pending_new_amount, Decimal('22.95'))
        # PENDING IN PROGRESS
        project_payouts_pending_in_progress = values.get('project_payouts_pending_in_progress')
        project_payouts_pending_in_progress_amount = values.get('project_payouts_pending_in_progress_amount')
        project_payouts_pending_in_progress_count = values.get('project_payouts_pending_in_progress_count')
        self.assertTrue(project_payouts_pending_in_progress.exists())
        self.assertEqual(project_payouts_pending_in_progress_count, 1)
        self.assertEqual(project_payouts_pending_in_progress_amount, Decimal('444'))
        # PENDING SETTLED
        project_payouts_settled = values.get('project_payouts_settled')
        project_payouts_settled_count = values.get('project_payouts_settled_count')
        project_payouts_settled_amount = values.get('project_payouts_settled_amount')
        self.assertTrue(project_payouts_settled.exists())
        self.assertEqual(project_payouts_settled_count, 2)
        self.assertEqual(project_payouts_settled_amount, Decimal('1333')) # 1000 + 333

        # ##### ORDER PAYMENTS ##### #
        order_payments = values.get('order_payments')
        order_payments_count = values.get('order_payments_count')
        order_payments_amount = values.get('order_payments_amount')
        self.assertTrue(order_payments.exists())
        self.assertEqual(order_payments_count, 2) # the valid one and the failed one
        self.assertEqual(order_payments_amount, Decimal('333')) # 333 + 0 (failed one does not have value)

        invalid_order_payments = values.get('invalid_order_payments')
        invalid_order_payments_count = values.get('invalid_order_payments_count')
        invalid_order_payments_amount = values.get('invalid_order_payments_amount')
        invalid_order_payments_transaction_fee = values.get('invalid_order_payments_transaction_fee')
        self.assertTrue(invalid_order_payments.exists())
        self.assertEqual(invalid_order_payments_count, 1)
        self.assertEqual(invalid_order_payments_amount, Decimal()) # failed one has no value
        self.assertEqual(invalid_order_payments_transaction_fee, Decimal())

        # ##### DOCDATA PAYMENTS ##### #
        remote_docdata_payments = values.get('remote_docdata_payments')
        remote_docdata_payments_count = values.get('remote_docdata_payments_count')
        remote_docdata_payments_amount = values.get('remote_docdata_payments_amount')
        self.assertTrue(remote_docdata_payments.exists())
        self.assertEqual(remote_docdata_payments_count, 2)
        self.assertEqual(remote_docdata_payments_amount, Decimal('123.59')) # 123.45 + 0.14

        # ##### DOCDATA PAYOUTS ##### #
        remote_docdata_payouts = values.get('remote_docdata_payouts')
        remote_docdata_payouts_count = values.get('remote_docdata_payouts_count')
        remote_docdata_payouts_amount = values.get('remote_docdata_payouts_amount')
        self.assertTrue(remote_docdata_payouts.exists())
        self.assertEqual(remote_docdata_payouts_count, 3)
        self.assertEqual(remote_docdata_payouts_amount, Decimal('21.25')) # 20 + 0.14 + 1.11

        # ##### BANK TRANSACTIONS ##### #
        transactions = values.get('transactions')
        transactions_count = values.get('transactions_count')
        transactions_amount = values.get('transactions_amount')
        self.assertTrue(transactions.exists())
        self.assertEqual(transactions_count, 5) # 1000 + 1.11 + 0.14 + 77 (mismatch) + 500 (debit transaction)
        # NOTE: amount below is currently not used in the admin
        # when decided to use it, verify if it makes sense to add the debit and credit together
        # maybe credit - debit is expected, and the value should be 578.25 in that case
        self.assertEqual(transactions_amount, Decimal('1578.25'))

        invalid_transactions = values.get('invalid_transactions')
        invalid_transactions_count = values.get('invalid_transactions_count')
        invalid_transactions_amount = values.get('invalid_transactions_amount')
        self.assertTrue(invalid_transactions.exists())
        self.assertEqual(invalid_transactions_count, 1)
        self.assertEqual(invalid_transactions_amount, Decimal('77'))
    def setUp(self):
        super(AccountingStatisticsTests, self).setUp()

        self.today = timezone.now()
        last_year = self.today.year - 1
        self.last_year = datetime.datetime(last_year, 1, 1, tzinfo=pytz.timezone('Europe/Amsterdam'))
        self.middle_date = datetime.datetime(last_year, 6, 1, tzinfo=pytz.timezone('Europe/Amsterdam'))

        # other categories from the fixtures are [u'Checking to savings', u'Savings to checking',
        # u'Bank costs', u'Donations to be transferred', u'Interest', u'Settle Bank costs', u'Total']
        self.CAMPAIGN_PAYOUT = BankTransactionCategory.objects.get(name='Campaign Payout')
        self.DOCDATA_PAYOUT = BankTransactionCategory.objects.get(name='Docdata payout')
        self.DOCDATA_PAYMENT = BankTransactionCategory.objects.get(name='Docdata payment')

        self.status = BankTransaction.IntegrityStatus # .Valid .UnknownTransaction .AmountMismatch
        self.creditdebit = BankTransaction.CreditDebit # .credit  .debit

        # ##### One organization has 2 projects ##### #
        self.organization = OrganizationFactory.create(name='test_org', slug='test_org')
        self.project1_owner = BlueBottleUserFactory(username='******', email='*****@*****.**', password='******')
        self.project2_owner = BlueBottleUserFactory(username='******', email='*****@*****.**', password='******')

        # deadline defaults to timezone.now() + timedelta(days=100)
        #  allow_overfunding defaults to True
        self.project1 =  ProjectFactory(owner=self.project1_owner, organization=self.organization,
                                        title='Project 1', amount_needed=1111, amount_asked=1111)
        self.project2 = ProjectFactory(owner=self.project2_owner, organization=self.organization,
                                       title='Project 2', amount_needed=2222, amount_asked=2222)

        # ##### Person 1 makes 1 order that contains 2 donations for both projects ##### #
        self.person1 = BlueBottleUserFactory(username='******', email='*****@*****.**', password='******')
        self.order1 = OrderFactory.create(user=self.person1)
        self.donation1_person1 = DonationFactory(order=self.order1, project=self.project1, amount=111)
        self.donation2_person1 = DonationFactory(order=self.order1, project=self.project2, amount=222)

        # ##### Person 2 makes 1 donations for project 1 ##### #
        self.person2 = BlueBottleUserFactory(username='******', email='*****@*****.**', password='******')
        self.order2 = OrderFactory.create(user=self.person2, status='success')
        self.donation1_person2 = DonationFactory(order=self.order2, project=self.project1, amount=1000)

        # ##### ORDER PAYMENT AND PAYMENT ##### #
        self.assertEqual(self.order1.status, 'created')
        self.order_payment = OrderPaymentFactory.create(order=self.order1)
        self.assertEqual(self.order1.status, 'locked')
        self.assertEqual(Payment.objects.all().count(), 0)
        self.order_payment.started()
        self.order_payment.save()
        self.payment = PaymentFactory.create(order_payment=self.order_payment)
        self.assertEqual(Payment.objects.all().count(), 1)
        self.assertEqual(self.order1.status, StatusDefinition.LOCKED)
        self.order_payment.authorized()
        self.order_payment.save()
        self.assertEqual(self.order1.status, StatusDefinition.PENDING)
        self.order_payment.settled()
        self.order_payment.save()
        self.assertEqual(self.order1.status, StatusDefinition.SUCCESS)
        # #####

        # ##### make Docdata Payout and Payment ##### #
        self.remoteDDPayout = RemoteDocdataPayoutFactory.create(collected_amount=Decimal('123.45'),
                                                                payout_amount=Decimal('20'))
        self.remoteDDPayment = RemoteDocdataPaymentFactory.create(remote_payout=self.remoteDDPayout,
                                                                  local_payment=self.payment,
                                                                  amount_collected=Decimal('123.45'),
                                                                  docdata_fee=Decimal('0.33'))
        self.assertEqual(self.remoteDDPayout.collected_amount, Decimal('123.45'))
        self.assertEqual(self.remoteDDPayout.payout_amount, Decimal('20'))
        self.assertEqual(self.remoteDDPayment.amount_collected, Decimal('123.45'))
        self.assertEqual(self.remoteDDPayment.docdata_fee, Decimal('0.33'))
        self.assertEqual(self.remoteDDPayment.status, 'valid')

        # completed should be between start and end to appear in the statistics
        self.project1_payout = ProjectPayoutFactory.create(
            completed=self.middle_date, status = StatusDefinition.SETTLED, project=self.project1,
            amount_raised=333, organization_fee=0, amount_payable=333)
        self.project2_payout = ProjectPayoutFactory.create(
            completed=self.middle_date, status = StatusDefinition.SETTLED, project=self.project2,
            amount_raised=1000, organization_fee=50, amount_payable=950)

        BankTransactionFactory.create(amount=Decimal('1000'),
                                      category=self.CAMPAIGN_PAYOUT,
                                      credit_debit=self.creditdebit.credit,
                                      status=self.status.Valid,
                                      payout=self.project2_payout,
                                      remote_payout=None,
                                      remote_payment=None,
                                      )
Ejemplo n.º 54
0
 def test_create_payment_with_wrong_payment_method(self, get_current_host):
     with self.assertRaises(PaymentException):
         order_payment = OrderPaymentFactory.create(payment_method="docdataIdeal", amount=Money(3500, XOF))
         adapter = VitepayPaymentAdapter(order_payment)
         adapter.create_payment()
Ejemplo n.º 55
0
    def setUp(self):
        super(BlueBottleOrderTestCase, self).setUp()

        self.order = OrderFactory.create()
        self.order_payment = OrderPaymentFactory.create(order=self.order)
Ejemplo n.º 56
0
 def test_create_payment(self, get_current_host):
     order = OrderFactory.create()
     DonationFactory.create(amount=Money(2000, XOF), order=order)
     order_payment = OrderPaymentFactory.create(payment_method="vitepayOrangemoney", order=order)
     adapter = VitepayPaymentAdapter(order_payment)
     self.assertEqual(adapter.payment.amount_100, 200000)
Ejemplo n.º 57
0
    def setUp(self):
        super(PaymentTestCase, self).setUp()
        self.init_projects()

        self.order = OrderFactory.create()
        self.order_payment = OrderPaymentFactory.create(order=self.order)
Ejemplo n.º 58
0
 def setUp(self):
     self.order = OrderFactory.create(total=35)
     self.order_payment = OrderPaymentFactory.create(order=self.order, payment_method='mock')
     self.service = PaymentService(order_payment=self.order_payment)
Ejemplo n.º 59
0
 def test_create_payment_with_wrong_currency(self, get_current_host):
     with self.assertRaises(PaymentException):
         order_payment = OrderPaymentFactory.create(payment_method="vitepayOrangemoney", amount=Money(200, EUR))
         VitepayPaymentAdapter(order_payment)
    def _initialize_payments(self):
        """
        Initialize some projects, donations, payments.
        """
        # required for project save
        self.init_projects()

        yesterday = timezone.now() - timedelta(days=1)

        self.project1 = ProjectFactory.create(status__sequence=5, campaign_started=yesterday)  # has no payout
        # has a new payout
        self.project2 = ProjectFactory.create(status__sequence=8, campaign_started=yesterday)
        # has an in_progress payout
        self.project3 = ProjectFactory.create(status__sequence=8, campaign_started=yesterday)
        # has a settled payout
        self.project4 = ProjectFactory.create(status__sequence=8, campaign_started=yesterday)

        # make donations for each project
        status_progressions = [
            # successful order
            (StatusDefinition.AUTHORIZED, StatusDefinition.SETTLED),
            # successful order, but RDP says it's chargeback
            (StatusDefinition.AUTHORIZED, StatusDefinition.SETTLED),
            # successful order, but RDP says it's refund
            (StatusDefinition.AUTHORIZED, StatusDefinition.SETTLED),
            # cancelled
            (StatusDefinition.CANCELLED,),
            # chargeback
            (StatusDefinition.AUTHORIZED, StatusDefinition.SETTLED, StatusDefinition.CHARGED_BACK),
            # refunded
            (StatusDefinition.AUTHORIZED, StatusDefinition.SETTLED, StatusDefinition.REFUNDED),
            # something else went wrong
            (StatusDefinition.AUTHORIZED, StatusDefinition.SETTLED, StatusDefinition.FAILED),
        ]
        for i, progressions in enumerate(status_progressions):

            order = OrderFactory.create()
            order_payment = OrderPaymentFactory.create(order=order)
            cluster_id = 'payment%d' % (i+1)

            DonationFactory.create(project=self.project1, order=order, amount=5)
            DonationFactory.create(project=self.project2, order=order, amount=10)
            DonationFactory.create(project=self.project3, order=order, amount=15)
            DonationFactory.create(project=self.project4, order=order, amount=20)

            payment = DocdataPaymentFactory.create(
                order_payment=order_payment,
                status=StatusDefinition.STARTED,
                merchant_order_id=cluster_id,
                payment_cluster_id=cluster_id,
                payment_cluster_key=hashlib.md5('%d' % order.pk).hexdigest(),
                default_pm='visa',
                total_gross_amount=order.total * 100,
            )

            # do the status progression, this sets of the order/order_payment status progression
            for status in progressions:
                payment.status = status
                payment.save()

        # some messed up situations
        j = len(status_progressions)
        _payments = []
        for i in range(j, j+2):
            order = OrderFactory.create()
            order_payment = OrderPaymentFactory.create(order=order)
            cluster_id = 'payment%d' % (i+1)

            DonationFactory.create(project=self.project1, order=order, amount=5)
            DonationFactory.create(project=self.project2, order=order, amount=10)

            payment = DocdataPaymentFactory.create(
                order_payment=order_payment,
                status=StatusDefinition.STARTED,
                merchant_order_id=cluster_id,
                payment_cluster_id=cluster_id,
                payment_cluster_key=hashlib.md5('%d' % order.pk).hexdigest(),
                default_pm='visa',
                total_gross_amount=order.total * 100,
            )
            _payments.append(payment)
            order_payment.authorized()
            order_payment.save()
            order_payment.settled()
            order_payment.save()

        DocdataPayment.objects.filter(id__in=[p.id for p in _payments]).update(status=StatusDefinition.SETTLED)

        # create remotedocdata payments that should match 7/9 of the local payments
        self.rdp_list = []
        for i, payment_type in enumerate(
                ('paid', 'chargedback', 'refund', None, 'chargedback', 'refund', None)
                ):
            if payment_type is None:
                continue
            amount_collected = Decimal(50) if payment_type == 'paid' else -Decimal(50)
            rdp = RemoteDocdataPaymentFactory.create(
                local_payment=None,
                triple_deal_reference='pid123456789t',
                payment_type=payment_type,
                merchant_reference='payment%d' % (i+1),
                amount_collected=amount_collected
            )
            self.rdp_list.append(rdp)
            update_remote_docdata_status(rdp)
            rdp.save()
        for payment_type in ('chargedback', 'refund'):
            i = i + 1
            rdp = RemoteDocdataPaymentFactory.create(
                local_payment=None,
                triple_deal_reference='pid123456789t',
                payment_type=payment_type,
                merchant_reference='payment%d' % (i+1),
                amount_collected=-Decimal(15)
            )
            self.rdp_list.append(rdp)
            update_remote_docdata_status(rdp)
            rdp.save()

        self.assertEqual(RemoteDocdataPayment.objects.count(), 7)

        # make some assertions
        for project in [self.project1, self.project2]:
            project.update_amounts(save=True)
            self.assertEqual(project.donation_set.count(), 9)  # = len(status_progressions) + 2 weirdo's

        for project in [self.project3, self.project4]:
            project.update_amounts(save=True)
            self.assertEqual(project.donation_set.count(), 7)  # = len(status_progressions)

        # bring payouts in desired state
        self.assertFalse(self.project1.projectpayout_set.exists())

        payout2 = self.project2.projectpayout_set.first()
        payout2.payout_rule = BaseProjectPayout.PayoutRules.not_fully_funded
        self.assertEqual(payout2.status, StatusDefinition.NEW)
        self.assertEqual(payout2.amount_raised, 50)

        payout3 = self.project3.projectpayout_set.first()
        payout3.payout_rule = BaseProjectPayout.PayoutRules.not_fully_funded
        payout3.in_progress()
        payout3.save()
        self.assertEqual(payout3.amount_raised, 45)

        payout4 = self.project4.projectpayout_set.first()
        payout4.payout_rule = BaseProjectPayout.PayoutRules.not_fully_funded
        payout4.in_progress()
        payout4.save()
        payout4.settled()
        payout4.save()
        self.assertEqual(payout4.amount_raised, 60)