Example #1
0
def get_or_create_funding_source(customer, name='My Bank'):
    """
    Returns funding source (bank) or creates verified
    funding source (bank) in Dwolla for test customer.

    name is used to simulate different test cases.

    name = "R01" Insufficient Funds:
             failing from the source bank account.

    name = "R01-late" Simulate funds failing from the
            source bank account post-settlement.
            Must click "Process bank transfers" twice.
    """
    dw = DwollaApi()
    for fs in dw.get_funding_sources(customer['id']):
        if fs['status'] == 'verified' and fs['type'] == 'bank':
            # Set funding source's name.
            dw.edit_funding_source_name(fs['id'], name)
            return fs

    data = {
        'routingNumber': '222222226',
        'accountNumber': '123456789',
        'type': 'savings',
        'name': name
    }
    print('Creating funding source --------')
    id = dw.create_funding_source(customer['id'], data)
    fs = dw.get_funding_source(id)
    print(fs)

    print('Initiating micro-deposits -------')
    res = dw.initiate_micro_deposits(fs['id'])
    print(res)

    print('Get status of micro-deposits -------')
    res = dw.get_micro_deposits(fs['id'])

    print('Verifying funding source -------')
    res = dw.verify_micro_deposits(
        fs['id'], '0.05', '0.05')
    print(res)

    print('Checking the status of funding source -------')
    fs = dw.get_funding_source(id)
    print(fs['status'])
    return fs
Example #2
0
 def init_dwolla_funding_source(self, id):
     """
     Currently not used.
     Init funding source in Dwolla from manually
     created account.
     """
     fs = self.model.objects.get(id=id)
     if fs.dwolla_id is not None and fs.created_at is None:
         dw = DwollaApi()
         d = dw.get_funding_source(fs.dwolla_id)
         fs.dwolla_id = d['id']
         fs.created_at = d['created']
         fs.status = d['status']
         fs.is_removed = d['removed']
         fs.typeb = d['type']
         fs.save()
Example #3
0
    def create_funding_source_iav(self, account_id, dwolla_id, test_dic=None):
        """
        User creates funding source via dwolla.js script in iframe
        using username and password on frontend.
        At first the funding source is created in Dwolla,
        then calling this function from API funding source created in database.

        test_dic - used for tests not calling Dwolla API.

        If Dwolla API fail, we can run this method later.
        FundingSourceIAVLog will contain failed data.

        If this is first FundingSource, set it as active funding source
        for user.
        """
        Account = apps.get_model('finance', 'Account')
        FundingSourceIAVLog = apps.get_model('bank', 'FundingSourceIAVLog')

        fs_log = FundingSourceIAVLog.objects.create(account_id, dwolla_id)
        account = Account.objects.get(id=account_id)

        if test_dic:
            d = test_dic
        else:
            dw = DwollaApi()
            d = dw.get_funding_source(dwolla_id)

        fs = self.model(account=account)
        fs.dwolla_id = d['id']
        fs.created_at = d['created']
        fs.status = d['status']
        fs.is_removed = d['removed']
        fs.typeb = d['type']
        fs.name = d['name']
        fs.verification_type = self.model.IAV
        fs.save()

        fs_log.is_processed = True
        fs_log.save()

        count = self.model.objects.filter(
            account__item__user=account.item.user).count()
        if count == 1:
            Account.objects.set_funding_source(account.id)

        return fs