2014-04-16 5 views
0

안녕하세요 저는 멍청한 질문이지만이 문서를 찾을 수는 없지만 동일한 거래에서 1 개 이상의 항목을 지불하고 싶습니다. 오류 :PayPal REST API를 사용하여 한 번에 여러 항목 지불 ASP.NET MVC

Exception in HttpConnection Execute: Invalid HTTP response The remote server returned an error: (400) Bad Request. 

메신저 아이템 목록 부분을 하드 코딩,하지만 난 Amount.Total beetween 차이 내 모든 아이템의 가격 * 수량의 가격을 understan 해달라고

public ActionResult CreatePayment(string description, decimal price, decimal tax = 0, decimal shipping = 0) 
    { 
     var viewData = new PayPalViewData(); 
     var guid = Guid.NewGuid().ToString(); 

     var paymentInit = new Payment 
     { 
      intent = "authorize", 
      payer = new Payer 
      { 
       payment_method = "paypal" 
      }, 
      transactions = new List<Transaction> 
      { 
       new Transaction 
       { 
        item_list = new ItemList{ 
         items = new List<Item>{ 
           new Item{ 
           name = "item 1", 
           currency = "USD", 
           price = "20", 
           quantity = "2" 
           }, 
           new Item{ 
           name = "item 2", 
           currency = "USD", 
           price = "40", 
           quantity = "1" 
           }, 
           new Item{ 
           name = "item 3", 
           currency = "USD", 
           price = "40", 
           quantity = "1" 
           } 
         } 
        }, 
        amount = new Amount 
        { 
         currency = "EUR", 
         total = (price + tax + shipping).ToString(), 
         details = new Details 
         { 
          subtotal = price.ToString(), 
          tax = tax.ToString(), 
          shipping = shipping.ToString() 
         } 
        }, 
        description = description 
       }, 
      }, 
      redirect_urls = new RedirectUrls 
      { 
       return_url = Utilities.ToAbsoluteUrl(HttpContext, String.Format("~/paypal/confirmed?id={0}", guid)), 
       cancel_url = Utilities.ToAbsoluteUrl(HttpContext, String.Format("~/paypal/canceled?id={0}", guid)), 
      }, 
     }; 

     viewData.JsonRequest = JObject.Parse(paymentInit.ConvertToJson()).ToString(Formatting.Indented); 

     try 
     { 
      var accessToken = new OAuthTokenCredential(ConfigManager.Instance.GetProperties()["ClientID"], ConfigManager.Instance.GetProperties()["ClientSecret"]).GetAccessToken(); 
      var apiContext = new APIContext(accessToken); 
      var createdPayment = paymentInit.Create(apiContext); 

      var approvalUrl = createdPayment.links.ToArray().FirstOrDefault(f => f.rel.Contains("approval_url")); 

      if (approvalUrl != null) 
      { 
       Session.Add(guid, createdPayment.id); 

       return Redirect(approvalUrl.href); 
      } 

      viewData.JsonResponse = JObject.Parse(createdPayment.ConvertToJson()).ToString(Formatting.Indented); 

      return View("Error", viewData); 
     } 
     catch (PayPalException ex) 
     { 
      viewData.ErrorMessage = ex.Message; 

      return View("Error", viewData); 
     } 
    } 

내가를 삭제하는 경우 item-list, 그것이 작동하지만, 단지 1 개의 아이템이 금액 에 나와 있습니다. 어떻게해야합니까? 이것에 대한 안내가 있습니까? 페이팔의 GUID 및 데모 전체 응답이 총은 세부 사항/항목 목록과 함께 추가하지 않는다는 것입니다 보지 않고있다 하나 개의 항목 만

감사

+3

http://stackoverflow.com/q/3308898 –

+0

HTTPS : //developer.paypal .com/docs/classic/use-cases/uc_webcheckout-multiple-items/ –

+0

고마워요.하지만 저는보기에 그것을하고 싶지 않습니다. 페이팔 링크는 Classic API를 사용하고 있습니다. 나머지 API를 사용하고 있습니다. 샘플이 없습니다. 가맹점 수수료 및 기타 정보 코드 –

답변

1

내 생각 엔,에 대한 것입니다. 유효성 검사는 모든 항목 값을 합산합니다.이 값은 부분합과 같아야하며 부분합 + 세금 (세부 사항)은 합계가 같아야합니다.

합 (item.price * item.count) == 소계

세부 합 == 전체