I am making a project for an online payment e-commerce
I think I got everything right as am following a Tutorial
Keep getting this Error: Not Authenticated Error I used the testing CC Numbers for testing purposes
My question is the following codes correct and I'm getting Not Authenticated Error because they are testing Credit Card Numbers.?
class PaymentView(View): def get(self, *args, **kwargs): # order return render(self.request, "payment.html") # `source` is obtained with Stripe.js; see https://stripe.com/docs/payments/accept-a-payment-charges#web-create-token def post(self, *args, **kwargs): order = Order.objects.get(user=self.request.user, ordered=False) token = self.request.POST.get('stripeToken') amount = int(order.get_total() * 100) try: charge = stripe.Charge.create( amount=amount, # cents currency="usd", source=token, ) # create payment payment = Payment() payment.stripe_charge_id = charge['id'] payment.user = self.request.user payment.amount = order.get_total() payment.save() # assign the payment to the order order.ordered = True order.payment = payment order.save() messages.success(self.request, "Your Order was Successful ! ") return redirect("/") except stripe.error.CardError as e: body = e.json_body err = body.get('error', {}) messages.error(self.request, f"{err.get('message')}") # Since it's a decline, stripe.error.CardError will be caught return redirect("/") except stripe.error.RateLimitError as e: # Too many requests made to the API too quickly messages.error(self.request, "Rate Limit Error") return redirect("/") except stripe.error.InvalidRequestError as e: # Invalid parameters were supplied to Stripe's API messages.error(self.request, "Invalid Parameters") return redirect("/") except stripe.error.AuthenticationError as e: # Authentication with Stripe's API failed # (maybe you changed API keys recently) messages.error(self.request, "Not Authenticated") return redirect("/") except stripe.error.APIConnectionError as e: # Network communication with Stripe failed messages.error(self.request, "Network Error") return redirect("/") except stripe.error.StripeError as e: # Display a very generic error to the user, and maybe send # yourself an email messages.error( self.request, "Something went wrong. You were not charged. Please Try Again.") return redirect("/") except Exception as e: # Something else happened, completely unrelated to Stripe # send an email to ourselves messages.error( self.request, "A serious Error Occured. We have been notified.") return redirect("/")
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bba17951-6ca3-4480-9423-e5d39e6ed270%40googlegroups.com.
No comments:
Post a Comment