Payflow是应用Paypal高级产品的必要部分,包括Paypal Payments Advanced。集成方法见此链接:https://ppmts.custhelp.com/app/answers/detail/a_id/929/
Part 1:创建一个Payflow的测试账户。
打开https://registration.paypal.com/welcomePage.do?country=US&mode=try,点击continue,填写表单,让Processor的值保持默认(FDMS Nashville)。下一个
页面,点击"Login to PayPal Manager",不要点击"continue"。
Part 2:创建一个sandbox的测试账户。
打开https://www.sandbox.paypal.com/home,点击"Sign Up",国家选择“United Kingdom”,这是因为在选择US作为测试账号的时候有一个已知的问题存在,但是
它只影响到测试账号,对正式账号没有影响。选择bussiness账户,注册一个国际为UK的sandbox账户。
Part 3:设置manager。
打开https://manager.paypal.com/登录。
Service Setting => Hosted Checkout Pages=>Set Up
1、Transaction Process Mode=>Test。
2、PayPal Sandbox email address=>UK Sandbox account。
3、选择Billing Information下的CSC。
4、Show confirmation page=>On my website。
5、Enable Secure Token=>Yes
Service Settings => Fraud Protection => Test Setup => Edit Standard Filters,取消所有的checkbox,点击deploy。
Part 4:配置Hosted Checkout Pages。
Service Settings => Hosted Checkout Pages => Customize,选择Layout C,要选择布局C,你要再Set Up里添加Return和Error URL。
Part 5:测试。
在教程页面底下有一个名为payflowbasictestdemos.zip的压缩包,下载他,按照实例代码修改。
/// <summary> /// 根据订单信息返回tokenId和token的组合对象NameValueCollection /// </summary> /// <param name="basketOrder"></param> /// <returns></returns> public NameValueCollection PayAdvanced(VM_BasketOrder basketOrder) { #region ReturnURL CancelURL string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority; string ReturnURL = baseUrl + Url.Action("ReturnPayAdvanced", "Checkout"); string CancelURL = baseUrl + Url.Action("CancelPayAdvanced", "Checkout"); string ErrorURL = baseUrl + Url.Action("ErrorPayAdvanced", "Checkout"); #endregion #region billAddress shipAddress StoredAddress billAddress = basketOrder.billto_sAddress; StoredAddress shipAddress = basketOrder.shipto_sAddress; #endregion #region 构建要传输的数据对象 NameValueCollection requestArray = new NameValueCollection() { {"PARTNER", "PayPal"}, {"VENDOR", "你的manager账户"}, {"USER", "你的manager账户"}, {"PWD", "你的manager密码"}, //根据securetokenid(唯一的)和CREATESECURETOKEN=Y,获取 a secure token //secure token30分钟内可用,且可用一次 {"CREATESECURETOKEN", "Y"}, {"SECURETOKENID", genId()}, {"TRXTYPE", "S"}, {"SHIPAMOUNT", basketOrder.ShippingAmount.ToString()}, {"AMT", basketOrder.Total.ToString()}, {"TAX", basketOrder.SalesTax.ToString()}, {"CURRENCY", "USD"}, {"RETURNURL", ReturnURL}, {"CANCELURL", CancelURL}, {"ERRORURL", ErrorURL}, {"BILLTOFIRSTNAME",billAddress.Name.AddressNameSplit()[0]}, {"BILLTOLASTNAME", billAddress.Name.AddressNameSplit()[1]}, {"BILLTOSTREET", billAddress.Street1}, {"BILLTOCITY",billAddress.City}, {"BILLTOSTATE",billAddress.State}, {"BILLTOZIP",billAddress.Zip}, {"BILLTOCOUNTRY",billAddress.Country}, {"BILLTOPHONE",billAddress.Phone}, {"SHIPTOFIRSTNAME", shipAddress.Name.AddressNameSplit()[0]}, {"SHIPTOLASTNAME", shipAddress.Name.AddressNameSplit()[1]}, {"SHIPTOSTREET", shipAddress.Street1}, {"SHIPTOCITY", shipAddress.City}, {"SHIPTOSTATE", shipAddress.State}, {"SHIPTOZIP",shipAddress.Zip}, {"SHIPTOCOUNTRY",shipAddress.Country}, {"SHIPTOPHONE",shipAddress.Phone}, }; #endregion NameValueCollection resp = run_payflow_call(requestArray); //将订单 信息 存入 session Session["VM_BasketOrder"] = Serialization.ScriptSerialize<VM_BasketOrder>(basketOrder); return resp; } /// <summary> /// 发送请求到Payflow 从PayPal获取Token /// /// </summary> /// <param name="requestArray">要传输的订单信息</param> /// <returns></returns> protected NameValueCollection run_payflow_call(NameValueCollection requestArray) { #region 发送请求到Payflow String nvpstring = ""; foreach (string key in requestArray) { var val = requestArray[key]; nvpstring += key + "[ " + val.Length + "]=" + val + "&"; } string urlEndpoint = "https://pilot-payflowpro.paypal.com/"; HttpWebRequest payReq = (HttpWebRequest)WebRequest.Create(urlEndpoint); payReq.Method = "POST"; payReq.ContentLength = nvpstring.Length; payReq.ContentType = "application/x-www-form-urlencoded"; StreamWriter sw = new StreamWriter(payReq.GetRequestStream()); sw.Write(nvpstring); sw.Close(); #endregion #region 获取Payflow的回复 HttpWebResponse payResp = (HttpWebResponse)payReq.GetResponse(); StreamReader sr = new StreamReader(payResp.GetResponseStream()); string response = sr.ReadToEnd(); sr.Close(); #endregion #region 将回复 转换成 NameValueCollection对象,返回 NameValueCollection dict = new NameValueCollection(); foreach (string nvp in response.Split('&')) { string[] keys = nvp.Split('='); dict.Add(keys[0], keys[1]); } return dict; #endregion } /// <summary> /// 创建唯一的TokenID,传递给PayPal 用来获取Token /// /// </summary> /// <returns></returns> protected string genId() { var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; var random = new Random(); var result = new string( Enumerable.Repeat(chars, 16) .Select(s => s[random.Next(s.Length)]) .ToArray()); return "MySecTokenID-" + result; //add a prefix to avoid confusion with the "SECURETOKEN" }
将返回的TokenId和Token放到下面的代码里
<iframe src="@("https://payflowlink.paypal.com?MODE=TEST&SECURETOKENID="+ViewBag.SECURETOKENID+"&SECURETOKEN="+ViewBag.SECURETOKEN)" name="test_iframe" scrolling="no" style=" width:480px;height:490px;border:0px;"></iframe>
PayPal的支付页面就被镶嵌到了你的网站里了。
Account Administration=>Processor&Merchant Bank Information=>Accepted Card Types下的设置可能会影响到你是否能收到信用卡付款,怎么设置我还不太清
楚,希望有人指点。