REST API payment.create不创建付款

时间:2014-12-02 22:14:16

标签: paypal

我有一个后端网络服务(不是网页),它试图从前端客户端创建付款。经过一段时间我没有在详细信息和事务列表之间进行数据匹配,我从沙坑中得到了合适的错误消息,解释了什么是错误,我最终得到了payment.create方法来执行而不会抛出异常。不幸的是,虽然我可以看到测试Web服务和paypal之间存在SSL流量,但是当例程返回时,我没有链接,也没有创建状态。我可能完全误解了api的机制,但是在没有任何错误或异常的情况下,我有点难过。

以下是我正在使用的代码:

    var config = ConfigManager.Instance.GetProperties();
    var clientid = config[BaseConstants.ClientId];
    var clientSecret = config[BaseConstants.ClientSecret];
    var accessToken = new OAuthTokenCredential(clientid, clientSecret, config).GetAccessToken();
    var apiContext = new APIContext(accessToken);
    var itemList = new ItemList() { items = new List<Item>() };
    using (var context = new PETTEntities3())
    {
      SubscriptionType subType = context.SubscriptionTypes.FirstOrDefault(s => s.SubscriptionTypeID == Subscription.SubscriptionTypeID);
      itemList.items.Add(new Item()
      {
        name = subType.SubscriptionName,
        currency = "NZD",
        price = (Subscription.Amount / (decimal)1.15).ToString("0.00"),
        quantity = "1",
        sku = subType.SubscriptionTypeID.ToString()
       });
       var payer = new Payer() { payment_method = "paypal" };
       var redirectUrls = new RedirectUrls()
       {
         cancel_url = ConfigurationManager.AppSettings["PaymentConfirmationURL"] + Subscription.PaymentApprovalID,
           return_url = ConfigurationManager.AppSettings["PaymentCancellationURL"] + Subscription.PaymentApprovalID
       };
       var details = new Details()
       {
         tax = (Subscription.Amount - decimal.Parse((Subscription.Amount / (decimal)1.15).ToString("0.00"))).ToString("0.00"),
         subtotal = (Subscription.Amount / (decimal)1.15).ToString("0.00"),
         shipping="0"
        };
        var amount = new Amount()
        {
          currency = "NZD",
          total = Subscription.Amount.ToString("0.00"),
          details = details              
        };
        var transactionList = new List<Transaction>();
        transactionList.Add(new Transaction()
        {
          description = "PETT Subscription.",
          invoice_number = "PETT1420" + Subscription.SubscriptionID.ToString(),
          amount = amount,
          item_list = itemList
        });
        Payment payment = new Payment()
        {
          intent = "sale",
          payer = payer,
          transactions = transactionList,
          redirect_urls = redirectUrls
        };
        payment.Create(apiContext);
.... At this point the payment state is still null and no links are present even though I appear to have a successful call with no exceptions.

我将非常感谢任何有关我所缺失的线索或见解。

1 个答案:

答案 0 :(得分:0)

多哈,非常明显。没有注意功能签名payment.create,它返回一个新的付款。您需要使用的,而不是用于调用的付款,例如:

付款paymentToUse = payment.Create(apiContext);

paymentToUse包含所有商品。