我正在構建一個EC網站,我的客戶可以通過PayPal API付款。現在,我正在學習如何使用Sandbox;參考此頁:https://developer.paypal.com/docs/integration/direct/billing-plans/PayPal REST API:試圖激活計費計劃,但獲得「HTTP/1.1 401未授權」
我已經成功完成了先決條件,即創建了一個PayPal應用程序, 獲取了一個訪問令牌,並進行了API調用。然後,我成功制定了計費計劃,在頁面上覆制並粘貼示例命令,只需更換訪問令牌即可。
現在,我想激活計費計劃,但不能成功。
使用的命令再次從頁面複製並粘貼,如下所示。
curl -v -k -X PATCH https://api.sandbox.paypal.com/v1/payments/billing-plans/P-7DC96732KA7763723UOPKETA/ \
-H 'X-PAYPAL-OAUTH-CONTEXT: {"consumer":{"accountNumber":1181198218909172527,"merchantId":"5KW8F2FXKX5HA"},"merchant":{"accountNumber":1659371090107732880,"merchantId":"2J6QB8YJQSJRJ"},"apiCaller":{"clientId":"AdtlNBDhgmQWi2xk6edqJVKklPFyDWxtyKuXuyVT-OgdnnKpAVsbKHgvqHHP","appId":"APP-6DV794347V142302B","payerId":"2J6QB8YJQSJRJ","accountNumber":"1659371090107732880"},"scopes":["https://api.paypal.com/v1/payments/.*","https://uri.paypal.com/services/payments/futurepayments","openid"]}' \
-H 'Content-Type: application/json' \
-d '[{
"op": "replace",
"path": "/",
"value": {
"state": "ACTIVE"
}
}]'
首先,按照指示,我剛剛更換計劃ID「P-7DC96732KA7763723UOPKETA」和我,在創建計劃之前的響應提供。
* Trying 173.0.82.78...
* Connected to api.sandbox.paypal.com (173.0.82.78) port 443 (#0)
* TLS 1.2 connection using TLS_RSA_WITH_AES_256_CBC_SHA256
* Server certificate: api.sandbox.paypal.com
* Server certificate: Symantec Class 3 Secure Server CA - G4
* Server certificate: VeriSign Class 3 Public Primary Certification Authority - G5
> PATCH /v1/payments/billing-plans/P-8AX21799EN516221GJMBOECA/ HTTP/1.1
> Host: api.sandbox.paypal.com
> User-Agent: curl/7.43.0
> Accept: */*
> X-PAYPAL-OAUTH-CONTEXT: {"consumer":{"accountNumber":1181198218909172527,"merchantId":"5KW8F2FXKX5HA"},"merchant":{"accountNumber":1659371090107732880,"merchantId":"2J6QB8YJQSJRJ"},"apiCaller":{"clientId":"AdtlNBDhgmQWi2xk6edqJVKklPFyDWxtyKuXuyVT-OgdnnKpAVsbKHgvqHHP","appId":"APP-6DV794347V142302B","payerId":"2J6QB8YJQSJRJ","accountNumber":"1659371090107732880"},"scopes":["ttps://api.paypal.com/v1/payments/.*","ttps://uri.paypal.com/services/payments/futurepayments","openid"]}
> Content-Type: application/json
> Content-Length: 78
>
* upload completely sent off: 78 out of 78 bytes
< HTTP/1.1 401 Unauthorized
< Date: Fri, 17 Feb 2017 12:18:47 GMT
< Server: Apache
< paypal-debug-id: c46e304b4bb46
< Paypal-Debug-Id: c46e304b4bb46
< Set-Cookie: X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D1880%26app%3Dplatformapiserv%26TIME%3D669689432%26HTTP_X_PP_AZ_LOCATOR%3D; Expires=Fri, 17 Feb 2017 12:48:47 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
< Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT
< Content-Length: 0
< Connection: close
< Content-Type: text/plain; charset=ISO-8859-1
<
* Closing connection 0
我嘗試了一些其他的參數替換,如客戶端ID,但沒有運氣。
我是否需要更換其他參數? 或者,我做錯了什麼?
你使用了正確的訪問令牌嗎? –
感謝您的發佈。是的,根據我保存的記錄,我使用了正確的訪問令牌,這是我從前提過程中獲得的;我想我不會成功制定計費計劃,否則。順便說一句,我現在的問題 - 激活計費計劃 - 並不需要訪問代碼,關於我需要在命令行中輸入的命令,如我的原始文章所示。如果錯了,請糾正我。再次感謝! – wiaylise
這已解決;請看我自己的答案。你對訪問令牌是正確的;我使用的成功命令包括訪問令牌。非常感謝您的幫助!! – wiaylise