0

車屋と車の所有者が登録して売買取引を作成できる電子商取引サイトに関するプロジェクトがあります。支払いの処理方法はすでにわかっています (買い手 = 車の所有者、売り手 = 車屋)。しかし、トランザクション情報 (paypal からサーバーへ) を取得する方法がわからないので、データベースに保存できます (トランザクション 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 データを独自のデータに関連付けることができます。たとえば、ローカル レコード ID が PayPal に渡されるように、常に PayPal 要求に送り状パラメーターを含めます。このようにして、請求書パラメーターとしても IPN に戻ります。これを、作業中のプロジェクトの既存のテーブルとの関係として使用するだけで、さらにカスタマイズすることなく、すべての IPN データをそのレコードで使用できます。

約 10 分で稼働させることができます。

于 2013-01-10T17:32:27.613 に答える