Python 在我的PayPal服务器端集成中,付款弹出窗口立即关闭。我该如何解决这个问题?
我正在尝试设置paypal服务器端集成,但我一直在一个非常简单的问题上磕磕绊绊paypal支付浏览器窗口短暂显示为正在加载,但在我做任何事情之前它就关闭了;它没有到达登录页面或任何地方。在我的django日志中,我没有看到任何错误。同样,当我搜索网络活动时,没有什么东西对我来说很突出。如果我使用贝宝授权页面的直接链接,我没有任何问题 视图.pyPython 在我的PayPal服务器端集成中,付款弹出窗口立即关闭。我该如何解决这个问题?,python,django,paypal,Python,Django,Paypal,我正在尝试设置paypal服务器端集成,但我一直在一个非常简单的问题上磕磕绊绊paypal支付浏览器窗口短暂显示为正在加载,但在我做任何事情之前它就关闭了;它没有到达登录页面或任何地方。在我的django日志中,我没有看到任何错误。同样,当我搜索网络活动时,没有什么东西对我来说很突出。如果我使用贝宝授权页面的直接链接,我没有任何问题 视图.py def setUpAuthorization(request, max_price = 100): environment = Sandbox
def setUpAuthorization(request, max_price = 100):
environment = SandboxEnvironment(client_id = settings.PAYPAL_CLIENT_ID
, client_secret = settings.PAYPAL_CLIENT_SECRET)
client = PayPalHttpClient(environment)
# get_item
request = OrdersCreateRequest()
# Make initial authorization
request.request_body(
{
"intent": "AUTHORIZE",
"application_context": {
"return_url": "https://www.example.com",
"cancel_url": "https://www.examples.com",
},
"purchase_units":[
{
"description": "DESCRIPTION",
"amount": {
"currency_code": "USD",
"value": max_price,
},
}
]}
)
response = client.execute(request)
data = response.result.__dict__['_dict']
links = data['links']
for link in links:
if link['rel'] == 'approve':
paypal_link = link['href']
# redirect(paypal_link)
return JsonResponse(data)
html
<div id="paypal-button-container"></div>
<script
src="https://www.paypal.com/sdk/js?client-id={{client_id}}">
</script>
<script>
var CSRF_TOKEN = '{{ csrf_token }}';
</script>
<script>
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
const csrftoken = getCookie('csrftoken');
</script>
<a href="{% url 'paypal:set-up-authorization' %}">test</a>
<script>
// Render the PayPal button into #paypal-button-container
paypal.Buttons({
// Call your server to set up the transaction
createOrder: function(data, actions) {
return fetch("{% url 'paypal:set-up-authorization' %}", {
method: 'POST',
headers: {'X-CSRFToken': csrftoken},
}).then(function(res) {
return res.json();
});
},
}).render('#paypal-button-container');
</script>
var CSRF_TOKEN='{{CSRF_TOKEN}}}';
函数getCookie(名称){
让cookieValue=null;
if(document.cookie&&document.cookie!=''){
常量cookies=document.cookie.split(“;”);
for(设i=0;i
我注意到CreateOrder API的主体中有一个坏字符串。请找到下面的屏幕截图,其中添加了额外的逗号符号
另外,附加了正确的JSON字符串以供参考,对我来说效果很好
{
"intent": "AUTHORIZE",
"application_context": {
"return_url": "https://www.example.com",
"cancel_url": "https://www.examples.com"
},
"purchase_units":[
{
"description": "DESCRIPTION",
"amount": {
"currency_code": "USD",
"value": max_price
}
}
]
}
谢谢
在您进行这些更新后,该按钮是否对您有效?我仍然有同样的问题,弹出窗口打开,似乎正在加载,然后关闭。它对我仍然有效,你可以在这里发布JSON正文以供参考。