Paypal does not send the number of items in cart - paypal

I have a simple paypal buy button. The user is redirected to paypal gateway to pay, where he can choose the number of items he wants to buy.
My problem is that I can't see the number of items (that the users entered) in the IPN variables on my server, the variable num_cart_items is always 1.
One way to solve my problem would be to disable this possibility for the user to choose the amount of item he wants to buy, but I am not sure it is possible.
Or to deduce the number of item from the price, but this is more a hack.
EDIT
Here is the object that I receive on my django server (using django-paypal, in the payment_was_successful signal), as you can see the query property has quantity1, but not the object itself:
{'created_at': datetime.datetime(2014, 6, 27, 10, 7, 50, 798488, tzinfo=<UTC>),
'last_name': u'LASTNAME',
'shipping_method': u'',
'query': u'mc_gross=3.00&protection_eligibility=Ineligible&item_number1=&payer_id=Q6E6KSFDPM3U6&tax=0.00&payment_date=03%3A06%3A57+Jun+27%2C+2014+PDT&payment_status=Completed&charset=windows-1252&mc_shipping=0.00&mc_handling=0.00&first_name=FIRSTNAME&mc_fee=0.35&notify_version=3.8&custom=%7B%22user%22%3A%22username%22%2C%22location%22%3A%7B%22x%22%3A202%2C%22y%22%3A223%7D%7D&payer_status=verified&business=email-facilitator%40gmail.com&num_cart_items=1&mc_handling1=0.00&verify_sign=SECRET_CODE&payer_email=email%40gmail.com&mc_shipping1=0.00&tax1=0.00&btn_id1=2965595&txn_id=2KW31663CC752394K&payment_type=instant&last_name=LASTNAME&item_name1=Romanescoins&receiver_email=email-facilitator%40gmail.com&payment_fee=&quantity1=3&receiver_id=CUMWR6T2ARF36&txn_type=cart&mc_gross_1=3.00&mc_currency=EUR&residence_country=FR&test_ipn=1&transaction_subject=%7B%22user%22%3A%22username%22%2C%22location%22%3A%7B%22x%22%3A202%2C%22y%22%3A223%7D%7D&payment_gross=&ipn_track_id=a48170aadb705',
'outstanding_balance': None,
'subscr_id': u'',
'auction_multi_item': None,
'item_name': u'',
'case_id': u'',
'address_name': u'',
'transaction_entity': u'',
'from_view': u'',
'auction_closing_date': None,
'password': u'',
'auction_buyer_id': u'',
'address_country_code': u'',
'address_city': u'',
'address_status': u'',
'auth_exp': u'',
'payer_email': u'email#gmail.com',
'mc_gross': Decimal('3.00'),
'reattempt': u'',
'handling_amount': None,
'reason_code': u'',
'remaining_settle': None,
'invoice': u'',
'address_state': u'',
'num_cart_items': 1,
'address_country': u'',
'payer_business_name': u'',
'first_name': u'FIRSTNAME',
'mc_shipping': Decimal('0.00'),
'flag_info': u'',
'for_auction': None,
'profile_status': u'',
'item_number': u'',
'business': u'email-facilitator#gmail.com',
'settle_currency': u'',
'shipping': None,
'amount': None,
'currency_code': u'',
'txn_id': u'2KW31663CC752394K',
'payment_status': u'Completed',
'payment_gross': None,
'retry_at': None,
'exchange_rate': None,
'residence_country': u'FR',
'payer_status': u'verified',
'address_street': u'',
'initial_payment_amount': None,
'auth_amount': None,
'custom': u'{"user":"username","location":{"x":202,"y":223}}',
'notify_version': Decimal('3.8'),
'period_type': u'',
'settle_amount': None,
'recurring': u'',
'pending_reason': u'',
'username': u'',
'tax': Decimal('0.00'),
'memo': u'',
'payer_id': u'Q6E6KSFDPM3U6',
'flag': False,
'mc_handling': Decimal('0.00'),
'address_zip': u'',
'mc_fee': Decimal('0.35'),
'payment_type': u'instant',
'amount1': None,
'recurring_payment_id': u'',
'protection_eligibility': u'Ineligible',
'receiver_email': u'email-facilitator#gmail.com',
'_state': <django.db.models.base.ModelState object at 0x2248550>,
'updated_at': datetime.datetime(2014, 6, 27, 10, 7, 50, 798510, tzinfo=<UTC>),
'time_created': None,
'mc_currency': u'EUR',
'option_name1': u'',
'subscr_date': None,
'option_name2': u'',
'txn_type': u'cart',
'recur_times': None,
'auth_status': u'',
'id': 90,
'rp_invoice_id': u'',
'payment_cycle': u'',
'subscr_effective': None,
'charset': u'windows-1252',
'parent_txn_id': u'',
'auth_id': u'',
'transaction_subject': u'{"user":"username","location":{"x":202,"y":223}}',
'contact_phone': u'',
'product_name': u'',
'test_ipn': True,
'receiver_id': u'CUMWR6T2ARF36',
'payment_date': datetime.datetime(2014, 6, 27, 3, 6, 57, tzinfo=<LocalTimezone>),
'amount_per_cycle': None,
'period2': u'',
'period3': u'',
'period1': u'',
'verify_sign': u'SECRET_CODE',
'flag_code': u'',
'ipaddress': '127.0.0.1',
'response': u'VERIFIED',
'product_type': u'',
'receipt_id': u'',
'amount3': None,
'amount2': None,
'next_payment_date': None,
'mc_amount3': None,
'mc_amount2': None,
'mc_amount1': None,
'case_creation_date': None,
'case_type': u'',
'quantity': None}

