我正在使用C#和PayPal Rest API来获取已批准的付款并执行。但是,我需要更新与已批准付款相关联的交易。PayPal文档如下所述:
“使用此调用来执行(完成)已得到支付人批准的PayPal付款。在执行付款时,您可以选择通过传入一个或多个交易来更新交易信息。”
以下是我的代码:
问题在于当我运行此代码时,会出现以下错误:
所以,我的问题是:如何接受已批准的付款,更新付款交易的价格,然后执行该付款?
“使用此调用来执行(完成)已得到支付人批准的PayPal付款。在执行付款时,您可以选择通过传入一个或多个交易来更新交易信息。”
以下是我的代码:
//Update the payment details in case totals changed because of a new address/zipcode
Details amountDetails = new Details();
amountDetails.subtotal = ValidationHelper.GetString(prices[Order.CartPricesEnum.Subtotal], "0");
amountDetails.tax = ValidationHelper.GetString(prices[Order.CartPricesEnum.Tax], "0");
amountDetails.shipping = ValidationHelper.GetString(prices[Order.CartPricesEnum.Shipping], "0");
Amount amount = new Amount();
amount.total = ValidationHelper.GetString(prices[Order.CartPricesEnum.Total], "0");
amount.currency = "USD";
amount.details = amountDetails;
//update the transaction to make sure we have accounted for any updated prices
Transactions trn = new Transactions();
trn.amount = amount;
List<Transactions> trns = new List<Transactions>();
trns.Add(trn);
//Create a payment execution object
PaymentExecution paymentExecution = new PaymentExecution();
paymentExecution.payer_id = payPalPayerID;
paymentExecution.transactions = trns;
//Execute (complete) the payment
Payment newPayment = payment.Execute(accessToken, paymentExecution);
问题在于当我运行此代码时,会出现以下错误:
{"name":"VALIDATION_ERROR","details":[{"field":"transactions[0].total","issue":"Required field missing"},{"field":"transactions[0].currency","issue":"Required field missing"},{"field":"transactions[0].amount","issue":"This field name is not defined for this resource type"}],"message":"Invalid request - see details","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR","debug_id":"bcba38f3c56d7"}
这告诉我缺少 .total 和 .currency,而且未定义 .amount 字段。然而,根据 PayPal API 文档,您可以清楚地看到我正在设置总金额和货币,而且交易对象上唯一可设置的字段是金额字段:
transactions
array of transaction objects
Transactional details if updating a payment. Note that this instance of the transactions object accepts only the amount object.
所以,我的问题是:如何接受已批准的付款,更新付款交易的价格,然后执行该付款?