Ejemplo n.º 1
0
    def get_customers(self, filter_data=None):
        '''
        Returns all customers. Sometimes they are too much and cause internal 
        server errors on CG. API call permits post parameters for filtering 
        which tends to fix this
        https://cheddargetter.com/developers#all-customers

        filter_data
            Will be processed by urlencode and can be used for filtering
            Example value: [
                ("subscriptionStatus": "activeOnly"),
                ("planCode[]": "100GB"), ("planCode[]": "200GB")
            ]
        '''
        customers = []

        try:
            response = self.client.make_request(path='customers/get',
                                                data=filter_data)
        except NotFound:
            response = None

        if response:
            customer_parser = CustomersParser()
            customers_data = customer_parser.parse_xml(response.content)
            for customer_data in customers_data:
                customers.append(Customer(product=self, **customer_data))

        return customers
Ejemplo n.º 2
0
    def get_customer(self, code):

        response = self.client.make_request(
            path='customers/get',
            params={'code': code},
        )
        cusotmer_parser = CustomersParser()
        customers_data = cusotmer_parser.parse_xml(response.content)

        return Customer(product=self, **customers_data[0])
Ejemplo n.º 3
0
    def cancel(self):
        client = self.customer.product.client
        response = client.make_request(
            path='customers/cancel',
            params={'code': self.customer.code},
        )

        cusotmer_parser = CustomersParser()
        customers_data = cusotmer_parser.parse_xml(response.content)
        customer_data = customers_data[0]
        self.customer.load_data(product=self.customer.product, **customer_data)
Ejemplo n.º 4
0
    def create_customer(self, code, first_name, last_name, email, plan_code,
                        company=None, is_vat_exempt=None, vat_number=None,
                        notes=None, first_contact_datetime=None,
                        referer=None, campaign_term=None,
                        campaign_name=None, campaign_source=None,
                        campaign_medium=None, campaign_content=None,
                        meta_data=None, initial_bill_date=None, method=None,
                        cc_number=None, cc_expiration=None,
                        cc_card_code=None, cc_first_name=None,
                        cc_last_name=None, cc_email=None, cc_company=None,
                        cc_country=None, cc_address=None, cc_city=None,
                        cc_state=None, cc_zip=None, coupon_code=None,
                        return_url=None, cancel_url=None, charges=None,
                        items=None):

        data = self.build_customer_post_data(code, first_name, last_name,
                                             email, plan_code, company,
                                             is_vat_exempt, vat_number,
                                             notes, first_contact_datetime,
                                             referer, campaign_term,
                                             campaign_name, campaign_source,
                                             campaign_medium, campaign_content,
                                             meta_data, initial_bill_date,
                                             method, cc_number, cc_expiration,
                                             cc_card_code, cc_first_name,
                                             cc_last_name, cc_email,
                                             cc_company, cc_country,
                                             cc_address, cc_city, cc_state,
                                             cc_zip, coupon_code, return_url,
                                             cancel_url)

        if charges:
            for i, charge in enumerate(charges):
                data['charges[%d][chargeCode]' % i] = charge['code']
                data['charges[%d][quantity]' % i] = charge.get('quantity', 1)
                data['charges[%d][eachAmount]' % i] = '%.2f' % (
                    charge['each_amount'])
                data['charges[%d][description]' % i] = charge.get(
                    'description', '')

        if items:
            for i, item in enumerate(items):
                data['items[%d][itemCode]' % i] = item['code']
                data['items[%d][quantity]' % i] = item.get('quantity', 1)

        response = self.client.make_request(path='customers/new', data=data)
        customer_parser = CustomersParser()
        customers_data = customer_parser.parse_xml(response.content)
        customer = Customer(product=self, **customers_data[0])

        return customer
Ejemplo n.º 5
0
    def get_customers(self):
        customers = []

        try:
            response = self.client.make_request(path='customers/get')
        except NotFound:
            response = None

        if response:
            cusotmer_parser = CustomersParser()
            customers_data = cusotmer_parser.parse_xml(response.content)
            for customer_data in customers_data:
                customers.append(Customer(product=self, **customer_data))

        return customers
Ejemplo n.º 6
0
 def load_data_from_xml(self, xml):
     cusotmer_parser = CustomersParser()
     customers_data = cusotmer_parser.parse_xml(xml)
     customer_data = customers_data[0]
     self.load_data(product=self.product, **customer_data)
