gpt4 book ai didi

Problem in setting up Shopify RecurringApplicationCharge in Django App(在Django App中设置Shopify RecurringApplicationCharge时出现问题)

转载 作者:bug小助手 更新时间:2023-10-24 17:10:51 26 4
gpt4 key购买 nike



I am following app structure with reference to https://github.com/Shopify/shopify_django_app repository. I am trying to set up billing for my app using shopify.RecurringApplicationCharge.

我正在遵循参考https://github.com/Shopify/shopify_django_app存储库的应用程序结构。我正在尝试使用Shopify.RecurringApplicationCharge为我的应用程序设置账单。


@shop_login_required
def buy_plan(request, id):
plan = PlanTable.objects.get(id=id)
context = {'plans': plan}
charge = shopify.RecurringApplicationCharge()
charge.name = plan.name
charge.price = plan.price
charge.test = True
charge.return_url = reverse('accept')
if charge.response_code == 201:
confirmation_url = charge['recurring_application_charge']['confirmation_url']
return redirect(confirmation_url)
else:
return render(request, 'home/billing.html', context)


I also tried the following as mentioned in https://github.com/Shopify/shopify_python_api#billing

我还尝试了https://github.com/Shopify/shopify_python_api#billing中提到的以下方法


@shop_login_required
def buy_plan(request, id):
plan = PlanTable.objects.get(id=id)
context = {'plans': plan}
charge = shopify.RecurringApplicationCharge.create({'name' : plan.name,'price' : plan.price, 'test' : True,'return_url' : reverse('accept')})
if charge.response_code == 201:
confirmation_url = charge['recurring_application_charge']['confirmation_url']
return redirect(confirmation_url)
else:
return render(request, 'home/billing.html', context)

But both these methods returned the following error:-

但这两种方法都返回了以下错误:-


ForbiddenAccess at /buy_plan/1
Response(code=403, body="b''", headers={'Date': 'Fri, 18 Aug 2023 12:52:49 GMT', 'Content-Type': 'text/html', 'Transfer-Encoding': 'chunked', 'Connection': 'close', 'X-Sorting-Hat-PodId': '319', 'X-Sorting-Hat-ShopId': '72702755136', 'Vary': 'Accept-Encoding', 'Referrer-Policy': 'origin-when-cross-origin', 'X-Frame-Options': 'DENY', 'X-ShopId': '72702755136', 'X-ShardId': '319', 'X-Stats-UserId': '', 'X-Stats-ApiClientId': '54612525057', 'X-Stats-ApiPermissionId': '604913992000', 'X-Shopify-API-Version': 'unstable', 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT': '1/40', 'X-Shopify-Shop-Api-Call-Limit': '1/40', 'Strict-Transport-Security': 'max-age=7889238', 'Server-Timing': 'processing;dur=92', 'X-Shopify-Stage': 'production', 'Content-Security-Policy': "default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; frame-ancestors 'none'; img-src 'self' data: blob: https:; script-src https://cdn.shopify.com https://cdn.shopifycdn.net https://checkout.shopifycs.com https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://js.braintreegateway.com https://c.paypal.com https://maps.googleapis.com https://www.google-analytics.com https://v.shopify.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Frecurring_application_charges&source%5Bsection%5D=admin_api&source%5Buuid%5D=99c55ce8-b483-4005-a18e-add193a2114c", 'X-Content-Type-Options': 'nosniff', 'X-Download-Options': 'noopen', 'X-Permitted-Cross-Domain-Policies': 'none', 'X-XSS-Protection': '1; mode=block; report=/xss-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Frecurring_application_charges&source%5Bsection%5D=admin_api&source%5Buuid%5D=99c55ce8-b483-4005-a18e-add193a2114c', 'X-Dc': 'gcp-asia-south1,gcp-us-central1,gcp-us-central1', 'X-Request-ID': '99c55ce8-b483-4005-a18e-add193a2114c', 'CF-Cache-Status': 'DYNAMIC', 'Report-To': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=JctaWU1iSmnNUr84N9i4Y8IDKVFPQBgV32a%2B5OseIheGbwENjrnosLQL0iyMKySYWpaVtGa91T7HNNKETgY4ap0msO4km8R%2FJF44TWKAA9UJeuBK0Q7%2FGqp7P%2BamF02SuTR85Wyry3pvQw%3D%3D"}],"group":"cf-nel","max_age":604800}', 'NEL': '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}', 'Server': 'cloudflare', 'CF-RAY': '7f8a4bceabcc17ab-MAA', 'alt-svc': 'h3=":443"; ma=86400'}, msg="Forbidden")

My urls.py file:

我的urls.py文件:


path('buy_plan/<str:id>', views.buy_plan, name='buy_plan'),
path('accept', views.accept, name='accept'),

My billing.html file:

我的billing.html文件:


{% extends "base.html" %}
{% block content %}

<h2>Plans</h2>
{% if plans %}
<div class="product-list">
{% for plan in plans %}
<div class="product-card">

<div class="product-info">
<h1><b>Name: </b>{{plan.name}}</h1>
<h2><b>Price: </b>{{plan.price}}</h2>
<a href="{% url 'buy_plan' plan.id %}">
<button class="custom-btn btn-2">Activate</button>
</a>
</div>
</div>
{% endfor %}
</div>
{% else %}
<em class="note">There are no plans.</em>
{% endif %}

{% endblock %}


Any details why this error is occuring and how to get rid of it would be appreciated.

任何细节,为什么会发生这个错误,以及如何摆脱它将不胜感激。


更多回答
优秀答案推荐

This problem was solved. The problem was that shopify requires redirect_uri to be HTTPS otherwise the RecurringApplicationCharge API request doesn't go through.

这个问题解决了。问题是Shopify要求reDirect_uri为HTTPS,否则RecurringApplicationCharge API请求无法通过。


更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com