最近做了一个在线支付,哎呀,把我给折腾的可不轻.搞了很长时间.    PayPal 是一家 eBay 公司,它是在线付款解决方案的全球领导者,在全世界有超过七千一百六十万个帐户用户。PayPal 可由易趣买家和卖家、在线零售商和其他商家在 56 个市场以 6 种货币使用:加元 欧元 英镑 美元 日元 澳元;PayPal 快速、安全而又方便,是跨国交易的理想解决方案。国内的支付宝和PayPal 类型是差不多的!

随着制作外贸网站的数量增多,有些客户针对国外需要用到PayPal 支付接口,今天找了些PayPal 支付接口方面的资料,以备以后查询!也可以点GO去看原文档.

1.到https://developer.paypal.com/注册一个开发帐号,好了之后再进入Sandbox建立测试用的Paypal虚拟帐号(至少应该建立一个Business的和一个Personal的),信息可以是假的,注意:这里的至少两个测试帐号是在你所建立的开发帐号里面建立的,不要注册错了;

2.测试是很麻烦,但是是必不可少的,因为如果客户买过一次出错之后,就不会来第二次了,所以花半天时间做测试是很重要的;

3.代码帖出来给大家参考一下,我做的是不很细,支付成功后返回的结果我就没有做,因为我在测试的时候已经没有问题了,所以没有做,改天有空会完善的;

ASP.Net/C#

using System;
using System.IO;
using System.Text;
using System.Net;
using System.Web;

public partial class csIPNexample :System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Post back to either sandbox or live
string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
string strLive = "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);

// Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
strRequest += "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;

//for proxy
//WebProxy proxy = new WebProxy(new Uri("http://url:port/#"));
//req.Proxy = proxy;

//Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();

if (strResponse == "VERIFIED")
{
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strResponse == "INVALID")
{
// log for manual investigation
}
else
{
//log response/ipn data for manual investigation
}
}
}

ASP.Net/VB

Imports System.Net
Imports System.IO

Partial Class vbIPNexample
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Post back to either sandbox or live
Dim strSandbox As String = "https://www.sandbox.paypal.com/cgi-bin/webscr"
Dim strLive As String = "https://www.paypal.com/cgi-bin/webscr"
Dim req As HttpWebRequest = CType(WebRequest.Create(strSandbox), HttpWebRequest)

'Set values for the request back
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
Dim Param() As Byte = Request.BinaryRead(HttpContext.Current.Request.ContentLength)
Dim strRequest As String = Encoding.ASCII.GetString(Param)
strRequest = strRequest + "&cmd=_notify-validate"
req.ContentLength = strRequest.Length

'for proxy
'Dim proxy As New WebProxy(New System.Uri("http://url:port/#"))
'req.Proxy = proxy

'Send the request to PayPal and get the response
Dim streamOut As StreamWriter = New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
streamOut.Write(strRequest)
streamOut.Close()
Dim streamIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
Dim strResponse As String = streamIn.ReadToEnd()
streamIn.Close()

If strResponse = "VERIFIED" Then
'check the payment_status is Completed
'check that txn_id has not been previously processed
'check that receiver_email is your Primary PayPal email
'check that payment_amount/payment_currency are correct
'处理付款
ElseIf strResponse = "INVALID" Then
'log for manual investigation
Else
'Response wasn't VERIFIED or INVALID, log for manual investigation
End If
End Sub
End Class

ASP/VBScript
 
 
(requires MSXML)

<mailto:%@LANGUAGE="VBScript">
<%
Dim Item_name, Item_number, Payment_status, Payment_amount
Dim Txn_id, Receiver_email, Payer_email
Dim objHttp, str

' read post from PayPal system and add 'cmd'
str = Request.Form & "&cmd=_notify-validate"

' post back to PayPal system to validate
set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
' set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0")
' set objHttp = Server.CreateObject("Microsoft.XMLHTTP")
objHttp.open "POST", "https://www.paypal.com/cgi-bin/webscr", false
objHttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
objHttp.Send str

' assign posted variables to local variables
Item_name = Request.Form("item_name")
Item_number = Request.Form("item_number")
Payment_status = Request.Form("payment_status")
Payment_amount = Request.Form("mc_gross")
Payment_currency = Request.Form("mc_currency")
Txn_id = Request.Form("txn_id")
Receiver_email = Request.Form("receiver_email")
Payer_email = Request.Form("payer_email")

' Check notification validation
if (objHttp.status <> 200 ) then
' HTTP error handling
elseif (objHttp.responseText = "VERIFIED") then
' check that Payment_status=Completed
' check that Txn_id has not been previously processed
' check that Receiver_email is your Primary PayPal email
' check that Payment_amount/Payment_currency are correct
' process payment
elseif (objHttp.responseText = "INVALID") then
' log for manual investigation
else
' error
end if
set objHttp = nothing
%>

