paypal数字商品支付的接口开发

Server 林涛 7944℃ 0评论

开通要求

客户必须:

· 正在从事数字商品销售

· 开设了企业账户

· 使用快速结账或自由组合付款

· 同意PayPal新的《用户协议》

· 另外同意PayPal的《小额付款费率协议》。

如何开通:

已经拥有快速结账或自由组合付款的商家可以通过登录PayPal账户,点击“我的业务设置” 轻松进行升级。没有快速结账或自由组合付款的商家需要安装其中一种解决方案,方法是点击数字商品子网站(www.paypal-biz.com/digitalgoods)上的“立即尝试”按钮。设置过程中已经集成了“数字商品”组件,并提供“立即尝试”指南和安装手册。设置快速结账仅需2-3天。设置自由组合付款的技术性较强(需要丰富的开发经验)——但它能够大大提升平台和支付的灵活性。

我的代码实现

配置文件 config.inc.php :

// paypal沙盒环境配置
  define("API_USERNAME", "卖家账号");
  define("API_PASSWORD", "卖家账号密码");
  define("API_SIGNATURE", "密钥");
  define('POST_URL', 'https://api-3t.sandbox.paypal.com/nvp');	// 提交地址

 define('VERSION', '65.1');		// 版本号
 define('SECK', 'SetExpressCheckout');	// 方式
 define('DECKP', 'DoExpressCheckoutPayment');
 define('RETURNURL', '返回地址');	// 返回地址
 define('CANCELURL', '取消返回地址');	// 取消返回地址
 define('CATEGORY', 'Digital');		// 商品类型
 define('REQCONFIRMSHIPPING', '0');	// 
 define('NOSHIPPING', '1');		// 航运费
 define('CURRENCYCODE', 'USD');	// 货币类型

支付文件 paypalpay.php :

 include_once ('config.inc.php');
 include_once ('./include/paypalClass.php');   // 对官方提供的接口进行封装
 $paypal = new paypalPaye();
 $nvps = array();
 $ordernum = date('YmdHis').str_pad($paypal->getMicrosecStr(), 6, "0", STR_PAD_LEFT);		// 订单号

 /**************** PayPal 数字商品固定参数 start ***************/

 $nvps["VERSION"] 				= VERSION;			// According to the sources I've talked to internally, this HAS to be set to 65.1.  No other version is currently supported. 
 $nvps["METHOD"] 				= SECK; 			// Since this is a special-purpose script that is designed to handle a single item purchase, I can get away with hardcoding most of my values.  In practice, this isn't such a good idea, but for a demo, it'll work.
 $nvps["RETURNURL"] 			= RETURNURL.'?ordernum='.$ordernum;
 $nvps["CANCELURL"] 			= CANCELURL;
 $nvps["REQCONFIRMSHIPPING"] 	= REQCONFIRMSHIPPING;	// Since it's a digital good (and not physical)
 $nvps["NOSHIPPING"] 			= NOSHIPPING;			// we don't need a shipping address.
 $nvps["PAYMENTREQUEST_0_CURRENCYCODE"] = CURRENCYCODE;	// Currency,Unified type

 /**************** PayPal 数字商品固定参数 end ***************/

 /*********************** Good Info Start **************************/ 

 $nvps["PAYMENTREQUEST_0_AMT"] 		= 0.00;		// 支付额总额,包括汇率(如果不是美元)  
 $nvps["PAYMENTREQUEST_0_ITEMAMT"] 	= 0.00;		// 所有商品总额

 // 如果是多个文件可以使用循环
 $nvps["L_PAYMENTREQUEST_0_ITEMCATEGORY0"] = CATEGORY;	// This is what makes the whole magic happen , don't forget this one!
 $nvps["L_PAYMENTREQUEST_0_NAME$i"] 	= [0]['name'];	// First good Name
 $nvps["L_PAYMENTREQUEST_0_DESC$i"] = [0]['name'];			// First good desc
 $nvps["L_PAYMENTREQUEST_0_AMT$i"] 	= [0]['price'];		// Quantity
 $nvps["L_PAYMENTREQUEST_0_QTY$i"] 	= 1; 			// First Quantity 

  /*********************** Good Info End **************************/

 $response = $paypal->RunAPICall($nvps); 	// Send the API call to PayPal.

 // Paypal not give us a token
 if(($response["ACK"] != "Success" && $response["ACK"] != "SuccessWithWarning") || !strlen($response["TOKEN"])){
	$paypal->PaymentError();
 }

 // Otherwise, grab our token and redirect the buyer to PayPal. 在弹出窗口中重定向买家到PayPal
//  header("Location: https://www.sandbox.paypal.com/incontext?token=" . $response["TOKEN"]);	// 测试环境
  header("Location: https://www.paypal.com/incontext?token=" . $response["TOKEN"]);	// 正式环境

欢迎对支付问题提出异议和讨论,请发送到我的邮箱mr.wulintao@gmail.com或者给我留言。

如需转载请注明: 转载自26点的博客

本文链接地址: paypal数字商品支付的接口开发

转载请注明:26点的博客 » paypal数字商品支付的接口开发

喜欢 (0)
发表我的评论
取消评论

表情