def topup(self):
        if settings.TEST_MODE:
            self.transaction.add_transaction_step(self.step, 'topup', SUCCESS, u'Test Mode on')
            return False

        plan = self.transaction.autorefill.plan
        form_fields = {
            'username': self.company.dollar_user,
            'password': self.company.dollar_pass,
            'phone_number': self.transaction.autorefill.phone_number,
            'Amount': plan.plan_cost,
            'company': self.company,
            'transaction': '%s' % self.transaction.id
        }
        if self.company.dollar_type == 'A':
            self.transaction.add_transaction_step(self.step, 'api', SUCCESS, 'Initializing the dollarphone API client')
            if not plan.api_id:
                raise Exception(
                    'API Id for this plan has not been updated, please request the admin to update the plan with the API ID')
            form_fields['OfferingId'] = plan.api_id
            form_fields['ProviderId'] = 0
            response = api.dp_api_request(form_fields)

        else:
            self.transaction.add_transaction_step(self.step, 'site', SUCCESS,
                                                  'Initializing the dollarphone Site client')
            form_fields['Carrier'] = plan.carrier.name
            form_fields['Plan'] = plan.plan_name
            form_fields['Amount'] = '$%s' % plan.plan_cost
            response = site.purchase_top_up_cash(form_fields)
        logger.debug('DP reciept %s %s' % (self.transaction.id, response['receipt_id']))
        if not response['status']:
            raise Exception(response['adv_status'])
        self.transaction.add_transaction_step(self.step, 'topup', SUCCESS, u'%s' % response['adv_status'])
 def dollarphone_api_request(self, plan):
     self.transaction.add_transaction_step('get pin', 'api_begin', SUCCESS, 'Initializing the dollarphone API client')
     if not plan.api_id:
             raise Exception('API Id for this plan has not been updated, '
                             'please request the admin to update the plan with the API ID')
     form_fields = {
             'username': self.company.dollar_user,
             'password': self.company.dollar_pass,
             'OfferingId': plan.api_id,
             'company': self.company,
             'Amount': plan.plan_cost,
             'phone_number': None,
             'ProviderId': 0,
             'transaction': '%s' % self.transaction.id
     }
     return api.dp_api_request(form_fields)