LUKIYA'S NEVERLAND

春去秋来,花谢花开。


这几天做PayPal的支付网关整合,查了不少文档,都是英文的,还说的不够简洁,整理了下,只需要很简单几步就可以让你的程序使用PayPal支付网关,保证简明,一看就懂。

1、申请测试帐号 (https://developer.paypal.com) ,并申请API Key。这方面太多例子跟文档,就不赘述了,如不知道请百度或谷歌。

2、在你的 .NET工程里添加服务引用,测试版应该连接到这里 (https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl)。

3、直接扣款模式代码如下。

PayPalAPIAAInterface paypal = new PayPalAPIAAInterfaceClient();

const string VERSION = "89.0";  // 根据你申请时最新的版本号决定

CustomSecurityHeaderType header = new CustomSecurityHeaderType();

UserIdPasswordType credentials = new UserIdPasswordType()
{
  Username = ConfigurationManager.AppSettings["APIUsername"],// API 用户名
  Password = ConfigurationManager.AppSettings["APIPassword"],  // API 密码
  Signature = ConfigurationManager.AppSettings["APISignature"],   // API 签名字符串
};

private void DoDirectPaymentTest()
{
      var req = new DoDirectPaymentReq();
      req.DoDirectPaymentRequest = new DoDirectPaymentRequestType();
      req.DoDirectPaymentRequest.Version = "89.0";

req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType
      {
        //PaymentAction = PaymentActionCodeType.Authorization,
        IPAddress = "61.175.209.109",
        PaymentDetails = new PaymentDetailsType { OrderTotal = new BasicAmountType { currencyID = CurrencyCodeType.USD, Value = "100.00" } },
        CreditCard = new CreditCardDetailsType
        {
          CardOwner = new PayerInfoType { Payer = "buyer_132949285@live.com" }, // 你申请的测试付款帐号邮件
          CreditCardNumber = "xxxxxxxxxxxxxxxxxx", // 你申请的测试付款帐号的信用卡号
          CVV2 = "123", // CVV2验证码,测试版随便填3位
          ExpMonth = 5 //你申请的测试付款帐号信用卡过期月,
          ExpMonthSpecified = true,
          ExpYear = 2018 //你申请的测试付款帐号信用卡过期年,
          ExpYearSpecified = true,
          CreditCardType = CreditCardTypeType.Visa //(类型可选)
        }
      };
      //
      var request = new DoDirectPaymentRequest(header, req);
      var response = paypal.DoDirectPayment(request);
}