How to redirect user to a returned URL python -


so im testing out paypal rest sdk , im using python cgi language(i know 2007), anyway i've hit roadblock,in cant redirect returned url page.

i tried print location method. , did not work me.

# create payment using paypal sample # sample code demonstrates how can process # paypal account based payment. # api used: /v1/payments/payment paypalrestsdk import payment import logging  logging.basicconfig(level=logging.info)  # payment # payment resource; create 1 using # above types , intent 'sale' payment = payment({ "intent": "sale",  # payer # resource representing payer funds payment # payment method 'paypal' "payer": {     "payment_method": "paypal"},  # redirect urls "redirect_urls": {     "return_url": "http://localhost:3000/payment/execute",     "cancel_url": "http://localhost:3000/"},  # transaction # transaction defines contract of # payment - payment , # fulfilling it. "transactions": [{      # itemlist     "item_list": {         "items": [{             "name": "item",             "sku": "item",             "price": "5.00",             "currency": "usd",             "quantity": 1}]},      # amount     # let's specify payment amount.     "amount": {         "total": "5.00",         "currency": "usd"},     "description": "this payment transaction description."}]})   # create payment , return status  if payment.create():  print("payment[%s] created successfully" % (payment.id))   # redirect user given approval url link in payment.links:     if link.method == "redirect":         # convert str avoid google appengine unicode issue         # https://github.com/paypal/rest-api-sdk-python/pull/58         redirect_url = str(link.href)         print("redirect approval: %s" % (redirect_url)) else:     print("error while creating payment:")     print(payment.error) 

so me out if guys new of anyway throw 301 or 302 on users browser. thank you.

i kinda solved on own. add code

print 'content-type: text/html' print 'location: %s' % redirecturl print # http says have have blank line between headers , content print '<html>' print '  <head>' print '    <meta http-equiv="refresh" content="0;url=%s" />' %redirecturl print '    <title>you going redirected</title>' print '  </head>'  print '  <body>' print '    redirecting... <a href="%s">click here if not redirected</a>' % redirecturl print '  </body>' print '</html>' 

know script redirects page charm.thank you


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -