예제 #1
0
    def process_payment(self):
        status = http.OK
        data = self.order.details
        data['status'] = 'OK'
        try:
            option_id = session.pop('valid_option', None)
            carts = self.order.goods.filter_by(price_option_id=option_id)
            if carts.count() != self.order.goods.count():
                raise t.DataError({'voucher': _('Invalid price option')})

            redemption = self.__redeem(voucher=data['voucher'],
                                       security=data['code'],
                                       deal=data['deal'])
            if redemption.status_code != http.OK:
                raise t.DataError({'voucher': _('Invalid voucher')})
            else:
                self.order.mark_paid()
                data.update(self.order.as_dict())
        except t.DataError as e:
            status = http.BAD_REQUEST
            data.update({
                'message': 'ERROR',
                'errors': e.as_dict(),
                'status': 'ERR'
            })

        return jsonify_status_code(data, status)
예제 #2
0
파일: api.py 프로젝트: rudimk/flamingo
    def post(self):
        status = http.CREATED
        data = request.json or abort(http.BAD_REQUEST)
        validation = self.validation.make_optional('concrete_product_id')

        # condition to ensure that we have a customer when item added to cart
        if current_user.is_anonymous():
            if session.get('customer_id'):
                customer = Customer.query.get_or_404(session['customer_id'])
            else:
                customer = Customer.create()
        else:
            customer = current_user.customer
        session['customer_id'] = customer.id
        data['customer_id'] = customer.id
        try:
            data = validation.check(data)
            product = mongo.db.products.find_one({'_id': data['product_id']})
            if product is None:
                raise t.DataError({'product_id': _('Product not fount')})

            cart = product.add_to_cart(customer=customer,
                                       amount=data['amount'],
                                       price_option_id=data['price_option_id'],
                                       service=data.get('service'))

            response = cart.as_dict()
        except t.DataError as e:
            status, response = http.BAD_REQUEST, e.as_dict()

        return jsonify_status_code(response, status)
예제 #3
0
파일: groupon.py 프로젝트: rudimk/flamingo
    def verify(self, data):
        status = http.OK
        try:
            data = self.validation.check(data)
            price_option = mongo.db.prices.find_one({
                'groupon.cda': data['deal']
            })
            if price_option is None:
                raise t.DataError({'deal': u'Invalid deal'})

            validation = self.__validate(voucher=data['voucher'],
                                         security=data['code'],
                                         deal=data['deal'])
            if validation.status_code != http.OK:
                raise t.DataError({'voucher': u'InvalidVoucher'})

            deal = filter(lambda deal: deal['cda'] == data['deal'],
                          price_option.groupon)

            data.update({
                'message': 'OK',
                'seats': deal[0]['number'],
                'option': price_option,
            })
        except t.DataError as e:
            data.update({
                'message': 'ERROR',
                'exception': e.as_dict(),
            })
            status = http.BAD_REQUEST

        return jsonify_status_code(data, status)
예제 #4
0
파일: api.py 프로젝트: rudimk/flamingo
    def delete(self, id):
        for key in ("identity.name", "identity.auth_type"):
            session.pop(key, None)

        identity_changed.send(current_app._get_current_object(), identity=AnonymousIdentity())
        logout_user()
        return jsonify_status_code(self._get_response(), http.NO_CONTENT)
예제 #5
0
    def process_payment(self):
        status = http.OK
        data = self.order.details
        data['status'] = 'OK'
        try:
            option_id = session.pop('valid_option', None)
            carts = self.order.goods.filter_by(price_option_id=option_id)
            if carts.count() != self.order.goods.count():
                raise t.DataError({'voucher': _('Invalid price option')})

            redemption = self.__redeem(voucher=data['voucher'],
                                       security=data['code'],
                                       deal=data['deal'])
            if redemption.status_code != http.OK:
                raise t.DataError({'voucher': _('Invalid voucher')})
            else:
                self.order.mark_paid()
                data.update(self.order.as_dict())
        except t.DataError as e:
            status = http.BAD_REQUEST
            data.update({
                'message': 'ERROR',
                'errors': e.as_dict(),
                'status': 'ERR'
            })

        return jsonify_status_code(data, status)
예제 #6
0
    def delete(self, id):
        for key in ('identity.name', 'identity.auth_type'):
            session.pop(key, None)

        identity_changed.send(current_app._get_current_object(),
                              identity=AnonymousIdentity())
        logout_user()
        return jsonify_status_code(self._get_response(), http.NO_CONTENT)
예제 #7
0
    def verify(self, data):
        status = http.OK
        try:
            data = self.validation.check(data)
            variant_id = data.pop('variant')
            order_cls = get_order_class()
            order = order_cls.get_by_payment_details(data)

            if order is not None:
                data.update({
                    'status': 'EXISTS',
                    'order': order.as_dict()
                })
                return jsonify_status_code(data, status)
            variant = BaseProductVariant.objects(id=variant_id).first()
            if variant is None:
                current_app.logger.debug("No variant")
                raise t.DataError({'deal': _('Invalid deal')})

            option, deal = self.__filter_option(variant, data['deal'])
            if option is None:
                current_app.logger.debug("No option")
                raise t.DataError({'deal': _('Invalid deal')})

            validation = self.__validate(voucher=data['voucher'],
                                         security=data['code'],
                                         deal=data['deal'])
            current_app.logger.info("Validation response: %s", validation)
            if validation.status_code != http.OK:
                raise t.DataError({'voucher': _('Invalid voucher')})

            session['valid_option'] = str(option.id)

            data.update({
                'status': 'OK',
                'seats': deal['number'],
                'option': option,
            })
        except t.DataError as e:
            data.update({
                'status': 'ERR',
                'errors': e.as_dict()
            })

        return jsonify_status_code(data, status)
예제 #8
0
    def __set_checkout(self, amount, payment_details):
        """ When a customer is ready to check out, use the SetExpressCheckout
            call to specify the amount of payment, return URL, and cancel
            URL. The SetExpressCheckout response contains a token for use in
            subsequent steps.
            Step 2 contained. Redirect the Customer to PayPal for
            Authorization.
        """
        session.update(payment_details)

        request_params = {
            'METHOD':
            SET_CHECKOUT,
            'NOSHIPPING':
            1,
            'REQCONFIRMSHIPPING':
            0,
            # FIXME: BuildError
            'RETURNURL':
            url_for('payment.process_payment',
                    payment_method=self.method_name,
                    _external=True),
            'CANCELURL':
            url_for('payment.cancel_payment',
                    payment_method=self.method_name,
                    _external=True)
        }
        # include description for items added to cart
        try:
            request_params.update(self.__prepare_cart_items())
        except AttributeError:
            sentry.captureException()
            return {
                'action':
                'redirect',
                'target':
                url_for('payment.error_payment',
                        payment_method=self.method_name,
                        _external=True)
            }

        response = self.__do_request(request_params)
        if response['ACK'] in RESPONSE_OK:
            self.order.set_payment_details(token=response['TOKEN'])
            webface_url = self.__get_redirect_url(response)
            response = self.order.as_dict()
            response.update({'action': 'redirect', 'target': webface_url})
            return jsonify_status_code(response)

        return {
            'action':
            'redirect',
            'target':
            url_for('payment.error_payment',
                    payment_method=self.method_name,
                    _external=True)
        }
예제 #9
0
파일: api.py 프로젝트: rudimk/flamingo
    def put(self, id):
        data, status = request.json or abort(http.BAD_REQUEST), http.ACCEPTED
        validation = t.Dict({"email": t.Email, "password": t.String}).append(self._authenticate).ignore_extra("*")

        try:
            validation.check(data)
            response = self._get_response()
        except t.DataError as e:
            response, status = e.as_dict(), http.NOT_FOUND

        return jsonify_status_code(response, status)
예제 #10
0
파일: api.py 프로젝트: rudimk/flamingo
    def post(self):
        status = http.CREATED
        try:
            if request.json:
                data = self.validation.check(request.json)
                response = self.__process_json(data)
            elif request.files:
                response = self.__process_form(request.form.to_dict())
        except t.DataError as e:
            status, response = http.BAD_REQUEST, e.as_dict()

        return jsonify_status_code(response, status)
예제 #11
0
    def verify(self, data):
        status = http.OK
        try:
            data = self.validation.check(data)
            variant_id = data.pop('variant')
            order_cls = get_order_class()
            order = order_cls.get_by_payment_details(data)

            if order is not None:
                data.update({'status': 'EXISTS', 'order': order.as_dict()})
                return jsonify_status_code(data, status)
            variant = BaseProductVariant.objects(id=variant_id).first()
            if variant is None:
                current_app.logger.debug("No variant")
                raise t.DataError({'deal': _('Invalid deal')})

            option, deal = self.__filter_option(variant, data['deal'])
            if option is None:
                current_app.logger.debug("No option")
                raise t.DataError({'deal': _('Invalid deal')})

            validation = self.__validate(voucher=data['voucher'],
                                         security=data['code'],
                                         deal=data['deal'])
            current_app.logger.info("Validation response: %s", validation)
            if validation.status_code != http.OK:
                raise t.DataError({'voucher': _('Invalid voucher')})

            session['valid_option'] = str(option.id)

            data.update({
                'status': 'OK',
                'seats': deal['number'],
                'option': option,
            })
        except t.DataError as e:
            data.update({'status': 'ERR', 'errors': e.as_dict()})

        return jsonify_status_code(data, status)
예제 #12
0
파일: paypal.py 프로젝트: itnow/flamaster
    def __set_checkout(self, amount, payment_details):
        """ When a customer is ready to check out, use the SetExpressCheckout
            call to specify the amount of payment, return URL, and cancel
            URL. The SetExpressCheckout response contains a token for use in
            subsequent steps.
            Step 2 contained. Redirect the Customer to PayPal for
            Authorization.
        """
        session.update(payment_details)

        request_params = {
            'METHOD': SET_CHECKOUT,
            'NOSHIPPING': 1,
            'REQCONFIRMSHIPPING': 0,
            # FIXME: BuildError
            'RETURNURL': url_for('payment.process_payment',
                                 payment_method=self.method_name,
                                 _external=True),
            'CANCELURL': url_for('payment.cancel_payment',
                                 payment_method=self.method_name,
                                 _external=True)
        }
        # include description for items added to cart
        try:
            request_params.update(self.__prepare_cart_items())
        except AttributeError:
            sentry.captureException()
            return {
                'action': 'redirect',
                'target': url_for('payment.error_payment',
                                  payment_method=self.method_name,
                                  _external=True)
            }

        response = self.__do_request(request_params)
        if response['ACK'] in RESPONSE_OK:
            self.order.set_payment_details(token=response['TOKEN'])
            webface_url = self.__get_redirect_url(response)
            response = self.order.as_dict()
            response.update({
                'action': 'redirect',
                'target': webface_url
            })
            return jsonify_status_code(response)

        return {
            'action': 'redirect',
            'target': url_for('payment.error_payment',
                              payment_method=self.method_name,
                              _external=True)
        }
예제 #13
0
파일: api.py 프로젝트: rudimk/flamingo
    def put(self, id):
        status = http.ACCEPTED
        data = request.json or abort(http.BAD_REQUEST)
        validation = self.validation.append(self._check_customer)
        try:
            data = validation.check(data)
            instance = self.get_object(id)
            if session['customer_id'] == instance.customer_id:
                response = instance.update(amount=data['amount']).as_dict()
            else:
                abort(http.UNAUTHORIZED)
        except t.DataError as e:
            status, response = http.BAD_REQUEST, e.as_dict()

        return jsonify_status_code(response, status)
예제 #14
0
파일: api.py 프로젝트: rudimk/flamingo
    def post(self):
        data = request.json or abort(http.BAD_REQUEST)
        try:
            data = self.validation.check(data)

            if not User.is_unique(data["email"]):
                raise t.DataError({"email": _("This email is already taken")})

            register_user(email=data["email"], password=data.get("password", ""))

            response, status = self._get_response(), http.CREATED

        except t.DataError as e:
            response, status = e.as_dict(), http.BAD_REQUEST
        return jsonify_status_code(response, status)
예제 #15
0
    def post(self):
        status = http.CREATED
        mimetype = 'application/json'
        try:
            if request.json:
                data = self.validation.check(request.json)
                response = self.__process_json(data)
            elif request.files.get('image'):
                response = self.__process_form()
                mimetype = 'text/html'
            else:
                raise t.DataError({'message': _('No data loaded')})
        except t.DataError as e:
            status, response = http.BAD_REQUEST, e.as_dict()

        return jsonify_status_code(response, status, mimetype)
예제 #16
0
    def post(self):
        status = http.CREATED
        mimetype = 'application/json'
        try:
            if request.json:
                data = self.validation.check(request.json)
                response = self.__process_json(data)
            elif request.files.get('image'):
                response = self.__process_form()
                mimetype = 'text/html'
            else:
                raise t.DataError({'message': _('No data loaded')})
        except t.DataError as e:
            status, response = http.BAD_REQUEST, e.as_dict()

        return jsonify_status_code(response, status, mimetype)
예제 #17
0
파일: groupon.py 프로젝트: rudimk/flamingo
    def process_payment(self):
        status = http.OK
        try:
            data = self.validation.check(request.json)
            customer = Customer.query.get_or_404(session['customer_id'])
            redemption = self.__redeem(voucher=data['voucher'],
                                       security=data['code'],
                                       deal=data['deal'])
            if redemption.status_code != http.OK:
                raise t.DataError({'voucher': u'InvalidVoucher'})

        except t.DataError as e:
            status = http.BAD_REQUEST
            data.update({
                'message': 'ERROR',
                'exception': e.as_dict(),
            })

        return jsonify_status_code(data, status)
