paypal无效的交易ID

时间:2013-08-08 00:48:30

标签: asp.net paypal

我正在asp.net项目中实现Paypal Express Checkout功能,该功能需要授权,然后取消或获取授权金额。我正在使用他们的版本= 104.0的API。

据我了解整个过程,我正在做正确的事情:

  • 我在付款明细中将ActionType设置为“授权”调用SetExpressCheckout方法

    SetExpressCheckoutRequestDetailsType reqDetails = new SetExpressCheckoutRequestDetailsType();
    reqDetails.ReturnURL = "http://some.url";
    reqDetails.CancelURL = "http://some.url";
    reqDetails.NoShipping = "1";
    reqDetails.OrderDescription = "You're about to buy items for " + payment.Amount.ToString("F");
    reqDetails.cpplogoimage = "http://some.ulr/image.jpb";
    reqDetails.PaymentDetails = new PaymentDetailsType[1];
    reqDetails.PaymentDetails[0] = new PaymentDetailsType();
    reqDetails.PaymentDetails[0].PaymentDetailsItem = new PaymentDetailsItemType[cart.LineItems.Count];
    int i = 0;
    foreach (LineItemModel li in cart.LineItems)
    {
        PaymentDetailsItemType item = new PaymentDetailsItemType();
        item.Amount = new BasicAmountType();
        item.Amount.Value = li.TotalIncludingShipping.ToString("F");
        item.Amount.currencyID = CurrencyCodeType.AUD;
        item.Name = li.ProductItem.DisplayName;
        item.Number = li.ProductItem.SKU;
        item.Quantity = li.Quantity.ToString();
        item.Description = "";
        reqDetails.PaymentDetails[0].PaymentDetailsItem.SetValue(item, i);
        i++;
    }
    reqDetails.OrderTotal = new BasicAmountType()
    {
        currencyID = CurrencyCodeType.AUD,
        Value = payment.Amount.ToString("F")
    };
    reqDetails.PaymentDetails[0].PaymentAction = PaymentActionCodeType.Authorization;
    reqDetails.PaymentDetails[0].PaymentActionSpecified = true;
    SetExpressCheckoutReq req = new SetExpressCheckoutReq()
    {
        SetExpressCheckoutRequest = new SetExpressCheckoutRequestType()
        {
            Version = "104.0",
            SetExpressCheckoutRequestDetails = reqDetails
        }
    };
    
  • 它很好,在Paypal的后端通知我的测试个人帐户我可以看到钱已经自动化的消息
  • 然后我打电话给DoExpressCheckout。这是请求代码

    DoExpressCheckoutPaymentReq payReq = new DoExpressCheckoutPaymentReq()
    {
        DoExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType()
        {
            Version = ConfigurationManager.AppSettings["PaypalAPIVersion"],
            DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType()
            {
                 Token = token,
                 PayerID = payerID,
                 PaymentDetails = new PaymentDetailsType[1]
            }
        }
    };           
    payReq.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentAction = PaymentActionCodeType.Authorization;
    payReq.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentActionSpecified = true;
    payReq.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentDetails[0] = new PaymentDetailsType();
    payReq.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentDetails[0].PaymentAction = PaymentActionCodeType.Authorization;
    payReq.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentDetails[0].PaymentActionSpecified = true;
    payReq.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentDetails[0].OrderTotal = new BasicAmountType();
    payReq.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentDetails[0].OrderTotal.currencyID = CurrencyCodeType.AUD;
    payReq.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentDetails[0].OrderTotal.Value = total.ToString("F");
    
  • 此请求也会返回“成功”。我保存响应的DoExpressCheckoutPaymentResponseDetails.PaymentInfo [0] .TransactionID供将来使用

  • 但是当我使用上一个响应中的事务ID运行DoAuthorize时,我得到“失败”。这是请求代码:

    DoAuthorizationReq authReq = new DoAuthorizationReq()
    {
        DoAuthorizationRequest = new DoAuthorizationRequestType() 
        {
            Version = "104.0",
            TransactionID = doCheckoutTransactionId
        }
    };
    authReq.DoAuthorizationRequest.Amount = new BasicAmountType();
    authReq.DoAuthorizationRequest.Amount.currencyID = CurrencyCodeType.AUD;
    authReq.DoAuthorizationRequest.Amount.Value = total.ToString("F");
    

响应显示“Failure”和Errors数组包含1项ErrorCode = 10609和消息“Invalid Transaction ID”

你有没有想过为什么会这样?

非常感谢!

1 个答案:

答案 0 :(得分:0)

要在授权后获取资金,您需要运行DoCapture,而不是DoAuthorization。