»»»美仑©本站聚集品质模板、JS特效、源码、模块、原创等丰富资源下载。
首页 教程 CMS教程 phpcms v9 PayPal支付模块

phpcms v9 PayPal支付模块

2018-01-30 11:23:41| 责任编辑: 小美| 查看: | 评论: 0| 百度已收录
摘要: 第一步:添加语言包 添加下面代码到 phpcms languages zh-cn pay lang php

第一步:添加语言包 添加下面代码到 phpcms\languages\zh-cn\pay.lang.php

  1. $LANG['paypal'] = 'PayPal支付'
  2. $LANG['paypal_tip'] = 'PayPal, 全球在线收付款解决方案领导者,快速,安全便捷的网上支付平台,为中国提供PayPal新用户培训及电子商务一站式专业服务。<a href="http://www.paypal.com" target="_blank"><font color="red">立即在线申请Paypal</font></a>'
  3. $LANG['paypal_account']  = '商户帐号'
  4. $LANG['paypal_currency'] = '支付货币'
  5. $LANG['paypal_sandbox'] = '测试环境(Sandbox)'
  6. $LANG['paypal_sandbox_range'][0] = "开启"
  7. $LANG['paypal_sandbox_range'][1] = "关闭"
  8. $LANG['paypal_currency_range']['AUD'] = '澳元'
  9. $LANG['paypal_currency_range']['CAD'] = '加元'
  10. $LANG['paypal_currency_range']['EUR'] = '欧元'
  11. $LANG['paypal_currency_range']['GBP'] = '英镑'
  12. $LANG['paypal_currency_range']['JPY'] = '日元'
  13. $LANG['paypal_currency_range']['USD'] = '美元'
  14. $LANG['paypal_currency_range']['HKD'] = '港元'