转载于:https://www.cnblogs.com/silverLee/archive/2009/11/05/1596834.html

ASP.Net/C# - PayPal接口文档相关推荐

  1. oracle web API,在Web API程序中使用Swagger做接口文档

    #### 创建Web API程序 在VS2019中创建一个ASP.NET Web应用程序,选择Web API来创建RESTful的HTTP服务项目,构选MVC和Web API核心引用. #### 安装 ...

  2. 【开源】.Net Api开放接口文档网站

    开源地址:http://git.oschina.net/chejiangyi/ApiView 开源QQ群: .net 开源基础服务  238543768 ApiView .net api的接口文档查看 ...

  3. DSO(dsoframer)的接口文档

    (开发环境)使用前先注册一下DSOFramer.ocx     操作:将DSOFramer.ocx复制到C:\windows\system32目录下,          开始->运行->r ...

  4. 在.Net Core中使用Swagger制作接口文档

    在实际开发过程中后台开发人员与前端(移动端)接口的交流会很频繁.所以需要一个简单的接口文档让双方可以快速定位到问题所在. Swagger可以当接口调试工具也可以作为简单的接口文档使用. 在传统的asp ...

  5. drf 安装_drf 生成接口文档

    REST framework可以自动帮助我们生成接口文档.接口文档以网页的方式呈现. 自动接口文档能生成的是继承自APIView及其子类的视图. 一.安装依赖 REST framewrok生成接口文档 ...

  6. DSO(dsoframer)的接口文档在VC++使用

    下面是别人的文章,读下面文章可大体了解DSOFramer接口,用的是.net版本的用法.不过了解后可以在VC++工程中导入DSOFramer的控件.自动生成的头文件做一个对比,然后就比较好使用这个控件 ...

  7. 人人通服务器返回为空,神州付直连接口文档新31全面值返回.pdf

    神州付支付平台 支付产品支付直连接口文档 更新日期:2009-3 版本号:3.1 目录 目录1 1 文档说明2 1.1 版本履历2 1.2 谁该读此文档2 1.3 名词缩写及定义2 2 产品简介3 3 ...

  8. Swagger 生成 PHP restful API 接口文档

    需求和背景 需求: 为客户端同事写接口文档的各位后端同学,已经在各种场合回忆了使用自动化文档工具前手写文档的血泪史. 我的故事却又不同,因为首先来说,我在公司是 Android 组负责人,属于上述血泪 ...

  9. js学习总结----crm客户管理系统之项目开发流程和api接口文档

    CRM ->客户管理系统 CMS ->内容发布管理系统 ERP ->企业战略信息管理系统 OA -> 企业办公管理系统 产品 / UI设计:需求分析,产品定位,市场调查...按 ...

最新文章

  1. Python列表List
  2. SQLServer2005表分区知识点摘要
  3. C#实现RSA加密解密
  4. 操作系统:第四章 文件管理1 - 文件逻辑结构,物理结构,文件目录,软硬连接,文件系统
  5. 谷歌A/B实验——重叠实验基础设施解读
  6. 上海电力学院计算机软件技术大作业,计算机网络应用设计 大作业报告.doc
  7. 团队开发——第一次冲刺第7天
  8. 给你一个亿-电视节目总结
  9. windows10系统电脑点击睡眠没反应怎么办?
  10. word回车后间距太大_word 里字体变大后再回车,两行间距太大怎么办
  11. linux getcwd 头文件,linux – rsync:getcwd():没有这样的文件或目录(2)
  12. 如何批量调整图片尺寸?
  13. 如何关闭 window10 自带的杀毒软件
  14. 幼儿识字软件测试自学,儿童识字App大PK:汉字王国只娱乐不学习
  15. Asterisk[1]
  16. mac使用git管理Github以及生成 SSH 公钥
  17. js计时器实现页面刷新和幻灯片效果
  18. 计算机cct 考试试题,基础计算机cct考试模拟试题.doc
  19. PHP开发的站长导航网源码
  20. 逆天!55英寸高色域曲面电视TCL H8800首触4999惊爆价

热门文章

  1. python变量类型是动态的_python内存动态分配过程详解
  2. HTML+CSS+JS实现React简单的计算器实例
  3. java jbutton 禁用_java-禁用后对jButton执行的操作
  4. java定义一个方法,向控制台输出99乘法表
  5. 中秋主题html,中秋节活动主题标语
  6. Redis内存回收策略
  7. Java成员方法的声明和调用
  8. php+错误+处理,PHP 错误处理手记!!!!!
  9. 阿联酋esma认证怎么做_百度爱采购企业认证是怎么做的?这些你要知道!
  10. 【youcans 的 OpenCV 例程 200 篇】104. 运动模糊退化模型