- 支付回调页支付信息
- vue需要把支付凭证传递给django,django把订单状态改为已支付,并在UserCourse表中存储用户购买课程信息
mounted() {
this.query = this.$route.query
payment_post(this.query).then((resp) => {
// ({"code": 999, "msg": "非法请求"})
this.msg = resp.msg
})
},
2.goods/views
中写视图函数
class PaymentApi(APIView):
def post(self, request):
data = request.data
# 获取订单对象
order_obj = Orders.objects.get(order_id=data.get('out_trade_no'))
# 需要保存支付宝订单信息,支付时间,支付状态
order_obj.trade_no = data.get('trade_no')
order_obj.pay_time = data.get('timestamp')
order_obj.status = 2
order_obj.save()
# 获取用户购买的课程对象和当前用户
course_obj = Course.objects.get(pk=order_obj.goods.course_id)
user = UserCourse(user=request.user, course=course_obj)
user.save()
return Response({"code": 200, "msg": "OK"})
3.goods/urls
中注册路由
urlpatterns = [
path('payment/', views.PaymentApi.as_view()) # /goods/payment/
]