[英]Paypal Refund Sale REST API Returning: Remote server returned an error: (404) Not Found
我正在使用Paypal .NET SDK嘗試執行付款和退款。 我有支付功能,但我無法退款。 我一直在查看Paypal的文檔和代碼示例,例如:
我的退款流程基於Paypal的代碼示例(上面的第一個鏈接),並在我自己的類庫中進行了稍微修改:
public class RefundTransaction
{
private readonly string _paypalUniqueTransactionId;
private readonly CurrencyEnum _currency;
private readonly decimal _orderTotal;
/// <summary>
/// Creates a refund with basic key fields.
/// </summary>
/// <param name="paypalUniqueTransactionId"></param>
/// <param name="currency"></param>
/// <param name="orderTotal"></param>
public RefundTransaction(string paypalUniqueTransactionId, CurrencyEnum currency, decimal orderTotal)
{
_paypalUniqueTransactionId = paypalUniqueTransactionId;
_currency = currency;
_orderTotal = orderTotal;
}
/// <summary>
/// Processes and completes a refund on a sale transaction.
/// </summary>
public void RefundWholeSale()
{
#region Set the refund details
Refund processRefund = new Refund
{
amount = new Amount()
{
currency = _currency.ToString(),
total = _orderTotal.ToString("N")
}
};
#endregion
#region Action the refund
Sale refundSale = new Sale()
{
id = _paypalUniqueTransactionId
};
Refund refundResponse = refundSale.Refund(Configuration.GetAPIContext(), processRefund);
#endregion
}
}
我得到的回復是404錯誤。 據我了解,此API調用使用/v1/payments/sale/{sale-id}/refund
端點。 我正在使用的銷售ID值是我在用戶付款后存儲的內容:PAY-XXXXXXXXXXXXXXXXXXXXXXX。
我使用正確的“銷售ID”嗎? Paypal帳戶是否需要特殊權限才能通過REST API進行退款?
任何有關這方面的幫助將不勝感激。
我終於搞定了。 我認為是銷售ID,實際上是不正確的。 銷售ID隱藏在related_resources
部分的Paypal .NET SDK中。
在代碼中創建付款時,我現在正在存儲銷售ID,您可以按如下方式檢索:
// Create a payment using a valid APIContext.
Payment createdPayment = payment.Create(Configuration.GetAPIContext());
string id = createdPayment.id; // This is no the Sale ID you're looking for...
string saleId = createdPayment.transactions[0].related_resources[0].sale.id;
我希望這可以幫助其他人解決同樣的問題。
在服務器上找不到請求的資源時將發生404錯誤。 我認為你錯過了完整的API網址,嘗試發布以下信息以及標題值。
https://api.sandbox.paypal.com/v1/payments/sale/<Transaction-Id>/refund
: https://api.sandbox.paypal.com/v1/payments/sale/<Transaction-Id>/refund
gt;/ https://api.sandbox.paypal.com/v1/payments/sale/<Transaction-Id>/refund
application/json
Bearer <Access-Token>
數據:
{ "amount": { "total": "2.34", "currency": "USD" } }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.