def test_unicode(self): payment_line = PaymentLine() payment_line.LineNum = 1 payment_line.Description = "Product Description" payment_line.Amount = 100 self.assertEquals(str(payment_line), "[1] Product Description 100")
def test_unicode(self): payment_line = PaymentLine() payment_line.Amount = 100 self.assertEqual(str(payment_line), "100")
def test_unicode(self): payment_line = PaymentLine() payment_line.Amount = 100 self.assertEquals(str(payment_line), "100")
def post_payment(doc_number="", amount=0, btcp_id=''): # post payment to QBO ''' doc_number: QBO invoice number amount: payment amount btcp_id: BTCPay invoice number ''' refresh_stored_tokens() qb = fetch('qbclient') # check if BTCPay is already in QBO as a pmt method pmt_method_list = PaymentMethod.filter(Name="BTCPay", qb=qb) try: # if BTCPay is already in QBO, set it as pmt method pmt_method = pmt_method_list[0] except IndexError: # if BTCPay is not in QBO, create it as pmt method new_pmt_method = PaymentMethod() new_pmt_method.Name = "BTCPay" new_pmt_method.save(qb=qb) # set newly created BTCPay pmt method as pmt method pmt_method_list = PaymentMethod.filter(Name="BTCPay", qb=qb) pmt_method = pmt_method_list[0] # check if QBO has asset acct for Bitcoin-BTCPay deposit_acct_list = Account.filter(Name="Bitcoin-BTCPay", qb=qb) try: # if Bitcoin-BTCPay is in QBO, set as deposit acct deposit_acct = deposit_acct_list[0] except IndexError: # if Bitcoin-BTCPay is not in QBO, create it as deposit acct new_acct = Account() new_acct.Name = "Bitcoin-BTCPay" new_acct.AccountSubType = "OtherCurrentAssets" new_acct.save(qb=qb) # set newly created Bitcoin-BTCPay acct as deposit acct deposit_acct_list = Account.filter(Name="Bitcoin-BTCPay", qb=qb) deposit_acct = deposit_acct_list[0] # pull list of invoice objects matching invoice number from QBO invoice_list = Invoice.filter(DocNumber=doc_number, qb=qb) try: # only one invoice can match the inv #, so pull it from list invoice = invoice_list[0] except IndexError: app.logger.warning(f'No such invoice exists: {doc_number}') return None else: # convert invoice object to linked invoice object linked_invoice = invoice.to_linked_txn() description = 'BTCPay: ' + btcp_id payment_line = PaymentLine() payment_line.Amount = amount payment_line.Description = description # attach linked invoice object to payment line object payment_line.LinkedTxn.append(linked_invoice) payment = Payment() payment.TotalAmt = amount payment.CustomerRef = invoice.CustomerRef # create deposit acct reference object from deposit acct object deposit_account_ref = Ref() deposit_account_ref.value = deposit_acct.Id # create pmt method reference object from pmt method object pmt_method_ref = Ref() pmt_method_ref.name = pmt_method.Name # attach pmt method ref, dep acct ref, and pmt line obj to pmt obj payment.PaymentMethodRef = pmt_method_ref payment.DepositToAccountRef = deposit_account_ref payment.Line.append(payment_line) payment.save(qb=qb) # save payment to temp redis store to fliter duplicates app.redis.set(btcp_id, 'payment', ex=21600) return "Payment Made: " + str(payment)