PayPal开票API请求 - 格式化

时间:2012-09-27 17:30:02

标签: curl paypal

有人可以向我解释PayPal示例中这些字符串值中“+”和“ - ”的重要性吗? PayPal文档实际上没有在API文档中解释这一点。

&invoice.itemList.item(0).name=Banana+Leaf+--+001 
&invoice.itemList.item(0).description=Banana+Leaf 

我发现某些值是URL编码的,而其他值则使用这些“+”和“ - ”字符而不是URL编码。

为什么?

由于

############################################################
// CreateAndSendInvoice HTTP headers (-H)
############################################################
curl -s --insecure
-H "X-PAYPAL-SECURITY-USERID: caller_UID"     // UserID from the Caller account
-H "X-PAYPAL-SECURITY-PASSWORD: caller_PSWD"  // Password from the Caller account
-H "X-PAYPAL-SECURITY-SIGNATURE: caller_Sig"  // Signature from the Caller account
-H "X-PAYPAL-REQUEST-DATA-FORMAT: XML" 
-H "X-PAYPAL-RESPONSE-DATA-FORMAT: XML" 
-H "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T"    // Sandbox AppID
https://svcs.sandbox.paypal.com/Invoice/CreateAndSendInvoice -d
"requestEnvelope.errorLanguage=en_US 
&invoice.merchantEmail=merchant%40domain.com 
&invoice.payerEmail=jbui-us-business2%40paypal.com 
&invoice.currencyCode=USD 
&invoice.itemList.item(0).name=Banana+Leaf+--+001 
&invoice.itemList.item(0).description=Banana+Leaf 
&invoice.itemList.item(0).quantity=1 
&invoice.itemList.item(0).unitPrice=1 
&invoice.itemList.item(0).taxName=Tax1 
&invoice.itemList.item(0).taxRate=10.25 
&invoice.paymentTerms=Net10 
&invoice.logoUrl=https%3A%2F%2Fwww.example.com%2FYour_logo.jpg" 

1 个答案:

答案 0 :(得分:0)

首先,-符号不需要进行URL编码。实际上,如果您查看此页面的网址,则会看到https://stackoverflow.com/questions/12626956/paypal-invoicing-api-requests-formatting,其中包含大量-个符号。

其次,空格可以由+%20表示,具体取决于它在网址中的位置。引自this answer

+ means a space only in application/x-www-form-encoded content,
such as the query part of a URL:

http://www.example.com/path/foo+bar/path?query+name=query+value

In this URL, the parameter name is 'query name' (with a space) and
the value is 'query value' (with a space), but the folder name in
the path is literally foo+bar, not 'foo bar'.

因此,对于您的示例,Banana+Leaf+--+001会转换为Banana Leaf -- 001Banana+Leaf转换为Banana Leaf