[web2py] (PWA) Send a Subscription information to my Server

2022-01-02 Thread mostwanted
Hi guys, I am still in the path of converting my app into a PWA. 
After subscribing the user to receive push messages I have to take save 
this information to the server into my database & this is where I am 
failing, I tried the code below to send the information to a function that 
will save into a database but the function is not receiving anything 
because i keep getting *TypeError: expected string or buffer *when i try to 
read the information.  Is there an easier way to grab information from 
JavaScript function as JSON data & send it to the server?

*function sendSubscriptionToBackEnd(subscription) {* 
* method: 'POST', *
*url: "{{=URL(''save_data")}},*
* headers: { 'Content-Type': 'application/json' }, *
* body: JSON.stringify(subscription) }) *
*  .then(function(response) {*
*if (!response.ok) {*
*throw new Error('Bad status code from server.'); } return response.json(); 
}) .then(function(responseData) { if (!(responseData.data && 
responseData.data.success)) { throw new Error('Bad response from server.'); 
} }); }*

Regards

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/d287bf6d-df95-47b7-ba3b-4062bc12b772n%40googlegroups.com.


[web2py] Estore Error with stripe

2022-01-02 Thread Maurice Waka
Hello I got this error when trying out the Estore app.
File "/home/maurice/web2py/applications/EStore/controllers/default.py" 
, line 
157, in pay
description="Purchase".encode('utf-8')
File "/home/maurice/web2py/gluon/contrib/stripe.py", line 115, in __init__
self.signature = sha1(repr((self.amount,self.description))).hexdigest()
TypeError: Unicode-objects must be encoded before hashing


part of the code in default is:

@auth.requires_login()
def checkout():
if session.checkout_form and not request.post_vars:
for key in session.checkout_form:
db.cart_order[key].default = session.checkout_form[key]
form = SQLFORM(db.cart_order).process(dbio=False)
if form.accepted:
session.checkout_form = form.vars
redirect(URL('pay'))
return locals()

def pay():#Not working, error # description: TypeError: Unicode-objects 
must be encoded before hashing
from gluon.contrib.stripe import StripeForm
results = price_cart()
stripe_form = StripeForm(
pk=STRIPE_PUBLIC_KEY,
sk=STRIPE_SECRET_KEY,
amount=int(100*results['total_with_shipping']),  # (amount is in 
cents)amount=int(100*results['total_with_shipping']),  
currency='eur',
currency_symbol='€',
description="Purchase".encode('utf-8')
)
stripe_form.process()

Help in correcting this error will be appreciated.
Thank you

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/96e2016b-92b6-4b43-8ae5-94cc6a082cc9n%40googlegroups.com.