Ejemplo n.º 7
0
    def test_paypal_customer_parse(self):
        customers_xml = self.load_file('paypal_customer.xml')
        parser = CustomersParser()

        expected = [{
            'campaign_content':
            '',
            'campaign_medium':
            '',
            'campaign_name':
            '',
            'campaign_source':
            '',
            'campaign_term':
            '',
            'code':
            'test',
            'company':
            '',
            'created_datetime':
            datetime(2011, 5, 16, 16, 36, 1, tzinfo=tzutc()),
            'email':
            '*****@*****.**',
            'first_contact_datetime':
            None,
            'first_name':
            'Test',
            'gateway_token':
            None,
            'id':
            '95d7696a-7fda-11e0-a51b-40403c39f8d9',
            'is_vat_exempt':
            '0',
            'last_name':
            'User',
            'meta_data': [],
            'modified_datetime':
            datetime(2011, 5, 16, 16, 36, 1, tzinfo=tzutc()),
            'notes':
            '',
            'referer':
            '',
            'referer_host':
            '',
            'subscriptions': [{
                'cancel_reason':
                'PayPal preapproval is pending',
                'cancel_type':
                'paypal-wait',
                'canceled_datetime':
                datetime(2011, 5, 16, 16, 36, 1, tzinfo=tzutc()),
                'cc_address':
                '',
                'cc_city':
                '',
                'cc_company':
                '',
                'cc_country':
                '',
                'cc_email':
                '',
                'cc_expiration_date':
                '2012-05-16T00:00:00+00:00',
                'cc_first_name':
                'Test',
                'cc_last_four':
                '',
                'cc_last_name':
                'User',
                'cc_state':
                '',
                'cc_type':
                '',
                'cc_zip':
                '',
                'created_datetime':
                datetime(2011, 5, 16, 16, 36, 1, tzinfo=tzutc()),
                'gateway_account': {
                    'gateway': 'PayPal_Simulator',
                    'id': '303f9a50-7fda-11e0-a51b-40403c39f8d9',
                    'type': 'paypal'
                },
                'gateway_token':
                'SIMULATED-4dd152718371a',
                'id':
                '95d804ba-7fda-11e0-a51b-40403c39f8d9',
                'invoices': [{
                    'billing_datetime':
                    datetime(2011, 6, 16, 16, 36, 1, tzinfo=tzutc()),
                    'charges': [{
                        'code':
                        'PAID_MONTHLY_RECURRING',
                        'created_datetime':
                        datetime(2011, 6, 16, 16, 36, 1, tzinfo=tzutc()),
                        'description':
                        '',
                        'each_amount':
                        Decimal('20.00'),
                        'id':
                        '',
                        'quantity':
                        Decimal('1'),
                        'type':
                        'recurring'
                    }],
                    'created_datetime':
                    datetime(2011, 5, 16, 16, 36, 1, tzinfo=tzutc()),
                    'id':
                    '95de499c-7fda-11e0-a51b-40403c39f8d9',
                    'number':
                    '1',
                    'paid_transaction_id':
                    '',
                    'type':
                    'subscription',
                    'vat_rate':
                    ''
                }],
                'items': [{
                    'code': 'MONTHLY_ITEM',
                    'created_datetime': None,
                    'id': 'd19b4970-6e5a-102e-b098-40402145ee8b',
                    'modified_datetime': None,
                    'name': 'Monthly Item',
                    'quantity': Decimal('0')
                }, {
                    'code': 'ONCE_ITEM',
                    'created_datetime': None,
                    'id': 'd19ef2f0-6e5a-102e-b098-40402145ee8b',
                    'modified_datetime': None,
                    'name': 'Once Item',
                    'quantity': Decimal('0')
                }],
                'plans': [{
                    'billing_frequency':
                    'monthly',
                    'billing_frequency_per':
                    'month',
                    'billing_frequency_quantity':
                    1,
                    'billing_frequency_unit':
                    'months',
                    'code':
                    'PAID_MONTHLY',
                    'created_datetime':
                    datetime(2011, 1, 7, 21, 5, 42, tzinfo=tzutc()),
                    'description':
                    '',
                    'id':
                    '11af9cfc-6bf2-102e-b098-40402145ee8b',
                    'initial_bill_count':
                    1,
                    'initial_bill_count_unit':
                    'months',
                    'is_active':
                    True,
                    'is_free':
                    False,
                    'items': [{
                        'code':
                        'MONTHLY_ITEM',
                        'created_datetime':
                        datetime(2011, 1, 10, 22, 40, 34, tzinfo=tzutc()),
                        'id':
                        'd19b4970-6e5a-102e-b098-40402145ee8b',
                        'is_periodic':
                        False,
                        'name':
                        'Monthly Item',
                        'overage_amount':
                        Decimal('0.00'),
                        'quantity_included':
                        Decimal('0')
                    }, {
                        'code':
                        'ONCE_ITEM',
                        'created_datetime':
                        datetime(2011, 1, 10, 22, 40, 34, tzinfo=tzutc()),
                        'id':
                        'd19ef2f0-6e5a-102e-b098-40402145ee8b',
                        'is_periodic':
                        False,
                        'name':
                        'Once Item',
                        'overage_amount':
                        Decimal('0.00'),
                        'quantity_included':
                        Decimal('0')
                    }],
                    'name':
                    'Paid Monthly',
                    'recurring_charge_amount':
                    Decimal('20.00'),
                    'recurring_charge_code':
                    'PAID_MONTHLY_RECURRING',
                    'setup_charge_amount':
                    Decimal('0.00'),
                    'setup_charge_code':
                    '',
                    'trial_days':
                    0
                }],
                'redirect_url':
                'https://cheddargetter.com/service/paypal/simulate/productId/2ccbecd6-6beb-102e-b098-40402145ee8b/id/95d7696a-7fda-11e0-a51b-40403c39f8d9?preapprovalkey=SIMULATED-4dd152718371a'
            }],
            'vat_number':
            ''
        }]
        result = parser.parse_xml(customers_xml)

        import pprint
        pp = pprint.PrettyPrinter(indent=4)
        pp.pprint(result)
        self.assertEquals(expected, result)