예제 #18
0
    def __set_checkout(self, amount, payment_details):
        """ When a customer is ready to check out, use the SetExpressCheckout
            call to specify the amount of payment, return URL, and cancel
            URL. The SetExpressCheckout response contains a token for use in
            subsequent steps.
            Step 2 contained. Redirect the Customer to PayPal for
            Authorization.
        """
        request_params = {
            'METHOD':
            SET_CHECKOUT,
            'PAYMENTREQUEST_0_AMT':
            amount,
            'PAYMENTREQUEST_0_PAYMENTACTION':
            ACTION,
            'PAYMENTREQUEST_0_CURRENCYCODE':
            CURRENCY,
            # FIXME: BuildError
            'RETURNURL':
            request.url_root.rstrip('/') + url_for(
                'payment.process_payment', payment_method=self.method_name),
            'CANCELURL':
            request.url_root.rstrip('/') +
            url_for('payment.cancel_payment', payment_method=self.method_name)
        }
        # include description for items added to cart
        request_params.update(self.__prepare_cart_items())
        response = self.__do_request(request_params)
        if response['ACK'] == RESPONSE_OK:
            self.order.set_payment_details(token=response['TOKEN'])
            webface_url = self.__get_redirect_url(response)
            response = self.order.as_dict()
            response.update({'action': 'redirect', 'target': webface_url})
            return jsonify_status_code(response)

        return {
            'action':
            'redirect',
            'target':
            url_for('payment.error_payment', payment_method=self.method_name)
        }
예제 #19
0
    def __set_checkout(self, amount, payment_details):
        """ When a customer is ready to check out, use the SetExpressCheckout
            call to specify the amount of payment, return URL, and cancel
            URL. The SetExpressCheckout response contains a token for use in
            subsequent steps.
            Step 2 contained. Redirect the Customer to PayPal for
            Authorization.
        """
        request_params = {
            'METHOD': SET_CHECKOUT,
            'PAYMENTREQUEST_0_AMT': amount,
            'PAYMENTREQUEST_0_PAYMENTACTION': ACTION,
            'PAYMENTREQUEST_0_CURRENCYCODE': CURRENCY,
            # FIXME: BuildError
            'RETURNURL': request.url_root.rstrip('/') + url_for(
                'payment.process_payment',
                payment_method=self.method_name),
            'CANCELURL': request.url_root.rstrip('/') + url_for(
                'payment.cancel_payment',
                payment_method=self.method_name)
        }
        # include description for items added to cart
        request_params.update(self.__prepare_cart_items())
        response = self.__do_request(request_params)
        if response['ACK'] == RESPONSE_OK:
            self.order.set_payment_details(token=response['TOKEN'])
            webface_url = self.__get_redirect_url(response)
            response = self.order.as_dict()
            response.update({
                'action': 'redirect',
                'target': webface_url
            })
            return jsonify_status_code(response)

        return {
            'action': 'redirect',
            'target': url_for('payment.error_payment',
                              payment_method=self.method_name)
        }
예제 #20
0
파일: api.py 프로젝트: rudimk/flamingo
    def post(self):
        status = http.CREATED
        data = request.json or abort(http.BAD_REQUEST)

        try:
            data = self.validation.check(data)
            address_type = data.pop("type")
            address = self.model.create(**data)
            if current_user.is_anonymous():
                session.get("customer_id") or abort(http.NOT_FOUND)
                customer = Customer.query.get_or_404(session["customer_id"])
            else:
                customer = current_user.customer

            customer.set_address(address_type, address)
            customer.save()

            response = self.serialize(address)
        except t.DataError as e:
            status, response = http.BAD_REQUEST, e.as_dict()

        return jsonify_status_code(response, status)
예제 #21
0
파일: groupon.py 프로젝트: zerix/flamaster
    def process_payment(self):
        status = http.OK
        data = self.order.details
        data['status'] = 'OK'
        try:
            redemption = self.__redeem(voucher=data['voucher'],
                                       security=data['code'],
                                       deal=data['deal'])
            if redemption.status_code != http.OK:
                raise t.DataError({'voucher': _('Invalid voucher')})
            else:
                self.order.mark_paid()
                data.update(self.order.as_dict())
        except t.DataError as e:
            status = http.BAD_REQUEST
            data.update({
                'message': 'ERROR',
                'errors': e.as_dict(),
                'status': 'ERR'
            })

        return jsonify_status_code(data, status)
예제 #22
0
파일: api.py 프로젝트: rudimk/flamingo
 def __build_response(self, items):
     response = {
         'objects': items,
         'meta': None
     }
     return jsonify_status_code(response)
예제 #23
0
 def get(self, id=None):
     return jsonify_status_code(self._get_response())
예제 #24
0
 def get(self, id=None):
     return jsonify_status_code(self._get_response())