0

我有一个关于电子商务网站的项目,在该网站上车店和车主可以注册并创建买卖交易。我已经弄清楚如何处理付款(买方=车主,卖方=车店)。但我不知道如何获取交易信息(从贝宝到我的服务器),所以我可以将它保存到我的数据库中。(例如交易 ID)。

这是我在车主购物车上的代码:

<div id="confrm-body">
<label> Summary of Service Requests:</label><br/>
<label>Services in your cart has been categorized by   the shops the offer them. Please pay each service request respectively.</label>
<br/><label>Check out:0/3</label>   <br/>
<?php get_sum_cart($_SESSION['cid']);?>
 </div>

以下是功能:

  <?php
function get_sum_cart($cid){
        $q_get_sum_cart="select distinct(tbl_cart.shop_id),shop_name from tbl_services,tbl_carshop,tbl_cart where tbl_cart.svc_id=tbl_services.svc_id
        and tbl_cart.shop_id=tbl_carshop.shop_id and tbl_cart.client_id='". $cid ."'";
        $get_sum_result=mysql_query($q_get_sum_cart);

        while($sum_row=mysql_fetch_array($get_sum_result)){
            $shop_id=$sum_row['shop_id'];
            $shop_name=$sum_row['shop_name'];   
            ?>
            <form action=<?php echo cart_url;?> method="post" > 
            <table class="tbl_summary">

                <tr>
                    <th colspan="6"><label class="h-lbl"><?php echo $shop_name?></label> <a id="<?php echo $shop_id?>" class="client-btn" href="#">Show/Hide</a></th>
                </tr>
                <div id="slide">
                <tbody class="tbl_summary_cont <?php echo $shop_id?>">
                <tr>
                    <th scope="col" class="sub-th" style="width:100px;"><label>Preview</label></th>
                    <th scope="col" class="sub-th" style="width:210px;"><label>Pacakage/Kit Name</label></th>
                    <th scope="col" class="sub-th" style="width:100px;"><label>Initial Charge</label></th>
                    <th scope="col" class="sub-th" style="width:100px;"><label>Tax</label></th>
                    <th scope="col" class="sub-th" style="width:110px;"><label>Payable</label></th>
                    <th scope="col" class="sub-th" style="width:150px;"><label>Date Added</label></th>

                <input type="hidden" name="business" value="<?php echo get_carshop_paypal($shop_id);?>">
                <input type="hidden" name="cmd" value="_cart">
                <input type="hidden" name="upload" value="1">
                <input type="hidden" name="rm" value="2">
                <input type="hidden" name="notify_url" value="https://localhost/test-ipn/">
                <input type="hidden" name="currency_code" value="<?php echo cart_currency;?>">
                <input type="hidden" name="lc" value="<?php echo cart_country;?>">
                <input type="hidden" name="return" value="<?php echo return_url;?>">

                </tr>

                <?php make_sum_tbl($shop_id,$cid);?>



                <tfoot>
                    <td colspan="6"><input type="submit" name="submit" class="submit" value=""> 

                    <div class="lbl_bill">

                        <?php $sub_total = sum_per_tbl($shop_id,$cid);?>
                        <label>Sub-total:<span>Php <?php echo number_format($sub_total,2);?></span></label>
                        <label>Discount:<span><?php echo $discount;?></span></label>
                        <label>Total:<span>Php <?php echo get_discount($sub_total);?></span></label>

                        </div>
                    </td>

                </tfoot>
                </tbody>
            </table>
            </form> 
            <?php   
            $o_t=$o_t + $sub_total;


        }
?>
                <label>Over-all Total of Payables:<span>Php <?php echo number_format($o_t,2);?></span></label>
<?php       

}

function make_sum_tbl($shop_id,$cid){
    $q_get_tbl="select cart_id,tbl_cart.svc_id,kit_name,material_fee,svc_fee,t_amnt,tax,shop_name,tbl_cart.date from tbl_services,tbl_carshop,tbl_cart where tbl_cart.svc_id=tbl_services.svc_id and tbl_cart.shop_id=tbl_carshop.shop_id
    and tbl_cart.client_id='".$cid."' and tbl_carshop.shop_id='".$shop_id."'";
    $get_tbl_result=mysql_query($q_get_tbl);
    $n=1;
    while($tbl_row=mysql_fetch_array($get_tbl_result)){
        ?>
            <tr class="<?php echo $class;?>">
            <td><label><img class="min-prev" src="<?php echo get_service_pic($tbl_row['svc_id']);?>"></label></td>
            <input type="hidden" name="item_number_<?php echo $n;?>" value="<?php echo $tbl_row['svc_id'];?>">
            <td><label><?php echo $tbl_row['kit_name'];?></label></td>
            <input type="hidden" name="item_name_<?php echo $n;?>" value="<?php echo $tbl_row['kit_name'];?>">
            <td><label><?php echo $tbl_row['material_fee']+$tbl_row['svc_fee'];?></label></td>
            <td><label><?php echo $tbl_row['tax'];?>%</label></td>  
            <td><label>Php<?php echo number_format($tbl_row['t_amnt'],2);?></label></td>
            <input type="hidden" name="amount_<?php echo $n;?>" value="<?php echo $tbl_row['t_amnt'];?>">
            <td><label><?php echo $tbl_row['date'];?></label></td>
            <td><label><?php echo $row['total'];?></label></td>
            </tr>
        <?php
        $n++;
    }
}
function sum_per_tbl($shop_id,$cid){
    $sum_q="select sum(t_amnt) as total from tbl_services,tbl_carshop,tbl_cart where tbl_cart.svc_id=tbl_services.svc_id and tbl_cart.shop_id=tbl_carshop.shop_id and tbl_cart.client_id='".$cid."' and tbl_carshop.shop_id='".$shop_id."'";
    $sum_result=mysql_query($sum_q);
    while($sum=mysql_fetch_array($sum_result)){
        $t=$sum['total'];
        }
        return $t;
    }


function get_discount($sub_total){
$disc=0;

$total=number_format($sub_total - ($sub_total * $disc),2);
return $total;
}   
?>

这是配置文件:

function get_carshop_paypal($shop_id){
$get_p_add= "select pay_pal from tbl_carshop_paypal where shop_id='".$shop_id."'";
$result=mysql_query($get_p_add);
while($row=mysql_fetch_array($result)){
    $shop_paypal=$row['pay_pal'];

}
return $shop_paypal;
}
define('base_url','http://'.$_SERVER['HTTP_HOST'].'/');
define('cart_currency','PHP');
define('cart_country','PH');
define('cart_url','https://www.sandbox.paypal.com/us/cgi-bin/webscr');
define('return_url',base_url.'/occs/accounts/client/index.php?p=con-transact&make='.$make.'&year='.$year.'&model='.$model);

这是我试图结合的(IPN_handler):

class Paypal_IPN
{

    private $_url;


    public function __construct($mode = 'live')
    {
        if ($mode == 'live')
        $this->_url = 'https://www.paypal.com/cgi-bin/webscr';

        else
        $this->_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
    }

    public function run()
    {
        $postFields = 'cmd=_notify-validate';



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

        }

        $ch = curl_init();

            curl_setopt_array($ch, array(
            CURLOPT_URL => $this->_url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => $postFields
        ));

        $result = curl_exec($ch);
        curl_close($ch);

        $fh = fopen('result.txt', 'w');
        fwrite($fh, $result . ' -- ' . $postFields);
        fclose($fh);

        echo $postFields;
    }
}?>

你们能告诉我如何做到这一点吗?

4

1 回答 1

0

您需要做的就是自定义该 IPN 库以包含您自己的数据库插入,然后确保在您的 PayPal 帐户配置文件中启用了 IPN。您还可以在按钮代码中使用 notify_url 来覆盖配置文件设置,但我喜欢将我的配置文件设置为默认 IPN 侦听器。

您可能对我的 PayPal IPN 的 PHP 模板感兴趣。它非常流行,虽然它可以重新开发为面向对象的类(我打算这样做),但它按原样工作得很好,并为您提供了一个有效的 IPN 解决方案,可将所有 IPN 记录在您的数据库中。

我几乎在所有项目中都使用它。只需安装 IPN 模板(下载中包含说明),然后您可以使用记录 ID 将 IPN 数据与您自己的数据相关联。例如,我总是在我的 PayPal 请求中包含 invoice 参数,以便将我的本地记录 ID 传递给 PayPal。这样,它也将作为发票参数返回 IPN。我只是将其用作与我正在工作的任何项目的现有表的关系,并且所有 IPN 数据都可用于该记录而无需任何进一步的定制。

您可以在大约 10 分钟内启动并运行它。

于 2013-01-10T17:32:27.613 回答