Ejemplo n.º 8
0
    def test_customers_parser_with_items(self):
        customers_xml = self.load_file('customers-with-items.xml')
        parser = CustomersParser()

        expected = [{
            'campaign_content':
            '',
            'campaign_medium':
            '',
            'campaign_name':
            '',
            'campaign_source':
            '',
            'campaign_term':
            '',
            'code':
            'test',
            'company':
            '',
            'created_datetime':
            datetime(2011, 1, 10, 23, 57, 58, tzinfo=tzutc()),
            'email':
            '*****@*****.**',
            'first_contact_datetime':
            None,
            'first_name':
            'Test',
            'gateway_token':
            None,
            'id':
            'a1f143e0-6e65-102e-b098-40402145ee8b',
            'is_vat_exempt':
            '0',
            'last_name':
            'User',
            'meta_data': [],
            'modified_datetime':
            datetime(2011, 1, 10, 23, 57, 58, tzinfo=tzutc()),
            'notes':
            '',
            'referer':
            '',
            'referer_host':
            '',
            'subscriptions': [{
                'cancel_reason':
                None,
                'cancel_type':
                None,
                'canceled_datetime':
                None,
                'cc_address':
                '123 Something St',
                'cc_city':
                'Someplace',
                'cc_company':
                'Some Co LLC',
                'cc_country':
                'United States',
                'cc_email':
                None,
                'cc_expiration_date':
                '2011-07-31T00:00:00+00:00',
                'cc_first_name':
                'Test',
                'cc_last_four':
                '1111',
                'cc_last_name':
                'User',
                'cc_state':
                'NY',
                'cc_type':
                'visa',
                'cc_zip':
                '12345',
                'created_datetime':
                datetime(2011, 1, 10, 23, 57, 58, tzinfo=tzutc()),
                'gateway_token':
                'SIMULATED',
                'id':
                'a1f27c60-6e65-102e-b098-40402145ee8b',
                'invoices': [{
                    'billing_datetime':
                    datetime(2011, 2, 10, 23, 57, 58, tzinfo=tzutc()),
                    'charges': [{
                        'code':
                        'TRACKED_MONTHLY_RECURRING',
                        'created_datetime':
                        datetime(2011, 2, 10, 23, 57, 58, tzinfo=tzutc()),
                        'description':
                        '',
                        'each_amount':
                        Decimal('10.00'),
                        'id':
                        '',
                        'quantity':
                        Decimal('1'),
                        'type':
                        'recurring'
                    }, {
                        'code':
                        'MONTHLY_ITEM',
                        'created_datetime':
                        datetime(2011, 1, 10, 23, 57, 58, tzinfo=tzutc()),
                        'description':
                        '',
                        'each_amount':
                        Decimal('10.00'),
                        'id':
                        '',
                        'quantity':
                        Decimal('1'),
                        'type':
                        'item'
                    }, {
                        'code':
                        'ONCE_ITEM',
                        'created_datetime':
                        datetime(2011, 1, 10, 23, 57, 58, tzinfo=tzutc()),
                        'description':
                        '',
                        'each_amount':
                        Decimal('10.00'),
                        'id':
                        '',
                        'quantity':
                        Decimal('1'),
                        'type':
                        'item'
                    }],
                    'created_datetime':
                    datetime(2011, 1, 10, 23, 57, 58, tzinfo=tzutc()),
                    'id':
                    'a1f7faaa-6e65-102e-b098-40402145ee8b',
                    'number':
                    '1',
                    'paid_transaction_id':
                    '',
                    'type':
                    'subscription',
                    'vat_rate':
                    ''
                }],
                'items': [{
                    'code':
                    'MONTHLY_ITEM',
                    'created_datetime':
                    datetime(2011, 1, 10, 23, 57, 58, tzinfo=tzutc()),
                    'id':
                    'd19b4970-6e5a-102e-b098-40402145ee8b',
                    'modified_datetime':
                    datetime(2011, 1, 10, 23, 57, 58, tzinfo=tzutc()),
                    'name':
                    'Monthly Item',
                    'quantity':
                    Decimal('3')
                }, {
                    'code':
                    'ONCE_ITEM',
                    'created_datetime':
                    datetime(2011, 1, 10, 23, 57, 58, tzinfo=tzutc()),
                    'id':
                    'd19ef2f0-6e5a-102e-b098-40402145ee8b',
                    'modified_datetime':
                    datetime(2011, 1, 10, 23, 57, 58, tzinfo=tzutc()),
                    'name':
                    'Once Item',
                    'quantity':
                    Decimal('1')
                }],
                'plans': [{
                    'billing_frequency':
                    'monthly',
                    'billing_frequency_per':
                    'month',
                    'billing_frequency_quantity':
                    1,
                    'billing_frequency_unit':
                    'months',
                    'code':
                    'TRACKED_MONTHLY',
                    'created_datetime':
                    datetime(2011, 1, 10, 22, 40, 34, tzinfo=tzutc()),
                    'description':
                    '',
                    'id':
                    'd19974a6-6e5a-102e-b098-40402145ee8b',
                    'initial_bill_count':
                    1,
                    'initial_bill_count_unit':
                    'months',
                    'is_active':
                    True,
                    'is_free':
                    False,
                    'items': [{
                        'code':
                        'MONTHLY_ITEM',
                        'created_datetime':
                        datetime(2011, 1, 10, 22, 40, 34, tzinfo=tzutc()),
                        'id':
                        'd19b4970-6e5a-102e-b098-40402145ee8b',
                        'is_periodic':
                        True,
                        'name':
                        'Monthly Item',
                        'overage_amount':
                        Decimal('10.00'),
                        'quantity_included':
                        Decimal('2')
                    }, {
                        'code':
                        'ONCE_ITEM',
                        'created_datetime':
                        datetime(2011, 1, 10, 22, 40, 34, tzinfo=tzutc()),
                        'id':
                        'd19ef2f0-6e5a-102e-b098-40402145ee8b',
                        'is_periodic':
                        False,
                        'name':
                        'Once Item',
                        'overage_amount':
                        Decimal('10.00'),
                        'quantity_included':
                        Decimal('0')
                    }],
                    'name':
                    'Tracked Monthly',
                    'recurring_charge_amount':
                    Decimal('10.00'),
                    'recurring_charge_code':
                    'TRACKED_MONTHLY_RECURRING',
                    'setup_charge_amount':
                    Decimal('0.00'),
                    'setup_charge_code':
                    '',
                    'trial_days':
                    0
                }],
                'redirect_url':
                None
            }],
            'vat_number':
            ''
        }]
        result = parser.parse_xml(customers_xml)

        import pprint
        pp = pprint.PrettyPrinter(indent=4)
        pp.pprint(result)
        self.assertEquals(expected, result)
