예제 #1
0
파일: views.py 프로젝트: muhiza/demp
    def post(self, request, format=None):
        data = request.data
        response = {}
        serializer = FinalizedOrderSerializer(data=data)
        if serializer.is_valid(raise_exception=True):
            request_data = serializer.data
            order_id = request_data.get("order_id")
            order = Order.objects.get(id=order_id)
            if not order.is_complete:
                order_total = order.order_total
                nonce = request_data.get("payment_method_nonce")
                if nonce:
                    result = braintree.Transaction.sale({
                        "amount":
                        order_total,
                        "payment_method_nonce":
                        nonce,
                        "billing": {
                            "postal_code":
                            "%s" % (order.billing_address.zipcode),
                        },
                        "options": {
                            "submit_for_settlement": True
                        }
                    })
                    success = result.is_success
                    if success:
                        #result.transaction.id to order
                        order.mark_completed(order_id=result.transaction.id)
                        #order.mark_completed(order_id="abc12344423")
                        order.cart.is_complete()
                        response["message"] = "Your order has been completed."
                        response["final_order_id"] = order.order_id
                        response["success"] = True
                    else:
                        #messages.success(request, "There was a problem with your order.")
                        error_message = result.message
                        #error_message = "Error"
                        response["message"] = error_message
                        response["success"] = False
            else:
                response["message"] = "Ordered has already been completed."
                response["success"] = False

        return Response(response)
예제 #2
0
    def post(self, request, format=None):
        data = request.data
        response = {}
        serializer = FinalizedOrderSerializer(data=data)
        if serializer.is_valid(raise_exception=True):
            request_data = serializer.data
            order_id = request_data.get("order_id")
            order = Order.objects.get(id=order_id)
            if not order.is_complete:
                order_total = order.order_total
                nonce = request_data.get("payment_method_nonce")
                if nonce:
                    result = braintree.Transaction.sale({
                        "amount": order_total,
                        "payment_method_nonce": nonce,
                        "billing": {
                            "postal_code": "%s" %(order.billing_address.zipcode),
                            
                         },
                        "options": {
                            "submit_for_settlement": True
                        }
                    })
                    success = result.is_success
                    if success:
                        #result.transaction.id to order
                        order.mark_completed(order_id=result.transaction.id)
                        #order.mark_completed(order_id="abc12344423")
                        order.cart.is_complete()
                        response["message"] = "Your order has been completed."
                        response["final_order_id"] = order.order_id
                        response["success"] = True
                    else:
                        #messages.success(request, "There was a problem with your order.")
                        error_message = result.message
                        #error_message = "Error"
                        response["message"] = error_message
                        response["success"] = False
            else:
                response["message"] = "Ordered has already been completed."
                response["success"] = False

        return Response(response)
예제 #3
0
파일: views.py 프로젝트: Toruitas/ecom
    def post(self, request, format=None):
        data = request.data
        response = {}
        serializer = FinalizedOrderSerializer(data=data)
        if serializer.is_valid(raise_exception=True):
            request_data = serializer.data
            order_id = request_data.get('order_id')
            order = Order.objects.get(id=order_id)
            if not order.is_complete:
                order_total = order.order_total
                nonce = request_data.get("payment_method_nonce")
                if nonce:
                    result = braintree.Transaction.sale({
                        'amount':order_total,
                        'payment_method_nonce':nonce,
                        'billing':{
                            'postal_code':'{}'.format(order.billing_address.zipcode)
                        },
                        'options':{
                            'submit_for_settlement':True
                        }
                    })
                    success = result.is_success
                    if success:
                        # result.transaction.id to order
                        # order.mark_completed(order_id=result.transaction.id)
                        order.mark_completed(order_id='abc12344423')
                        order.cart.is_complete()
                        response['message'] = 'your order has been completed'
                        response['final_order_id'] = order.order_id
                        response['success'] = True
                    else:
                        #messages.success(request, "there was a problem with your order")
                        error_message = result.message
                        # error_message = "error"
                        response['message'] = error_message
                        response['success'] = False
            else:
                response['message'] = "Order has already been completed"
                response['success'] = False

        return Response(response)
예제 #4
0
    def post(self, request, format=None):
        data = request.data
        response = {}
        serializer = FinalizedOrderSerializer(data=data)
        if serializer.is_valid(raise_exception=True):
            request_data = serializer.data
            order_id = request_data.get("order_id")
            order = Order.objects.get(id=order_id)
            if not order.is_complete:  #is_complete is a method used @property in order model
                order_total = order.order_total
                nonce = request_data.get("payment_method_nonce")
                if nonce:
                    result = braintree.Transaction.sale({
                        'amount':
                        order_total,
                        'payment_method_nonce':
                        nonce,
                        'billing': {
                            'postal_code': f'{order.billing_address.zipcode}',
                        },
                        'options': {
                            'submit_for_settlement': True
                        }
                    })
                    success = result.is_success
                    if success:
                        # result.transiction.id to order
                        order.mark_completed(order_id=result.transaction.id)
                        order.cart.is_complete()
                        response['message'] = 'Your order has been completed.'
                        response['final_order_id'] = order.order_id
                        response['success'] = True
                    else:
                        error_message = result.message
                        response['message'] = error_message
                        response['success'] = False
            else:
                response['message'] = 'Order has already been completed.'
                response['success'] = False

        return Response(response)