我想重定向我的用户后,他已经作出了付款(成功或失败)到一个页面自动。
目前,付款进行得很顺利,stripe上的更新也很成功,我设法用我的django视图检索到了必要的信息。
然而,成功支付后,没有发生重定向。有几个文档,但我找不到一种方法来做它与react组件提出的条纹自己。
我该如何继续?
这是我作品
- 报价. js**:按条带React组件
<stripe-pricing-table
pricing-table-id="prctbl_<my_pricing_table_key>"
publishable-key="pk_test_<my-stripe-public-key>"
// user informations for update subscriptions django model
customer-email={`${info_user.info_user.email}`}
client-reference-id={`${info_user.info_user.id}`}
>
</stripe-pricing-table>
当我点击订阅按钮时,一切都很好。付款是在stripe上进行的,我用django在我的webhook中检索信息
- 查看次数. py**
class StripeWebhookView(APIView):
permission_classes = []
authentication_classes = []
helpers = AbonnementHelpers
updating = UpdateAbonnementHelpers
def post(self, request):
payload = request.body
sig_header = request.META['HTTP_STRIPE_SIGNATURE']
endpoint_secret = STRIPE_WEBHOOK_SECRET
# webhook
try:
event = stripe.Webhook.construct_event(
payload, sig_header, endpoint_secret
)
except ValueError as e:
return Response(status=status.HTTP_400_BAD_REQUEST)
except stripe.error.SignatureVerificationError as e:
return Response(status=status.HTTP_400_BAD_REQUEST)
# full session data recovery
if event['type'] == 'checkout.session.completed':
info_event = self.helpers().stripe_event(event)
user = UserAccount.objects.get(id=info_event['user_id'])
# check if user subscription exist in my database
try:
abo = Abonnement.objects.get(user=user)
self.updating.update_abo(
abo=abo,
subscription_id=info_event['subscription_id'],
num_facture=info_event['num_facture'],
is_paid=info_event['is_paid'],
expire_at=info_event['expire_at'],
price=info_event['price'],
abo_id=info_event['abonnement_id'],
customer_id=info_event['customer_id'],
plan=info_event['plan']
)
# if not exist, create the subscription with django model
except ObjectDoesNotExist:
abo = Abonnement(
user=user,
email=user.email,
stripe_subscription_id=info_event['subscription_id'],
numero_facture=info_event['num_facture'],
is_paid=info_event['is_paid'],
abonne_jusquau=info_event['expire_at'],
price=info_event['price'],
abonnement_id=info_event['abonnement_id'],
stripe_user_id=info_event['customer_id'],
plan=info_event['plan']
)
abo.save()
return Response(status=status.HTTP_200_OK)
return Response(status=status.HTTP_200_OK)
# here i try several things but not working currently (with redirect)
class SuccessView(View):
def get(self, request):
return redirect('/success')
class CancelView(View):
def get(self, request):
return render(request, 'cancel.html', {})
这里是我的订阅应用程序的附属URL路径
- 网址. py**
urlpatterns = [
# it's ok !
path('stripe-webhook', views.StripeWebhookView.as_view(), name='create-payment-intent'),
# not use currently
path('success', views.SuccessView.as_view(), name='success'),
path('cancel', views.CancelView.as_view(), name='cancel'),
]
- 型号. py**
class Abonnement(models.Model):
user = models.OneToOneField(UserAccount, on_delete=models.CASCADE)
email = models.EmailField(max_length=50, unique=True)
stripe_subscription_id = models.CharField(max_length=255)
is_paid = models.BooleanField(default=False)
paye_le = models.DateTimeField(auto_now_add=True)
abonne_jusquau = models.DateTimeField(blank=True)
price = models.FloatField(default=0.0, blank=True)
numero_facture = models.CharField(max_length=150, blank=True)
abonnement_id = models.CharField(max_length=255)
stripe_user_id = models.CharField(max_length=255)
last_update = models.DateTimeField(blank=True, null=True)
plan = models.CharField(max_length=15)
def __str__(self):
return f"{self.user} {self.plan}"
付款后,我得到一个页面,"成功付款",但没有重定向到应用程序,也没有可能返回到应用程序. URL看起来像这样:https://checkout.stripe.com/c/pay/cs_test_b1m[...]ERl#fid[...]ICUl
[...]=若干数字和字母的序列
我做错了什么?谢谢你的帮助
1条答案
按热度按时间kknvjkwl1#
要设置成功付款后重定向到您的应用程序,可以通过在 Jmeter 板中的pricing table page中设置来完成。您可以在每个价格中选择
Don't show confirmation page
以禁用显示Stripe的确认页面,并设置返回URL以定向到您的网站。下面是您可以设置它的位置的屏幕截图: