我正在使用 Paypal .NET SDK 尝试执行付款和退款。我有支付功能,但是我无法执行退款。我一直在查看 Paypal 的文档和代码示例,例如:
- > http://paypal.github.io/PayPal-NET-SDK/Samples/SaleRefund.aspx.html
- > https://developer.paypal.com/docs/api/payments/#sale_refund
我的退款流程基于 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;
我希望这可以帮助其他人解决同样的问题。
关于asp.net - Paypal 退款销售 REST API 返回 : Remote server returned an error: (404) Not Found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38935513/