def get_access_token(self, request, callback=None): "Fetch access token from callback request." callback = request.build_absolute_uri(callback or request.path) if not self.check_application_state(request, callback): logger.error('Application state check failed.') return None if 'code' in request.GET: args = { 'client_id': self.provider.consumer_key, 'redirect_uri': callback, 'client_secret': self.provider.consumer_secret, 'code': request.GET['code'], 'grant_type': 'authorization_code', } else: logger.error('No code returned by the provider') return None try: response = self.request('post', self.provider.access_token_url, data=args) response.raise_for_status() except RequestException as e: logger.error('Unable to fetch access token: {0}'.format(e)) return None else: return response.text
def get_access_token(self, request, callback=None): """Fetch access token from callback request.""" callback = request.build_absolute_uri(callback or request.path) if not self.check_application_state(request): logger.error("Application state check failed.") return None if "code" in request.GET: args = { "client_id": self.consumer_key, "redirect_uri": callback, "client_secret": self.consumer_secret, "code": request.GET["code"], "grant_type": "authorization_code", } else: logger.error("No code returned by the provider") return None try: response = self.request("post", self.access_token_url, data=args) response.raise_for_status() except RequestException as e: logger.error("Unable to fetch access token: {0}".format(e)) return None else: return response.text
def get_access_token(self, request, callback=None): "Fetch access token from callback request." callback = request.build_absolute_uri(callback or request.path) if not self.check_application_state(request, callback): logger.error('Application state check failed.') return None if 'code' in request.GET: args = { 'client_id': self.provider.key, 'redirect_uri': callback, 'client_secret': self.provider.secret, 'code': request.GET['code'], 'grant_type': 'authorization_code', } else: logger.error('No code returned by the provider') return None try: response = self.request('post', self.provider.access_token_url, data=args) response.raise_for_status() except RequestException as e: logger.error('Unable to fetch access token: {0}'.format(e)) return None else: return response.text
def get_redirect_args(self, request, callback): "Get request parameters for redirect url." callback = request.build_absolute_uri(callback) return { 'client_id': self.provider.key, 'redirect_uri': callback, 'response_type': 'code', }
def payment(request): saved_address = BillingAddress.objects.get_or_create(user=request.user)[0] if not saved_address.is_fully_filled(): messages.info(request, "Please Complete Billing Address") return redirect('payment:checkout') if not request.user.profile.is_fully_filled(): messages.info(request, "Please Complete your profile Details") return redirect('home:home') store_id = 'rahay5e7c01054d7ed' store_pass = '******' mypayment = SSLCSession(sslc_is_sandbox=True, sslc_store_id=store_id, sslc_store_pass=store_pass) status_url = request.build_absolute_uri(reverse('payment:complete')) mypayment.set_urls(success_url=status_url, fail_url=status_url, cancel_url=status_url, ipn_url=status_url) order_qs = Order.objects.filter(user=request.user, ordered=False) order_items = order_qs[0].orderitems.all() order_items_count = order_qs[0].orderitems.count() order_total = order_qs[0].get_totals() mypayment.set_product_integration(total_amount=Decimal(order_total), currency='BDT', product_category='Mixed', product_name=order_items, num_of_item=order_items_count, shipping_method='Courier', product_profile='None') current_user = request.user mypayment.set_customer_info(name=current_user.profile.full_name, email=current_user.email, address1=current_user.profile.address, address2=current_user.profile.address, city=current_user.profile.city, postcode=current_user.profile.zipcode, country=current_user.profile.country, phone=current_user.profile.phone) mypayment.set_shipping_info(shipping_to=current_user.profile.full_name, address=saved_address.address, city=saved_address.city, postcode=saved_address.postcode, country=saved_address.country) response_data = mypayment.init_payment() return redirect(response_data['GatewayPageURL'])
def get_request_token(self, request, callback): "Fetch the OAuth request token. Only required for OAuth 1.0." callback = force_unicode(request.build_absolute_uri(callback)) try: response = self.request('post', self.provider.request_token_url, oauth_callback=callback) except RequestException: # TODO: Logging return None else: return response.text
def get_redirect_args(self, request, callback): "Get request parameters for redirect url." callback = force_unicode(request.build_absolute_uri(callback)) raw_token = self.get_request_token(request, callback) token, secret = self.parse_raw_token(raw_token) if token is not None and secret is not None: request.session[self.session_key] = raw_token return { 'oauth_token': token, 'oauth_callback': callback, }
def get_request_token(self, request, callback): "Fetch the OAuth request token. Only required for OAuth 1.0." callback = force_unicode(request.build_absolute_uri(callback)) try: response = self.request('post', self.provider.request_token_url, oauth_callback=callback) response.raise_for_status() except RequestException as e: logger.error('Unable to fetch request token: {0}'.format(e)) return None else: return response.text
def get_redirect_args(self, request, callback): "Get request parameters for redirect url." callback = force_text(request.build_absolute_uri(callback)) raw_token = self.get_request_token(request, callback) token, secret = self.parse_raw_token(raw_token) if token is not None and secret is not None: request.session[self.session_key] = raw_token return { 'oauth_token': token, 'oauth_callback': callback, }
def get_request_token(self, request, callback): "Fetch the OAuth request token. Only required for OAuth 1.0." callback = force_text(request.build_absolute_uri(callback)) try: response = self.request('post', self.provider.request_token_url, oauth_callback=callback) response.raise_for_status() except RequestException as e: logger.error('Unable to fetch request token: {0}'.format(e)) return None else: return response.text
def get_redirect_args(self, request, callback): "Get request parameters for redirect url." callback = request.build_absolute_uri(callback) args = { 'client_id': self.provider.key, 'redirect_uri': callback, 'response_type': 'code', } state = self.get_application_state(request, callback) if state is not None: args['state'] = state request.session[self.session_key] = state return args
def get_redirect_args(self, request, callback): "Get request parameters for redirect url." callback = request.build_absolute_uri(callback) args = { 'client_id': self.provider.consumer_key, 'redirect_uri': callback, 'response_type': 'code', } state = self.get_application_state(request, callback) if state is not None: args['state'] = state request.session[self.session_key] = state return args
def get_redirect_args(self, request, callback): """Get request parameters for redirect url.""" callback = force_text(request.build_absolute_uri(callback)) raw_token = self.get_request_token(request, callback) token, secret, _ = self.parse_raw_token(raw_token) if token is not None and secret is not None: request.session[self.session_key] = raw_token args = {"oauth_token": token, "oauth_callback": callback} scope = self.get_scope(request) if scope: args["scope"] = self.scope_separator.join(self.get_scope(request)) return args
def get_access_token(self, request, callback=None): "Fetch access token from callback request." raw_token = request.session.get(self.session_key, None) verifier = request.GET.get('oauth_verifier', None) if raw_token is not None and verifier is not None: data = {'oauth_verifier': verifier} callback = request.build_absolute_uri(callback or request.path) callback = force_unicode(callback) try: response = self.request('post', self.provider.access_token_url, token=raw_token, data=data, oauth_callback=callback) except RequestException: # TODO: Logging return None else: return response.text return None
def get_redirect_args(self, request, callback): """Get request parameters for redirect url.""" callback = force_text(request.build_absolute_uri(callback)) raw_token = self.get_request_token(request, callback) token, secret, _ = self.parse_raw_token(raw_token) if token is not None and secret is not None: request.session[self.session_key] = raw_token args = { 'oauth_token': token, 'oauth_callback': callback, } scope = self.get_scope(request) if scope: args['scope'] = self.scope_separator.join(self.get_scope(request)) return args
def get_access_token(self, request, callback=None): "Fetch access token from callback request." raw_token = request.session.get(self.session_key, None) verifier = request.GET.get('oauth_verifier', None) if raw_token is not None and verifier is not None: data = {'oauth_verifier': verifier} callback = request.build_absolute_uri(callback or request.path) callback = force_unicode(callback) try: response = self.request('post', self.provider.access_token_url, token=raw_token, data=data, oauth_callback=callback) response.raise_for_status() except RequestException as e: logger.error('Unable to fetch access token: {0}'.format(e)) return None else: return response.text return None
def get_redirect_args(self, request, callback): """Get request parameters for redirect url.""" callback = request.build_absolute_uri(callback) args = {"client_id": self.consumer_key, "redirect_uri": callback, "response_type": "code"} scope = self.get_scope(request) if scope: args["scope"] = self.scope_separator.join(self.get_scope(request)) state = self.get_application_state(request, callback) if state is not None: args["state"] = state request.session[self.session_key] = state auth_params = self.get_auth_params(request) if auth_params: args.update(auth_params) return args
def get_access_token(self, request, callback=None): "Fetch access token from callback request." callback = request.build_absolute_uri(callback or request.path) if 'code' in request.GET: args = { 'client_id': self.provider.key, 'redirect_uri': callback, 'client_secret': self.provider.secret, 'code': request.GET['code'], 'grant_type': 'authorization_code', } else: return None try: response = self.request('post', self.provider.access_token_url, data=args) except RequestException: # TODO: Logging return None else: return response.text
def get_access_token(self, request, callback=None): "Fetch access token from callback request." raw_token = request.session.get(self.session_key, None) verifier = request.GET.get('oauth_verifier', None) if raw_token is not None and verifier is not None: data = {'oauth_verifier': verifier} callback = request.build_absolute_uri(callback or request.path) callback = force_text(callback) try: response = self.request('post', self.provider.access_token_url, token=raw_token, data=data, oauth_callback=callback) response.raise_for_status() except RequestException as e: logger.error('Unable to fetch access token: {0}'.format(e)) return None else: return response.text return None
def get_redirect_args(self, request, callback): """Get request parameters for redirect url.""" callback = request.build_absolute_uri(callback) args = { 'client_id': self.consumer_key, 'redirect_uri': callback, 'response_type': 'code', } scope = self.get_scope(request) if scope: args['scope'] = self.scope_separator.join(self.get_scope(request)) state = self.get_application_state(request, callback) if state is not None: args['state'] = state request.session[self.session_key] = state auth_params = self.get_auth_params(request) if auth_params: args.update(auth_params) return args