Esempio n. 1
0
    def test_dwolla_customer(self):

        account_ref = XupplyReferences().accounts_ref.document(
            self.account.accountID)
        account_ref.set(self.account.to_any_object())
        employee_ref = account_ref.collection('Employees').document(
            self.employee.employeeID)
        try:
            employee_doc = employee_ref.get()
            employee_dict = employee_doc.to_dict()

            dwolla_customers = XupplyDwollaCustomer(
                app_token=self.dwolla_token).find(
                    search=self.employee.firstName, limit=1)
            dwolla_customer = dwolla_customers[0]
            dwollaId = dwolla_customer['id']
            print(dwolla_customer['firstName'])
            result = XupplyDwollaCustomer(app_token=self.dwolla_token).remove(
                dwollaId=dwollaId)
            self.assertEqual(result.body['status'], 'deactivated')
            employee_ref.delete()
            employee_doc = employee_ref.get()
        except Exception as e:
            employee_dict = {}

        self.assertEqual(employee_dict, {})

        employee_ref.set(self.employee.to_any_object())

        employee_doc = employee_ref.get()
        employee_dict = employee_doc.to_dict()

        self.assertEqual(employee_dict['employeeID'], 'TestUser')

        data = {
            'accountID': self.accountID,
        }

        res = self.app.post("/api/v1/dwolla/customer",
                            json=data,
                            content_type='application/json',
                            headers=self.headers)
        self.assertEqual(res.status_code, 200)
        status = json.loads(res.data.decode("utf-8"))['status']
        statusText = json.loads(res.data.decode("utf-8"))['statusText']
        dwollaId = json.loads(res.data.decode("utf-8"))['data']['dwollaId']

        self.assertTrue(dwollaId)

        account_doc = account_ref.get()
        account_dict = account_doc.to_dict()

        self.assertEqual(account_dict['merchantHash'], dwollaId)
Esempio n. 2
0
    def test_braintree_customer(self):

        account_ref = XupplyReferences().accounts_ref.document(
            self.account.accountID)

        # braintree_customers = XupplyBraintreeCustomer(gateway=self.gateway).get(payment)
        # braintree_customer = braintree_customers[0]
        # braintreeId = braintree_customer['id']
        # print(braintree_customer['firstName'])
        # result = XupplyBraintreeCustomer(gateway=self.gateway).remove(braintreeId=braintreeId)
        ''''''
        # Check Better!!!!
        # self.assertEqual(result.body['status'], 'deactivated')
        ''''''

        account_ref.delete()
        account_doc = account_ref.get()
        account_dict = account_doc.to_dict()
        if not account_dict:
            account_dict = {}

        self.assertEqual(account_dict, {})

        account_ref.set(self.account.to_any_object())

        account_doc = account_ref.get()
        account_dict = account_doc.to_dict()

        self.assertEqual(account_dict['accountID'], 'TestAccount')

        data = {
            'accountID': self.accountID,
        }

        res = self.app.post("/api/v1/braintree/customer",
                            json=data,
                            content_type='application/json',
                            headers=self.headers)
        self.assertEqual(res.status_code, 200)
        status = json.loads(res.data.decode("utf-8"))['status']
        statusText = json.loads(res.data.decode("utf-8"))['statusText']
        braintreeId = json.loads(
            res.data.decode("utf-8"))['data']['braintreeId']

        self.assertTrue(braintreeId)

        account_doc = account_ref.get()
        account_dict = account_doc.to_dict()

        self.assertEqual(account_dict['merchantHash'], braintreeId)
