PayPal Payflow Pro API提交含引号字段报错问题咨询
I'm submitting form data via HTTP POST to the https://pilot-payflowpro.paypal.com API, formatting parameters into a requestString joined with & (using application/x-www-form-urlencoded content type). When parameter values contain quotation characters like single quotes or " (e.g., the value "Les Clefs d Or Fund"), I get this error:
PayPal. Some required information is missing or incorrect. Please correct the fields below and try again
Here's the relevant TypeScript code snippet:
public async sendPayPalRequest( donationInfo: DonationInfoModel, ): Promise<string> { const templateString = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; const transactionDetails: IPayPalTransactionInfo = { // ... other properties currency: 'USD', comment1: StringHelper.replaceQuotationWithBacktick(donationInfo.fundName), // ... other properties }; // ... additional setup logic const requestParameters = []; for (const key in transactionDetails) { if (transactionDetails.hasOwnProperty(key)) { requestParameters.push( `${key.toUpperCase()}[${transactionDetails[key].length}]=${transactionDetails[key]}`, ); } } const requestString = requestParameters.join('&'); const response = await axios.post(process.env.PAYPAL_TRANSACTION_URL, requestString, { headers: { 'content-type': 'application/x-www-form-urlencoded', }, }); return response.data; }
Right now, I've found that replacing quotes with "" or "^" lets the payment request go through successfully. But I'm wondering if other developers have faced this issue and found a more robust, standardized solution?
内容的提问来源于stack exchange,提问作者Gregory Sidh

