贝宝和Php?

时间:2010-02-11 10:19:02

标签: php

我有两种方法可以检查用户:

1.if user input (Amount field < 5(user credit):
   do update database the remain amount in my database table.
2.if user input(Amount field) > 5(user credit):
  Do paypal transaction with the submit form.



 <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="payPalForm">        
    <input type="hidden" name="item_number" value="01 - General Payment to FreelanceSwitch.com">
    <input name="item_name" type="hidden" id="item_name"  size="45" value="Posting job">    
    <input type="hidden" name="cmd" value="_xclick">    
    <input type="hidden" name="no_note" value="1">    
    <input type="hidden" name="business" value="seller_1265789181_biz@xxx.xxx.xx">    
    <input type="hidden" name="currency_code" value="USD">    
    <input type="hidden" name="return" value="http://freelanceswitch.com/payment-complete/">       
    Paying Page:<input name="amount" type="text" id="amount" size="5">   
    <input type="submit" name="Submit" value="Pay">            
    </form>

任何人都可以告诉我如何处理带有条件的贝宝提交表格。?

感谢。

谢谢@Donny Kurnia,现在我尝试过:

EDIT ::

function compare_user_credit($paying_price, $user_credit){

    $db = &JFactory::getDBO();
    $user =& JFactory::getUser();
    $user_id = $user->get('id');

    if ($paying_price <= $user_credit) {        
        $remain_credit = $user_credit - $paying_price;
        //DO UPDATE:enough credit
        update_user_credit_after_paying($remain_credit,$user_id);
        $action_after_paying = header("Location: index.php?xxxx=5");
     }
    # Case2 direct to paypal with the submit form.
    else if ($paying_price > $user_credit){
       //Need submit form to paypal.
       $action_after_paying = header("Location: index.php=xxxx&paypal=".$_POST["amount"]);
    }
    return $action_after_paying;
}
$output = '<form method="POST" > ';
     $output .='<h1>Credit:'.get_credit().'</h1>';
     $output .= ' Paying Page <input type="text" name="amount" size=3 max_length=5 />';
     $output .='<input type="submit" name="pay" value="pay" />' ;
     echo $output;

if(isset($_POST["pay"])){
    compare_user_credit($_POST["amount"], $user_credit);

}

在案例02中,我可以使用Paypal吗。(通过提交表单直接发送给PayPal。)

1 个答案:

答案 0 :(得分:1)

也许您可以收到表单提交到您自己的代码,然后检查它的价值。如果满足第一个条件,请执行数据库更新。如果它满足第二个条件,则将用户重定向到具有将提交给paypal的隐藏表单的页面。您可以使用数据库或以前的表单输入中的数据填充此隐藏表单中的数据,并放置一个javascript代码,以便在加载页面时自动提交表单。

在我的代码中,我使用Micah Carrick's Paypal IPN class将数据发送到paypal。该类有一个关于如何显示隐藏表单的示例代码,如果禁用了javascript,则会提交一个提交按钮。