num_cart_items is the number of distinct items in the cart. The quantity of each item is in quantity1, quantity2, etc, for a shopping-cart transaction, otherwise in quantity.
This is all documented.

Related

how to read value from Json flutter

hello i have an object Json which have some values as payload , key , card .. so i aim to get the data i need directly with key "payload" .
var dataFinal= tag.data.toString();
and this what i get if i print my data
[log] handle {nfca: {identifier: [12, 4, 18, 17], atqa: [4, 0], maxTransceiveLength: 253, sak: 8, timeout: 618}, mifareclassic: {identifier: [99, 4, 150, 17], blockCount: 64, maxTransceiveLength: 253, sectorCount: 16, size: 1024, timeout: 618, type: 0}, ndef: {identifier: [99, 4, 150, 17], isWritable: true, maxSize: 716, canMakeReadOnly: false, cachedMessage: {records: [{typeNameFormat: 1, type: [84], identifier: [], payload: [1,45,989]}]}, type: com.nxp.ndef.mifareclassic}}
how can i get the payload value ?
You can check out the function jsonDecode() which expects a string as a param and returns dynamic or Map in your case
import 'dart:convert';
Map<String,dynamic> data = jsonDecode(tag.data.toString());
print(data["nfca"]);

inserting list of dicts as JSON binary into peewee model

