Paypal退款销售REST API返回:远程服务器返回错误:(404)Not Found

时间:2016-08-13 17:59:58

标签: asp.net paypal paypal-rest-sdk

我正在使用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。

我是否使用了正确的&#34;销售ID&#34;? Paypal帐户是否需要特殊权限以允许通过REST API退款?

对此有任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:3)

我终于开始工作了。我认为是销售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;

我希望这可以帮助其他人解决同样的问题。

答案 1 :(得分:0)

在服务器上找不到请求的资源时,将发生404错误。我认为你错过了完整的API网址,尝试发布以下信息以及标题值。

  • 网址:https://api.sandbox.paypal.com/v1/payments/sale/&lt;Transaction-Id&gt;/refund
  • 内容类型:application/json
  • 授权:Bearer <Access-Token>
  • 数据:

    {
      "amount":
      {
      "total": "2.34",
      "currency": "USD"
      }
    }