第二步:保存下面代码命名为“PayPal.class.php”到\phpcms\modules\pay\classes

  1. <?php  
  2. if (isset($set_modules) && $set_modules == TRUE) 
  3. {         
  4.     $i = isset($modules) ? count($modules) : 0; 
  5.   
  6.     $modules[$i]['code']    = basename(__FILE__'.class.php'); 
  7.     $modules[$i]['name']    = L('paypal''''pay');    
  8.     $modules[$i]['desc']    = L('paypal_tip''''pay'); 
  9.     $modules[$i]['is_cod']  = '0'
  10.     $modules[$i]['is_online']  = '1'
  11.     $modules[$i]['author']  = 'PHPCMS开发团队'
  12.     $modules[$i]['website'] = 'http://www.paypal.com'
  13.     $modules[$i]['version'] = '1.0.0'
  14.     $modules[$i]['config']  = array
  15.              array('name' => 'paypal_account','type' => 'text','value' => ''), 
  16.         array('name' => 'paypal_currency','type' => 'select','value' => 'USD'), 
  17.                 array('name' => 'paypal_sandbox','type' => 'select','value' => '1'
  18.     ); 
  19.     return
  20. pc_base::load_app_class('pay_abstract','','0'); 
  21.   
  22. class PayPal extends paymentabstract{         
  23.         public function __construct($config = array()) {         
  24.                 if (!emptyempty($config)) $this->set_config($config); 
  25.                 $paypal_currency_arr = array('AUD','CAD','EUR','GBP','JPY','USD','HKD'); 
  26.                 $this->config['currency'] = in_array($this->config['paypal_currency'],$paypal_currency_arr) ? $this->config['paypal_currency'] : 'USD'
  27.             if($this->config['paypal_sandbox']==0){ 
  28.                          $this->config['gateway_url'] = 'https://www.sandbox.paypal.com/cgi-bin/webscr'
  29.                          $this->config['verify_url'] = 'www.sandbox.paypal.com';         
  30.                 } 
  31.                 else
  32.                          $this->config['gateway_url'] = 'https://www.paypal.com/cgi-bin/webscr'
  33.                          $this->config['verify_url'] = 'www.paypal.com';         
  34.                 } 
  35.                 $this->config['gateway_method'] = 'POST'
  36.                 $this->config['return_url'] = return_url('PayPal'); 
  37.                 $this->config['notify_url'] = return_url('PayPal',1);                 
  38.                 //pc_base::load_app_func('alipay'); 
  39.         } 
  40.   
  41.         public function getpreparedata() { 
  42.                  
  43.                 //固定值                 
  44.                 $prepare_data['cmd'] = '_xclick'
  45.                  
  46.                 //商户帐号  
  47.                 $prepare_data['business'] = $this->config['paypal_account']; 
  48.                  
  49.                 //返回地址 
  50.                 $prepare_data['return'] = $this->config['return_url']; 
  51.                  
  52.                 //字符集 
  53.                 $prepare_data['charset'] = CHARSET; 
  54.                  
  55.                 //不提示邮寄低级 
  56.                 $prepare_data['no_shipping'] = 1; 
  57.                  
  58.                 //付款说明 
  59.                 $prepare_data['no_note'] = ''
  60.                  
  61.                 //支付货币 
  62.                 $prepare_data['currency_code'] = $this->config['currency']; 
  63.                  
  64.                 //支付通知地址 
  65.                 $prepare_data['notify_url'] = $this->config['notify_url']; 
  66.                  
  67.                 //订单号 
  68.                 $prepare_data['invoice'] = $this->order_info['id']; 
  69.                  
  70.                 //订单名称 
  71.                 $prepare_data['item_name'] = $this->product_info['name']; 
  72.                  
  73.                 //订单金额 
  74.                 $prepare_data['amount'] = $this->product_info['price']; 
  75.                  
  76.                 return $prepare_data
  77.         } 
  78.          
  79.         /** 
  80.          * GET 支付后返回(没有对交易结果进行写入) 
  81.          *  
  82.          */ 
  83.     public function receive() { 
  84.             showmessage('交易完成 返回查看交易结果',APP_PATH.'index.php?m=pay&c=deposit&a=init'); 
  85.                 return false; 
  86.     }         
  87.   
  88.     /** 
  89.          * POST接收数据 
  90.          * 状态码说明  (0 交易完成 1 交易失败 2 交易超时 3 交易处理中 4 交易未支付 5交易取消6交易发生错误) 
  91.          */ 
  92.     public function notify() { 
  93.                 $req = 'cmd=_notify-validate'
  94.                 foreach($_POST as $key=>$value) { 
  95.                         $value = urlencode(stripslashes($value)); 
  96.                         $req .= "&$key=$value"
  97.                 } 
  98.   
  99.                 $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"
  100.                 $header .= "Content-Type:application/x-www-form-urlencoded\r\n"
  101.                 $header .= "Content-Length:".strlen($req)."\r\n\r\n"
  102.   
  103.                 $fp = fsockopen($this->config['verify_url'], 80, $errno$errstr, 30); 
  104.   
  105.                 $item_invoice = $_POST['invoice']; 
  106.                 $item_number = $_POST['item_number']; 
  107.                 $payment_status = $_POST['payment_status']; 
  108.                 $payment_amount = $_POST['mc_gross']; 
  109.                 $payment_currency = $_POST['mc_currency']; 
  110.                 $txn_id = $_POST['txn_id']; 
  111.                 $receiver_email = $_POST['receiver_email']; 
  112.                 $payer_email = $_POST['payer_email'];                 
  113.                  
  114.                 $return_data['order_id'] = $item_invoice
  115.                 $return_data['order_total'] = $return_data['price'] = $payment_amount
  116.                  
  117.                 //判断回复 POST 是否创建成功 
  118.                 if (!$fp) { 
  119.                         $return_data['order_status'] = 6; 
  120.                         fclose($fp); 
  121.                         error_log(date('m-d H:i:s',SYS_TIME).'| POST: HTTP errer |'."\r\n", 3, CACHE_PATH.'pay_error_log.php');                                         
  122.                         return $return_data
  123.                 } else { 
  124.                         fputs($fp$header.$req); 
  125.                         while (!feof($fp)) { 
  126.                                 $res = fgets($fp, 1024); 
  127.                                 //已经通过认证 
  128.                                 if (strcmp ($res"VERIFIED") == 0) { 
  129.                                         if($payment_status != 'Completed'){ 
  130.                                                 $return_data['order_status'] = 3; 
  131.                                                 fclose($fp);                                                                         
  132.                                                 return $return_data
  133.                                         } 
  134.                                         if($receiver_email != $this->config['paypal_account']) 
  135.                     { 
  136.                                                 $return_data['order_status'] = 6; 
  137.                         fclose($fp); 
  138.                                                 error_log(date('m-d H:i:s',SYS_TIME).'| POST: receiver_email errer |'."\r\n", 3, CACHE_PATH.'pay_error_log.php');                                         
  139.                                                 return $return_data
  140.                     } 
  141.                                         if($payment_currency != $this->config['currency']) 
  142.                     { 
  143.                                                 $return_data['order_status'] = 6; 
  144.                         fclose($fp); 
  145.                                                 error_log(date('m-d H:i:s',SYS_TIME).'| POST: currency errer |'."\r\n", 3, CACHE_PATH.'pay_error_log.php');                                         
  146.                                                 return $return_data
  147.                     } 
  148.                                         $return_data['order_status'] = 0; 
  149.                                 } else if (strcmp($res"INVALID") == 0) { 
  150.                                         $return_data['order_status'] = 6; 
  151.                                         error_log(date('m-d H:i:s',SYS_TIME).'| POST: INVALID errer |'."\r\n", 3, CACHE_PATH.'pay_error_log.php');                                        return $return_data
  152.                                 } 
  153.                         } 
  154.                         fclose($fp); 
  155.                 } 
  156.                 return $return_data
  157.     } 
  158.     /** 
  159.      * 相应服务器应答状态 
  160.      * @param $result 
  161.      */ 
  162.     public function response($result) { 
  163.             if (FALSE == $resultecho 'fail'
  164.                 else echo 'success'
  165.     } 
  166. ?> 

说明:
要正常使用PayPal后台设置”即时付款通知“必须开启 不然支付成功后系统不能收到PayPal 通知消息

保存文件编码根据自己网站编码来
支付不能在内网测试 应为内网收不到PayPal 通知消息
 
支付截图
相关热词搜索:模块
精彩阅读
会员登录
广告位

关注我们:美仑视觉

官方QQ群

微信平台

全国服务热线:

0769-33232320

【版权声明】本站内容由互联网用户自发贡献,本站不拥有所有权,不承担相关法律责任。如果发现本站有涉嫌抄袭的内容,欢迎发送邮件至Email:admin@meil88.com 举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。

Copyright   ©2013-2018  美仑视觉  Powered by©Meil88!  公安备案:粤ICP备15022042号