PayPal API混淆 – ExpressCheckout使用哪一个

我正在考虑PayPal提供的各种集成,因为我只想提供PayPal作为付款选项,我将使用Express Checkout。 话虽如此,似乎可以通过多种方式进行整合:

  1. 名称值对
  2. 经典API(SDK)
  3. 宁静的API。

我遇到的问题是.NET SDK是经典API集的一部分,显然已被弃用(来源: https : //github.com/paypal/merchant-sdk-dotnet )。 RESTful API没有提到有关ExpressCheckout的任何内容,所以我假设 NVP是要走的路。

有人可以澄清最佳路线,因为我不想在事情被弃用时重写它。

有关信息:我正在使用带有C#的ASP.NET MVC。

首先,只有两个API:

  1. 经典API
    • 请求和响应有效负载的格式为NVP and SOAP
    • PayPal Merchant SDK for .NET ( GitHub | NuGet )提供对Express Checkout的官方PayPal SDK支持
  2. REST API
    • 请求和响应有效负载格式为JSON
    • PayPal .NET SDK提供的官方PayPal SDK支持( GitHub | NuGet )

通过PayPal名称 – 值对API (NVP API),您只需向PayPal发送HTTP请求并使用名称 – 值对指定请求参数,即可利用PayPal API的function。 NVP API是PayPal SOAP API的轻量级替代品,可以访问与SOAP API相同的一组function。

有关Classic API与REST API的几点要考虑:

  • 经典API不会很快被弃用。 您可以使用Classic API。
  • 此外,REST API不支持许多在Classic API中工作的变量/参数。
  • REST API可用于信用卡和PayPal付款(快速结账体系结构)。

由于您使用的是.NET SDK,因此可以继续使用它,因为它使用的是Classic API + NVP。

我更喜欢SOAP,因为它是一个干净的代码,带有类。

看看改编的C#代码:

 private paypalProxy.CustomSecurityHeaderType getCredentials() { paypalProxy.CustomSecurityHeaderType header = new paypalProxy.CustomSecurityHeaderType(); header.Credentials = new paypalProxy.UserIdPasswordType(); header.Credentials.Username = ""; header.Credentials.Password = ""; header.Credentials.Signature = ""; header.Credentials.Subject = ""; return header; } private paypalProxy.BasicAmountType getAmountValue(Decimal valor) { paypalProxy.BasicAmountType amt = new paypalProxy.BasicAmountType(); amt.currencyID = paypalProxy.CurrencyCodeType.BRL; amt.Value = valor.ToString("N2").Replace(",", "."); return amt; } public paypalProxy.SetExpressCheckoutResponseType ExpressCheckout(Venda venda, string emailComprador, Decimal valor, Decimal valorFrete, string shipToName, string shipToStreet, string shipToStreet2, string shipToCity, string shipToState, string shipToZip, string shipToCountryCode, string billingToName, string billingToStreet, string billingToStreet2, string billingToCity, string billingToState, string billingToZip, string billingToCountryCode) { #region Header/Identification paypalProxy.CustomSecurityHeaderType header = getCredentials(); #endregion #region Body paypalProxy.SetExpressCheckoutReq requisicao = new paypalProxy.SetExpressCheckoutReq(); #region Body configuration requisicao.SetExpressCheckoutRequest = new paypalProxy.SetExpressCheckoutRequestType(); requisicao.SetExpressCheckoutRequest.Version = "109.0"; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails = new paypalProxy.SetExpressCheckoutRequestDetailsType(); requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.OrderTotal = getAmountValue(valor + valorFrete - venda.valorFreteDesconto); requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.BuyerEmail = emailComprador; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.ReturnURL = "" requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.CancelURL = "" requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.PaymentAction = paypalProxy.PaymentActionCodeType.Sale; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.ReqConfirmShipping = "0"; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.AddressOverride = "0"; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.AllowNote = "0"; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.BrandName = "" requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.ShippingMethod = ShippingServiceCodeType.CustomCode; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.cppheaderimage = "http://.../logo.jpg" #endregion #region Shipping Details requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.Address = new paypalProxy.AddressType(); requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.Address.Name = shipToName; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.Address.Street1 = shipToStreet; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.Address.Street2 = shipToStreet2; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.Address.CityName = shipToCity; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.Address.StateOrProvince = shipToState; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.Address.PostalCode = shipToZip; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.Address.Country = paypalProxy.CountryCodeType.BR; #endregion #region Billing Address requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.BillingAddress = new paypalProxy.AddressType(); requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.BillingAddress.Name = billingToName; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.BillingAddress.Street1 = billingToStreet; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.BillingAddress.Street2 = billingToStreet2; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.BillingAddress.CityName = billingToCity; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.BillingAddress.StateOrProvince = billingToState; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.BillingAddress.PostalCode = billingToZip; requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.BillingAddress.Country = paypalProxy.CountryCodeType.BR; #endregion #region Payment detail PaymentDetailsType paymentDetail = new PaymentDetailsType(); #region ITEMS List paymentItems = new List(); foreach (var item in venda.Product) { PaymentDetailsItemType itemPaypal = new PaymentDetailsItemType(); itemPaypal.Name = item.Produto; //itemPaypal.Description = item.ProductName; itemPaypal.Amount = getAmountValue(item.value); itemPaypal.Quantity = item.qtd.ToString(); itemPaypal.ItemURL = item.UrlImage; paymentItems.Add(itemPaypal); } #region DISCOUNT if (venda.isDesconto) { PaymentDetailsItemType itemPaypal = new PaymentDetailsItemType(); itemPaypal.Name = "Discount"; itemPaypal.Description = "Discount"; itemPaypal.Amount = getAmountValue(venda.Discount * (-1)); itemPaypal.Quantity = "1"; paymentItems.Add(itemPaypal); } #endregion paymentDetail.ItemTotal = getAmountValue(valor); #endregion #region Shipping if (ShippingValue > 0) { paymentDetail.ShippingTotal = getAmountValue(ShippingValue); } if (venda.ShippingDiscount > 0) { paymentDetail.ShippingDiscount = getAmountValue(venda.ShippingDiscount); } #endregion paymentDetail.OrderDescription = string.Format("SALE {0} Nº {1}", "XPTO eCommerce", "Sale ID"); paymentDetail.PaymentDetailsItem = paymentItems.ToArray(); paymentDetail.AllowedPaymentMethod = AllowedPaymentMethodType.AnyFundingSource; paymentDetail.InvoiceID = venda.IdVenda.ToString(); List paymentDetails = new List(); paymentDetails.Add(paymentDetail); requisicao.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails.PaymentDetails = paymentDetails.ToArray(); #endregion #endregion #region Sending to Paypal and waiting for token in var TIPO paypalProxy.SetExpressCheckoutResponseType tipo = null; paypalProxy.PayPalAPIAAInterfaceClient cliente = new paypalProxy.PayPalAPIAAInterfaceClient(); tipo = cliente.SetExpressCheckout(ref header, requisicao); #endregion return tipo; }