错误处理 javascript(paypal 沙盒平台)
error handling javascript (paypal sandbox platform)
我正在尝试使用 JavaScript 构建一个 PayPal 沙盒平台,但不幸的是,我没有从 PayPal 中找到任何有效的(至少对我而言)内容,用于使用 vanilla [=99= 设置平台应用程序].
我用这个PayPal guide集成了以下代码:
<!-- Replace "test" with your own sandbox Business account app client ID -->
<script src="https://www.paypal.com/sdk/js?client-id=test¤cy=USD"></script>
<!-- Set up a container element for the button -->
<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
// Sets up the transaction when a payment button is clicked
createOrder: (data, actions) => {
return actions.order.create({
purchase_units: [{
amount: {
value: '77.44' // Can also reference a variable or function
}
}]
});
},
// Finalize the transaction after payer approval
onApprove: (data, actions) => {
return actions.order.capture().then(function(orderData) {
// Successful capture! For dev/demo purposes:
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
const transaction = orderData.purchase_units[0].payments.captures[0];
alert(`Transaction ${transaction.status}: ${transaction.id}\n\nSee console for all available details`);
// When ready to go live, remove the alert and show a success message within this page. For example:
// const element = document.getElementById('paypal-button-container');
// element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: actions.redirect('thank_you.html');
});
}
}).render('#paypal-button-container');
</script>
它用于“简单”付款,当我直接输入收款人的 client id
时,但我想将其用作某种 platform/marketplace,其中不同的人提供东西并直接收到他们的钱...
我发现this configuration guide在平台内引用商家并更改
<script src="https://www.paypal.com/sdk/js?client-id=test¤cy=USD"></script>
至
<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID&merchant-id=XXX"></script>
并且我使用了平台的客户端沙箱 ID(使用 PayPal 创建)并添加了应该接收款项的帐户 ID。但是从那以后付款过程就不再有效了,我收到了一堆错误:
POST https://www.sandbox.paypal.com/v2/checkout/orders/1N412585WU345820U/capture 403
- Here and according to PayPal API responses它说,我的平台需要批准,但根据我的 PayPal 平台应用程序中的信息框,它说沙盒应用程序不需要批准 运行:
POST https://www.sandbox.paypal.com/smart/api/order/1N412585WU345820U/capture 500
- 根据 PayPal API responses 这似乎是 PayPal 方面的错误,但我相信在我的情况下它可以在“主要问题”中解决(无论它是什么...)
Uncaught Error: Api: /smart/api/order/1N412585WU345820U/capture returned status code: 500 (Corr ID: 3d42a7056c067)
- 根据 PayPal API responses 这似乎也是 PayPal 的内部服务器错误
仍然可能是我使用了错误的 JavaScript 片段来集成 PayPay 平台,但到目前为止我没有发现任何不同,在我看来这更适合...
更新 13.04.
这是我目前正在尝试开始工作的确切代码块:
<script src="https://www.paypal.com/sdk/js?client-id=ARoShWzmlqdngxfJ31ly7ZADrsyWU3Fa3fhlOJF0mJXdpIaZ5z99R7VkQuMEb_4Z_azlHfuo7Mk4k5qK&merchant-id=<?= $paypal ?>¤cy=EUR"></script>
<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
createOrder: (data, actions) => {
return actions.order.create({
purchase_units: [{
amount: {
value: '<?= $amount ?>' // Can also reference a variable or function
}
}]
});
},
onApprove: (data, actions) => {
return actions.order.capture().then(function(orderData) {
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
const transaction = orderData.purchase_units[0].payments.captures[0];
actions.redirect('http://localhost/exit.php');
});
}
}).render('#paypal-button-container');
</script>
我从存储所有信息的数据库中获取 PHP 变量。还尝试手动添加 ID 而不是 PHP 变量,但没有更改任何内容。
顺便说一句:如果我点击 PayPal 按钮进行支付,第二个 window 登录 PayPal 打开,我可以使用我的沙盒帐户之一登录,价格也是正确的。在尝试完成付款后,我没有被转发到 http://localhost/exit.php
,而是收到以下错误。
这是显示的所有日志的图像。刚刚将超时错误识别为第一个错误,但不确定是否会触发问题:
更新二 13.04.
如本 I tried to onboard the sellers via the Partner Referrals API using this sample from PayPal. I first created an access token and then wanted to generate a singup link with this access token. But instead of the desired response 中所述,我在尝试生成 singup link:
时在命令提示符中收到一条消息 INVALID_REQUEST
{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"b54a8fd49ab4c","information_link":"","details":[{"issue":"INVALID_PARAMETER_SYNTAX","description":"Referral data is not a valid json object."}],"links":[]}* Connection #0 to host api-m.sandbox.paypal.com left intact
我在 Google 上搜索,但没有真正找到有用的回复。不幸的是,information_link
字段是空的。
这是我的要求:
curl -v -X POST https://api-m.sandbox.paypal.com/v2/customer/partner-referrals \ -H "Content-Type: application/json" \ -H "Authorization: Bearer A21AAJAr6XCnxUwsXGpH_Hv55XrrDh-wct-FnmSFQzFrY4mNHatkD--IaHXlUSOUBipsItfdxb56S371AdrEK7gFmcHEXEiJA" \ -d '{"tracking_id": "PayPal-ID","operations": [{"operation": "API_INTEGRATION", "api_integration_preference": {"rest_api_integration": {"integration_method": "PAYPAL","integration_type": "THIRD_PARTY","third_party_details": {"features": ["PAYMENT","REFUND"]}}}}],"products": ["EXPRESS_CHECKOUT"],"legal_consents": [{"type": "SHARE_DATA_CONSENT","granted": true}]}'
这是我得到的回复:
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying 151.101.1.35:443...
* Connected to api-m.sandbox.paypal.com (151.101.1.35) port 443 (#0)
* schannel: disabled automatic use of client certificate
* schannel: ALPN, offering http/1.1
* schannel: ALPN, server accepted to use http/1.1
> POST /v2/customer/partner-referrals HTTP/1.1
> Host: api-m.sandbox.paypal.com
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Type: application/json
> Authorization: Bearer A21AAJAr6XCnxUwsXGpH_Hv55XrrDh-wct-FnmSFQzFrY4mNHatkD--IaHXlUSOUBipsItfdxb56S371AdrEK7gFmcHEXEiJA
> Content-Length: 14
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< Connection: keep-alive
< Content-Length: 278
< Content-Type: application/json;charset=utf-8
< Server: nginx/1.18.0 (Ubuntu)
< Cache-Control: max-age=0, no-cache, no-store, must-revalidate
< Etag: W/"116-GOos19pXDvjfMGG/lkQZOQx3ysM"
< Paypal-Debug-Id: b54a8fd49ab4c
< Set-Cookie: ts_c=vr%3D2321e53c1800a609769dd99dffff68d4%26vt%3D2321e53c1800a609769dd99dffff68d5; Domain=.paypal.com; Path=/; Expires=Sun, 13 Apr 2025 07:00:42 GMT; Secure; SameSite=None; HttpOnly
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< Accept-Ranges: bytes
< Via: 1.1 varnish, 1.1 varnish
< Edge-Control: max-age=0
< Date: Wed, 13 Apr 2022 13:34:25 GMT
< X-Served-By: cache-fra19126-FRA, cache-muc13976-MUC
< X-Cache: MISS, MISS
< X-Cache-Hits: 0, 0
< X-Timer: S1649856865.498776,VS0,VE171
<
{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"b54a8fd49ab4c","information_link":"","details":[{"issue":"INVALID_PARAMETER_SYNTAX","description":"Referral data is not a valid json object."}],"links":[]}* Connection #0 to host api-m.sandbox.paypal.com left intact
Note: Unnecessary use of -X or --request, POST is already inferred.
* Could not resolve host: \
* Closing connection 1
curl: (6) Could not resolve host: \
Note: Unnecessary use of -X or --request, POST is already inferred.
* Could not resolve host: \
* Closing connection 2
curl: (6) Could not resolve host: \
Note: Unnecessary use of -X or --request, POST is already inferred.
* Could not resolve host: \
* Closing connection 3
curl: (6) Could not resolve host: \
Note: Unnecessary use of -X or --request, POST is already inferred.
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
curl: (3) bad range specification in URL position 2:
[{operation:
^
解决方案
必须像 Preston PHX 那样先加入卖家 using the cUrl commands from the PayPal documentation. My code from Update II 13.04. was correct. It just happend, that it got cut off inside the command prompt. So using Postman 解决了问题,现在一切正常!
500 错误无关紧要,只是因为 403 之后的回退尝试而发生。
出现 403 的原因可能多种多样,但如果您在 SDK 行中包含一个 merchant-id,那么还应该有一个带有 merchant_id
键的 payee
对象在订单创建中的价值。有关详细信息,请参阅 orders create API reference。
确保the REST APP with the client-id您正在使用的具有适当的权限。如果缓存现有访问令牌,更改权限最多可能需要 9 小时,但您也可以创建新应用。
我正在尝试使用 JavaScript 构建一个 PayPal 沙盒平台,但不幸的是,我没有从 PayPal 中找到任何有效的(至少对我而言)内容,用于使用 vanilla [=99= 设置平台应用程序].
我用这个PayPal guide集成了以下代码:
<!-- Replace "test" with your own sandbox Business account app client ID -->
<script src="https://www.paypal.com/sdk/js?client-id=test¤cy=USD"></script>
<!-- Set up a container element for the button -->
<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
// Sets up the transaction when a payment button is clicked
createOrder: (data, actions) => {
return actions.order.create({
purchase_units: [{
amount: {
value: '77.44' // Can also reference a variable or function
}
}]
});
},
// Finalize the transaction after payer approval
onApprove: (data, actions) => {
return actions.order.capture().then(function(orderData) {
// Successful capture! For dev/demo purposes:
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
const transaction = orderData.purchase_units[0].payments.captures[0];
alert(`Transaction ${transaction.status}: ${transaction.id}\n\nSee console for all available details`);
// When ready to go live, remove the alert and show a success message within this page. For example:
// const element = document.getElementById('paypal-button-container');
// element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: actions.redirect('thank_you.html');
});
}
}).render('#paypal-button-container');
</script>
它用于“简单”付款,当我直接输入收款人的 client id
时,但我想将其用作某种 platform/marketplace,其中不同的人提供东西并直接收到他们的钱...
我发现this configuration guide在平台内引用商家并更改
<script src="https://www.paypal.com/sdk/js?client-id=test¤cy=USD"></script>
至
<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID&merchant-id=XXX"></script>
并且我使用了平台的客户端沙箱 ID(使用 PayPal 创建)并添加了应该接收款项的帐户 ID。但是从那以后付款过程就不再有效了,我收到了一堆错误:
POST https://www.sandbox.paypal.com/v2/checkout/orders/1N412585WU345820U/capture 403
- Here and according to PayPal API responses它说,我的平台需要批准,但根据我的 PayPal 平台应用程序中的信息框,它说沙盒应用程序不需要批准 运行:
- Here and according to PayPal API responses它说,我的平台需要批准,但根据我的 PayPal 平台应用程序中的信息框,它说沙盒应用程序不需要批准 运行:
POST https://www.sandbox.paypal.com/smart/api/order/1N412585WU345820U/capture 500
- 根据 PayPal API responses 这似乎是 PayPal 方面的错误,但我相信在我的情况下它可以在“主要问题”中解决(无论它是什么...)
Uncaught Error: Api: /smart/api/order/1N412585WU345820U/capture returned status code: 500 (Corr ID: 3d42a7056c067)
- 根据 PayPal API responses 这似乎也是 PayPal 的内部服务器错误
仍然可能是我使用了错误的 JavaScript 片段来集成 PayPay 平台,但到目前为止我没有发现任何不同,在我看来这更适合...
更新 13.04.
这是我目前正在尝试开始工作的确切代码块:
<script src="https://www.paypal.com/sdk/js?client-id=ARoShWzmlqdngxfJ31ly7ZADrsyWU3Fa3fhlOJF0mJXdpIaZ5z99R7VkQuMEb_4Z_azlHfuo7Mk4k5qK&merchant-id=<?= $paypal ?>¤cy=EUR"></script>
<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
createOrder: (data, actions) => {
return actions.order.create({
purchase_units: [{
amount: {
value: '<?= $amount ?>' // Can also reference a variable or function
}
}]
});
},
onApprove: (data, actions) => {
return actions.order.capture().then(function(orderData) {
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
const transaction = orderData.purchase_units[0].payments.captures[0];
actions.redirect('http://localhost/exit.php');
});
}
}).render('#paypal-button-container');
</script>
我从存储所有信息的数据库中获取 PHP 变量。还尝试手动添加 ID 而不是 PHP 变量,但没有更改任何内容。
顺便说一句:如果我点击 PayPal 按钮进行支付,第二个 window 登录 PayPal 打开,我可以使用我的沙盒帐户之一登录,价格也是正确的。在尝试完成付款后,我没有被转发到 http://localhost/exit.php
,而是收到以下错误。
这是显示的所有日志的图像。刚刚将超时错误识别为第一个错误,但不确定是否会触发问题:
更新二 13.04.
如本
INVALID_REQUEST
{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"b54a8fd49ab4c","information_link":"","details":[{"issue":"INVALID_PARAMETER_SYNTAX","description":"Referral data is not a valid json object."}],"links":[]}* Connection #0 to host api-m.sandbox.paypal.com left intact
我在 Google 上搜索,但没有真正找到有用的回复。不幸的是,information_link
字段是空的。
这是我的要求:
curl -v -X POST https://api-m.sandbox.paypal.com/v2/customer/partner-referrals \ -H "Content-Type: application/json" \ -H "Authorization: Bearer A21AAJAr6XCnxUwsXGpH_Hv55XrrDh-wct-FnmSFQzFrY4mNHatkD--IaHXlUSOUBipsItfdxb56S371AdrEK7gFmcHEXEiJA" \ -d '{"tracking_id": "PayPal-ID","operations": [{"operation": "API_INTEGRATION", "api_integration_preference": {"rest_api_integration": {"integration_method": "PAYPAL","integration_type": "THIRD_PARTY","third_party_details": {"features": ["PAYMENT","REFUND"]}}}}],"products": ["EXPRESS_CHECKOUT"],"legal_consents": [{"type": "SHARE_DATA_CONSENT","granted": true}]}'
这是我得到的回复:
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying 151.101.1.35:443...
* Connected to api-m.sandbox.paypal.com (151.101.1.35) port 443 (#0)
* schannel: disabled automatic use of client certificate
* schannel: ALPN, offering http/1.1
* schannel: ALPN, server accepted to use http/1.1
> POST /v2/customer/partner-referrals HTTP/1.1
> Host: api-m.sandbox.paypal.com
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Type: application/json
> Authorization: Bearer A21AAJAr6XCnxUwsXGpH_Hv55XrrDh-wct-FnmSFQzFrY4mNHatkD--IaHXlUSOUBipsItfdxb56S371AdrEK7gFmcHEXEiJA
> Content-Length: 14
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< Connection: keep-alive
< Content-Length: 278
< Content-Type: application/json;charset=utf-8
< Server: nginx/1.18.0 (Ubuntu)
< Cache-Control: max-age=0, no-cache, no-store, must-revalidate
< Etag: W/"116-GOos19pXDvjfMGG/lkQZOQx3ysM"
< Paypal-Debug-Id: b54a8fd49ab4c
< Set-Cookie: ts_c=vr%3D2321e53c1800a609769dd99dffff68d4%26vt%3D2321e53c1800a609769dd99dffff68d5; Domain=.paypal.com; Path=/; Expires=Sun, 13 Apr 2025 07:00:42 GMT; Secure; SameSite=None; HttpOnly
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< Accept-Ranges: bytes
< Via: 1.1 varnish, 1.1 varnish
< Edge-Control: max-age=0
< Date: Wed, 13 Apr 2022 13:34:25 GMT
< X-Served-By: cache-fra19126-FRA, cache-muc13976-MUC
< X-Cache: MISS, MISS
< X-Cache-Hits: 0, 0
< X-Timer: S1649856865.498776,VS0,VE171
<
{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"b54a8fd49ab4c","information_link":"","details":[{"issue":"INVALID_PARAMETER_SYNTAX","description":"Referral data is not a valid json object."}],"links":[]}* Connection #0 to host api-m.sandbox.paypal.com left intact
Note: Unnecessary use of -X or --request, POST is already inferred.
* Could not resolve host: \
* Closing connection 1
curl: (6) Could not resolve host: \
Note: Unnecessary use of -X or --request, POST is already inferred.
* Could not resolve host: \
* Closing connection 2
curl: (6) Could not resolve host: \
Note: Unnecessary use of -X or --request, POST is already inferred.
* Could not resolve host: \
* Closing connection 3
curl: (6) Could not resolve host: \
Note: Unnecessary use of -X or --request, POST is already inferred.
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
curl: (3) bad range specification in URL position 2:
[{operation:
^
解决方案
必须像 Preston PHX 那样先加入卖家
500 错误无关紧要,只是因为 403 之后的回退尝试而发生。
出现 403 的原因可能多种多样,但如果您在 SDK 行中包含一个 merchant-id,那么还应该有一个带有 merchant_id
键的 payee
对象在订单创建中的价值。有关详细信息,请参阅 orders create API reference。
确保the REST APP with the client-id您正在使用的具有适当的权限。如果缓存现有访问令牌,更改权限最多可能需要 9 小时,但您也可以创建新应用。