Integration Quickbook online api to rails app - ruby-on-rails-3

I am integrating
rails application to Quickbooks online
using API.
Use gem Quickbooks-ruby
But want to add discount, add taxes into invoice but not success even not found how to pass in API.

invoice = Quickbooks::Model::Invoice.new
invoice.customer_id = 1
invoice.txn_date = Date.civil(2014, 3, 27)
invoice.doc_number = "001"
transaction_tax = Quickbooks::Model::TransactionTaxDetail.new
# Point to a saved tax code in QBO, e.g. this points to id = 2,
# which is a NYC tax code saved on QBO account = 10% sales tax
transaction_tax.txn_tax_code_id = 2
transaction_tax.total_tax = 134.10
invoice.txn_tax_detail = transaction_tax
sales_line_item = Quickbooks::Model::InvoiceLineItem.new
sales_line_item.amount = 1490
sales_line_item.description = "CCM ice skates"
sales_line_item.sales_item! do |detail|
detail.unit_price = 149
detail.quantity = 10
detail.item_id = 1 # Item ID here
detail.tax_code_id = 'TAX' # for US must be 'NON' or 'TAX'
end
discount_line_item = Quickbooks::Model::InvoiceLineItem.new
discount_line_item.amount = 149
discount_line_item.discount_item! do |detail|
detail.discount_percent = 10
detail.percent_based = true
detail.discount_account_id = 99
end
invoice.line_items << sales_line_item
invoice.line_items << discount_line_item
service = Quickbooks::Service::Invoice.new
service.access_token = OAuth::AccessToken.new($qb_oauth_consumer, "token", "secret")
service.company_id = "9991111222"
created_invoice = service.create(invoice)

There should be something like JAXB in ruby for object serialization/deserialization.
From the following link, you can download QB endpoint definations and data class defination(as XSD). You need to generate data classes from it.
https://developer.intuit.com/docs/#api/deki/files/2466/v3.1_dataservices.zip
Then using any standard ruby based OAuth lib, you can make call to QB API Endpoints.
You can use the setter methods of the data class( in your case - invoice ) to populate data/to construct the payload. ( I don't have any ready example of this. But I guess it is not hard to find in net)
For doc, you can refer the following two links.
https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/030_entity_services_reference/invoice
https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/030_entity_services_reference/invoice#DiscountLineDetail
Thanks

Related

Send 'Comment' or additional field with Global Payments HPP - PHP SDK - RXP JS

How do you send additional data through to Global Payments like 'Comment', 'CustomerNumber' or 'ProductId' using the HPP with PHP SDK / RXP JS?
I have tried the following and cannot see any documentation for it.
// Add 3D Secure 2 Mandatory and Recommended Fields
$hostedPaymentData = new HostedPaymentData();
$hostedPaymentData->customerName = 'Your name';
$hostedPaymentData->customerEmail = 'email#email.com';
// not working
$hostedPaymentData->customerNumber = '48898984';
$hostedPaymentData->productId = '48898984';
$hostedPaymentData->comment1 = '48898984';

Django how to maintain a session?

I'm developing an e-commerce site and I'm working on the shopping cart functionality. When the user is not connected I create a session for him so that he can add products to the basket which is normal, when the user decides to place this order I ask him to connect but when he connects he loses the session that I had created for him and another session is assigned to him. The cause is that once connected it loses all its products selected in the screen. After reading the documentation on django sessions I found nothing that could help me.
here is my code for more details:
models.py
class Cart(models.Model):
session_id = models.CharField(max_length=150)
product = models.ForeignKey(Products, on_delete=models.CASCADE)
quantity = models.PositiveIntegerField(default=0, validators=[MinValueValidator(1)])
updated = models.fields.DateTimeField(auto_now=True)
created = models.fields.DateTimeField(auto_now_add=True)
deleted = models.fields.BooleanField(default=False)
def __str__(self) -> str:
return str(self.product)
views.py
class FrontProductAddCart(View):
def post(self, request, product_pk):
session_id = request.session._get_or_create_session_key()
product = models.Products.objects.get(pk=product_pk)
objet, create = models.Cart.objects.get_or_create(session_id=session_id, product=product)
quantity = request.POST.get("quantity")
if quantity:
objet.quantity = quantity
objet.save()
else:
objet.quantity += 1
objet.save()
return HttpResponse(
"",
headers={
"HX-Trigger": json.dumps({
"product_add_cart": context_processors.get_total_number_products(request)
})
}
)

BAPI or FM for Promise to pay creation?

I'm working with Promises to pay in UDM_SUPERVISOR transaction and I need to upload Promise to pay data using BAPI/FM from an excel file.
There is a data migration template which will include all the required fields for the creation of a Customer Promise To Pay in the system.
The migration will happen using LTMC migration cockpit tool. Is there any BAPI/FM I can use for uploading Promise To Pay?
Try function modules from FDM_P2P_SERVICES group which is Promise to Pay API.
For example UDM dashboard calls FDM_P2P_CREATE FM under the hood
ls_p2p_partner-obj_type = 'KNB1'.
ls_p2p_partner-obj_key = '0030000001CA09'.
ls_p2p_attr-fin_comp_code = "CA09".
ls_p2p_attr-fin_customer = '0030000001".
ls_p2p_attr-fin_p2p_curr = 'CAD".
ls_p2p_attr-fin_p2p_date = ls_p2p_attr-fin_p2p_due_date = "20220530".
ls_p2p_attr-fin_promised_by = 'Sandeep Phogat".
ls_p2p_attr-fin_contact_tel = "9058262323".
ls_p2p_attr-fin_contact_key = "0000000003".
APPEND ls_p2p_attr TO lt_p2p_attr.
ls_gen_inv_for_partner-obj_type = "BSEG".
ls_gen_inv_for_partner-obj_key = "CA0901000001752017001".
ls_gen_inv_for_partner-open_amount = "0.75".
ls_gen_inv_for_partner-max_p2p_amount = "0.75".
ls_gen_inv_for_partner-assigned_p2p_amount = "0.75".
ls_gen_inv_for_partner-p2p_curr = "CAD".
ls_gen_inv_for_partner-due_date = "20170515".
ls_gen_inv_for_partner-overdue_by = "1841".
ls_gen_inv_for_partner-case_type = "CAPP".
APPEND ls_gen_inv_for_partner TO lt_gen_inv_for_partner.
CALL FUNCTION 'FDM_P2P_CREATE'
EXPORTING
is_p2p_partner = ls_p2p_partner
it_p2p_attr = lt_p2p_attr
it_p2p_invoice = lt_gen_inv_for_partner
IMPORTING
et_p2p_created = lt_p2p_crea_for_partner
EXCEPTIONS
get_number_failure = 1
case_interface_failure = 2.
If you want to upload promises from file, please check /HEX/UPLOAD_P2P standard report.

How to scrape a data table that has multiple pages using selenium?

I'm extracting NBA stats from my yahoo fantasy account. Below is the code that I made in jupyter notebook using selenium. Each page shows 25 players and a total of 720 players. I did a for loop that will scrape players in increments of 25 instead of one by one.
for k in range (0,725,25):
Players = driver.find_elements_by_xpath('//tbody/tr/td[2]/div/div/div/div/a')
Team_Position = driver.find_elements_by_xpath('//span[#class= "Fz-xxs"]')
Games_Played = driver.find_elements_by_xpath('//tbody/tr/td[7]/div')
Minutes_Played = driver.find_elements_by_xpath('//tbody/tr/td[11]/div')
FGM_A = driver.find_elements_by_xpath('//tbody/tr/td[12]/div')
FTM_A = driver.find_elements_by_xpath('//tbody/tr/td[14]/div')
Three_Points = driver.find_elements_by_xpath('//tbody/tr/td[16]/div')
PTS = driver.find_elements_by_xpath('//tbody/tr/td[17]/div')
REB = driver.find_elements_by_xpath('//tbody/tr/td[18]/div')
AST = driver.find_elements_by_xpath('//tbody/tr/td[19]/div')
ST = driver.find_elements_by_xpath('//tbody/tr/td[20]/div')
BLK = driver.find_elements_by_xpath('//tbody/tr/td[21]/div')
TO = driver.find_elements_by_xpath('//tbody/tr/td[22]/div')
NBA_Stats = []
for i in range(len(Players)):
players_stats = {'Name': Players[i].text,
'Position': Team_Position[i].text,
'GP': Games_Played[i].text,
'MP': Minutes_Played[i].text,
'FGM/A': FGM_A[i].text,
'FTM/A': FTM_A[i].text,
'3PTS': Three_Points[i].text,
'PTS': PTS[i].text,
'REB': REB[i].text,
'AST': AST[i].text,
'ST': ST[i].text,
'BLK': BLK[i].text,
'TO': TO[i].text}
driver.get('https://basketball.fantasysports.yahoo.com/nba/28951/players?status=ALL&pos=P&cut_type=33&stat1=S_AS_2021&myteam=0&sort=AR&sdir=1&count=' + str(k))
The browser will go page by page after it's done. I print out the results. It only scrape 1 player. What did I do wrong?
A picture of my codes and printing the results
It's hard to see what the issue here is without looking at the original page (can you provide a URL?), however looking at this:
next = driver.find_element_by_xpath('//a[#id = "yui_3_18_1_1_1636840807382_2187"]')
"1636840807382" looks like a Javascript timestamp, so I would guess that the reference you've got hardcoded there is dynamically generated, so the element "yui_3_18_1_1_1636840807382_2187" no longer exists.

Apache Flume with 2 different interceptors on same source

I am trying to add 2 different interceptors on the same source and send the intercepted data to 2 different channels.
But, I was not able to configure the same. Couldn't find any documentation about the same. Also, I am having some issues with the channel selectors. Not sure how to select a channel with the different interceptors.
Here is my code so far:
a1.sources = syslog_udp
a1.channels = chan1 chan2
a1.sinks = sink1 sink2 //both are different kafka sinks
a1.sources.syslog_udp.type = syslogudp
a1.sources.syslog_udp.port = 514
a1.sources.syslog_udp.host = 0.0.0.0
a1.sources.syslog_udp.keepFields = true
a1.sources.syslog_udp.interceptors = i1 i2
a1.sources.syslog_udp.interceptors.i1.type = regex_filter
a1.sources.syslog_udp.interceptors.i1.regex = '<regex_string1>'
a1.sources.syslog_udp.interceptors.i1.excludeEvents = false
a1.sources.syslog_udp.interceptors.i2.type = regex_filter
a1.sources.syslog_udp.interceptors.i2.regex = '<regex_string1>'|'<regex_string2>'
a1.sources.syslog_udp.interceptors.i2.excludeEvents = false
a1.sources.syslog_udp.selector.type = multiplexing
a1.sources.syslog_udp.channels = chan1 chan2
a1.channels.chan1.type = memory
a1.channels.chan1.capacity = 200
a1.channels.chan2.type = memory
a1.channels.chan2.capacity = 200
Seems like there is no straight-forward setup for this.
A work-around for this kind of layout is to have a single/wider channel interceptor in one agent, pipe the output to an avro-sink and setup a new agent for the avro-source and set-up the new channel interceptor on that.