Ejemplo n.º 9
0
    def test_customers_parser_with_no_items(self):
        customers_xml = self.load_file('customers-without-items.xml')
        parser = CustomersParser()

        expected = [{
            'campaign_content':
            '',
            'campaign_medium':
            '',
            'campaign_name':
            '',
            'campaign_source':
            '',
            'campaign_term':
            '',
            'code':
            'test',
            'company':
            '',
            'created_datetime':
            datetime(2011, 1, 10, 5, 45, 51, tzinfo=tzutc()),
            'email':
            '*****@*****.**',
            'first_contact_datetime':
            None,
            'first_name':
            'Test',
            'gateway_token':
            None,
            'id':
            '10681b62-6dcd-102e-b098-40402145ee8b',
            'is_vat_exempt':
            '0',
            'last_name':
            'User',
            'meta_data': [{
                'created_datetime':
                datetime(2011, 1, 10, 5, 45, 51, tzinfo=tzutc()),
                'id':
                '106953e2-6dcd-102e-b098-40402145ee8b',
                'modified_datetime':
                datetime(2011, 1, 10, 5, 45, 51, tzinfo=tzutc()),
                'name':
                'key2',
                'value':
                'value_2'
            }, {
                'created_datetime':
                datetime(2011, 1, 10, 5, 45, 51, tzinfo=tzutc()),
                'id':
                '1068b7a2-6dcd-102e-b098-40402145ee8b',
                'modified_datetime':
                datetime(2011, 1, 10, 5, 45, 51, tzinfo=tzutc()),
                'name':
                'key_1',
                'value':
                'value_1'
            }],
            'modified_datetime':
            datetime(2011, 1, 10, 5, 45, 51, tzinfo=tzutc()),
            'notes':
            '',
            'referer':
            '',
            'referer_host':
            '',
            'subscriptions': [{
                'cancel_reason':
                None,
                'cancel_type':
                None,
                'canceled_datetime':
                None,
                'cc_address':
                '',
                'cc_city':
                '',
                'cc_company':
                '',
                'cc_country':
                '',
                'cc_email':
                None,
                'cc_expiration_date':
                '',
                'cc_first_name':
                '',
                'cc_last_four':
                '',
                'cc_last_name':
                '',
                'cc_state':
                '',
                'cc_type':
                '',
                'cc_zip':
                '',
                'created_datetime':
                datetime(2011, 1, 10, 5, 45, 51, tzinfo=tzutc()),
                'gateway_token':
                '',
                'id':
                '106953e3-6dcd-102e-b098-40402145ee8b',
                'invoices': [{
                    'billing_datetime':
                    datetime(2011, 2, 10, 5, 45, 51, tzinfo=tzutc()),
                    'charges': [{
                        'code':
                        'FREE_MONTHLY_RECURRING',
                        'created_datetime':
                        datetime(2011, 2, 10, 5, 45, 51, tzinfo=tzutc()),
                        'description':
                        '',
                        'each_amount':
                        Decimal('0.00'),
                        'id':
                        '',
                        'quantity':
                        Decimal('1'),
                        'type':
                        'recurring'
                    }],
                    'created_datetime':
                    datetime(2011, 1, 10, 5, 45, 51, tzinfo=tzutc()),
                    'id':
                    '106ed222-6dcd-102e-b098-40402145ee8b',
                    'number':
                    '1',
                    'paid_transaction_id':
                    '',
                    'type':
                    'subscription',
                    'vat_rate':
                    ''
                }],
                'items': [],
                'plans': [{
                    'billing_frequency':
                    'monthly',
                    'billing_frequency_per':
                    'month',
                    'billing_frequency_quantity':
                    1,
                    'billing_frequency_unit':
                    'months',
                    'code':
                    'FREE_MONTHLY',
                    'created_datetime':
                    datetime(2011, 1, 7, 20, 46, 43, tzinfo=tzutc()),
                    'description':
                    'A free monthly plan',
                    'id':
                    '6b0d13f4-6bef-102e-b098-40402145ee8b',
                    'initial_bill_count':
                    1,
                    'initial_bill_count_unit':
                    'months',
                    'is_active':
                    True,
                    'is_free':
                    True,
                    'items': [],
                    'name':
                    'Free Monthly',
                    'recurring_charge_amount':
                    Decimal('0.00'),
                    'recurring_charge_code':
                    'FREE_MONTHLY_RECURRING',
                    'setup_charge_amount':
                    Decimal('0.00'),
                    'setup_charge_code':
                    '',
                    'trial_days':
                    0
                }],
                'redirect_url':
                None
            }],
            'vat_number':
            ''
        }]
        result = parser.parse_xml(customers_xml)

        import pprint
        pp = pprint.PrettyPrinter(indent=4)
        pp.pprint(result)

        self.assertEquals(expected, result)