gpt4 book ai didi

php - Paypal API v2 响应指定的资源不存在

转载 作者:太空宇宙 更新时间:2023-11-03 15:43:27 28 4
gpt4 key购买 nike

我试图在服务器端/capture资金,但我收到错误消息“指定的资源不存在”。

我已经放置了为沙盒和欧元货币配置的 Paypal 脚本:

<script src='https://www.paypal.com/sdk/js?client-id=sb&currency=EUR&commit=true&disable-funding=card,credit' ></script>

然后,按如下所述配置按钮

paypal.Buttons( {
createOrder : function( data, actions ) {
return actions.order.create( {
"intent" : "CAPTURE",
"purchase_units" : [ { amount : { "value" : cart-total-amount,
"currency_code" : "EUR",
} } ] } );
},
onApprove: function( data, actions ) {
/*
MY SERVER API
*/
_this.api( "my-server-api-url/cart/submit/",
{ "items" : _this.cart.items,
"invoice" : _this.cart.invoice,
"paymentmethod" : "paypal",
"orderid" : data.orderID,
"payerid" : data.payerID,
}, function( data ) {
alert( data.message );
} );
},
style: { "layout" : "horizontal",
"color" : "blue",
"shape" : "rect",
"label" : "paypal",
"tagline" : false,
"height" : 40,
},
} ).render( "#paypal-button-id" );

只是解释一下代码:

_this = 对我的类(class)/图书馆的引用

_this.cart.items = 发票上的项目

_this.cart.invoice = 发票详情

$orderid = data.orderID(来自上面的js)

然后,在服务器端,我从 Paypal(变量 $accesstoken)正确获取了 token ,但是当我尝试获取资金时出现错误。

  $curl = curl_init( "https://api.sandbox.paypal.com/v2/checkout/orders/" . $orderid . "/capture" );
curl_setopt( $curl, CURLOPT_POST, true );
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $curl, CURLOPT_HEADER, false );
curl_setopt( $curl, CURLINFO_HEADER_OUT, true );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_HTTPHEADER, [ "Content-Type: application/json",
"Authorization: Bearer " . $accesstoken,
"Accept: application/json",
] );
$result = curl_exec( $curl );
curl_close( $ch );
curl_close( $curl );

错误(json_decoded 然后是 print_r):

stdClass Object
(
[name] => RESOURCE_NOT_FOUND
[details] => Array
(
[0] => stdClass Object
(
[location] => path
[issue] => INVALID_RESOURCE_ID
[description] => Specified resource ID does not exist. Please check the resource ID and try again.
)

)

[message] => The specified resource does not exist.
[debug_id] => cb446322c3a2c
[links] => Array
(
[0] => stdClass Object
(
[href] => https://developer.paypal.com/docs/api/orders/v2/#error-INVALID_RESOURCE_ID
[rel] => information_link
[method] => GET
)
)
)

基本上我在客户端创建一个订单(通过 Js 使用 Paypal API),然后我在服务器端捕获它。

我在这个过程中缺少什么?

最佳答案

包含 js 文件时缺少 client-id:

<script src='https://www.paypal.com/sdk/js?client-id=[CLIENT-ID-HERE]&currency=EUR&commit=true&disable-funding=card,credit' ></script>

关于php - Paypal API v2 响应指定的资源不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55316799/

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