加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 如何将paypal与codeigniter集成?

发布时间:2020-12-13 17:26:07 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试将PayPal付款与我的codeigniter项目集成.我的项目是关于一个约会网站,其中两个不同的用户互相交流.因此,我正在销售计划,在此基础上,将为用户提供访问权限,以便在该段时间内向其他人发送消息.为此我开发了一个非常简单的页面,其中包含可从不同计划
我正在尝试将PayPal付款与我的codeigniter项目集成.我的项目是关于一个约会网站,其中两个不同的用户互相交流.因此,我正在销售计划,在此基础上,将为用户提供访问权限,以便在该段时间内向其他人发送消息.为此我开发了一个非常简单的页面,其中包含可从不同计划中选择的单选按钮.
这些是以下计划

  • one month ($2)
  • Two month ($4)
  • Three month ($6)
  • Four month ($8)
  • Five month ($10)

等等

  • Six month ($12)

因此,用户可以从上面选择任何计划,然后可以继续进一步支付PayPal的金额.在我们网站上拥有帐户的用户可以使用此页面.
所以我们可以将当前用户的所有细节转移到PayPal,例如 – 姓名,电子邮件等.

我曾尝试阅读很多关于如何整合paypal的文章,但没有一篇能帮助我.
因为我是codeigniter的新手.

我还在paypal上创建了Paypal和沙盒帐户.我从sourceforge.net下载了php-toolkit并单独使用它,然后运行正常.但是当我尝试在codeigniter中实现时,它不需要任何地方.

请帮我 !!

编辑:

<?php 

    //Configuration File
    include_once APPPATH.'../php_paypal/includes/config.inc.php'; 

    //Global Configuration File
    include_once APPPATH.'../php_paypal/includes/global_config.inc.php';

?> 
<?php echo form_open('https://www.sandbox.paypal.com/cgi-bin/webscr');?>   

 <input type="hidden" name="amount" value="9.95">
 <input type="hidden" name="item_name" value="Test Payment">
</form>

这就是我想要创造的东西.之前我曾尝试在表单操作中使用“process.php”,但我在codeigniter中收到了URL错误.所以我想为什么不用这种方式.我知道有函数负责向paypal发送值.但通过这种行动方法.我被重定向到简单的paypal页面.

解决方法

您可以按照以下步骤操作.

Step1创建IPN表单.确保将IPN URL(通知URL)传递给paypal.

对于Form变量,您可以参考https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/

<form name="paypalFrm" id="paypalFrm" action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_ext-enter">
    <input type="hidden" name="redirect_cmd" value="_xclick-subscriptions">
    <input type="hidden" name="return" value="<?php echo $return_url;?>">
    <input type="hidden" name="cancel_return" value="<?php echo $cancel_return;?>">
    <input type="hidden" name="notify_url" value="<?php echo $notify_url;?>">
    <input type="hidden" name="custom" value="<?php echo $custom.",".$custom2;?>">
    <input type="hidden" name="business" value="<?php echo $business_id;?>">
    <input type="hidden" name="item_name" value="<?php echo $item_name;?>">
    <input type="hidden" name="item_number" value="1">
    <input type="hidden" name="no_note" value="1">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="a3" value="<?php echo $plan_amount;?>">  
    <input type="hidden" name="p3" value="1">  
    <input type="hidden" name="t3" value="M">   
    <input type="hidden" name="src" value="1">
    <input type="hidden" name="sra" value="1">
    <input type="hidden" name="srt" value="12">
    <input type="hidden" name="first_name" value="<?php echo $txtname;?>">
    <input type="hidden" name="lc" value="<?php echo $merchant_country;?>">
    <input type="hidden" name="email" value="<?php echo $txtemail;?>">
</form>

步骤2创建IPN控制器.详细了解审查https://developer.paypal.com/docs/classic/ipn/gs_IPN/

$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) { $_POST[$key] = mysql_real_escape_string($value); }         

foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}

$header = ''; 
$header .= "POST /cgi-bin/webscr HTTP/1.0rn";
$header .= "Content-Type: application/x-www-form-urlencodedrn";
$header .= "Content-Length: " . strlen($req) . "rnrn";
$fp = fsockopen('www.sandbox.paypal.com',80,$errno,$errstr,30);

// assign posted variables to local variables

$content['payment_status']      = $this->input->post('payment_status');
$content['payment_amount']      = $this->input->post('mc_gross');
$content['payment_currency']    = $this->input->post('mc_currency');
$content['txn_id']              = $this->input->post('txn_id');
$content['receiver_email']      = $this->input->post('receiver_email');
$content['payer_email']         = $this->input->post('payer_email');    
$custom                         = explode(",",$this->input->post('custom'));
$content['payment_id']          = $custom[0];
$content['type']                = $custom[1];
$content['txn_type']            = $this->input->post('txn_type');        
$content['paydate']             = date('Y-m-d H:i:s');


if (!$fp)
{
    // HTTP ERROR
}
else
{

    fputs ($fp,$header . $req);
    if (!feof($fp))
    {
        $res = fgets ($fp,1024);

        if(strcasecmp($content['txn_type'],"subscr_payment") == 0)
        {
            //Action            
        }
        else if(strcasecmp($content['payment_status'],"Completed") == 0)
        {
            //Action            
        }
        else if(strcasecmp($content['txn_type'],"subscr_cancel") == 0)
        {
           //Action            
        }
    }
    fclose ($fp);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读