2010-02-11 28 views
2

我有兩種方式可供用戶檢查:paypal和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="[email protected]">  
    <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天安,現在我已經試過:

編輯::

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); 

} 

我怎麼能這樣做與PayPal案例02

回答

1
(直接到貝寶與提交表單。)

也許你可以接收表單提交給你自己的代碼,然後檢查它的價值。如果滿足第一個條件,則執行數據庫更新。如果它滿足第二個條件,則將用戶重定向到具有隱藏表單的頁面,該頁面將提交給貝寶。您可以使用數據庫中的數據或以前的表單輸入填充隱藏表單中的數據,並放置一個JavaScript代碼,以便在加載頁面時自動提交表單。

在我的代碼中,我使用Micah Carrick's Paypal IPN class將數據發送到paypal。該類有一個關於如何顯示隱藏表單的示例代碼,以及在JavaScript被禁用時提交按鈕。

+0

謝謝!可以給我個建議如何在情況下做02(查看我更新的帖子) – kn3l 2010-02-12 02:53:45

+0

好的。它的工作原理,感謝你的班級。 – kn3l 2010-02-12 04:24:27

+0

很高興聽到它的作品,順便說一句,這不是我的課,信用應該交給Micah;)這個類實際上只是包裝了您可以在Paypal開發人員的文檔中找到的關於PHP語言IPN的代碼示例。 Micah做得很好,把所有這些代碼放入一個可以輕鬆使用的類中。 – 2010-02-12 14:36:16