Esempio n. 3
0
    def test_dwolla_employee_transfer(self):

        account_ref = XupplyReferences().accounts_ref.document(self.account.accountID)
        account_ref.set(self.account.to_any_object())
        employee_ref = account_ref.collection('Employees').document(self.employee.employeeID)
        payment_ref = employee_ref.collection('Payments').document(self.payment.paymentID)
        transfer_ref = employee_ref.collection('Transfers').document(self.transfer.transferId)
        try:
            transfer_doc = transfer_ref.get()
            transfer_dict = transfer_doc.to_dict()
            #
            # dwolla_customers = XupplyDwollaCustomer(app_token=self.dwolla_token).find(search=self.employee.firstName, limit=1)
            # dwolla_customer = dwolla_customers[0]
            # dwollaId = dwolla_customer['id']
            # print(dwolla_customer['firstName'])
            # result = XupplyDwollaPayment(dwollaId=self.employee.merchantHash, app_token=self.dwolla_token).remove(paymentID=paymentID)
            # self.assertEqual(result.body['status'], 'deactivated')
            transfer_ref.delete()
            transfer_foc = transfer_ref.get()
        except Exception as e:
            transfer_dict = {}

        # result = XupplyDwollaTransfer(dwollaId=self.employee.merchantHash, app_token=self.dwolla_token).find()
        # print(result)
        # print(error)
        self.assertEqual(transfer_dict, {})

        transfer_ref.set(self.transfer.to_any_object())

        account_doc = account_ref.get()
        account_dict = account_doc.to_dict()

        employee_doc = employee_ref.get()
        employee_dict = employee_doc.to_dict()

        payment_doc = payment_ref.get()
        payment_dict = payment_doc.to_dict()

        transfer_doc = transfer_ref.get()
        transfer_dict = transfer_doc.to_dict()

        self.assertEqual(transfer_dict['transferId'], 'TestTransfer')

        data = {
            'toPaymentId': payment_dict['paymentID'],
            'toMerchantId': account_dict['merchantHash'],
            'accountID': self.accountID,
            'transferId': self.transfer.transferId,
        }

        res = self.app.post(
                "/api/v1/dwolla/transfer",
                json=data,
                content_type='application/json',
                headers=self.headers
        )

        self.assertEqual(res.status_code, 200)
        status = json.loads(res.data.decode("utf-8"))['status']
        statusText = json.loads(res.data.decode("utf-8"))['statusText']
        transferId = json.loads(res.data.decode("utf-8"))['data']['transferId']

        self.assertTrue(transferId)

        transfer_doc = transfer_ref.get()
        transfer_dict = transfer_doc.to_dict()

        self.assertEqual(transfer_dict['hash'], transferId)
Esempio n. 4
0
    def test_dwolla_employee_payment(self):

        # Set Account (incase)
        account_ref = XupplyReferences().accounts_ref.document(
            self.account.accountID)
        account_ref.set(self.account.to_any_object())

        # Get Employee Dict
        employee_ref = account_ref.collection('Employees').document(
            self.employee.employeeID)
        employee_doc = employee_ref.get()
        employee_dict = employee_doc.to_dict()

        # Get Payment Ref
        payment_ref = account_ref.collection('Payments').document(
            self.payment.paymentID)

        try:
            payment_doc = payment_ref.get()
            payment_dict = payment_doc.to_dict()
            dwolla_payments = XupplyDwollaPayment(
                dwollaId=employee_dict['merchantHash'],
                app_token=self.dwolla_token).find(search=self.payment.name,
                                                  limit=1)
            dwolla_payment = dwolla_payments[0]
            merchantHash = dwolla_payment['id']
            self.assertEqual(dwolla_payment['name'], 'ABC - Bank')
            result = XupplyDwollaPayment(
                dwollaId=employee_dict['merchantHash'],
                app_token=self.dwolla_token).remove(paymentID=merchantHash)
            self.assertEqual(result.body['removed'], True)
            payment_ref.delete()
            payment_doc = payment_ref.get()
        except Exception as e:
            payment_dict = {}

        self.assertEqual(payment_dict, {})

        payment_ref.set(self.payment.to_any_object())

        payment_doc = payment_ref.get()
        payment_dict = payment_doc.to_dict()

        self.assertEqual(payment_dict['paymentID'], 'TestPayment')

        data = {
            'merchantHash': account_dict['merchantHash'],
            'accountID': self.accountID,
            'accountNumber': self.account_number,
            'routingNumber': self.routing_number,
            'paymentID': self.payment.paymentID,
        }

        res = self.app.post("/api/v1/dwolla/payment",
                            json=data,
                            content_type='application/json',
                            headers=self.headers)

        self.assertEqual(res.status_code, 200)
        status = json.loads(res.data.decode("utf-8"))['status']
        statusText = json.loads(res.data.decode("utf-8"))['statusText']
        paymentID = json.loads(res.data.decode("utf-8"))['data']['paymentID']

        self.assertTrue(paymentID)

        payment_doc = payment_ref.get()
        payment_dict = payment_doc.to_dict()

        self.assertEqual(payment_dict['merchantHash'], paymentID)