I have a simple list of dicts I want to insert into my LabelModel table in my postgres DB
l = [{'label': 'A',
'x': 132.56338500976562,
'y': 333.7539367675781,
'width': 183.78598022460938,
'height': 404.6580505371094,
'score': 0.9848693609237671},
{'label': 'B',
'x': 179.97842407226562,
'y': 367.101318359375,
'width': 127.43386840820312,
'height': 59.047882080078125,
'score': 0.965998113155365},
{'label': 'C',
'x': 431.1368408203125,
'y': 365.9712219238281,
'width': 127.59616088867188,
'height': 60.77362060546875,
'score': 0.9622131586074829}]
class TblLabelByAI(BaseModel):
name = pw.TextField()
labels = BinaryJSONField()
modified_at = pw.DateField(default=datetime.datetime.utcnow)
q = {"imagename":"testname","labels":l}
TblLabelByAI.get_or_create(**q)
Is there any reason I get the following:
ProgrammingError: operator does not exist: jsonb = record
LINE 1: ...testname') AND ("t1"."labels" = (CAST('{...
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
Peewee: 3.14.9
Python 3.8
#coleifer - amazing work btw
Here is a workaround:
from psycopg2.extras import Json
data = [{'x': 123, 'y': 123},{'x': 123, 'y': 123},{'x': 123, 'y': 123}]
data = Json(data)

Pyspark Loses Metadata After MinMaxScaler

I'm using the student data set from:
https://archive.ics.uci.edu/ml/machine-learning-databases/00320/
If I scale the features in the pipeline it loses the bulk of the metadata which I need later. Here is the basic setup without scaling to produce the metadata. The scaling options are commented for easy replication.
I'm selecting out numeric and categorical columns I wish to use for the model. Here is my data setup and pipeline without scaling to see the metadata.
# load data
from pyspark.sql import SparkSession
spark = SparkSession.builder.appName('student-performance').getOrCreate()
df_raw = spark.read.options(delimiter=';', header=True, inferSchema=True).csv('student-mat.csv')
# specify columns and filter
cols_cate = ['school', 'sex', 'Pstatus', 'Mjob', 'Fjob', 'famsup', 'activities', 'higher', 'internet', 'romantic']
cols_num = ['age', 'Medu', 'Fedu', 'studytime', 'failures', 'famrel', 'goout', 'Dalc', 'Walc', 'health', 'absences', 'G1', 'G2']
col_label = ['G3']
keep = cols_cate + cols_num + col_label
df_keep = df_raw.select(keep)
# setup pipeline
from pyspark.ml.feature import OneHotEncoder, StringIndexer, VectorAssembler, MinMaxScaler
cols_assembly = []
stages = []
for col in cols_cate:
string_index = StringIndexer(inputCol=col, outputCol=col+'-indexed')
encoder = OneHotEncoder(inputCol=string_index.getOutputCol(), outputCol=col+'-encoded')
cols_assembly.append(encoder.getOutputCol())
stages += [string_index, encoder]
# assemble vectors
assembler_input = cols_assembly + cols_num
assembler = VectorAssembler(inputCols=assembler_input, outputCol='features')
stages += [assembler]
# MinMaxScalar option - will need to change 'features' -> 'scaled-features' later
#scaler = MinMaxScaler(inputCol='features', outputCol='scaled-features')
#stages += [scaler]
# apply pipeline
from pyspark.ml import Pipeline
pipeline = Pipeline(stages=stages)
pipelineModel = pipeline.fit(df_keep)
df_pipe = pipelineModel.transform(df_keep)
cols_selected = ['features'] + cols_cate + cols_num + ['G3']
df_pipe = df_pipe.select(cols_selected)
Make the training data, fit a model, and get predictions.
from pyspark.ml.regression import LinearRegression
train, test = df_pipe.randomSplit([0.7, 0.3], seed=14)
lr = LinearRegression(featuresCol='features',labelCol='G3', maxIter=10, regParam=0.3, elasticNetParam=0.8)
lrModel = lr.fit(train)
lr_preds = lrModel.transform(test)
Checking the metadata of the "features" column I have a lot of information here.
lr_preds.schema['features'].metadata
Output:
{'ml_attr': {'attrs': {'numeric': [{'idx': 16, 'name': 'age'},
{'idx': 17, 'name': 'Medu'},
{'idx': 18, 'name': 'Fedu'},
{'idx': 19, 'name': 'studytime'},
{'idx': 20, 'name': 'failures'},
{'idx': 21, 'name': 'famrel'},
{'idx': 22, 'name': 'goout'},
{'idx': 23, 'name': 'Dalc'},
{'idx': 24, 'name': 'Walc'},
{'idx': 25, 'name': 'health'},
{'idx': 26, 'name': 'absences'},
{'idx': 27, 'name': 'G1'},
{'idx': 28, 'name': 'G2'}],
'binary': [{'idx': 0, 'name': 'school-encoded_GP'},
{'idx': 1, 'name': 'sex-encoded_F'},
{'idx': 2, 'name': 'Pstatus-encoded_T'},
{'idx': 3, 'name': 'Mjob-encoded_other'},
{'idx': 4, 'name': 'Mjob-encoded_services'},
{'idx': 5, 'name': 'Mjob-encoded_at_home'},
{'idx': 6, 'name': 'Mjob-encoded_teacher'},
{'idx': 7, 'name': 'Fjob-encoded_other'},
{'idx': 8, 'name': 'Fjob-encoded_services'},
{'idx': 9, 'name': 'Fjob-encoded_teacher'},
{'idx': 10, 'name': 'Fjob-encoded_at_home'},
{'idx': 11, 'name': 'famsup-encoded_yes'},
{'idx': 12, 'name': 'activities-encoded_yes'},
{'idx': 13, 'name': 'higher-encoded_yes'},
{'idx': 14, 'name': 'internet-encoded_yes'},
{'idx': 15, 'name': 'romantic-encoded_no'}]},
'num_attrs': 29}}
If I add scaling after the VectorAssembler (commented-out above) in the pipeline, retrain, and make predictions again, it loses all of this metadata.
lr_preds.schema['scaled-features'].metadata
Output:
{'ml_attr': {'num_attrs': 29}}
Is there any way to get this metadata back? Thanks in advance!
mck's suggestion of using 'features' from lr_preds works to get the metadata, it's unchanged. Thank you.
the column features should remain in the dataframelr_preds, maybe you can get it from that column instead?

Fail to redirect in Flask under a post request

I am working on a small website about food written by Flask. However, I have trouble with redirecting users to a new page after they type in something in the search bar and then click the search button.
#app.route('/', methods = ['GET','POST'])
def home():
if request.method == "POST":
search = request.form['search']
print(search)
sql_search = 'SELECT Food.name,Food.area,Food.price,Food.description,Food.available_amount,Food.score,AVG_PRICE,AVG_SCORE,User.selling_score FROM Food LEFT JOIN(SELECT Food.name, Food.area ,AVG(Food.price) AS AVG_PRICE,AVG(Food.score) AS AVG_SCORE FROM Food GROUP BY Food.name, Food.area) NEW_FOOD ON Food.name = NEW_FOOD.name AND Food.area = NEW_FOOD.area LEFT JOIN User ON Food.maker_id = User.id WHERE Food.name LIKE "%s" ORDER BY Food.price,Food.score DESC,User.selling_score DESC' % search
search_list = db.session.execute(sql_search).fetchall()
search_l = process_dict(search_list, attr_search)
print(search_l)
return redirect(url_for('test'), code = 303)
return render_template('home.html')
This is the output from the terminal after I search "curry" on the homepage.
curry
[{'name': 'curry', 'area': 61801, 'price': 6.0, 'description': 'nice', 'available_amount': 1, 'score': 5.0, 'AVG_PRICE': 6.0, 'AVG_SCORE': 5.0, 'seller_score': 0.0}, {'name': 'curry', 'area': 61820, 'price': 8.0, 'description': 'ok', 'available_amount': 2, 'score': 5.0, 'AVG_PRICE': 8.666666666666666, 'AVG_SCORE': 4.0, 'seller_score': 0.0}, {'name': 'curry', 'area': 61820, 'price': 8.0, 'description': 'excellent', 'available_amount': 2, 'score': 4.0, 'AVG_PRICE': 8.666666666666666, 'AVG_SCORE': 4.0, 'seller_score': 0.0}, {'name': 'curry', 'area': 61820, 'price': 10.0, 'description': 'excellent', 'available_amount': 1, 'score': 3.0, 'AVG_PRICE': 8.666666666666666, 'AVG_SCORE': 4.0, 'seller_score': 0.0}]
10.193.20.119 - - [31/Mar/2018 20:40:41] "POST / HTTP/1.1" 303 -
10.193.20.119 - - [31/Mar/2018 20:40:41] "GET /test HTTP/1.1" 200
Although the terminal shows that it sends a get request to the page I want to redirect to, my page actually has no change. Does anyone have some ideas about what is going wrong with my code?
And this is the code for my simple test page:
#app.route('/test')
# #login_required
def test():
return "hello"

How to use Time in Google Charts?

I'm using Google Charts. Here's an example data from Google's website:
var data = new google.visualization.DataTable(
{
cols: [{id: 'task', label: 'Employee Name', type: 'string'},
{id: 'startDate', label: 'Start Date', type: 'date'}],
rows: [{c:[{v: 'Mike'}, {v: new Date(2008, 1, 28), f:'February 28, 2008'}]},
{c:[{v: 'Bob'}, {v: new Date(2007, 5, 1)}]},
{c:[{v: 'Alice'}, {v: new Date(2006, 7, 16)}]},
{c:[{v: 'Frank'}, {v: new Date(2007, 11, 28)}]},
{c:[{v: 'Floyd'}, {v: new Date(2005, 3, 13)}]},
{c:[{v: 'Fritz'}, {v: new Date(2011, 6, 1)}]}
]
}
)
I'd like to use hours and minutes also in the date variables. I haven't found an example syntax on the website, has anyone tried this before? Thanks in advance.
The Mozilla Developer Network has an extensive JavaScript reference, including on the Date object. See the following constructor syntax:
new Date()
new Date(milliseconds)
new Date(dateString)
new Date(year, month, day [, hour, minute, second, millisecond ])
So for 2011-06-01 at 1:37 PM, you could do:
new Date(2011, 5, 1, 13, 37)
Please note that months are zero-based, so the 5 above represents the 6th month (i.e. June).
N.B. I have very little familiarity with Google Charts, so I would accept edits to make this question more relevant to the O.P.'s question.